diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-08-28 17:27:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 17:27:53 +0200 |
commit | 9ed5485ae353c0cb3c8b2f6a97f2e905d77afd71 (patch) | |
tree | 363d8fe629fc7b7be5be32a1e155b69bfcf76984 /app | |
parent | 3564484c2cdec5b53826fd7967b4b29a55dda8f1 (diff) | |
download | AntennaPod-9ed5485ae353c0cb3c8b2f6a97f2e905d77afd71.zip |
Restore Nextcloud login state when recreated (#6600)
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java index 14440be47..2c9e555f1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java @@ -23,6 +23,7 @@ import de.danoeh.antennapod.net.sync.nextcloud.NextcloudLoginFlow; public class NextcloudAuthenticationFragment extends DialogFragment implements NextcloudLoginFlow.AuthenticationCallback { public static final String TAG = "NextcloudAuthenticationFragment"; + private static final String EXTRA_LOGIN_FLOW = "LoginFlow"; private NextcloudAuthDialogBinding viewBinding; private NextcloudLoginFlow nextcloudLoginFlow; private boolean shouldDismiss = false; @@ -40,17 +41,34 @@ public class NextcloudAuthenticationFragment extends DialogFragment dialog.setView(viewBinding.getRoot()); viewBinding.chooseHostButton.setOnClickListener(v -> { - viewBinding.errorText.setVisibility(View.GONE); - viewBinding.chooseHostButton.setVisibility(View.GONE); - viewBinding.loginProgressContainer.setVisibility(View.VISIBLE); nextcloudLoginFlow = new NextcloudLoginFlow(AntennapodHttpClient.getHttpClient(), viewBinding.serverUrlText.getText().toString(), getContext(), this); - nextcloudLoginFlow.start(); + startLoginFlow(); }); - + if (savedInstanceState != null && savedInstanceState.getStringArrayList(EXTRA_LOGIN_FLOW) != null) { + nextcloudLoginFlow = NextcloudLoginFlow.fromInstanceState(AntennapodHttpClient.getHttpClient(), + getContext(), this, savedInstanceState.getStringArrayList(EXTRA_LOGIN_FLOW)); + startLoginFlow(); + } return dialog.create(); } + private void startLoginFlow() { + viewBinding.errorText.setVisibility(View.GONE); + viewBinding.chooseHostButton.setVisibility(View.GONE); + viewBinding.loginProgressContainer.setVisibility(View.VISIBLE); + viewBinding.serverUrlText.setEnabled(false); + nextcloudLoginFlow.start(); + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + if (nextcloudLoginFlow != null) { + outState.putStringArrayList(EXTRA_LOGIN_FLOW, nextcloudLoginFlow.saveInstanceState()); + } + } + @Override public void onDismiss(@NonNull DialogInterface dialog) { super.onDismiss(dialog); @@ -75,7 +93,7 @@ public class NextcloudAuthenticationFragment extends DialogFragment SynchronizationCredentials.setHosturl(server); SynchronizationCredentials.setUsername(username); SyncService.fullSync(getContext()); - if (isVisible()) { + if (isResumed()) { dismiss(); } else { shouldDismiss = true; @@ -88,5 +106,6 @@ public class NextcloudAuthenticationFragment extends DialogFragment viewBinding.errorText.setVisibility(View.VISIBLE); viewBinding.errorText.setText(errorMessage); viewBinding.chooseHostButton.setVisibility(View.VISIBLE); + viewBinding.serverUrlText.setEnabled(true); } } |