diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-24 03:05:28 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-24 03:05:28 +0000 |
commit | 9725d5e411e4c33d5d274749006811e17531d961 (patch) | |
tree | 4d90025ec9be4a92d8f2f2fbd9ce24b6b28f8f64 /app | |
parent | 18aec38d9f4d79afe0748b4bae1dfe11a3ee24ef (diff) | |
download | infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.tar infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.tar.gz infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.tar.bz2 infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.tar.lz infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.tar.xz infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.tar.zst infinity-for-reddit-9725d5e411e4c33d5d274749006811e17531d961.zip |
Login using Chrome custom tab. Remove option to set setDomStorageEnabled() in LoginActivity.
Diffstat (limited to 'app')
8 files changed, 104 insertions, 71 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6c533f12..b9867479 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,6 +36,7 @@ tools:replace="android:label"> <activity android:name=".activities.LoginChromeCustomTabActivity" + android:label="@string/login_activity_label" android:parentActivityName=".activities.MainActivity" android:theme="@style/AppTheme.Slidable" android:launchMode="singleTop" diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index 549ab1c4..99d134dd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -12,7 +12,6 @@ import android.text.util.Linkify; import android.util.Log; import android.view.InflateException; import android.view.MenuItem; -import android.view.View; import android.webkit.CookieManager; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -55,7 +54,6 @@ import retrofit2.Retrofit; public class LoginActivity extends BaseActivity { - private static final String ENABLE_DOM_STATE = "EDS"; private static final String IS_AGREE_TO_USER_AGGREMENT_STATE = "IATUAS"; @Inject @@ -77,7 +75,6 @@ public class LoginActivity extends BaseActivity { @Inject Executor mExecutor; private String authCode; - private boolean enableDom = false; private boolean isAgreeToUserAgreement = false; private ActivityLoginBinding binding; @@ -110,16 +107,10 @@ public class LoginActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (savedInstanceState != null) { - enableDom = savedInstanceState.getBoolean(ENABLE_DOM_STATE); isAgreeToUserAgreement = savedInstanceState.getBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE); } - if (enableDom) { - binding.twoFaInfOTextViewLoginActivity.setVisibility(View.GONE); - } - binding.webviewLoginActivity.getSettings().setJavaScriptEnabled(true); - binding.webviewLoginActivity.getSettings().setDomStorageEnabled(enableDom); Uri baseUri = Uri.parse(APIUtils.OAUTH_URL); Uri.Builder uriBuilder = baseUri.buildUpon(); @@ -133,16 +124,6 @@ public class LoginActivity extends BaseActivity { String url = uriBuilder.toString(); binding.fabLoginActivity.setOnClickListener(view -> { - /*new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.have_trouble_login_title) - .setMessage(R.string.have_trouble_login_message) - .setPositiveButton(R.string.yes, (dialogInterface, i) -> { - enableDom = !enableDom; - ActivityCompat.recreate(this); - }) - .setNegativeButton(R.string.no, null) - .show();*/ - Intent intent = new Intent(this, LoginChromeCustomTabActivity.class); startActivity(intent); finish(); @@ -284,7 +265,6 @@ public class LoginActivity extends BaseActivity { @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); - outState.putBoolean(ENABLE_DOM_STATE, enableDom); outState.putBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE, isAgreeToUserAgreement); } @@ -305,7 +285,7 @@ public class LoginActivity extends BaseActivity { @Override protected void applyCustomTheme() { - binding.coordinatorLayoutLoginActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + binding.getRoot().setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutLoginActivity, null, binding.toolbarLoginActivity); binding.twoFaInfOTextViewLoginActivity.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); Drawable infoDrawable = Utils.getTintedDrawable(this, R.drawable.ic_info_preference_24dp, mCustomThemeWrapper.getPrimaryIconColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java index 84c06ea6..58db6f7b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java @@ -8,16 +8,15 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; import android.os.Handler; +import android.view.View; import android.widget.Toast; -import androidx.activity.EdgeToEdge; import androidx.annotation.NonNull; import androidx.browser.customtabs.CustomTabColorSchemeParams; import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsService; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; + +import com.google.android.material.snackbar.Snackbar; import org.greenrobot.eventbus.EventBus; import org.json.JSONException; @@ -39,6 +38,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.asynctasks.ParseAndInsertNewAccount; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ActivityLoginChromeCustomTabBinding; import ml.docilealligator.infinityforreddit.events.NewUserLoggedInEvent; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -67,49 +67,34 @@ public class LoginChromeCustomTabActivity extends BaseActivity { CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private ActivityLoginChromeCustomTabBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); + setImmersiveModeNotApplicable(); + super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_login_chrome_custom_tab); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + //EdgeToEdge.enable(this); + binding = ActivityLoginChromeCustomTabBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + /*ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; - }); + });*/ applyCustomTheme(); - ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(getPackageManager()); - if (!resolveInfos.isEmpty()) { - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - // add share action to menu list - builder.setShareState(CustomTabsIntent.SHARE_STATE_ON); - builder.setDefaultColorSchemeParams( - new CustomTabColorSchemeParams.Builder() - .setToolbarColor(mCustomThemeWrapper.getColorPrimary()) - .build()); - CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); - customTabsIntent.intent.putExtra("com.google.android.apps.chrome.EXTRA_OPEN_NEW_INCOGNITO_TAB", true); + setSupportActionBar(binding.toolbarLoginChromeCustomTabActivity); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); - try { - Uri.Builder uriBuilder = Uri.parse(APIUtils.OAUTH_URL).buildUpon(); - uriBuilder.appendQueryParameter(APIUtils.CLIENT_ID_KEY, APIUtils.CLIENT_ID); - uriBuilder.appendQueryParameter(APIUtils.RESPONSE_TYPE_KEY, APIUtils.RESPONSE_TYPE); - uriBuilder.appendQueryParameter(APIUtils.STATE_KEY, APIUtils.STATE); - uriBuilder.appendQueryParameter(APIUtils.REDIRECT_URI_KEY, APIUtils.REDIRECT_URI); - uriBuilder.appendQueryParameter(APIUtils.DURATION_KEY, APIUtils.DURATION); - uriBuilder.appendQueryParameter(APIUtils.SCOPE_KEY, APIUtils.SCOPE); + openLoginPage(); - customTabsIntent.launchUrl(this, uriBuilder.build()); - } catch (ActivityNotFoundException e) { - // TODO catch this - } - } + binding.openWebpageButtonLoginChromeCustomTabActivity.setOnClickListener(view -> { + openLoginPage(); + }); } @Override @@ -118,9 +103,12 @@ public class LoginChromeCustomTabActivity extends BaseActivity { Uri uri = intent.getData(); if (uri == null) { + binding.openWebpageButtonLoginChromeCustomTabActivity.setVisibility(View.VISIBLE); return; } + binding.openWebpageButtonLoginChromeCustomTabActivity.setVisibility(View.GONE); + String authCode = uri.getQueryParameter("code"); if (authCode != null) { String state = uri.getQueryParameter("state"); @@ -220,7 +208,45 @@ public class LoginChromeCustomTabActivity extends BaseActivity { @Override protected void applyCustomTheme() { + binding.getRoot().setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutLoginChromeCustomTabActivity, null, binding.toolbarLoginChromeCustomTabActivity); + binding.openWebpageButtonLoginChromeCustomTabActivity.setTextColor(mCustomThemeWrapper.getButtonTextColor()); + binding.openWebpageButtonLoginChromeCustomTabActivity.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); + if (typeface != null) { + binding.openWebpageButtonLoginChromeCustomTabActivity.setTypeface(typeface); + } + } + + private void openLoginPage() { + ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(getPackageManager()); + if (!resolveInfos.isEmpty()) { + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + // add share action to menu list + builder.setShareState(CustomTabsIntent.SHARE_STATE_ON); + builder.setDefaultColorSchemeParams( + new CustomTabColorSchemeParams.Builder() + .setToolbarColor(mCustomThemeWrapper.getColorPrimary()) + .build()); + CustomTabsIntent customTabsIntent = builder.build(); + customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); + customTabsIntent.intent.putExtra("com.google.android.apps.chrome.EXTRA_OPEN_NEW_INCOGNITO_TAB", true); + + try { + Uri.Builder uriBuilder = Uri.parse(APIUtils.OAUTH_URL).buildUpon(); + uriBuilder.appendQueryParameter(APIUtils.CLIENT_ID_KEY, APIUtils.CLIENT_ID); + uriBuilder.appendQueryParameter(APIUtils.RESPONSE_TYPE_KEY, APIUtils.RESPONSE_TYPE); + uriBuilder.appendQueryParameter(APIUtils.STATE_KEY, APIUtils.STATE); + uriBuilder.appendQueryParameter(APIUtils.REDIRECT_URI_KEY, APIUtils.REDIRECT_URI); + uriBuilder.appendQueryParameter(APIUtils.DURATION_KEY, APIUtils.DURATION); + uriBuilder.appendQueryParameter(APIUtils.SCOPE_KEY, APIUtils.SCOPE); + customTabsIntent.launchUrl(this, uriBuilder.build()); + } catch (ActivityNotFoundException e) { + Snackbar.make(binding.getRoot(), R.string.custom_tab_not_available, Snackbar.LENGTH_LONG).show(); + } + } else { + Snackbar.make(binding.getRoot(), R.string.custom_tab_not_available, Snackbar.LENGTH_LONG).show(); + } } private ArrayList<ResolveInfo> getCustomTabsPackages(PackageManager pm) { diff --git a/app/src/main/res/drawable/ic_help_24dp.xml b/app/src/main/res/drawable/ic_help_24dp.xml deleted file mode 100644 index 81e329b9..00000000 --- a/app/src/main/res/drawable/ic_help_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="24dp" - android:height="24dp" - android:viewportWidth="24" - android:viewportHeight="24"> - <path - android:pathData="M11,18h2v-2h-2v2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5 0,-2.21 -1.79,-4 -4,-4z" - android:fillColor="#ffffff"/> -</vector> diff --git a/app/src/main/res/drawable/ic_login_24dp.xml b/app/src/main/res/drawable/ic_login_24dp.xml new file mode 100644 index 00000000..2e5aa22b --- /dev/null +++ b/app/src/main/res/drawable/ic_login_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="960" + android:viewportHeight="960"> + <path + android:pathData="M480,840v-80h280v-560L480,200v-80h280q33,0 56.5,23.5T840,200v560q0,33 -23.5,56.5T760,840L480,840ZM400,680 L345,622 447,520L120,520v-80h327L345,338l55,-58 200,200 -200,200Z" + android:fillColor="#e8eaed"/> +</vector> diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 4c4d3e9f..1f7ef7c6 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:id="@+id/coordinator_layout_login_activity" tools:application="ml.docilealligator.infinityforreddit.activities.LoginActivity"> <com.google.android.material.appbar.AppBarLayout @@ -52,6 +51,6 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" android:layout_gravity="bottom|end" - android:src="@drawable/ic_help_24dp" /> + android:src="@drawable/ic_login_24dp" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> diff --git a/app/src/main/res/layout/activity_login_chrome_custom_tab.xml b/app/src/main/res/layout/activity_login_chrome_custom_tab.xml index 534433ff..0bf28118 100644 --- a/app/src/main/res/layout/activity_login_chrome_custom_tab.xml +++ b/app/src/main/res/layout/activity_login_chrome_custom_tab.xml @@ -1,10 +1,37 @@ <?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".activities.LoginChromeCustomTabActivity"> -</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file + <com.google.android.material.appbar.AppBarLayout + android:id="@+id/appbar_layout_login_chrome_custom_tab_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> + + <androidx.appcompat.widget.Toolbar + android:id="@+id/toolbar_login_chrome_custom_tab_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="?attr/actionBarSize" + app:popupTheme="@style/AppTheme.PopupOverlay" + app:navigationIcon="?attr/homeAsUpIndicator" /> + + </com.google.android.material.appbar.AppBarLayout> + + <com.google.android.material.button.MaterialButton + android:id="@+id/open_webpage_button_login_chrome_custom_tab_activity" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + android:text="@string/open_login_page" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + +</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8049801c..f15f2893 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1049,7 +1049,7 @@ <string name="top_score">%1$s pts</string> - <string name="login_activity_2fa_prompt">If you have 2-factor authentication enabled, kindly type your password like the following: <password>:<2FA code>.\nExample: yourpass:123456</string> + <string name="login_activity_2fa_prompt">2-factor authentication: <password>:<2FA code>.\nExample: yourpass:123456\nGoogle login or having trouble login: click the bottom right button.</string> <string name="block_user">Block User</string> <string name="block_user_success">Blocked</string> @@ -1157,8 +1157,8 @@ <string name="choose_a_user">Choose a user</string> - <string name="have_trouble_login_title">Having Trouble Login</string> - <string name="have_trouble_login_message">Do you want to try another way to login?</string> + <string name="open_login_page">Open login page</string> + <string name="custom_tab_not_available">Chrome custom tab not available. Is Chrome or Firefox installed?</string> <string name="vote">Vote</string> |