diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-03 03:14:25 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-03 03:14:25 +0000 |
commit | 4652b70b376d2a8589bed77ee0f2089eb36b233d (patch) | |
tree | 221acec4490fda32525adfe96595e373fe15637f /app/src | |
parent | 6f64303df8c776cf187d3e8820b67c1901804815 (diff) | |
download | infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.tar infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.tar.gz infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.tar.bz2 infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.tar.lz infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.tar.xz infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.tar.zst infinity-for-reddit-4652b70b376d2a8589bed77ee0f2089eb36b233d.zip |
Add a FAB in LoginActivity to setDomStorageEnabled.
Diffstat (limited to 'app/src')
4 files changed, 60 insertions, 5 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 210a81c7..49455183 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -10,6 +10,7 @@ import android.os.Bundle; 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; @@ -19,8 +20,11 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.app.ActivityCompat; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.r0adkll.slidr.Slidr; import org.json.JSONException; @@ -34,13 +38,13 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.asynctasks.ParseAndInsertNewAccountAsyncTask; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.FetchMyInfo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.asynctasks.ParseAndInsertNewAccountAsyncTask; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -51,6 +55,8 @@ import retrofit2.Retrofit; public class LoginActivity extends BaseActivity { + private static final String ENABLE_DOM_STATE = "EDS"; + @BindView(R.id.coordinator_layout_login_activity) CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_login_activity) @@ -61,6 +67,8 @@ public class LoginActivity extends BaseActivity { TextView twoFAInfoTextView; @BindView(R.id.webview_login_activity) WebView webView; + @BindView(R.id.fab_login_activity) + FloatingActionButton fab; @Inject @Named("no_oauth") Retrofit mRetrofit; @@ -78,6 +86,7 @@ public class LoginActivity extends BaseActivity { @Inject CustomThemeWrapper mCustomThemeWrapper; private String authCode; + private boolean enableDom = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -108,7 +117,28 @@ public class LoginActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); + if (savedInstanceState != null) { + enableDom = savedInstanceState.getBoolean(ENABLE_DOM_STATE); + } + + fab.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(); + }); + + if (enableDom) { + twoFAInfoTextView.setVisibility(View.GONE); + } + webView.getSettings().setJavaScriptEnabled(true); + webView.getSettings().setDomStorageEnabled(enableDom); Uri baseUri = Uri.parse(APIUtils.OAUTH_URL); Uri.Builder uriBuilder = baseUri.buildUpon(); @@ -228,6 +258,12 @@ public class LoginActivity extends BaseActivity { } @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(ENABLE_DOM_STATE, enableDom); + } + + @Override public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; } @@ -244,6 +280,7 @@ public class LoginActivity extends BaseActivity { twoFAInfoTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); Drawable infoDrawable = Utils.getTintedDrawable(this, R.drawable.ic_info_preference_24dp, mCustomThemeWrapper.getPrimaryIconColor()); twoFAInfoTextView.setCompoundDrawablesWithIntrinsicBounds(infoDrawable, null, null, null); + applyFABTheme(fab); } @Override diff --git a/app/src/main/res/drawable/ic_help_24dp.xml b/app/src/main/res/drawable/ic_help_24dp.xml new file mode 100644 index 00000000..81e329b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_help_24dp.xml @@ -0,0 +1,9 @@ +<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/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 470a6124..2452a367 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -47,4 +47,12 @@ </LinearLayout> + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fab_login_activity" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/fab_margin" + android:layout_gravity="bottom|end" + android:src="@drawable/ic_help_24dp" /> + </androidx.coordinatorlayout.widget.CoordinatorLayout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 50eab52f..e965361a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1016,7 +1016,8 @@ <string name="add_subreddit_or_user_to_multireddit_failed">Unable to add %1$s to multireddit %2$s</string> <string name="choose_a_user">Choose a user</string> - <!-- TODO: Remove or change this placeholder text --> - <string name="hello_blank_fragment">Hello blank fragment</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> </resources> |