Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2020-06-06 14:01:41 +0300
committerStefan Niedermann <info@niedermann.it>2020-06-06 14:01:41 +0300
commitf9a1c7bbe40cd46a247d53d3bf5353e079ed48ac (patch)
tree273af287a885c8882a1d1f8218ae8e5ff0613315 /app/src/main
parent4c2a01c693f1b93cd26f542391d2a0ee17fc0202 (diff)
Handle already existing account
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java120
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/util/SSOUtil.java4
-rw-r--r--app/src/main/res/layout/drawer_layout.xml42
3 files changed, 77 insertions, 89 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java
index 488e6ecc..f0410e46 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java
@@ -4,7 +4,6 @@ import android.animation.AnimatorInflater;
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Intent;
-import android.database.sqlite.SQLiteConstraintException;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
@@ -37,6 +36,7 @@ import com.nextcloud.android.sso.exceptions.AccountImportCancelledException;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
+import com.nextcloud.android.sso.exceptions.TokenMismatchException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.nextcloud.android.sso.model.SingleSignOnAccount;
@@ -665,71 +665,71 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- // Check which request we're responding to
- if (requestCode == create_note_cmd) {
- // Make sure the request was successful
- if (resultCode == RESULT_OK) {
- //not need because of db.synchronisation in createActivity
-
- Bundle bundle = data.getExtras();
- if (bundle != null && bundle.containsKey(CREATED_NOTE)) {
- DBNote createdNote = (DBNote) bundle.getSerializable(CREATED_NOTE);
- if (createdNote != null) {
- adapter.add(createdNote);
+ switch (requestCode) {
+ case create_note_cmd: {
+ // Make sure the request was successful
+ if (resultCode == RESULT_OK) {
+ //not need because of db.synchronisation in createActivity
+
+ Bundle bundle = data.getExtras();
+ if (bundle != null && bundle.containsKey(CREATED_NOTE)) {
+ DBNote createdNote = (DBNote) bundle.getSerializable(CREATED_NOTE);
+ if (createdNote != null) {
+ adapter.add(createdNote);
+ } else {
+ Log.w(TAG, "createdNote must not be null");
+ }
} else {
- Log.w(TAG, "createdNote must not be null");
+ Log.w(TAG, "Provide at least " + CREATED_NOTE);
}
- } else {
- Log.w(TAG, "Provide at least " + CREATED_NOTE);
}
+ listView.scrollToPosition(0);
+ break;
}
- listView.scrollToPosition(0);
- } else if (requestCode == server_settings) {
- // Recreate activity completely, because theme switching makes problems when only invalidating the views.
- // @see https://github.com/stefan-niedermann/nextcloud-notes/issues/529
- recreate();
- } else if (requestCode == manage_account) {
- if (resultCode == RESULT_FIRST_USER) {
- selectAccount(null);
+ case server_settings: {
+ // Recreate activity completely, because theme switching makes problems when only invalidating the views.
+ // @see https://github.com/stefan-niedermann/nextcloud-notes/issues/529
+ recreate();
+ break;
}
- } else {
- try {
- AccountImporter.onActivityResult(requestCode, resultCode, data, this, (ssoAccount) -> {
- CapabilitiesWorker.update(this);
- new Thread(() -> {
- Log.i(TAG, "Added account: " + "name:" + ssoAccount.name + ", " + ssoAccount.url + ", userId" + ssoAccount.userId);
- try {
- Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
- final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null);
- db.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities);
- Log.i(TAG, capabilities.toString());
- runOnUiThread(() -> {
- selectAccount(ssoAccount.name);
- binding.accountNavigation.setVisibility(VISIBLE);
- binding.drawerLayout.closeDrawer(GravityCompat.START);
- });
- } catch (SQLiteConstraintException e) {
- if (db.getAccounts().size() > 1) { // TODO ideally only show snackbar when this is a not migrated account
- runOnUiThread(() -> {
- BrandedSnackbar.make(coordinatorLayout, R.string.account_already_imported, Snackbar.LENGTH_LONG).show();
- selectAccount(ssoAccount.name);
- binding.accountNavigation.setVisibility(VISIBLE);
- binding.drawerLayout.closeDrawer(GravityCompat.START);
- });
+ case manage_account: {
+ if (resultCode == RESULT_FIRST_USER) {
+ selectAccount(null);
+ }
+ break;
+ }
+ default: {
+ try {
+ AccountImporter.onActivityResult(requestCode, resultCode, data, this, (ssoAccount) -> {
+ CapabilitiesWorker.update(this);
+ new Thread(() -> {
+ Log.i(TAG, "Added account: " + "name:" + ssoAccount.name + ", " + ssoAccount.url + ", userId" + ssoAccount.userId);
+ try {
+ Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
+ final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null);
+ db.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities);
+ Log.i(TAG, capabilities.toString());
+ runOnUiThread(() -> selectAccount(ssoAccount.name));
+ } catch (Exception e) {
+ if (e instanceof TokenMismatchException && db.getLocalAccountByAccountName(ssoAccount.name) != null) {
+ Log.w(TAG, "Received " + TokenMismatchException.class.getSimpleName() + " and the given ssoAccount.name (" + ssoAccount.name + ") does already exist in the database. Assume that this account has already been imported.");
+ runOnUiThread(() -> {
+ selectAccount(ssoAccount.name);
+ coordinatorLayout.post(() -> BrandedSnackbar.make(coordinatorLayout, R.string.account_already_imported, Snackbar.LENGTH_LONG).show());
+ });
+ } else {
+ e.printStackTrace();
+ runOnUiThread(() -> {
+ binding.activityNotesListView.progressCircular.setVisibility(GONE);
+ ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
+ });
+ }
}
- } catch (Exception e) {
- e.printStackTrace();
- runOnUiThread(() -> {
- binding.accountNavigation.setVisibility(GONE);
- binding.drawerLayout.openDrawer(GravityCompat.START);
- binding.activityNotesListView.progressCircular.setVisibility(GONE);
- ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
- });
- }
- }).start();
- });
- } catch (AccountImportCancelledException e) {
- Log.i(TAG, "AccountImport has been cancelled.");
+ }).start();
+ });
+ } catch (AccountImportCancelledException e) {
+ Log.i(TAG, "AccountImport has been cancelled.");
+ }
}
}
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/util/SSOUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/util/SSOUtil.java
index 5089f14d..77fa0d2c 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/util/SSOUtil.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/util/SSOUtil.java
@@ -45,9 +45,7 @@ public class SSOUtil {
try {
SingleAccountHelper.getCurrentSingleSignOnAccount(context);
return true;
- } catch (NextcloudFilesAppAccountNotFoundException e) {
- return false;
- } catch (NoCurrentAccountSelectedException e) {
+ } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
return false;
}
}
diff --git a/app/src/main/res/layout/drawer_layout.xml b/app/src/main/res/layout/drawer_layout.xml
index fe101069..32b5d118 100644
--- a/app/src/main/res/layout/drawer_layout.xml
+++ b/app/src/main/res/layout/drawer_layout.xml
@@ -59,36 +59,26 @@
android:textSize="24sp" />
</RelativeLayout>
- <LinearLayout
- android:id="@+id/accountNavigation"
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/navigationList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical">
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ app:layoutManager="LinearLayoutManager"
+ tools:itemCount="6"
+ tools:listitem="@layout/item_navigation" />
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/navigationList"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
- app:layoutManager="LinearLayoutManager"
- tools:itemCount="6"
- tools:listitem="@layout/item_navigation" />
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/navigationMenu"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingTop="8dp"
- android:paddingBottom="8dp"
- app:layoutManager="LinearLayoutManager"
- tools:itemCount="3"
- tools:listitem="@layout/item_navigation" />
- </LinearLayout>
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/navigationMenu"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ app:layoutManager="LinearLayoutManager"
+ tools:itemCount="3"
+ tools:listitem="@layout/item_navigation" />
</LinearLayout>
-
</androidx.core.widget.NestedScrollView>
-
</com.google.android.material.navigation.NavigationView>
-
</androidx.drawerlayout.widget.DrawerLayout> \ No newline at end of file