From b7dbacb00015b4851cf2bbac2e2d6edd3c7ec95e Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Thu, 5 Dec 2013 12:27:45 +0000
Subject: [PATCH] Replaced ContactAddedView with a toast (development task
 #39).

---
 .../invitation/AddContactActivity.java        | 22 ++++++--
 .../android/invitation/ContactAddedView.java  | 55 -------------------
 2 files changed, 17 insertions(+), 60 deletions(-)
 delete mode 100644 briar-android/src/net/sf/briar/android/invitation/ContactAddedView.java

diff --git a/briar-android/src/net/sf/briar/android/invitation/AddContactActivity.java b/briar-android/src/net/sf/briar/android/invitation/AddContactActivity.java
index fb02e7c71f..25fe6b53cf 100644
--- a/briar-android/src/net/sf/briar/android/invitation/AddContactActivity.java
+++ b/briar-android/src/net/sf/briar/android/invitation/AddContactActivity.java
@@ -5,6 +5,7 @@ import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
 import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
 import static android.bluetooth.BluetoothAdapter.STATE_ON;
 import static android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION;
+import static android.widget.Toast.LENGTH_LONG;
 import static java.util.logging.Level.INFO;
 import static java.util.logging.Level.WARNING;
 
@@ -14,6 +15,7 @@ import java.util.logging.Logger;
 
 import javax.inject.Inject;
 
+import net.sf.briar.R;
 import net.sf.briar.android.identity.LocalAuthorItem;
 import net.sf.briar.android.identity.LocalAuthorItemComparator;
 import net.sf.briar.android.identity.LocalAuthorSpinnerAdapter;
@@ -38,6 +40,7 @@ import android.content.IntentFilter;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
+import android.widget.Toast;
 
 public class AddContactActivity extends RoboActivity
 implements InvitationListener {
@@ -100,7 +103,8 @@ implements InvitationListener {
 				} else if(contactName == null) {
 					setView(new CodesDoNotMatchView(this));
 				} else {
-					setView(new ContactAddedView(this));
+					showToastAndFinish();
+					return;
 				}
 			} else {
 				// A background task exists - listen to it and get its state
@@ -132,9 +136,12 @@ implements InvitationListener {
 				} else if(!remoteCompared) {
 					setView(new WaitForContactView(this));
 				} else if(localMatched && remoteMatched) {
-					if(contactName == null)
+					if(contactName == null) {
 						setView(new ContactDetailsView(this));
-					else setView(new ContactAddedView(this));
+					} else {
+						showToastAndFinish();
+						return;
+					}
 				} else {
 					setView(new CodesDoNotMatchView(this));
 				}
@@ -161,6 +168,11 @@ implements InvitationListener {
 		view.wifiStateChanged();
 	}
 
+	private void showToastAndFinish() {
+		Toast.makeText(this, R.string.contact_added, LENGTH_LONG).show();
+		finish();
+	}
+
 	@Override
 	public void onResume() {
 		super.onResume();
@@ -185,7 +197,7 @@ implements InvitationListener {
 	public void onDestroy() {
 		super.onDestroy();
 		if(task != null) task.removeListener(this);
-		unregisterReceiver(receiver);
+		if(receiver != null) unregisterReceiver(receiver);
 	}
 
 	void setView(AddContactView view) {
@@ -366,7 +378,7 @@ implements InvitationListener {
 		runOnUiThread(new Runnable() {
 			public void run() {
 				contactName = remoteName;
-				setView(new ContactAddedView(AddContactActivity.this));
+				showToastAndFinish();
 			}
 		});
 	}
diff --git a/briar-android/src/net/sf/briar/android/invitation/ContactAddedView.java b/briar-android/src/net/sf/briar/android/invitation/ContactAddedView.java
deleted file mode 100644
index 30890a554e..0000000000
--- a/briar-android/src/net/sf/briar/android/invitation/ContactAddedView.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package net.sf.briar.android.invitation;
-
-import static android.view.Gravity.CENTER;
-import static net.sf.briar.android.util.CommonLayoutParams.WRAP_WRAP;
-import net.sf.briar.R;
-import android.content.Context;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-class ContactAddedView extends AddContactView implements OnClickListener {
-
-	ContactAddedView(Context ctx) {
-		super(ctx);
-	}
-
-	void populate() {
-		removeAllViews();
-		Context ctx = getContext();
-		LinearLayout innerLayout = new LinearLayout(ctx);
-		innerLayout.setOrientation(HORIZONTAL);
-		innerLayout.setGravity(CENTER);
-
-		ImageView icon = new ImageView(ctx);
-		icon.setImageResource(R.drawable.navigation_accept);
-		innerLayout.addView(icon);
-
-		TextView added = new TextView(ctx);
-		added.setTextSize(22);
-		added.setPadding(10, 10, 10, 10);
-		added.setText(R.string.contact_added);
-		innerLayout.addView(added);
-		addView(innerLayout);
-
-		TextView contactName = new TextView(ctx);
-		contactName.setGravity(CENTER);
-		contactName.setTextSize(22);
-		contactName.setPadding(10, 0, 10, 10);
-		contactName.setText(container.getContactName());
-		addView(contactName);
-
-		Button doneButton = new Button(ctx);
-		doneButton.setLayoutParams(WRAP_WRAP);
-		doneButton.setText(R.string.done_button);
-		doneButton.setOnClickListener(this);
-		addView(doneButton);
-	}
-
-	public void onClick(View view) {
-		container.finish();
-	}
-}
-- 
GitLab