Skip to content

Commit

Permalink
Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed May 16, 2023
1 parent 03b7a43 commit 5bea0f2
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AppVersionPreference : Preference {
private fun updatePreferenceView(title: TextView, summary: TextView) {
val appVersion = appVersion
val titleColor: Int = context.resources.getColor(R.color.fontAppbar, null)
title.text = StringUtils.getColoredSpan(
title.text = StringUtils.getColorSpan(
context.getString(R.string.app_name),
titleColor
)
Expand Down
139 changes: 116 additions & 23 deletions app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand Down Expand Up @@ -188,6 +189,10 @@ public void onCreate(Bundle savedInstanceState) {
// More
setupMoreCategory(titleColor);

// About
// Not required in NMC
//setupAboutCategory(appVersion);

// Data Privacy
setupDataPrivacyCategory(titleColor);

Expand Down Expand Up @@ -247,15 +252,103 @@ private void setupDevCategory(PreferenceScreen preferenceScreen) {
}
}

private void setupAboutCategory(String appVersion) {
final PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("about");
viewThemeUtils.files.themePreferenceCategory(preferenceCategoryAbout);

/* About App */
Preference pAboutApp = findPreference("about_app");
if (pAboutApp != null) {
pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));

String buildNumber = getResources().getString(R.string.buildNumber);

if (TextUtils.isEmpty(buildNumber)) {
pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
} else {
pAboutApp.setSummary(String.format(getString(R.string.about_version_with_build),
appVersion,
buildNumber));
}
}

// license
boolean licenseEnabled = getResources().getBoolean(R.bool.license_enabled);
Preference licensePreference = findPreference("license");
if (licensePreference != null) {
if (licenseEnabled) {
licensePreference.setSummary(R.string.prefs_gpl_v2);
licensePreference.setOnPreferenceClickListener(preference -> {
DisplayUtils.startLinkIntent(this, R.string.license_url);
return true;
});
} else {
preferenceCategoryAbout.removePreference(licensePreference);
}
}

// privacy
boolean privacyEnabled = getResources().getBoolean(R.bool.privacy_enabled);
Preference privacyPreference = findPreference("privacy");
if (privacyPreference != null) {
if (privacyEnabled && URLUtil.isValidUrl(getString(R.string.privacy_url))) {
privacyPreference.setOnPreferenceClickListener(preference -> {
try {
Uri privacyUrl = Uri.parse(getString(R.string.privacy_url));
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(privacyUrl.getLastPathSegment());

Intent intent;
if (MimeTypeUtil.isPDF(mimeType)) {
intent = new Intent(Intent.ACTION_VIEW, privacyUrl);
DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_pdf_app_available);
} else {
intent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
intent.putExtra(ExternalSiteWebView.EXTRA_TITLE,
getResources().getString(R.string.privacy));
intent.putExtra(ExternalSiteWebView.EXTRA_URL, privacyUrl.toString());
intent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
intent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1);
}

startActivity(intent);
} catch (Exception e) {
Log_OC.e(TAG, "Could not parse privacy url");
preferenceCategoryAbout.removePreference(privacyPreference);
}
return true;
});
} else {
preferenceCategoryAbout.removePreference(privacyPreference);
}
}

// source code
boolean sourcecodeEnabled = getResources().getBoolean(R.bool.sourcecode_enabled);
Preference sourcecodePreference = findPreference("sourcecode");
if (sourcecodePreference != null) {
if (sourcecodeEnabled) {
sourcecodePreference.setOnPreferenceClickListener(preference -> {
DisplayUtils.startLinkIntent(this, R.string.sourcecode_url);
return true;
});
} else {
preferenceCategoryAbout.removePreference(sourcecodePreference);
}
}
}

/**
* NMC customization
*/
private void setupDataPrivacyCategory(int titleColor) {
PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("data_protection");
preferenceCategoryAbout.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_data_privacy),
preferenceCategoryAbout.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_data_privacy),
titleColor));

