mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-23 05:16:15 +03:00
Handle already existing account
This commit is contained in:
parent
4c2a01c693
commit
f9a1c7bbe4
3 changed files with 81 additions and 93 deletions
|
@ -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,8 +665,8 @@ 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) {
|
||||
switch (requestCode) {
|
||||
case create_note_cmd: {
|
||||
// Make sure the request was successful
|
||||
if (resultCode == RESULT_OK) {
|
||||
//not need because of db.synchronisation in createActivity
|
||||
|
@ -684,15 +684,21 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
|
|||
}
|
||||
}
|
||||
listView.scrollToPosition(0);
|
||||
} else if (requestCode == server_settings) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
} else if (requestCode == manage_account) {
|
||||
break;
|
||||
}
|
||||
case manage_account: {
|
||||
if (resultCode == RESULT_FIRST_USER) {
|
||||
selectAccount(null);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
try {
|
||||
AccountImporter.onActivityResult(requestCode, resultCode, data, this, (ssoAccount) -> {
|
||||
CapabilitiesWorker.update(this);
|
||||
|
@ -703,29 +709,22 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
|
|||
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);
|
||||
});
|
||||
}
|
||||
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.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) {
|
||||
|
@ -733,6 +732,7 @@ public class NotesListViewActivity extends LockedActivity implements NoteClickLi
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrentAccountAvatar() {
|
||||
try {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,12 +59,6 @@
|
|||
android:textSize="24sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/accountNavigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/navigationList"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -85,10 +79,6 @@
|
|||
tools:itemCount="3"
|
||||
tools:listitem="@layout/item_navigation" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</com.google.android.material.navigation.NavigationView>
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
Loading…
Reference in a new issue