1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 14:21:16 +00:00

Display syncthing's API key in Settings/About dialog (fixes #164) (#167)

* Display syncthing's api key in Settings/About dialog (fixes #164)

* Click to copy API key to clipboard

* Imported translation de-DE
This commit is contained in:
Catfriend1 2018-12-30 17:11:50 +01:00 committed by GitHub
parent 7fb47b3aba
commit 105ead51ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 8 deletions

View file

@ -2,7 +2,10 @@ package com.nutomic.syncthingandroid.activities;
import android.Manifest; import android.Manifest;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -106,11 +109,16 @@ public class SettingsActivity extends SyncthingActivity {
Preference.OnPreferenceClickListener { Preference.OnPreferenceClickListener {
private static final String TAG = "SettingsFragment"; 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_EXPORT_CONFIG = "export_config";
private static final String KEY_IMPORT_CONFIG = "import_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_DATABASE = "st_reset_database";
private static final String KEY_ST_RESET_DELTAS = "st_reset_deltas"; 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 NotificationHandler mNotificationHandler;
@Inject SharedPreferences mPreferences; @Inject SharedPreferences mPreferences;
@ -147,6 +155,7 @@ public class SettingsActivity extends SyncthingActivity {
private EditTextPreference mHttpProxyAddress; private EditTextPreference mHttpProxyAddress;
private Preference mSyncthingVersion; private Preference mSyncthingVersion;
private Preference mSyncthingApiKey;
private SyncthingService mSyncthingService; private SyncthingService mSyncthingService;
private RestApi mRestApi; private RestApi mRestApi;
@ -239,8 +248,9 @@ public class SettingsActivity extends SyncthingActivity {
mSocksProxyAddress = (EditTextPreference) findPreference(Constants.PREF_SOCKS_PROXY_ADDRESS); mSocksProxyAddress = (EditTextPreference) findPreference(Constants.PREF_SOCKS_PROXY_ADDRESS);
mHttpProxyAddress = (EditTextPreference) findPreference(Constants.PREF_HTTP_PROXY_ADDRESS); mHttpProxyAddress = (EditTextPreference) findPreference(Constants.PREF_HTTP_PROXY_ADDRESS);
Preference appVersion = findPreference("app_version");
mSyncthingVersion = findPreference("syncthing_version"); mSyncthingVersion = findPreference("syncthing_version");
Preference appVersion = screen.findPreference("app_version"); mSyncthingApiKey = findPreference(KEY_SYNCTHING_API_KEY);
mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked()); mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked());
mUseWifiWhitelist.setEnabled(mRunOnWifi.isChecked()); mUseWifiWhitelist.setEnabled(mRunOnWifi.isChecked());
@ -257,10 +267,14 @@ public class SettingsActivity extends SyncthingActivity {
mCategoryRunConditions = findPreference("category_run_conditions"); mCategoryRunConditions = findPreference("category_run_conditions");
setPreferenceCategoryChangeListener(mCategoryRunConditions, this::onRunConditionPreferenceChange); setPreferenceCategoryChangeListener(mCategoryRunConditions, this::onRunConditionPreferenceChange);
/* Syncthing options */
undoIgnoredDevicesFolders.setOnPreferenceClickListener(this);
/* Import and Export */
exportConfig.setOnPreferenceClickListener(this); exportConfig.setOnPreferenceClickListener(this);
importConfig.setOnPreferenceClickListener(this); importConfig.setOnPreferenceClickListener(this);
undoIgnoredDevicesFolders.setOnPreferenceClickListener(this); /* Debug */
debugFacilitiesEnabled.setOnPreferenceChangeListener(this); debugFacilitiesEnabled.setOnPreferenceChangeListener(this);
environmentVariables.setOnPreferenceChangeListener(this); environmentVariables.setOnPreferenceChangeListener(this);
stResetDatabase.setOnPreferenceClickListener(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, "")); 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, "")); handleHttpProxyPreferenceChange(screen.findPreference(Constants.PREF_HTTP_PROXY_ADDRESS), mPreferences.getString(Constants.PREF_HTTP_PROXY_ADDRESS, ""));
/* About */
try { try {
appVersion.setSummary(getActivity().getPackageManager() String versionName = getActivity().getPackageManager()
.getPackageInfo(getActivity().getPackageName(), 0).versionName); .getPackageInfo(getActivity().getPackageName(), 0).versionName;
appVersion.setSummary("v" + versionName);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
Log.d(TAG, "Failed to get app version name"); Log.d(TAG, "Failed to get app version name");
} }
mSyncthingApiKey.setOnPreferenceClickListener(this);
openSubPrefScreen(screen); openSubPrefScreen(screen);
} }
@ -331,10 +348,12 @@ public class SettingsActivity extends SyncthingActivity {
(currentState == SyncthingService.State.ACTIVE); (currentState == SyncthingService.State.ACTIVE);
mCategorySyncthingOptions.setEnabled(isSyncthingRunning); mCategorySyncthingOptions.setEnabled(isSyncthingRunning);
if (!isSyncthingRunning) if (!isSyncthingRunning) {
return; return;
}
mSyncthingVersion.setSummary(mRestApi.getVersion()); mSyncthingVersion.setSummary(mRestApi.getVersion());
mSyncthingApiKey.setSummary(mRestApi.getApiKey());
mOptions = mRestApi.getOptions(); mOptions = mRestApi.getOptions();
mGui = mRestApi.getGui(); mGui = mRestApi.getGui();
@ -618,6 +637,14 @@ public class SettingsActivity extends SyncthingActivity {
}) })
.show(); .show();
return true; 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: default:
return false; return false;
} }

