Skip to content

Commit

Permalink
Fix Data sync/reset
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielcoderX committed Aug 16, 2024
1 parent 8c0d002 commit 8b8beb6
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 234 deletions.
19 changes: 3 additions & 16 deletions app/src/main/java/org/bepass/oblivion/base/ApplicationLoader.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.bepass.oblivion.base;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;

import androidx.appcompat.app.AppCompatDelegate;

import org.bepass.oblivion.utils.FileManager;
import org.bepass.oblivion.utils.ThemeHelper;

/**
Expand All @@ -17,10 +17,6 @@ public class ApplicationLoader extends Application {
// Tag for logging purposes
private static final String TAG = "ApplicationLoader";

// Context reference
@SuppressLint("StaticFieldLeak")
private static Context context;

/**
* This method is called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created.
*
Expand All @@ -29,17 +25,8 @@ public class ApplicationLoader extends Application {
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
FileManager.initialize(this); // Initialize FileManager with Application context
ThemeHelper.getInstance().init();
ThemeHelper.getInstance().applyTheme();
}

/**
* Returns the application context.
*
* @return The application context.
*/
public static Context getAppCtx() {
return context;
}
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/org/bepass/oblivion/base/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.bepass.oblivion.base;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import androidx.activity.result.ActivityResult;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import org.bepass.oblivion.utils.ColorUtils;
import org.bepass.oblivion.utils.FileManager;
import org.bepass.oblivion.utils.SystemUtils;

