aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-05-24 03:05:28 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-05-24 03:05:28 +0000
commit9725d5e411e4c33d5d274749006811e17531d961 (patch)
tree4d90025ec9be4a92d8f2f2fbd9ce24b6b28f8f64 /app/src/main/java/ml/docilealligator/infinityforreddit
parent18aec38d9f4d79afe0748b4bae1dfe11a3ee24ef (diff)
downloadinfinity-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/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java92
2 files changed, 60 insertions, 54 deletions
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) {