View file

@ -776,6 +776,10 @@ public class RestApi {
}); });
} }
public String getApiKey() {
return mApiKey;
}
public URL getUrl() { public URL getUrl() {
return mUrl; return mUrl;
} }

View file

@ -559,6 +559,12 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<!-- Title of the preference showing this app's version name --> <!-- Title of the preference showing this app's version name -->
<string name="app_version_title">Syncthing-Fork Wrapper Version</string> <string name="app_version_title">Syncthing-Fork Wrapper Version</string>
<!-- Title of the preference showing the REST API key -->
<string name="syncthing_api_key">Syncthing API Key (Klicke zum Kopieren)</string>
<!-- Shown when the API key is copied to the clipboard -->
<string name="api_key_copied_to_clipboard">Syncthing API Key in die Zwischenablage kopiert</string>
<!-- FolderPickerAcitivity --> <!-- FolderPickerAcitivity -->

View file

@ -567,6 +567,12 @@ Please report any problems you encounter via Github.</string>
<!-- Title of the preference showing this app's version name --> <!-- Title of the preference showing this app's version name -->
<string name="app_version_title">Syncthing-Fork Wrapper Version</string> <string name="app_version_title">Syncthing-Fork Wrapper Version</string>
<!-- Title of the preference showing the REST API key -->
<string name="syncthing_api_key">Syncthing API Key (click to copy)</string>
<!-- Shown when the API key is copied to the clipboard -->
<string name="api_key_copied_to_clipboard">Syncthing API key copied to clipboard</string>
<!-- FolderPickerAcitivity --> <!-- FolderPickerAcitivity -->

View file

@ -276,12 +276,22 @@
</Preference> </Preference>
<Preference <Preference
android:persistent="false"
android:selectable="false"
android:key="app_version"
android:title="@string/app_version_title" />
<Preference
android:persistent="false"
android:selectable="false"
android:key="syncthing_version" android:key="syncthing_version"
android:title="@string/syncthing_version_title" /> android:title="@string/syncthing_version_title" />
<Preference <Preference
android:key="app_version" android:persistent="false"
android:title="@string/app_version_title" /> android:selectable="true"
android:key="syncthing_api_key"
android:title="@string/syncthing_api_key" />
</PreferenceScreen> </PreferenceScreen>