mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-30 11:34:43 +01:00
Secure mode is available.
This commit is contained in:
parent
31a7c2be3a
commit
a288c70c59
@ -174,6 +174,7 @@ dependencies {
|
|||||||
implementation 'com.github.FunkyMuse:Crashy:1.1.0'
|
implementation 'com.github.FunkyMuse:Crashy:1.1.0'
|
||||||
|
|
||||||
//implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
|
//implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
|
||||||
|
//annotationProcessor "androidx.lifecycle:compiler:2.2.0"
|
||||||
|
|
||||||
implementation 'androidx.palette:palette:1.0.0'
|
implementation 'androidx.palette:palette:1.0.0'
|
||||||
|
|
||||||
|
@ -284,4 +284,6 @@ public interface AppComponent {
|
|||||||
void inject(TrendingActivity trendingActivity);
|
void inject(TrendingActivity trendingActivity);
|
||||||
|
|
||||||
void inject(WikiActivity wikiActivity);
|
void inject(WikiActivity wikiActivity);
|
||||||
|
|
||||||
|
void inject(Infinity infinity);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -15,15 +18,26 @@ import com.livefront.bridge.Bridge;
|
|||||||
import com.livefront.bridge.SavedStateHandler;
|
import com.livefront.bridge.SavedStateHandler;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
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.NetworkWifiStatusReceiver;
|
||||||
import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver;
|
import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver;
|
||||||
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
|
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||||
|
|
||||||
public class Infinity extends Application implements LifecycleObserver {
|
public class Infinity extends Application implements LifecycleObserver {
|
||||||
private AppComponent mAppComponent;
|
private AppComponent mAppComponent;
|
||||||
private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver;
|
private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver;
|
||||||
|
private boolean lock = false;
|
||||||
|
private boolean isSecureMode;
|
||||||
|
@Inject
|
||||||
|
@Named("default")
|
||||||
|
SharedPreferences mSharedPreferences;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -33,12 +47,16 @@ public class Infinity extends Application implements LifecycleObserver {
|
|||||||
.appModule(new AppModule(this))
|
.appModule(new AppModule(this))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
//ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
mAppComponent.inject(this);
|
||||||
|
|
||||||
/*registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
isSecureMode = mSharedPreferences.getBoolean(SharedPreferencesUtils.SECURE_MODE, false);
|
||||||
|
|
||||||
|
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
|
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
|
@Override
|
||||||
@ -48,7 +66,11 @@ public class Infinity extends Application implements LifecycleObserver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResumed(@NonNull Activity activity) {
|
public void onActivityResumed(@NonNull Activity activity) {
|
||||||
|
/*if (lock && !(activity instanceof LockScreenActivity)) {
|
||||||
|
lock = false;
|
||||||
|
Intent intent = new Intent(activity, LockScreenActivity.class);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,7 +92,9 @@ public class Infinity extends Application implements LifecycleObserver {
|
|||||||
public void onActivityDestroyed(@NonNull Activity activity) {
|
public void onActivityDestroyed(@NonNull Activity activity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});*/
|
});
|
||||||
|
|
||||||
|
//ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
||||||
|
|
||||||
Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
|
Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
|
||||||
@Override
|
@Override
|
||||||
@ -86,6 +110,8 @@ public class Infinity extends Application implements LifecycleObserver {
|
|||||||
|
|
||||||
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
|
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
|
||||||
|
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
|
|
||||||
mNetworkWifiStatusReceiver =
|
mNetworkWifiStatusReceiver =
|
||||||
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext()))));
|
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext()))));
|
||||||
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
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));
|
registerReceiver(new WallpaperChangeReceiver(), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @OnLifecycleEvent(Lifecycle.Event.ON_START)
|
/*@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
// public void appInForeground(){
|
public void appInForeground() {
|
||||||
// Toast.makeText(this, "Foreground", Toast.LENGTH_SHORT).show();
|
lock = true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
// public void appInBackground(){
|
public void appInBackground(){
|
||||||
// Toast.makeText(this, "Background", Toast.LENGTH_SHORT).show();
|
|
||||||
// }
|
}*/
|
||||||
|
|
||||||
public AppComponent getAppComponent() {
|
public AppComponent getAppComponent() {
|
||||||
return mAppComponent;
|
return mAppComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onToggleSecureModeEvent(ToggleSecureModeEvent secureModeEvent) {
|
||||||
|
isSecureMode = secureModeEvent.isSecureMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package ml.docilealligator.infinityforreddit.activities;
|
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.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
@ -17,9 +20,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
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 {
|
public class LockScreenActivity extends BaseActivity {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -79,7 +79,5 @@ public class LockScreenActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() { }
|
||||||
moveTaskToBack(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.events;
|
||||||
|
|
||||||
|
public class ToggleSecureModeEvent {
|
||||||
|
public boolean isSecureMode;
|
||||||
|
|
||||||
|
public ToggleSecureModeEvent(boolean isSecureMode) {
|
||||||
|
this.isSecureMode = isSecureMode;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package ml.docilealligator.infinityforreddit.settings;
|
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.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -18,14 +21,12 @@ import java.util.concurrent.Executor;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
|
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
|
||||||
|
import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
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 {
|
public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
private AppCompatActivity activity;
|
private AppCompatActivity activity;
|
||||||
@ -40,6 +41,7 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
((Infinity) activity.getApplication()).getAppComponent().inject(this);
|
((Infinity) activity.getApplication()).getAppComponent().inject(this);
|
||||||
|
|
||||||
SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER);
|
SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER);
|
||||||
|
SwitchPreference secureModeSwitch = findPreference(SharedPreferencesUtils.SECURE_MODE);
|
||||||
|
|
||||||
if (requireAuthToAccountSectionSwitch != null) {
|
if (requireAuthToAccountSectionSwitch != null) {
|
||||||
requireAuthToAccountSectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
requireAuthToAccountSectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@ -47,6 +49,13 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (secureModeSwitch != null) {
|
||||||
|
secureModeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
EventBus.getDefault().post(new ToggleSecureModeEvent((Boolean) newValue));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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 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 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 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 DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
|
||||||
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
|
||||||
|
@ -593,6 +593,8 @@
|
|||||||
<string name="settings_separate_post_and_comments_in_portrait_mode">Separate Post And Comments in Portrait Mode</string>
|
<string name="settings_separate_post_and_comments_in_portrait_mode">Separate Post And Comments in Portrait Mode</string>
|
||||||
<string name="settings_separate_post_and_comments_in_landscape_mode">Separate Post And Comments in Landscape Mode</string>
|
<string name="settings_separate_post_and_comments_in_landscape_mode">Separate Post And Comments in Landscape Mode</string>
|
||||||
<string name="settings_use_bottom_toolbar_in_media_viewer_title">Use Bottom Toolbar in Media Viewer</string>
|
<string name="settings_use_bottom_toolbar_in_media_viewer_title">Use Bottom Toolbar in Media Viewer</string>
|
||||||
|
<string name="settings_secure_mode_title">Secure Mode</string>
|
||||||
|
<string name="settings_secure_mode_summary">Screenshot and video recording are not allowed. No preview in recent app screen.</string>
|
||||||
|
|
||||||
<string name="no_link_available">Cannot get the link</string>
|
<string name="no_link_available">Cannot get the link</string>
|
||||||
|
|
||||||
|
@ -5,4 +5,10 @@
|
|||||||
app:key="require_auth_to_account_section"
|
app:key="require_auth_to_account_section"
|
||||||
app:title="@string/settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title" />
|
app:title="@string/settings_require_authentication_to_go_to_account_section_in_navigation_drawer_title" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
app:defaultValue="false"
|
||||||
|
app:key="secure_mode"
|
||||||
|
app:title="@string/settings_secure_mode_title"
|
||||||
|
app:summary="@string/settings_secure_mode_summary" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user