Implement share public key button

This commit is contained in:
Niels Andriesse 2019-06-05 16:45:12 +10:00
parent bb180ff2d5
commit 7d24ab12a2
3 changed files with 21 additions and 0 deletions

View file

@ -1529,5 +1529,8 @@
<string name="activity_key_pair_copy_button_title">Copy</string>
<string name="activity_key_pair_mnemonic_copied_message">Copied to Clipboard</string>
<string name="activity_key_pair_register_button_title">Register</string>
<!-- Settings -->
<string name="activity_settings_share_public_key_button_title">Share Public Key</string>
<string name="activity_settings_public_key_copied_message">Copied to Clipboard</string>
</resources>

View file

@ -33,4 +33,8 @@
android:title="@string/preferences__advanced"
android:icon="@drawable/ic_advanced_24dp"/>
<Preference android:key="preference_category_public_key"
android:title="@string/activity_settings_share_public_key_button_title"
android:icon="@drawable/ic_textsms_24dp"/>
</PreferenceScreen>

View file

@ -18,6 +18,8 @@
package org.thoughtcrime.securesms;
import android.annotation.TargetApi;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -33,6 +35,7 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.preference.Preference;
import android.widget.Toast;
import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment;
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
@ -68,6 +71,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
private static final String PREFERENCE_CATEGORY_CHATS = "preference_category_chats";
private static final String PREFERENCE_CATEGORY_DEVICES = "preference_category_devices";
private static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced";
private static final String PREFERENCE_CATEGORY_PUBLIC_KEY = "preference_category_public_key";
private final DynamicTheme dynamicTheme = new DynamicTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
@ -154,6 +158,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_DEVICES));
this.findPreference(PREFERENCE_CATEGORY_ADVANCED)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_ADVANCED));
this.findPreference(PREFERENCE_CATEGORY_PUBLIC_KEY)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PUBLIC_KEY));
if (VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
tintIcons(getActivity());
@ -205,6 +211,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
Drawable chats = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_forum_white_24dp));
Drawable devices = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_laptop_white_24dp));
Drawable advanced = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_advanced_white_24dp));
Drawable publicKey = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_share_white_24dp));
int[] tintAttr = new int[]{R.attr.pref_icon_tint};
TypedArray typedArray = context.obtainStyledAttributes(tintAttr);
@ -226,6 +233,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
this.findPreference(PREFERENCE_CATEGORY_CHATS).setIcon(chats);
this.findPreference(PREFERENCE_CATEGORY_DEVICES).setIcon(devices);
this.findPreference(PREFERENCE_CATEGORY_ADVANCED).setIcon(advanced);
this.findPreference(PREFERENCE_CATEGORY_PUBLIC_KEY).setIcon(publicKey);
}
private class CategoryClickListener implements Preference.OnPreferenceClickListener {
@ -262,6 +270,12 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
case PREFERENCE_CATEGORY_ADVANCED:
fragment = new AdvancedPreferenceFragment();
break;
case PREFERENCE_CATEGORY_PUBLIC_KEY:
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("public key", "public key"); // TODO: Use actual public key
clipboard.setPrimaryClip(clip);
Toast.makeText(getContext(), R.string.activity_settings_public_key_copied_message, Toast.LENGTH_SHORT).show();
break;
default:
throw new AssertionError();
}