mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 08:02:24 +00:00
Add share button for safety numbers
Fixes #5798 Closes #5854 // FREEBIE
This commit is contained in:
committed by
Moxie Marlinspike
parent
0abe56171a
commit
92aeafc261
@@ -16,7 +16,9 @@
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
@@ -33,6 +35,8 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -122,10 +126,22 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
|
||||
menu.clear();
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
inflater.inflate(R.menu.verify_identity, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: finish(); return true;
|
||||
case R.id.verify_identity__share: handleShare(); return true;
|
||||
case android.R.id.home: finish(); return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -173,6 +189,25 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void handleShare() {
|
||||
String shareString =
|
||||
getString(R.string.VerifyIdentityActivity_our_signal_safety_numbers) + "\n" +
|
||||
displayFragment.getFormattedSafetyNumbers() + "\n";
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.VerifyIdentityActivity_our_signal_safety_numbers));
|
||||
intent.putExtra(Intent.EXTRA_TEXT, shareString);
|
||||
intent.setType("text/plain");
|
||||
|
||||
try {
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.VerifyIdentityActivity_share_safety_numbers_via)));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(VerifyIdentityActivity.this, R.string.VerifyIdentityActivity_no_app_to_share_to, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class VerifyDisplayFragment extends Fragment implements Recipients.RecipientsModifiedListener {
|
||||
|
||||
public static final String REMOTE_NUMBER = "remote_number";
|
||||
@@ -294,6 +329,21 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
|
||||
this.clickListener = listener;
|
||||
}
|
||||
|
||||
public String getFormattedSafetyNumbers() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < codes.length; i++) {
|
||||
result.append(codes[i].getText());
|
||||
|
||||
if (i != codes.length - 1) {
|
||||
if (((i+1) % 4) == 0) result.append('\n');
|
||||
else result.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private void setFingerprintViews(Fingerprint fingerprint) {
|
||||
String digits = fingerprint.getDisplayableFingerprint().getDisplayText();
|
||||
int partSize = digits.length() / codes.length;
|
||||
|
||||
Reference in New Issue
Block a user