//privacy settings
Preference privacySettingPreference = findPreference("privacy_settings");
if (privacySettingPreference != null) {
privacySettingPreference.setTitle(StringUtils.getColoredSpan(getString(R.string.privacy_settings),
privacySettingPreference.setTitle(StringUtils.getColorSpan(getString(R.string.privacy_settings),
titleColor));
privacySettingPreference.setOnPreferenceClickListener(preference -> {

Expand All @@ -267,7 +360,7 @@ private void setupDataPrivacyCategory(int titleColor) {
Preference privacyPolicyPreference = findPreference("privacy_policy");

if (privacyPolicyPreference != null) {
privacyPolicyPreference.setTitle(StringUtils.getColoredSpan(getString(R.string.privacy_policy),
privacyPolicyPreference.setTitle(StringUtils.getColorSpan(getString(R.string.privacy_policy),
titleColor));
if (URLUtil.isValidUrl(getString(R.string.privacy_url))) {
privacyPolicyPreference.setOnPreferenceClickListener(preference -> {
Expand Down Expand Up @@ -303,7 +396,7 @@ private void setupDataPrivacyCategory(int titleColor) {
// source code
Preference sourcecodePreference = findPreference("sourcecode");
if (sourcecodePreference != null) {
sourcecodePreference.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_open_source),
sourcecodePreference.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_open_source),
titleColor));
if (URLUtil.isValidUrl(getString(R.string.sourcecode_url))) {
sourcecodePreference.setOnPreferenceClickListener(preference -> {
Expand All @@ -324,13 +417,13 @@ private void setupDataPrivacyCategory(int titleColor) {

private void setUpInfoCategory(int titleColor) {
PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("info");
preferenceCategoryAbout.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_info),
preferenceCategoryAbout.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_info),
titleColor));
}

private void setupMoreCategory(int titleColor) {
PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
preferenceCategoryMore.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_more),
preferenceCategoryMore.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_more),
titleColor));

setupAutoUploadPreference(preferenceCategoryMore, titleColor);
Expand Down Expand Up @@ -359,7 +452,7 @@ private void setupLoggingPreference(PreferenceCategory preferenceCategoryMore, i
boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG;
Preference pLogger = findPreference("logger");
if (pLogger != null) {
pLogger.setTitle(StringUtils.getColoredSpan(getString(R.string.logs_title),
pLogger.setTitle(StringUtils.getColorSpan(getString(R.string.logs_title),
titleColor));
if (loggerEnabled) {
pLogger.setOnPreferenceClickListener(preference -> {
Expand Down Expand Up @@ -513,7 +606,7 @@ private void removeE2E(PreferenceCategory preferenceCategoryMore) {

private void setupAutoUploadPreference(PreferenceCategory preferenceCategoryMore, int titleColor) {
Preference autoUpload = findPreference("syncedFolders");
autoUpload.setTitle(StringUtils.getColoredSpan(getString(R.string.drawer_synced_folders),
autoUpload.setTitle(StringUtils.getColorSpan(getString(R.string.drawer_synced_folders),
titleColor));
if (getResources().getBoolean(R.bool.syncedFolder_light)) {
preferenceCategoryMore.removePreference(autoUpload);
Expand All @@ -534,8 +627,8 @@ private void setupBackupPreference(int titleColor) {
? StringUtils.getColorSpan(getString(R.string.backup_title), titleColor)
: StringUtils.getColorSpan(getString(R.string.contact_backup_title), titleColor));
pContactsBackup.setSummary(showCalendarBackup
? StringUtils.getColorSpan(getString(R.string.prefs_daily_backup_summary), titleColor)
: StringUtils.getColorSpan(getString(R.string.prefs_daily_contact_backup_summary), titleColor));
? getString(R.string.prefs_daily_backup_summary)
: getString(R.string.prefs_daily_contact_backup_summary));
pContactsBackup.setOnPreferenceClickListener(preference -> {
ContactsPreferenceActivity.startActivityWithoutSidebar(this);
return true;
Expand Down Expand Up @@ -568,7 +661,7 @@ private void setupCalendarPreference(PreferenceCategory preferenceCategoryMore)

private void setupDetailsCategory(int titleColor, PreferenceScreen preferenceScreen) {
PreferenceCategory preferenceCategoryDetails = (PreferenceCategory) findPreference("details");
preferenceCategoryDetails.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_details),
preferenceCategoryDetails.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_details),
titleColor));

boolean fPassCodeEnabled = getResources().getBoolean(R.bool.passcode_enabled);
Expand All @@ -592,7 +685,7 @@ private void setupDetailsCategory(int titleColor, PreferenceScreen preferenceScr
private void setupShowMediaScanNotifications(PreferenceCategory preferenceCategoryDetails,
boolean fShowMediaScanNotifications, int titleColor) {
SwitchPreference mShowMediaScanNotifications = (SwitchPreference) findPreference(PREFERENCE_SHOW_MEDIA_SCAN_NOTIFICATIONS);
mShowMediaScanNotifications.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_storage_path),
mShowMediaScanNotifications.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_storage_path),
titleColor));
if (fShowMediaScanNotifications) {
preferenceCategoryDetails.removePreference(mShowMediaScanNotifications);
Expand All @@ -602,7 +695,7 @@ private void setupShowMediaScanNotifications(PreferenceCategory preferenceCatego
private void setupHiddenFilesPreference(PreferenceCategory preferenceCategoryDetails,
boolean fShowHiddenFilesEnabled, int titleColor) {
showHiddenFiles = (ThemeableSwitchPreference) findPreference("show_hidden_files");
showHiddenFiles.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_show_hidden_files),
showHiddenFiles.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_show_hidden_files),
titleColor));
if (fShowHiddenFilesEnabled) {
showHiddenFiles.setOnPreferenceClickListener(preference -> {
Expand All @@ -618,7 +711,7 @@ private void setupLockPreference(PreferenceCategory preferenceCategoryDetails,
boolean passCodeEnabled,
boolean deviceCredentialsEnabled, int titleColor) {
lock = (ListPreference) findPreference(PREFERENCE_LOCK);
lock.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_lock),
lock.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_lock),
titleColor));
if (lock != null && (passCodeEnabled || deviceCredentialsEnabled)) {
ArrayList<String> lockEntries = new ArrayList<>(3);
Expand Down Expand Up @@ -669,7 +762,7 @@ private void setupLockPreference(PreferenceCategory preferenceCategoryDetails,
private void setupAutoUploadCategory(int titleColor, PreferenceScreen preferenceScreen) {
PreferenceCategory preferenceCategorySyncedFolders =
(PreferenceCategory) findPreference("synced_folders_category");
preferenceCategorySyncedFolders.setTitle(StringUtils.getColoredSpan(getString(R.string.drawer_synced_folders),
preferenceCategorySyncedFolders.setTitle(StringUtils.getColorSpan(getString(R.string.drawer_synced_folders),
titleColor));

if (!getResources().getBoolean(R.bool.syncedFolder_light)) {
Expand All @@ -679,7 +772,7 @@ private void setupAutoUploadCategory(int titleColor, PreferenceScreen preference
final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProviderImpl(this);

final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference("synced_folder_on_wifi");
pUploadOnWifiCheckbox.setTitle(StringUtils.getColoredSpan(getString(R.string.auto_upload_on_wifi),
pUploadOnWifiCheckbox.setTitle(StringUtils.getColorSpan(getString(R.string.auto_upload_on_wifi),
titleColor));
pUploadOnWifiCheckbox.setChecked(
arbitraryDataProvider.getBooleanValue(user, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
Expand Down Expand Up @@ -708,7 +801,7 @@ private void setupAutoUploadCategory(int titleColor, PreferenceScreen preference

private void setUpServiceCategory(int titleColor) {
PreferenceCategory preferenceCategoryService = (PreferenceCategory) findPreference("service");
preferenceCategoryService.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_service),
preferenceCategoryService.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_service),
titleColor));
setupHelpPreference(titleColor);
setupImprintPreference(titleColor);
Expand All @@ -717,7 +810,7 @@ private void setUpServiceCategory(int titleColor) {
private void setupHelpPreference(int titleColor) {
Preference pHelp = findPreference("help");
if (pHelp != null) {
pHelp.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_help),
pHelp.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_help),
titleColor));
pHelp.setOnPreferenceClickListener(preference -> {
String helpWeb = getString(R.string.url_help);
Expand All @@ -733,7 +826,7 @@ private void setupHelpPreference(int titleColor) {
private void setupImprintPreference(int titleColor) {
Preference pImprint = findPreference("imprint");
if (pImprint != null) {
pImprint.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_imprint),
pImprint.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_imprint),
titleColor));
pImprint.setOnPreferenceClickListener(preference -> {
String imprintWeb = getString(R.string.url_imprint);
Expand Down Expand Up @@ -792,21 +885,21 @@ private void disableLock(String lock) {

private void setupAccountInfoCategory(int titleColor) {
PreferenceCategory preferenceCategoryAccountInfo = (PreferenceCategory) findPreference("account_info");
preferenceCategoryAccountInfo.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_account_info),
preferenceCategoryAccountInfo.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_account_info),
titleColor));

Preference autoUpload = findPreference("user_name");
autoUpload.setTitle(StringUtils.getColoredSpan(accountManager.getUser().toOwnCloudAccount().getDisplayName(),
autoUpload.setTitle(StringUtils.getColorSpan(accountManager.getUser().toOwnCloudAccount().getDisplayName(),
titleColor));
}

private void setupGeneralCategory(int titleColor) {
PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general");
preferenceCategoryGeneral.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_category_general),
preferenceCategoryGeneral.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_category_general),
titleColor));

prefStoragePath = (ListPreference) findPreference(AppPreferencesImpl.STORAGE_PATH);
prefStoragePath.setTitle(StringUtils.getColoredSpan(getString(R.string.prefs_storage_path),
prefStoragePath.setTitle(StringUtils.getColorSpan(getString(R.string.prefs_storage_path),
titleColor));
if (prefStoragePath != null) {
StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
Expand Down
Loading

0 comments on commit 5bea0f2

Please sign in to comment.