diff --git a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index 0cd36f58..f3a370f3 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -2,7 +2,10 @@ package com.nutomic.syncthingandroid.activities; import android.Manifest; import android.app.AlertDialog; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -106,11 +109,16 @@ public class SettingsActivity extends SyncthingActivity { Preference.OnPreferenceClickListener { private static final String TAG = "SettingsFragment"; + // Settings/Syncthing + private static final String KEY_UNDO_IGNORED_DEVICES_FOLDERS = "undo_ignored_devices_folders"; + // Settings/Import and Export private static final String KEY_EXPORT_CONFIG = "export_config"; private static final String KEY_IMPORT_CONFIG = "import_config"; - private static final String KEY_UNDO_IGNORED_DEVICES_FOLDERS = "undo_ignored_devices_folders"; + // Settings/Debug private static final String KEY_ST_RESET_DATABASE = "st_reset_database"; private static final String KEY_ST_RESET_DELTAS = "st_reset_deltas"; + // Settings/About + private static final String KEY_SYNCTHING_API_KEY = "syncthing_api_key"; @Inject NotificationHandler mNotificationHandler; @Inject SharedPreferences mPreferences; @@ -147,6 +155,7 @@ public class SettingsActivity extends SyncthingActivity { private EditTextPreference mHttpProxyAddress; private Preference mSyncthingVersion; + private Preference mSyncthingApiKey; private SyncthingService mSyncthingService; private RestApi mRestApi; @@ -239,8 +248,9 @@ public class SettingsActivity extends SyncthingActivity { mSocksProxyAddress = (EditTextPreference) findPreference(Constants.PREF_SOCKS_PROXY_ADDRESS); mHttpProxyAddress = (EditTextPreference) findPreference(Constants.PREF_HTTP_PROXY_ADDRESS); + Preference appVersion = findPreference("app_version"); mSyncthingVersion = findPreference("syncthing_version"); - Preference appVersion = screen.findPreference("app_version"); + mSyncthingApiKey = findPreference(KEY_SYNCTHING_API_KEY); mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked()); mUseWifiWhitelist.setEnabled(mRunOnWifi.isChecked()); @@ -257,10 +267,14 @@ public class SettingsActivity extends SyncthingActivity { mCategoryRunConditions = findPreference("category_run_conditions"); setPreferenceCategoryChangeListener(mCategoryRunConditions, this::onRunConditionPreferenceChange); + /* Syncthing options */ + undoIgnoredDevicesFolders.setOnPreferenceClickListener(this); + + /* Import and Export */ exportConfig.setOnPreferenceClickListener(this); importConfig.setOnPreferenceClickListener(this); - undoIgnoredDevicesFolders.setOnPreferenceClickListener(this); + /* Debug */ debugFacilitiesEnabled.setOnPreferenceChangeListener(this); environmentVariables.setOnPreferenceChangeListener(this); stResetDatabase.setOnPreferenceClickListener(this); @@ -287,12 +301,15 @@ public class SettingsActivity extends SyncthingActivity { handleSocksProxyPreferenceChange(screen.findPreference(Constants.PREF_SOCKS_PROXY_ADDRESS), mPreferences.getString(Constants.PREF_SOCKS_PROXY_ADDRESS, "")); handleHttpProxyPreferenceChange(screen.findPreference(Constants.PREF_HTTP_PROXY_ADDRESS), mPreferences.getString(Constants.PREF_HTTP_PROXY_ADDRESS, "")); + /* About */ try { - appVersion.setSummary(getActivity().getPackageManager() - .getPackageInfo(getActivity().getPackageName(), 0).versionName); + String versionName = getActivity().getPackageManager() + .getPackageInfo(getActivity().getPackageName(), 0).versionName; + appVersion.setSummary("v" + versionName); } catch (PackageManager.NameNotFoundException e) { Log.d(TAG, "Failed to get app version name"); } + mSyncthingApiKey.setOnPreferenceClickListener(this); openSubPrefScreen(screen); } @@ -331,10 +348,12 @@ public class SettingsActivity extends SyncthingActivity { (currentState == SyncthingService.State.ACTIVE); mCategorySyncthingOptions.setEnabled(isSyncthingRunning); - if (!isSyncthingRunning) + if (!isSyncthingRunning) { return; + } mSyncthingVersion.setSummary(mRestApi.getVersion()); + mSyncthingApiKey.setSummary(mRestApi.getApiKey()); mOptions = mRestApi.getOptions(); mGui = mRestApi.getGui(); @@ -618,6 +637,14 @@ public class SettingsActivity extends SyncthingActivity { }) .show(); return true; + case KEY_SYNCTHING_API_KEY: + // Copy syncthing's API key to clipboard. + ClipboardManager clipboard = (ClipboardManager) getActivity().getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(getString(R.string.syncthing_api_key), mSyncthingApiKey.getSummary()); + clipboard.setPrimaryClip(clip); + Toast.makeText(getActivity(), R.string.api_key_copied_to_clipboard, Toast.LENGTH_SHORT) + .show(); + return true; default: return false; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index 1ea9e383..4c124374 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -776,6 +776,10 @@ public class RestApi { }); } + public String getApiKey() { + return mApiKey; + } + public URL getUrl() { return mUrl; } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 4e09c8c7..ca4385ef 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -559,6 +559,12 @@ Bitte melden Sie auftretende Probleme via GitHub. Syncthing-Fork Wrapper Version + + Syncthing API Key (Klicke zum Kopieren) + + + Syncthing API Key in die Zwischenablage kopiert + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d2d4133a..d85df797 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -567,6 +567,12 @@ Please report any problems you encounter via Github. Syncthing-Fork Wrapper Version + + Syncthing API Key (click to copy) + + + Syncthing API key copied to clipboard + diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index d2ba6269..3e272d62 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -276,12 +276,22 @@ + + + android:persistent="false" + android:selectable="true" + android:key="syncthing_api_key" + android:title="@string/syncthing_api_key" />