|
@@ -22,8 +22,11 @@ package com.nextcloud.talk.controllers;
|
|
|
|
|
|
import android.animation.Animator;
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
+import android.app.KeyguardManager;
|
|
|
|
+import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
|
+import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.security.KeyChain;
|
|
import android.security.KeyChain;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
@@ -31,10 +34,17 @@ import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
|
+import android.view.WindowManager;
|
|
import android.widget.Checkable;
|
|
import android.widget.Checkable;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
-
|
|
|
|
|
|
+import androidx.annotation.NonNull;
|
|
|
|
+import androidx.annotation.Nullable;
|
|
|
|
+import androidx.core.view.ViewCompat;
|
|
|
|
+import androidx.work.OneTimeWorkRequest;
|
|
|
|
+import androidx.work.WorkManager;
|
|
|
|
+import autodagger.AutoInjector;
|
|
|
|
+import butterknife.BindView;
|
|
import com.bluelinelabs.conductor.RouterTransaction;
|
|
import com.bluelinelabs.conductor.RouterTransaction;
|
|
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
|
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
|
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
|
|
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
|
|
@@ -53,43 +63,25 @@ import com.nextcloud.talk.models.RingtoneSettings;
|
|
import com.nextcloud.talk.models.database.UserEntity;
|
|
import com.nextcloud.talk.models.database.UserEntity;
|
|
import com.nextcloud.talk.utils.ApiUtils;
|
|
import com.nextcloud.talk.utils.ApiUtils;
|
|
import com.nextcloud.talk.utils.DoNotDisturbUtils;
|
|
import com.nextcloud.talk.utils.DoNotDisturbUtils;
|
|
|
|
+import com.nextcloud.talk.utils.SecurityUtils;
|
|
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
|
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
|
import com.nextcloud.talk.utils.database.user.UserUtils;
|
|
import com.nextcloud.talk.utils.database.user.UserUtils;
|
|
import com.nextcloud.talk.utils.glide.GlideApp;
|
|
import com.nextcloud.talk.utils.glide.GlideApp;
|
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
|
import com.nextcloud.talk.utils.preferences.MagicUserInputModule;
|
|
import com.nextcloud.talk.utils.preferences.MagicUserInputModule;
|
|
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
|
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
|
|
-import com.yarolegovich.mp.MaterialChoicePreference;
|
|
|
|
-import com.yarolegovich.mp.MaterialEditTextPreference;
|
|
|
|
-import com.yarolegovich.mp.MaterialPreferenceCategory;
|
|
|
|
-import com.yarolegovich.mp.MaterialPreferenceScreen;
|
|
|
|
-import com.yarolegovich.mp.MaterialStandardPreference;
|
|
|
|
-import com.yarolegovich.mp.MaterialSwitchPreference;
|
|
|
|
-
|
|
|
|
|
|
+import com.yarolegovich.mp.*;
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
+import io.reactivex.disposables.Disposable;
|
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
|
|
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
|
|
-
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
|
|
+import javax.inject.Inject;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URISyntaxException;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-
|
|
|
|
-import javax.inject.Inject;
|
|
|
|
-
|
|
|
|
-import androidx.annotation.NonNull;
|
|
|
|
-import androidx.annotation.Nullable;
|
|
|
|
-import androidx.core.view.ViewCompat;
|
|
|
|
-import androidx.work.OneTimeWorkRequest;
|
|
|
|
-import androidx.work.WorkManager;
|
|
|
|
-import autodagger.AutoInjector;
|
|
|
|
-import butterknife.BindView;
|
|
|
|
-import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
-import io.reactivex.disposables.Disposable;
|
|
|
|
-import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@AutoInjector(NextcloudTalkApplication.class)
|
|
@AutoInjector(NextcloudTalkApplication.class)
|
|
public class SettingsController extends BaseController {
|
|
public class SettingsController extends BaseController {
|
|
@@ -153,6 +145,21 @@ public class SettingsController extends BaseController {
|
|
@BindView(R.id.settings_always_vibrate)
|
|
@BindView(R.id.settings_always_vibrate)
|
|
MaterialSwitchPreference shouldVibrateSwitchPreference;
|
|
MaterialSwitchPreference shouldVibrateSwitchPreference;
|
|
|
|
|
|
|
|
+ @BindView(R.id.settings_incognito_keyboard)
|
|
|
|
+ MaterialSwitchPreference incognitoKeyboardSwitchPreference;
|
|
|
|
+
|
|
|
|
+ @BindView(R.id.settings_screen_security)
|
|
|
|
+ MaterialSwitchPreference screenSecuritySwitchPreference;
|
|
|
|
+
|
|
|
|
+ @BindView(R.id.settings_link_previews)
|
|
|
|
+ MaterialSwitchPreference linkPreviewsSwitchPreference;
|
|
|
|
+
|
|
|
|
+ @BindView(R.id.settings_screen_lock)
|
|
|
|
+ MaterialSwitchPreference screenLockSwitchPreference;
|
|
|
|
+
|
|
|
|
+ @BindView(R.id.settings_screen_lock_timeout)
|
|
|
|
+ MaterialChoicePreference screenLockTimeoutChoicePreference;
|
|
|
|
+
|
|
@BindView(R.id.message_text)
|
|
@BindView(R.id.message_text)
|
|
TextView messageText;
|
|
TextView messageText;
|
|
|
|
|
|
@@ -168,11 +175,17 @@ public class SettingsController extends BaseController {
|
|
@Inject
|
|
@Inject
|
|
UserUtils userUtils;
|
|
UserUtils userUtils;
|
|
|
|
|
|
|
|
+ @Inject
|
|
|
|
+ Context context;
|
|
|
|
+
|
|
private UserEntity currentUser;
|
|
private UserEntity currentUser;
|
|
private String credentials;
|
|
private String credentials;
|
|
|
|
|
|
private OnPreferenceValueChangedListener<String> proxyTypeChangeListener;
|
|
private OnPreferenceValueChangedListener<String> proxyTypeChangeListener;
|
|
private OnPreferenceValueChangedListener<Boolean> proxyCredentialsChangeListener;
|
|
private OnPreferenceValueChangedListener<Boolean> proxyCredentialsChangeListener;
|
|
|
|
+ private OnPreferenceValueChangedListener<Boolean> screenSecurityChangeListener;
|
|
|
|
+ private OnPreferenceValueChangedListener<Boolean> screenLockChangeListener;
|
|
|
|
+ private OnPreferenceValueChangedListener<String> screenLockTimeoutChangeListener;
|
|
|
|
|
|
private Disposable profileQueryDisposable;
|
|
private Disposable profileQueryDisposable;
|
|
private Disposable dbQueryDisposable;
|
|
private Disposable dbQueryDisposable;
|
|
@@ -198,8 +211,10 @@ public class SettingsController extends BaseController {
|
|
getCurrentUser();
|
|
getCurrentUser();
|
|
|
|
|
|
appPreferences.registerProxyTypeListener(proxyTypeChangeListener = new ProxyTypeChangeListener());
|
|
appPreferences.registerProxyTypeListener(proxyTypeChangeListener = new ProxyTypeChangeListener());
|
|
- appPreferences.registerProxyCredentialsListener(proxyCredentialsChangeListener = new
|
|
|
|
- ProxyCredentialsChangeListener());
|
|
|
|
|
|
+ appPreferences.registerProxyCredentialsListener(proxyCredentialsChangeListener = new ProxyCredentialsChangeListener());
|
|
|
|
+ appPreferences.registerScreenSecurityListener(screenSecurityChangeListener = new ScreenSecurityChangeListener());
|
|
|
|
+ appPreferences.registerScreenLockListener(screenLockChangeListener = new ScreenLockListener());
|
|
|
|
+ appPreferences.registerScreenLockTimeoutListener(screenLockTimeoutChangeListener = new ScreenLockTimeoutListener());
|
|
|
|
|
|
List<String> listWithIntFields = new ArrayList<>();
|
|
List<String> listWithIntFields = new ArrayList<>();
|
|
listWithIntFields.add("proxy_port");
|
|
listWithIntFields.add("proxy_port");
|
|
@@ -223,6 +238,20 @@ public class SettingsController extends BaseController {
|
|
shouldVibrateSwitchPreference.setVisibility(View.GONE);
|
|
shouldVibrateSwitchPreference.setVisibility(View.GONE);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
|
|
+ incognitoKeyboardSwitchPreference.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
|
|
+ screenLockSwitchPreference.setVisibility(View.GONE);
|
|
|
|
+ screenLockTimeoutChoicePreference.setVisibility(View.GONE);
|
|
|
|
+ } else {
|
|
|
|
+ screenLockSwitchPreference.setSummary(String.format(Locale.getDefault(),
|
|
|
|
+ getResources().getString(R.string.nc_settings_screen_lock_desc),
|
|
|
|
+ getResources().getString(R.string.nc_app_name)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
if (!TextUtils.isEmpty(getResources().getString(R.string.nc_privacy_url))) {
|
|
if (!TextUtils.isEmpty(getResources().getString(R.string.nc_privacy_url))) {
|
|
privacyButton.addPreferenceClickListener(view12 -> {
|
|
privacyButton.addPreferenceClickListener(view12 -> {
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().
|
|
@@ -327,7 +356,46 @@ public class SettingsController extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
if (shouldVibrateSwitchPreference.getVisibility() == View.VISIBLE) {
|
|
if (shouldVibrateSwitchPreference.getVisibility() == View.VISIBLE) {
|
|
- ((Checkable)shouldVibrateSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getShouldVibrateSetting());
|
|
|
|
|
|
+ ((Checkable) shouldVibrateSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getShouldVibrateSetting());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ((Checkable) screenSecuritySwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenSecured());
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
+ ((Checkable) incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
+ ((Checkable) incognitoKeyboardSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsKeyboardIncognito());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ((Checkable) linkPreviewsSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getAreLinkPreviewsAllowed());
|
|
|
|
+
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
+ KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
|
|
|
+
|
|
|
|
+ if (keyguardManager.isKeyguardSecure()) {
|
|
|
|
+ screenLockSwitchPreference.setEnabled(true);
|
|
|
|
+ screenLockTimeoutChoicePreference.setEnabled(true);
|
|
|
|
+ ((Checkable) screenLockSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(appPreferences.getIsScreenLocked());
|
|
|
|
+
|
|
|
|
+ screenLockTimeoutChoicePreference.setEnabled(appPreferences.getIsScreenLocked());
|
|
|
|
+
|
|
|
|
+ if (appPreferences.getIsScreenLocked()) {
|
|
|
|
+ screenLockTimeoutChoicePreference.setAlpha(1.0f);
|
|
|
|
+ } else {
|
|
|
|
+ screenLockTimeoutChoicePreference.setAlpha(0.38f);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ screenLockSwitchPreference.setAlpha(1.0f);
|
|
|
|
+ } else {
|
|
|
|
+ screenLockSwitchPreference.setEnabled(false);
|
|
|
|
+ screenLockTimeoutChoicePreference.setEnabled(false);
|
|
|
|
+ appPreferences.removeScreenLock();
|
|
|
|
+ appPreferences.removeScreenLockTimeout();
|
|
|
|
+ ((Checkable) screenLockSwitchPreference.findViewById(R.id.mp_checkable)).setChecked(false);
|
|
|
|
+ screenLockSwitchPreference.setAlpha(0.38f);
|
|
|
|
+ screenLockTimeoutChoicePreference.setAlpha(0.38f);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
String ringtoneName = "";
|
|
String ringtoneName = "";
|
|
@@ -532,6 +600,9 @@ public class SettingsController extends BaseController {
|
|
if (appPreferences != null) {
|
|
if (appPreferences != null) {
|
|
appPreferences.unregisterProxyTypeListener(proxyTypeChangeListener);
|
|
appPreferences.unregisterProxyTypeListener(proxyTypeChangeListener);
|
|
appPreferences.unregisterProxyCredentialsListener(proxyCredentialsChangeListener);
|
|
appPreferences.unregisterProxyCredentialsListener(proxyCredentialsChangeListener);
|
|
|
|
+ appPreferences.unregisterScreenSecurityListener(screenSecurityChangeListener);
|
|
|
|
+ appPreferences.unregisterScreenLockListener(screenLockChangeListener);
|
|
|
|
+ appPreferences.unregisterScreenLockTimeoutListener(screenLockTimeoutChangeListener);
|
|
}
|
|
}
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
}
|
|
}
|
|
@@ -594,6 +665,46 @@ public class SettingsController extends BaseController {
|
|
return getResources().getString(R.string.nc_app_name);
|
|
return getResources().getString(R.string.nc_app_name);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private class ScreenLockTimeoutListener implements OnPreferenceValueChangedListener<String> {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onChanged(String newValue) {
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
+ SecurityUtils.createKey(appPreferences.getScreenLockTimeout());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private class ScreenLockListener implements OnPreferenceValueChangedListener<Boolean> {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onChanged(Boolean newValue) {
|
|
|
|
+ screenLockTimeoutChoicePreference.setEnabled(newValue);
|
|
|
|
+
|
|
|
|
+ if (newValue) {
|
|
|
|
+ screenLockTimeoutChoicePreference.setAlpha(1.0f);
|
|
|
|
+ } else {
|
|
|
|
+ screenLockTimeoutChoicePreference.setAlpha(0.38f);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private class ScreenSecurityChangeListener implements OnPreferenceValueChangedListener<Boolean> {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onChanged(Boolean newValue) {
|
|
|
|
+ if (newValue) {
|
|
|
|
+ if (getActivity() != null) {
|
|
|
|
+ getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (getActivity() != null) {
|
|
|
|
+ getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private class ProxyCredentialsChangeListener implements OnPreferenceValueChangedListener<Boolean> {
|
|
private class ProxyCredentialsChangeListener implements OnPreferenceValueChangedListener<Boolean> {
|
|
|
|
|
|
@Override
|
|
@Override
|