Add login info view

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-29 12:11:39 +02:00 committed by Alper Öztürk
parent 8f06ba68a8
commit 7d9bdbb03e
4 changed files with 89 additions and 7 deletions

View File

@ -34,19 +34,27 @@ import android.os.IBinder;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import com.blikoon.qrcodescanner.QrCodeActivity;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@ -991,7 +999,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
setContentView(accountSetupWebviewBinding.getRoot());
if (!isLoginProcessCompleted) {
anonymouslyPostLoginRequest(mServerInfo.mBaseUrl + WEB_LOGIN);
if (!isRedirectedToTheDefaultBrowser) {
anonymouslyPostLoginRequest(mServerInfo.mBaseUrl + WEB_LOGIN);
isRedirectedToTheDefaultBrowser = true;
} else {
initLoginInfoView();
}
// initWebViewLogin(mServerInfo.mBaseUrl + WEB_LOGIN, false);
}
}
@ -1006,6 +1019,19 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
}
}
// region LoginInfoView
private void initLoginInfoView() {
LinearLayout loginFlowLayout = accountSetupWebviewBinding.loginFlowV2.getRoot();
MaterialButton cancelButton = accountSetupWebviewBinding.loginFlowV2.cancelButton;
loginFlowLayout.setVisibility(View.VISIBLE);
cancelButton.setOnClickListener(v -> {
loginFlowExecutorService.shutdown();
recreate();
});
}
// endregion
/**
* Chooses the right icon and text to show to the user for the received operation result.
*
@ -1597,6 +1623,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
private final ScheduledExecutorService loginFlowExecutorService = Executors.newSingleThreadScheduledExecutor();
private boolean isLoginProcessCompleted = false;
private boolean isRedirectedToTheDefaultBrowser = false;
private void poolLogin(PlainClient client) {
loginFlowExecutorService.scheduleAtFixedRate(() -> {
@ -1654,6 +1681,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
}
checkOcServer();
loginFlowExecutorService.shutdown();
}
/**

View File

@ -7,21 +7,31 @@
~ SPDX-License-Identifier: AGPL-3.0-or-later
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<!-- Login Flow V1 -->
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/login_webview">
</WebView>
<!-- Login Flow V2 -->
<include
tools:visibility="visible"
android:visibility="gone"
android:id="@+id/login_flow_v2"
layout="@layout/login_flow_info_layout_v2" />
<ProgressBar
android:id="@+id/login_webview_progress_bar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>
android:indeterminate="true" />
</FrameLayout>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud - Android Client
~
~ SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
~ SPDX-License-Identifier: AGPL-3.0-or-later
-->
<LinearLayout
android:id="@+id/login_flow_info_v2"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"
android:gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:text="@string/authenticator_activity_please_complete_login_process"
android:layout_width="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="@dimen/splash_text_size"
android:layout_marginBottom="@dimen/standard_double_margin"
android:layout_height="wrap_content"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/cancel_button"
app:backgroundTint="@color/white"
android:textColor="@color/black"
android:theme="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="300dp"
android:layout_gravity="center"
android:gravity="center"
app:strokeColor="@color/white"
android:layout_marginBottom="@dimen/standard_double_margin"
android:layout_height="wrap_content"
app:cornerRadius="@dimen/button_corner_radius"
android:text="@string/authenticator_activity_cancel_login" />
</LinearLayout>

View File

@ -334,6 +334,9 @@
<string name="auth_account_does_not_exist">The account is not added on this device yet</string>
<string name="auth_access_failed">Access failed: %1$s</string>
<string name="authenticator_activity_cancel_login">Cancel Login</string>
<string name="authenticator_activity_please_complete_login_process">Please complete login process in your browser</string>
<string name="favorite">Add to favorites</string>
<string name="unset_favorite">Remove from favourites</string>
<string name="encrypted">Set as encrypted</string>