/**
Expand Down Expand Up @@ -42,6 +41,7 @@ public abstract class BaseActivity<B extends ViewDataBinding> extends AppCompatA
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FileManager.initialize(this); // Initialize FileManager with Activity context
// Inflates the layout and initializes the binding object
binding = DataBindingUtil.setContentView(this, getLayoutResourceId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand All @@ -50,4 +50,4 @@ this, getStatusBarColor(), ColorUtils.isColorDark(getStatusBarColor())
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bepass.oblivion.enums.ConnectionState;
import org.bepass.oblivion.service.OblivionVpnService;
import org.bepass.oblivion.utils.ColorUtils;
import org.bepass.oblivion.utils.FileManager;
import org.bepass.oblivion.utils.SystemUtils;

/**
Expand All @@ -39,6 +40,7 @@ public abstract class StateAwareBaseActivity<B extends ViewDataBinding> extends
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FileManager.initialize(this); // Initialize FileManager with Activity context
binding = DataBindingUtil.setContentView(this, getLayoutResourceId());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
SystemUtils.setStatusBarColor(
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/java/org/bepass/oblivion/component/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;

import org.bepass.oblivion.R;
import org.bepass.oblivion.utils.LocalController;

import java.io.File;

Expand Down Expand Up @@ -54,13 +54,6 @@ private void setupAttrs(@NonNull Context context, @Nullable AttributeSet attrs,
}
}

public void setColor(int color) {
if (color != 0) {
setColorFilter(LocalController.getColor(color), PorterDuff.Mode.SRC_ATOP);
}
invalidate();
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ public void run() {
private static PowerManager.WakeLock wLock;
private static ConnectionState lastKnownState = ConnectionState.DISCONNECTED;
public static synchronized void startVpnService(Context context) {
FileManager.initialize(context);
Intent intent = new Intent(context.getApplicationContext(), OblivionVpnService.class);
Intent intent = new Intent(context, OblivionVpnService.class);
intent.setAction(OblivionVpnService.FLAG_VPN_START);
context.startService(intent);
}

public static synchronized void stopVpnService(Context context) {
Intent intent = new Intent(context.getApplicationContext(), OblivionVpnService.class);
Intent intent = new Intent(context, OblivionVpnService.class);
intent.setAction(OblivionVpnService.FLAG_VPN_STOP);
context.startService(intent);

Expand Down Expand Up @@ -502,7 +501,6 @@ private void setLastKnownState(ConnectionState lastKnownState) {
}

private String getNotificationText() {
FileManager.initialize(this);
boolean usePsiphon = FileManager.getBoolean("USERSETTING_psiphon");
boolean useWarp = FileManager.getBoolean("USERSETTING_gool");
boolean proxyMode = FileManager.getBoolean("USERSETTING_proxymode");
Expand All @@ -522,7 +520,6 @@ private String getNotificationText() {
}

private void createNotification() {
FileManager.initialize(this);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
NotificationChannelCompat notificationChannel = new NotificationChannelCompat.Builder(
"vpn_service", NotificationManagerCompat.IMPORTANCE_DEFAULT)
Expand Down Expand Up @@ -559,7 +556,6 @@ public void removeConnectionStateObserver(String key) {
}

private void configure() throws Exception {
FileManager.initialize(this);
boolean proxyModeEnabled = FileManager.getBoolean("USERSETTING_proxymode");
if (proxyModeEnabled) {
// Proxy mode logic
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/org/bepass/oblivion/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ protected int getStatusBarColor() {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Initialize the LocaleHandler and set the locale
localeHandler = new LocaleHandler(this);

FileManager.initialize(this);
super.onCreate(savedInstanceState);
// Update background based on current theme
ThemeHelper.getInstance().updateActivityBackground(binding.getRoot());
FileManager.cleanOrMigrateSettings(binding.getRoot().getContext());
FileManager.cleanOrMigrateSettings(this); // Pass this context
setupUI();
setupVPNConnection();
requestNotificationPermission();
Expand All @@ -83,21 +82,22 @@ private void setupVPNConnection() {
}

private void handleVpnSwitch(boolean enableVpn) {
FileManager.initialize(this);
if (enableVpn) {
if (lastKnownConnectionState.isDisconnected()) {
Intent vpnIntent = OblivionVpnService.prepare(this);
if (vpnIntent != null) {
vpnPermissionLauncher.launch(vpnIntent);
} else {
startVpnService(binding.getRoot().getContext());
startVpnService(this); // Use this context
}
NetworkUtils.monitorInternetConnection(lastKnownConnectionState, this);
} else if (lastKnownConnectionState.isConnecting()) {
stopVpnService(binding.getRoot().getContext());
stopVpnService(this); // Use this context
}
} else {
if (!lastKnownConnectionState.isDisconnected()) {
stopVpnService(this);
stopVpnService(this); // Use this context
}
}
}
Expand Down
40 changes: 3 additions & 37 deletions app/src/main/java/org/bepass/oblivion/ui/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void handleOnBackPressed() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String name = parent.getItemAtPosition(position).toString();
Triple<String, String, Integer> codeAndName = CountryUtils.getCountryCode(ApplicationLoader.getAppCtx(), name);
Triple<String, String, Integer> codeAndName = CountryUtils.getCountryCode(getApplicationContext(), name);
FileManager.set("USERSETTING_country", codeAndName.getFirst());
FileManager.set("USERSETTING_country_index", position); // Save the selected country index
}
Expand Down Expand Up @@ -170,46 +170,12 @@ public void onNothingSelected(AdapterView<?> parent) {
}

private void resetAppData() {
clearSharedPreferences();

try {
deleteDir(getCacheDir());
} catch (Exception e) {
e.printStackTrace();
}

try {
deleteDir(getFilesDir());
} catch (Exception e) {
e.printStackTrace();
}

FileManager.resetToDefault();
FileManager.cleanOrMigrateSettings(this);
Intent intent = new Intent(this, MainActivity.class);
finish();
startActivity(intent);
}

private void clearSharedPreferences() {
FileManager.resetToDefault();
}

private boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < Objects.requireNonNull(children).length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
return dir.delete();
} else if (dir != null && dir.isFile()) {
return dir.delete();
} else {
return false;
}
}

private void settingBasicValuesFromSPF() {
binding.endpoint.setText(FileManager.getString("USERSETTING_endpoint"));
binding.port.setText(FileManager.getString("USERSETTING_port"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import android.view.View;

import org.bepass.oblivion.R;
import org.bepass.oblivion.base.ApplicationLoader;
import org.bepass.oblivion.base.BaseActivity;
import org.bepass.oblivion.databinding.ActivitySplashScreenBinding;
import org.bepass.oblivion.utils.FileManager;
import org.bepass.oblivion.utils.LocaleHandler;
import org.bepass.oblivion.utils.ThemeHelper;

Expand Down
Loading

0 comments on commit 8b8beb6

Please sign in to comment.