From dd9539aa3fc6727943f2e490c49f8b37d1c0bd67 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Mon, 12 Sep 2016 09:55:48 +0200 Subject: [PATCH] Added UI for chans --- .../ch/dissem/apps/abit/MainActivity.java | 178 +++++++++++++----- .../res/layout/dialog_input_passphrase.xml | 14 ++ app/src/main/res/values-de/strings.xml | 12 +- app/src/main/res/values/strings.xml | 6 + 4 files changed, 156 insertions(+), 54 deletions(-) create mode 100644 app/src/main/res/layout/dialog_input_passphrase.xml diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java index 1baf37e..b1e9ded 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java @@ -16,6 +16,7 @@ package ch.dissem.apps.abit; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.ComponentName; import android.content.Context; @@ -23,6 +24,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.graphics.Point; +import android.os.AsyncTask; import android.os.Bundle; import android.os.IBinder; import android.support.v4.app.Fragment; @@ -33,6 +35,8 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.CompoundButton; import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; import com.github.amlcurran.showcaseview.ShowcaseView; import com.github.amlcurran.showcaseview.targets.Target; @@ -72,6 +76,7 @@ import ch.dissem.apps.abit.util.Preferences; import ch.dissem.bitmessage.BitmessageContext; import ch.dissem.bitmessage.entity.BitmessageAddress; import ch.dissem.bitmessage.entity.Plaintext; +import ch.dissem.bitmessage.entity.payload.Pubkey; import ch.dissem.bitmessage.entity.valueobject.Label; import static ch.dissem.apps.abit.service.BitmessageService.isRunning; @@ -102,6 +107,7 @@ public class MainActivity extends AppCompatActivity private static final Logger LOG = LoggerFactory.getLogger(MainActivity.class); private static final int ADD_IDENTITY = 1; private static final int MANAGE_IDENTITY = 2; + private static final int ADD_CHAN = 3; public static WeakReference instance; @@ -230,36 +236,45 @@ public class MainActivity extends AppCompatActivity for (BitmessageAddress identity : bmc.addresses().getIdentities()) { LOG.info("Adding identity " + identity.getAddress()); profiles.add(new ProfileDrawerItem() - .withIcon(new Identicon(identity)) - .withName(identity.toString()) - .withNameShown(true) - .withEmail(identity.getAddress()) - .withTag(identity) + .withIcon(new Identicon(identity)) + .withName(identity.toString()) + .withNameShown(true) + .withEmail(identity.getAddress()) + .withTag(identity) ); } if (profiles.isEmpty()) { // Create an initial identity BitmessageAddress identity = Singleton.getIdentity(this); profiles.add(new ProfileDrawerItem() - .withIcon(new Identicon(identity)) - .withName(identity.toString()) - .withEmail(identity.getAddress()) - .withTag(identity) + .withIcon(new Identicon(identity)) + .withName(identity.toString()) + .withEmail(identity.getAddress()) + .withTag(identity) ); } profiles.add(new ProfileSettingDrawerItem() - .withName("Add Identity") - .withDescription("Create new identity") - .withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add) - .actionBar() - .paddingDp(5) - .colorRes(R.color.icons)) - .withIdentifier(ADD_IDENTITY) + .withName(getString(R.string.add_identity)) + .withDescription(getString(R.string.add_identity_summary)) + .withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add) + .actionBar() + .paddingDp(5) + .colorRes(R.color.icons)) + .withIdentifier(ADD_IDENTITY) ); profiles.add(new ProfileSettingDrawerItem() - .withName(getString(R.string.manage_identity)) - .withIcon(GoogleMaterial.Icon.gmd_settings) - .withIdentifier(MANAGE_IDENTITY) + .withName(getString(R.string.add_chan)) + .withDescription(getString(R.string.add_chan_summary)) + .withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add) + .actionBar() + .paddingDp(5) + .colorRes(R.color.icons)) + .withIdentifier(ADD_CHAN) + ); + profiles.add(new ProfileSettingDrawerItem() + .withName(getString(R.string.manage_identity)) + .withIcon(GoogleMaterial.Icon.gmd_settings) + .withIdentifier(MANAGE_IDENTITY) ); // Create the AccountHeader accountHeader = new AccountHeaderBuilder() @@ -272,35 +287,10 @@ public class MainActivity extends AppCompatActivity currentProfile) { switch (profile.getIdentifier()) { case ADD_IDENTITY: - new AlertDialog.Builder(MainActivity.this) - .setMessage(R.string.add_identity_warning) - .setPositiveButton(android.R.string.yes, new - DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int which) { - BitmessageAddress identity = bmc - .createIdentity(false); - IProfile newProfile = new - ProfileDrawerItem() - .withName(identity.toString()) - .withEmail(identity.getAddress()) - .withTag(identity); - if (accountHeader.getProfiles() != null) { - // we know that there are 2 setting - // elements. - // Set the new profile above them ;) - accountHeader.addProfile( - newProfile, accountHeader - .getProfiles().size() - - 2); - } else { - accountHeader.addProfiles(newProfile); - } - } - }) - .setNegativeButton(android.R.string.no, null) - .show(); + addIdentityDialog(); + break; + case ADD_CHAN: + addChanDialog(); break; case MANAGE_IDENTITY: Intent show = new Intent(MainActivity.this, @@ -359,9 +349,9 @@ public class MainActivity extends AppCompatActivity drawerItems.add(item); } drawerItems.add(new PrimaryDrawerItem() - .withName(R.string.archive) - .withTag(null) - .withIcon(CommunityMaterial.Icon.cmd_archive) + .withName(R.string.archive) + .withTag(null) + .withIcon(CommunityMaterial.Icon.cmd_archive) ); drawerItems.add(new DividerDrawerItem()); drawerItems.add(new PrimaryDrawerItem() @@ -434,6 +424,73 @@ public class MainActivity extends AppCompatActivity .build(); } + private void addIdentityDialog() { + new AlertDialog.Builder(MainActivity.this) + .setMessage(R.string.add_identity_warning) + .setPositiveButton(android.R.string.yes, new + DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + Toast.makeText(MainActivity.this, + R.string.toast_long_running_operation, + Toast.LENGTH_SHORT).show(); + new AsyncTask() { + @Override + protected BitmessageAddress doInBackground(Void... args) { + return bmc.createIdentity(false, Pubkey.Feature.DOES_ACK); + } + + @Override + protected void onPostExecute(BitmessageAddress chan) { + Toast.makeText(MainActivity.this, + R.string.toast_identity_created, + Toast.LENGTH_SHORT).show(); + addIdentityEntry(chan); + } + }.execute(); + } + }) + .setNegativeButton(android.R.string.no, null) + .show(); + } + + private void addChanDialog() { + @SuppressLint("InflateParams") + final View dialogView = getLayoutInflater().inflate(R.layout.dialog_input_passphrase, null); + new AlertDialog.Builder(MainActivity.this) + .setMessage(R.string.add_chan) + .setView(dialogView) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + TextView passphrase = (TextView) dialogView.findViewById(R.id.passphrase); + Toast.makeText(MainActivity.this, R.string.toast_long_running_operation, + Toast.LENGTH_SHORT).show(); + new AsyncTask() { + @Override + protected BitmessageAddress doInBackground(String... args) { + String pass = args[0]; + BitmessageAddress chan = bmc.createChan(pass); + chan.setAlias(pass); + bmc.addresses().save(chan); + return chan; + } + + @Override + protected void onPostExecute(BitmessageAddress chan) { + Toast.makeText(MainActivity.this, + R.string.toast_chan_created, + Toast.LENGTH_SHORT).show(); + addIdentityEntry(chan); + } + }.execute(passphrase.getText().toString()); + } + }) + .setNegativeButton(R.string.cancel, null) + .show(); + } + @Override protected void onResume() { instance = new WeakReference<>(this); @@ -441,6 +498,25 @@ public class MainActivity extends AppCompatActivity super.onResume(); } + private void addIdentityEntry(BitmessageAddress identity) { + IProfile newProfile = new + ProfileDrawerItem() + .withName(identity.toString()) + .withEmail(identity.getAddress()) + .withTag(identity); + if (accountHeader.getProfiles() != null) { + // we know that there are 3 setting + // elements. + // Set the new profile above them ;) + accountHeader.addProfile( + newProfile, accountHeader + .getProfiles().size() + - 3); + } else { + accountHeader.addProfiles(newProfile); + } + } + @Override protected void onPause() { super.onPause(); diff --git a/app/src/main/res/layout/dialog_input_passphrase.xml b/app/src/main/res/layout/dialog_input_passphrase.xml new file mode 100644 index 0000000..db9c2ae --- /dev/null +++ b/app/src/main/res/layout/dialog_input_passphrase.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 95d73b8..9068551 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -13,6 +13,8 @@ Einstellungen Identität hinzufügen Eine neue Identität erstellen + Chan hinzufügen + Einen Chan hinzufügen oder erstellen Broadcast Abbrechen Importieren @@ -60,10 +62,10 @@ Öffentlicher Schlüssel verfügbar Öffentlicher Schlüssel noch nicht verfügbar QR-Code - Mehrere Identitäten zu haben bedeutet einen höheren Resourcenverbrauch. Sind Sie sicher? + Mehrere Identitäten zu haben bedeutet einen höheren Resourcenverbrauch. Bist Du sicher? Teilen - Sind Sie sicher dass dieser Kontakt gelöscht werden soll? - Sind Sie sicher dass diese Identität gelöscht werden soll? Sie werden keine Nachrichten mehr empfangen können welche an diese Adresse gesendet werden, und es est nicht möglich diese Aktion rückgängig zu machen. + Bist Du sicher dass dieser Kontakt gelöscht werden soll? + Bist Du sicher dass diese Identität gelöscht werden soll? Nachrichten, welche an diese Adresse gesendet werden, können nicht mehr empfangen werden und es est nicht möglich diese Aktion rückgängig zu machen. Kontakt erfassen QR-Code scannen Solange kein aktiver Knoten gestartet ist, werden keine Meldungen empfangen oder gesendet. Dies braucht jedoch viele Resourcen und Daten. @@ -75,4 +77,8 @@ Als Alternative kann in den Einstellungen ein vertrauenswürdiger Knoten konfigu Exportieren Identität wirklich exportieren? Der Export wird die privaten Schlüssel unverschlüsselt enthalten. Schreiben + Passphrase + Chan erstellt + Dies kann einige Minuten dauern + Identität erstellt \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49e4b52..6dc6dca 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,6 +14,8 @@ Manage Identity Add Identity Create new identity + Add Chan + Add or create a chan Import Contact Settings @@ -78,4 +80,8 @@ As an alternative you could configure a trusted node in the settings, but as of Export Do you really want to export your identity? The export will contain the unencrypted private keys. Compose + passphrase + This may take a few minutes + Identity created + Chan created