From 696270c1afaa2f08ee71f3587273c30faeb7af8a Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Thu, 8 Jun 2017 12:53:53 +0200 Subject: [PATCH] Add persistent account and fixed some errors. --- SharkNet-Api-Android | 2 +- app/app.iml | 43 ++++++++++++++----- app/build.gradle | 1 - .../net/sharksystem/sharknet/SharkApp.java | 12 +----- .../sharknet/main/MainActivity.java | 7 ++- .../sharknet/main/StartupFragment.java | 9 +++- .../sharksystem/sharknet/nfc/NFCActivity.java | 32 +++++++------- 7 files changed, 67 insertions(+), 39 deletions(-) diff --git a/SharkNet-Api-Android b/SharkNet-Api-Android index bed4af4..851a1b4 160000 --- a/SharkNet-Api-Android +++ b/SharkNet-Api-Android @@ -1 +1 @@ -Subproject commit bed4af4e65b56125846c1206e50c2d1305428e15 +Subproject commit 851a1b4bd92268ea19e8eee3f590d6daa327bfef diff --git a/app/app.iml b/app/app.iml index 69f36a2..b4ea24d 100644 --- a/app/app.iml +++ b/app/app.iml @@ -62,13 +62,6 @@ - - - - - - - @@ -76,6 +69,13 @@ + + + + + + + @@ -90,6 +90,7 @@ + @@ -117,13 +118,35 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 4161f8b..4f7ad1a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,6 +61,5 @@ dependencies { compile 'com.android.support:cardview-v7:24.2.1' compile 'com.android.support:recyclerview-v7:24.2.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' - compile 'com.facebook.stetho:stetho:1.5.0' compile project(':api') } diff --git a/app/src/main/java/net/sharksystem/sharknet/SharkApp.java b/app/src/main/java/net/sharksystem/sharknet/SharkApp.java index 8f791a5..bb6f707 100644 --- a/app/src/main/java/net/sharksystem/sharknet/SharkApp.java +++ b/app/src/main/java/net/sharksystem/sharknet/SharkApp.java @@ -4,8 +4,6 @@ import android.support.multidex.MultiDex; import android.support.multidex.MultiDexApplication; -import com.facebook.stetho.Stetho; - import net.sharksystem.api.models.Chat; import net.sharksystem.api.models.Contact; import net.sharksystem.api.models.Message; @@ -30,12 +28,6 @@ public SharkApp() { MultiDex.install(this); } - @Override - public void onCreate() { - super.onCreate(); - Stetho.initializeWithDefaults(this); - } - public static Context getContext() { return instance; } @@ -84,11 +76,11 @@ public void resetMessage() { this.message = null; } - public void activateDummy(){ + public void activateDummy() { isDummy = true; } - public boolean isDummy(){ + public boolean isDummy() { return isDummy; } } diff --git a/app/src/main/java/net/sharksystem/sharknet/main/MainActivity.java b/app/src/main/java/net/sharksystem/sharknet/main/MainActivity.java index 67f6d74..e9e2881 100644 --- a/app/src/main/java/net/sharksystem/sharknet/main/MainActivity.java +++ b/app/src/main/java/net/sharksystem/sharknet/main/MainActivity.java @@ -78,6 +78,10 @@ public void onClick(DialogInterface dialog,int id) { } else { if(getSharkApp().isDummy()) onCreateDummyDataSelected(); } + + if(mApi.getAccount()!=null){ + mStartupFragment.showOldUSerButton(); + } } @@ -144,7 +148,7 @@ public void onError(Throwable error) { @Override public void onUsePreviousProfileSelected() { - Toast.makeText(this, "This is not yet supported.", Toast.LENGTH_SHORT).show(); + onSuccess(); } @Override @@ -168,6 +172,7 @@ public void onCreateProfile(final Contact contact) { Single single = Single.fromCallable(new Callable() { @Override public Object call() throws Exception { + mApi.clearDbs(); mApi.setAccount(contact); getSharkApp().setAccount(mApi.getAccount()); mApi.initPki(); diff --git a/app/src/main/java/net/sharksystem/sharknet/main/StartupFragment.java b/app/src/main/java/net/sharksystem/sharknet/main/StartupFragment.java index fc54b9a..669e708 100644 --- a/app/src/main/java/net/sharksystem/sharknet/main/StartupFragment.java +++ b/app/src/main/java/net/sharksystem/sharknet/main/StartupFragment.java @@ -16,6 +16,8 @@ public class StartupFragment extends Fragment implements View.OnClickListener { + private View mPreviousAccount; + public interface StartupFragmentButtonListener{ void onCreateNewProfileSelected(); void onCreateDummyDataSelected(); @@ -43,7 +45,9 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, View view = inflater.inflate(R.layout.main_startup_fragment, container, false); // view.findViewById(R.id.button_create_dummy_data).setOnClickListener(this); - view.findViewById(R.id.button_use_previous_profile).setOnClickListener(this); + mPreviousAccount = view.findViewById(R.id.button_use_previous_profile); + mPreviousAccount.setOnClickListener(this); + mPreviousAccount.setVisibility(View.GONE); view.findViewById(R.id.button_create_new_profile).setOnClickListener(this); return view; @@ -65,4 +69,7 @@ public void onClick(View v) { break; } } + public void showOldUSerButton(){ + mPreviousAccount.setVisibility(View.VISIBLE); + } } diff --git a/app/src/main/java/net/sharksystem/sharknet/nfc/NFCActivity.java b/app/src/main/java/net/sharksystem/sharknet/nfc/NFCActivity.java index 768bb68..f615031 100644 --- a/app/src/main/java/net/sharksystem/sharknet/nfc/NFCActivity.java +++ b/app/src/main/java/net/sharksystem/sharknet/nfc/NFCActivity.java @@ -135,21 +135,23 @@ public void run() { onPublicKeyDialog.dismiss(); } - AlertDialog.Builder builder = new AlertDialog.Builder(NFCActivity.this); - builder.setMessage("We received " + certificates.size() + " certificates from " + certificates.get(0).getSigner().getName() + ". There where also " + contacts.size() + " Contacts" + ". Do you want to include them?").setTitle("New Certificates and Contacts"); - builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mNfcPkiPortEventListener.onCertificatesDecision(true); - } - }).setNegativeButton("No", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mNfcPkiPortEventListener.onCertificatesDecision(false); - } - }); - onCertificateDialog = builder.create(); - onCertificateDialog.show(); + if(!certificates.isEmpty()){ + AlertDialog.Builder builder = new AlertDialog.Builder(NFCActivity.this); + builder.setMessage("We received " + certificates.size() + " certificates from " + certificates.get(0).getSigner().getName() + ". There where also " + contacts.size() + " Contacts" + ". Do you want to include them?").setTitle("New Certificates and Contacts"); + builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mNfcPkiPortEventListener.onCertificatesDecision(true); + } + }).setNegativeButton("No", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mNfcPkiPortEventListener.onCertificatesDecision(false); + } + }); + onCertificateDialog = builder.create(); + onCertificateDialog.show(); + } } }); }