|
27 | 27 | import android.os.Bundle; |
28 | 28 | import android.os.Handler; |
29 | 29 | import android.os.Looper; |
30 | | -import android.preference.ListPreference; |
31 | 30 | import android.preference.Preference; |
32 | 31 | import android.preference.PreferenceActivity; |
33 | 32 | import android.preference.PreferenceCategory; |
|
65 | 64 | import com.owncloud.android.lib.common.ExternalLinkType; |
66 | 65 | import com.owncloud.android.lib.common.utils.Log_OC; |
67 | 66 | import com.owncloud.android.providers.DocumentsStorageProvider; |
68 | | -import com.owncloud.android.ui.ListPreferenceDialog; |
69 | 67 | import com.owncloud.android.ui.ThemeableSwitchPreference; |
70 | 68 | import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask; |
71 | 69 | import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment; |
|
80 | 78 | import com.owncloud.android.utils.theme.CapabilityUtils; |
81 | 79 | import com.owncloud.android.utils.theme.ViewThemeUtils; |
82 | 80 |
|
83 | | -import java.util.ArrayList; |
84 | 81 | import java.util.Objects; |
85 | 82 |
|
86 | 83 | import javax.inject.Inject; |
@@ -129,7 +126,7 @@ public class SettingsActivity extends PreferenceActivity |
129 | 126 |
|
130 | 127 | private Uri serverBaseUri; |
131 | 128 |
|
132 | | - private ListPreferenceDialog lock; |
| 129 | + private Preference lock; |
133 | 130 | private ThemeableSwitchPreference showHiddenFiles; |
134 | 131 | private ThemeableSwitchPreference showEcosystemApps; |
135 | 132 | private AppCompatDelegate delegate; |
@@ -212,9 +209,8 @@ public void onBackPressed() { |
212 | 209 |
|
213 | 210 | private void showPasscodeDialogIfEnforceAppProtection() { |
214 | 211 | if (MDMConfig.INSTANCE.enforceProtection(this) && Objects.equals(preferences.getLockPreference(), SettingsActivity.LOCK_NONE) && lock != null) { |
215 | | - lock.showDialog(); |
216 | | - lock.dismissible(false); |
217 | | - lock.enableCancelButton(false); |
| 212 | + Intent intent = ExtendedSettingsActivity.Companion.createIntent(this, ExtendedSettingsActivityDialog.AppPasscode, false); |
| 213 | + startActivityForResult(intent, ExtendedSettingsActivityDialog.AppPasscode.getResultId()); |
218 | 214 | } |
219 | 215 | } |
220 | 216 |
|
@@ -742,63 +738,33 @@ private void setupShowEcosystemAppsPreference(PreferenceCategory preferenceCateg |
742 | 738 | private void setupLockPreference(PreferenceCategory preferenceCategoryDetails, |
743 | 739 | boolean passCodeEnabled, |
744 | 740 | boolean deviceCredentialsEnabled) { |
745 | | - boolean enforceProtection = MDMConfig.INSTANCE.enforceProtection(this); |
746 | | - lock = (ListPreferenceDialog) findPreference(PREFERENCE_LOCK); |
747 | | - int optionSize = 3; |
748 | | - if (enforceProtection) { |
749 | | - optionSize = 2; |
750 | | - } |
751 | | - |
| 741 | + lock = findPreference(PREFERENCE_LOCK); |
752 | 742 | if (lock != null && (passCodeEnabled || deviceCredentialsEnabled)) { |
753 | | - ArrayList<String> lockEntries = new ArrayList<>(optionSize); |
754 | | - lockEntries.add(getString(R.string.prefs_lock_using_passcode)); |
755 | | - lockEntries.add(getString(R.string.prefs_lock_using_device_credentials)); |
756 | | - |
757 | | - ArrayList<String> lockValues = new ArrayList<>(optionSize); |
758 | | - lockValues.add(LOCK_PASSCODE); |
759 | | - lockValues.add(LOCK_DEVICE_CREDENTIALS); |
760 | | - |
761 | | - if (!enforceProtection) { |
762 | | - lockEntries.add(getString(R.string.prefs_lock_none)); |
763 | | - lockValues.add(LOCK_NONE); |
764 | | - } |
| 743 | + String currentLock = preferences.getLockPreference(); |
| 744 | + updateLockSummary(lock, currentLock); |
765 | 745 |
|
766 | | - if (!passCodeEnabled) { |
767 | | - lockEntries.remove(getString(R.string.prefs_lock_using_passcode)); |
768 | | - lockValues.remove(LOCK_PASSCODE); |
769 | | - } else if (!deviceCredentialsEnabled || !DeviceCredentialUtils.areCredentialsAvailable(getApplicationContext())) { |
770 | | - lockEntries.remove(getString(R.string.prefs_lock_using_device_credentials)); |
771 | | - lockValues.remove(LOCK_DEVICE_CREDENTIALS); |
772 | | - } |
773 | | - |
774 | | - String[] lockEntriesArr = new String[lockEntries.size()]; |
775 | | - lockEntriesArr = lockEntries.toArray(lockEntriesArr); |
776 | | - String[] lockValuesArr = new String[lockValues.size()]; |
777 | | - lockValuesArr = lockValues.toArray(lockValuesArr); |
778 | | - |
779 | | - lock.setEntries(lockEntriesArr); |
780 | | - lock.setEntryValues(lockValuesArr); |
781 | | - lock.setSummary(lock.getEntry()); |
782 | | - |
783 | | - lock.setOnPreferenceChangeListener((preference, o) -> { |
784 | | - pendingLock = LOCK_NONE; |
785 | | - String oldValue = ((ListPreference) preference).getValue(); |
786 | | - String newValue = (String) o; |
787 | | - if (!oldValue.equals(newValue)) { |
788 | | - if (LOCK_NONE.equals(oldValue)) { |
789 | | - enableLock(newValue); |
790 | | - } else { |
791 | | - pendingLock = newValue; |
792 | | - disableLock(oldValue); |
793 | | - } |
794 | | - } |
795 | | - return false; |
| 746 | + lock.setOnPreferenceClickListener(preference -> { |
| 747 | + Intent intent = ExtendedSettingsActivity.Companion.createIntent(this, ExtendedSettingsActivityDialog.AppPasscode); |
| 748 | + startActivityForResult(intent, ExtendedSettingsActivityDialog.AppPasscode.getResultId()); |
| 749 | + return true; |
796 | 750 | }); |
797 | 751 | } else { |
798 | 752 | preferenceCategoryDetails.removePreference(lock); |
799 | 753 | } |
800 | 754 | } |
801 | 755 |
|
| 756 | + private void updateLockSummary(Preference lockPreference, String lockValue) { |
| 757 | + String summary; |
| 758 | + if (LOCK_PASSCODE.equals(lockValue)) { |
| 759 | + summary = getString(R.string.prefs_lock_using_passcode); |
| 760 | + } else if (LOCK_DEVICE_CREDENTIALS.equals(lockValue)) { |
| 761 | + summary = getString(R.string.prefs_lock_using_device_credentials); |
| 762 | + } else { |
| 763 | + summary = getString(R.string.prefs_lock_none); |
| 764 | + } |
| 765 | + lockPreference.setSummary(summary); |
| 766 | + } |
| 767 | + |
802 | 768 | private void setupAutoUploadCategory(PreferenceScreen preferenceScreen) { |
803 | 769 | final PreferenceCategory preferenceCategorySyncedFolders = |
804 | 770 | (PreferenceCategory) findPreference("synced_folders_category"); |
@@ -853,8 +819,10 @@ private void enableLock(String lock) { |
853 | 819 | } |
854 | 820 |
|
855 | 821 | private void changeLockSetting(String value) { |
856 | | - lock.setValue(value); |
857 | | - lock.setSummary(lock.getEntry()); |
| 822 | + preferences.setLockPreference(value); |
| 823 | + if (lock != null) { |
| 824 | + updateLockSummary(lock, value); |
| 825 | + } |
858 | 826 | DocumentsStorageProvider.notifyRootsChanged(this); |
859 | 827 | } |
860 | 828 |
|
@@ -1067,6 +1035,19 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
1067 | 1035 | // needed for to change status bar color |
1068 | 1036 | recreate(); |
1069 | 1037 | } |
| 1038 | + } else if (requestCode == ExtendedSettingsActivityDialog.AppPasscode.getResultId() && data != null) { |
| 1039 | + String selectedLock = data.getStringExtra(ExtendedSettingsActivityDialog.AppPasscode.getKey()); |
| 1040 | + if (selectedLock != null) { |
| 1041 | + String currentLock = preferences.getLockPreference(); |
| 1042 | + if (!currentLock.equals(selectedLock)) { |
| 1043 | + if (LOCK_NONE.equals(currentLock)) { |
| 1044 | + enableLock(selectedLock); |
| 1045 | + } else { |
| 1046 | + pendingLock = selectedLock; |
| 1047 | + disableLock(currentLock); |
| 1048 | + } |
| 1049 | + } |
| 1050 | + } |
1070 | 1051 | } else if (requestCode == REQ_ALL_FILES_ACCESS) { |
1071 | 1052 | final PreferenceCategory preferenceCategorySync = (PreferenceCategory) findPreference("sync"); |
1072 | 1053 | setupAllFilesAccessPreference(preferenceCategorySync); |
|
0 commit comments