diff options
Diffstat (limited to 'app/src/main/java/ml')
6 files changed, 74 insertions, 24 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 47c27b13..2fc08bd9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -284,4 +284,6 @@ public interface AppComponent { void inject(TrendingActivity trendingActivity); void inject(WikiActivity wikiActivity); + + void inject(Infinity infinity); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java index 1ea45d67..fafedeac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java @@ -1,10 +1,13 @@ package ml.docilealligator.infinityforreddit; +import android.app.Activity; import android.app.Application; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.os.Bundle; +import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -15,15 +18,26 @@ import com.livefront.bridge.Bridge; import com.livefront.bridge.SavedStateHandler; import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + +import javax.inject.Inject; +import javax.inject.Named; import ml.docilealligator.infinityforreddit.broadcastreceivers.NetworkWifiStatusReceiver; import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver; import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; +import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; public class Infinity extends Application implements LifecycleObserver { private AppComponent mAppComponent; private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver; + private boolean lock = false; + private boolean isSecureMode; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; @Override public void onCreate() { @@ -33,12 +47,16 @@ public class Infinity extends Application implements LifecycleObserver { .appModule(new AppModule(this)) .build(); - //ProcessLifecycleOwner.get().getLifecycle().addObserver(this); + mAppComponent.inject(this); - /*registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { + isSecureMode = mSharedPreferences.getBoolean(SharedPreferencesUtils.SECURE_MODE, false); + + registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) { - activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + if (isSecureMode) { + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } } @Override @@ -48,7 +66,11 @@ public class Infinity extends Application implements LifecycleObserver { @Override public void onActivityResumed(@NonNull Activity activity) { - + /*if (lock && !(activity instanceof LockScreenActivity)) { + lock = false; + Intent intent = new Intent(activity, LockScreenActivity.class); + activity.startActivity(intent); + }*/ } @Override @@ -70,7 +92,9 @@ public class Infinity extends Application implements LifecycleObserver { public void onActivityDestroyed(@NonNull Activity activity) { } - });*/ + }); + + //ProcessLifecycleOwner.get().getLifecycle().addObserver(this); Bridge.initialize(getApplicationContext(), new SavedStateHandler() { @Override @@ -86,6 +110,8 @@ public class Infinity extends Application implements LifecycleObserver { EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus(); + EventBus.getDefault().register(this); + mNetworkWifiStatusReceiver = new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext())))); registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); @@ -93,17 +119,22 @@ public class Infinity extends Application implements LifecycleObserver { registerReceiver(new WallpaperChangeReceiver(), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED)); } -// @OnLifecycleEvent(Lifecycle.Event.ON_START) -// public void appInForeground(){ -// Toast.makeText(this, "Foreground", Toast.LENGTH_SHORT).show(); -// } -// -// @OnLifecycleEvent(Lifecycle.Event.ON_STOP) -// public void appInBackground(){ -// Toast.makeText(this, "Background", Toast.LENGTH_SHORT).show(); -// } + /*@OnLifecycleEvent(Lifecycle.Event.ON_START) + public void appInForeground() { + lock = true; + } + + @OnLifecycleEvent(Lifecycle.Event.ON_STOP) + public void appInBackground(){ + + }*/ public AppComponent getAppComponent() { return mAppComponent; } + + @Subscribe + public void onToggleSecureModeEvent(ToggleSecureModeEvent secureModeEvent) { + isSecureMode = secureModeEvent.isSecureMode; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java index 8dc39275..3ba73440 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java @@ -1,5 +1,8 @@ package ml.docilealligator.infinityforreddit.activities; +import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; +import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; + import android.content.SharedPreferences; import android.os.Bundle; @@ -17,9 +20,6 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; -import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; - public class LockScreenActivity extends BaseActivity { @Inject @@ -79,7 +79,5 @@ public class LockScreenActivity extends BaseActivity { } @Override - public void onBackPressed() { - moveTaskToBack(true); - } + public void onBackPressed() { } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java new file mode 100644 index 00000000..a7c27eb3 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.events; + +public class ToggleSecureModeEvent { + public boolean isSecureMode; + + public ToggleSecureModeEvent(boolean isSecureMode) { + this.isSecureMode = isSecureMode; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java index cb6917c8..c4dd2b16 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java @@ -1,5 +1,8 @@ package ml.docilealligator.infinityforreddit.settings; +import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; +import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; + import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -18,14 +21,12 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; +import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; -import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; - public class SecurityPreferenceFragment extends PreferenceFragmentCompat { private AppCompatActivity activity; @@ -40,6 +41,7 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER); + SwitchPreference secureModeSwitch = findPreference(SharedPreferencesUtils.SECURE_MODE); if (requireAuthToAccountSectionSwitch != null) { requireAuthToAccountSectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -47,6 +49,13 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if (secureModeSwitch != null) { + secureModeSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ToggleSecureModeEvent((Boolean) newValue)); + return true; + }); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 47b1f109..f3247d99 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -186,6 +186,7 @@ public class SharedPreferencesUtils { public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed"; public static final String DEFAULT_LINK_POST_LAYOUT_KEY = "default_link_post_layout"; public static final String USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER = "use_bottom_toolbar_in_media_viewer"; + public static final String SECURE_MODE = "secure_mode"; public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; |