Added UI for chans

This commit is contained in:
Christian Basler 2016-09-12 09:55:48 +02:00
parent da73388d8c
commit dd9539aa3f
4 changed files with 156 additions and 54 deletions

View File

@ -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<MainActivity> 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<Void, Void, BitmessageAddress>() {
@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<String, Void, BitmessageAddress>() {
@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();

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/passphrase"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="@string/passphrase"
android:inputType="textMultiLine"/>
</LinearLayout>

View File

@ -13,6 +13,8 @@
<string name="action_settings">Einstellungen</string>
<string name="add_identity">Identität hinzufügen</string>
<string name="add_identity_summary">Eine neue Identität erstellen</string>
<string name="add_chan">Chan hinzufügen</string>
<string name="add_chan_summary">Einen Chan hinzufügen oder erstellen</string>
<string name="broadcast">Broadcast</string>
<string name="cancel">Abbrechen</string>
<string name="do_import">Importieren</string>
@ -60,10 +62,10 @@
<string name="pubkey_available">Öffentlicher Schlüssel verfügbar</string>
<string name="pubkey_not_available">Öffentlicher Schlüssel noch nicht verfügbar</string>
<string name="alt_qr_code">QR-Code</string>
<string name="add_identity_warning">Mehrere Identitäten zu haben bedeutet einen höheren Resourcenverbrauch. Sind Sie sicher?</string>
<string name="add_identity_warning">Mehrere Identitäten zu haben bedeutet einen höheren Resourcenverbrauch. Bist Du sicher?</string>
<string name="share">Teilen</string>
<string name="delete_contact_warning">Sind Sie sicher dass dieser Kontakt gelöscht werden soll?</string>
<string name="delete_identity_warning">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.</string>
<string name="delete_contact_warning">Bist Du sicher dass dieser Kontakt gelöscht werden soll?</string>
<string name="delete_identity_warning">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.</string>
<string name="create_contact">Kontakt erfassen</string>
<string name="scan_qr_code">QR-Code scannen</string>
<string name="full_node_description">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
<string name="export">Exportieren</string>
<string name="confirm_export">Identität wirklich exportieren? Der Export wird die privaten Schlüssel unverschlüsselt enthalten.</string>
<string name="compose_message">Schreiben</string>
<string name="passphrase">Passphrase</string>
<string name="toast_chan_created">Chan erstellt</string>
<string name="toast_long_running_operation">Dies kann einige Minuten dauern</string>
<string name="toast_identity_created">Identität erstellt</string>
</resources>

View File

@ -14,6 +14,8 @@
<string name="manage_identity">Manage Identity</string>
<string name="add_identity">Add Identity</string>
<string name="add_identity_summary">Create new identity</string>
<string name="add_chan">Add Chan</string>
<string name="add_chan_summary">Add or create a chan</string>
<string name="title_activity_open_bitmessage_link">Import Contact</string>
<string name="action_settings">Settings</string>
@ -78,4 +80,8 @@ As an alternative you could configure a trusted node in the settings, but as of
<string name="export">Export</string>
<string name="confirm_export">Do you really want to export your identity? The export will contain the unencrypted private keys.</string>
<string name="compose_message">Compose</string>
<string name="passphrase">passphrase</string>
<string name="toast_long_running_operation">This may take a few minutes</string>
<string name="toast_identity_created">Identity created</string>
<string name="toast_chan_created">Chan created</string>
</resources>