Add a button to the captcha layouts to hard reset them

multisite
Floens 10 years ago
parent b8d459d142
commit 8c0d512d52
  1. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java
  2. 19
      Clover/app/src/main/java/org/floens/chan/ui/layout/CaptchaLayout.java
  3. 2
      Clover/app/src/main/java/org/floens/chan/ui/layout/CaptchaLayoutInterface.java
  4. 6
      Clover/app/src/main/java/org/floens/chan/ui/layout/LegacyCaptchaLayout.java
  5. 31
      Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java
  6. 1
      Clover/app/src/main/java/org/floens/chan/ui/theme/DarkTheme.java
  7. 2
      Clover/app/src/main/java/org/floens/chan/ui/theme/Theme.java
  8. BIN
      Clover/app/src/main/res/drawable-hdpi/ic_refresh_black_24dp.png
  9. BIN
      Clover/app/src/main/res/drawable-mdpi/ic_refresh_black_24dp.png
  10. BIN
      Clover/app/src/main/res/drawable-xhdpi/ic_refresh_black_24dp.png
  11. BIN
      Clover/app/src/main/res/drawable-xxhdpi/ic_refresh_black_24dp.png
  12. BIN
      Clover/app/src/main/res/drawable-xxxhdpi/ic_refresh_black_24dp.png
  13. 31
      Clover/app/src/main/res/layout/layout_reply_captcha.xml

@ -65,7 +65,7 @@ import static org.floens.chan.utils.AndroidUtils.getAttrColor;
import static org.floens.chan.utils.AndroidUtils.getString; import static org.floens.chan.utils.AndroidUtils.getString;
public class ThemeSettingsController extends Controller implements View.OnClickListener { public class ThemeSettingsController extends Controller implements View.OnClickListener {
private static PostCell.PostCellCallback DUMMY_POST_CALLBACK = new PostCell.PostCellCallback() { private PostCell.PostCellCallback DUMMY_POST_CALLBACK = new PostCell.PostCellCallback() {
private Loadable loadable = new Loadable("g", 1234); private Loadable loadable = new Loadable("g", 1234);
@Override @Override

@ -64,6 +64,8 @@ public class CaptchaLayout extends WebView implements CaptchaLayoutInterface {
this.siteKey = siteKey; this.siteKey = siteKey;
this.lightTheme = lightTheme; this.lightTheme = lightTheme;
AndroidUtils.hideKeyboard(this);
WebSettings settings = getSettings(); WebSettings settings = getSettings();
settings.setJavaScriptEnabled(true); settings.setJavaScriptEnabled(true);
@ -100,14 +102,19 @@ public class CaptchaLayout extends WebView implements CaptchaLayoutInterface {
if (loaded) { if (loaded) {
loadUrl("javascript:grecaptcha.reset()"); loadUrl("javascript:grecaptcha.reset()");
} else { } else {
loaded = true; hardReset();
}
}
String html = IOUtils.assetAsString(getContext(), "captcha/captcha.html"); @Override
html = html.replace("__site_key__", siteKey); public void hardReset() {
html = html.replace("__theme__", lightTheme ? "light" : "dark"); loaded = true;
loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null); String html = IOUtils.assetAsString(getContext(), "captcha/captcha.html");
} html = html.replace("__site_key__", siteKey);
html = html.replace("__theme__", lightTheme ? "light" : "dark");
loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null);
} }
private void onCaptchaLoaded() { private void onCaptchaLoaded() {

@ -21,4 +21,6 @@ public interface CaptchaLayoutInterface {
void initCaptcha(String baseUrl, String siteKey, boolean lightTheme, CaptchaCallback callback); void initCaptcha(String baseUrl, String siteKey, boolean lightTheme, CaptchaCallback callback);
void reset(); void reset();
void hardReset();
} }

@ -130,6 +130,11 @@ public class LegacyCaptchaLayout extends LinearLayout implements CaptchaLayoutIn
this.callback = callback; this.callback = callback;
} }
@Override
public void hardReset() {
reset();
}
@Override @Override
public void reset() { public void reset() {
input.setText(""); input.setText("");
@ -141,6 +146,7 @@ public class LegacyCaptchaLayout extends LinearLayout implements CaptchaLayoutIn
} }
private void submitCaptcha() { private void submitCaptcha() {
AndroidUtils.hideKeyboard(this);
callback.captchaEntered(this, challenge, input.getText().toString()); callback.captchaEntered(this, challenge, input.getText().toString());
} }

@ -28,6 +28,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -61,8 +62,11 @@ import static org.floens.chan.utils.AndroidUtils.setRoundItemBackground;
public class ReplyLayout extends LoadView implements View.OnClickListener, AnimationUtils.LayoutAnimationProgress, ReplyPresenter.ReplyPresenterCallback, TextWatcher, ImageDecoder.ImageDecoderCallback, SelectionListeningEditText.SelectionChangedListener { public class ReplyLayout extends LoadView implements View.OnClickListener, AnimationUtils.LayoutAnimationProgress, ReplyPresenter.ReplyPresenterCallback, TextWatcher, ImageDecoder.ImageDecoderCallback, SelectionListeningEditText.SelectionChangedListener {
private ReplyPresenter presenter; private ReplyPresenter presenter;
private ReplyLayoutCallback callback; private ReplyLayoutCallback callback;
private boolean newCaptcha = ChanSettings.postNewCaptcha.get();
private View replyInputLayout; private View replyInputLayout;
private FrameLayout captchaContainer;
private ImageView captchaHardReset;
private CaptchaLayoutInterface captchaLayout; private CaptchaLayoutInterface captchaLayout;
private boolean openingName; private boolean openingName;
@ -141,6 +145,12 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
setRoundItemBackground(submit); setRoundItemBackground(submit);
submit.setOnClickListener(this); submit.setOnClickListener(this);
captchaContainer = (FrameLayout) LayoutInflater.from(getContext()).inflate(R.layout.layout_reply_captcha, this, false);
captchaHardReset = (ImageView) captchaContainer.findViewById(R.id.reset);
theme().refreshDrawable.apply(captchaHardReset);
setRoundItemBackground(captchaHardReset);
captchaHardReset.setOnClickListener(this);
setView(replyInputLayout); setView(replyInputLayout);
} }
@ -167,9 +177,9 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
@Override @Override
public LayoutParams getLayoutParamsForView(View view) { public LayoutParams getLayoutParamsForView(View view) {
if (view == replyInputLayout || (view == captchaLayout && captchaLayout instanceof LegacyCaptchaLayout)) { if (view == replyInputLayout || (view == captchaContainer && !newCaptcha)) {
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
} else if (view == captchaLayout && captchaLayout instanceof CaptchaLayout) { } else if (view == captchaContainer && newCaptcha) {
return new LayoutParams(LayoutParams.MATCH_PARENT, dp(300)); return new LayoutParams(LayoutParams.MATCH_PARENT, dp(300));
} else { } else {
// Loadbar // Loadbar
@ -198,7 +208,9 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
presenter.onSubmitClicked(); presenter.onSubmitClicked();
}/* else if (v == preview) { }/* else if (v == preview) {
// TODO // TODO
}*/ }*/ else if (v == captchaHardReset) {
captchaLayout.hardReset();
}
} }
@Override @Override
@ -218,16 +230,20 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
break; break;
case CAPTCHA: case CAPTCHA:
if (captchaLayout == null) { if (captchaLayout == null) {
if (ChanSettings.postNewCaptcha.get()) { if (newCaptcha) {
captchaLayout = new CaptchaLayout(getContext()); captchaLayout = new CaptchaLayout(getContext());
} else { } else {
captchaLayout = (CaptchaLayoutInterface) LayoutInflater.from(getContext()).inflate(R.layout.layout_captcha_legacy, this, false); captchaLayout = (CaptchaLayoutInterface) LayoutInflater.from(getContext()).inflate(R.layout.layout_captcha_legacy, captchaContainer, false);
} }
captchaContainer.addView((View) captchaLayout, 0);
}
if (newCaptcha) {
AndroidUtils.hideKeyboard(this);
} }
setView((View) captchaLayout); setView(captchaContainer);
AndroidUtils.hideKeyboard(this);
break; break;
} }
} }
@ -321,6 +337,7 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
@Override @Override
public void updateCommentCount(int count, int maxCount, boolean over) { public void updateCommentCount(int count, int maxCount, boolean over) {
commentCounter.setText(count + "/" + maxCount); commentCounter.setText(count + "/" + maxCount);
//noinspection ResourceAsColor
commentCounter.setTextColor(over ? 0xffff0000 : getAttrColor(getContext(), R.attr.text_color_secondary)); commentCounter.setTextColor(over ? 0xffff0000 : getAttrColor(getContext(), R.attr.text_color_secondary));
} }

@ -36,5 +36,6 @@ public class DarkTheme extends Theme {
historyDrawable = new ThemeDrawable(R.drawable.ic_history_white_24dp, 1f); historyDrawable = new ThemeDrawable(R.drawable.ic_history_white_24dp, 1f);
listAddDrawable = new ThemeDrawable(R.drawable.ic_playlist_add_white_24dp, 1f); listAddDrawable = new ThemeDrawable(R.drawable.ic_playlist_add_white_24dp, 1f);
helpDrawable = new ThemeDrawable(R.drawable.ic_help_outline_white_24dp, 1f); helpDrawable = new ThemeDrawable(R.drawable.ic_help_outline_white_24dp, 1f);
refreshDrawable = new ThemeDrawable(R.drawable.ic_refresh_white_24dp, 1f);
} }
} }

@ -68,6 +68,7 @@ public class Theme {
public ThemeDrawable historyDrawable; public ThemeDrawable historyDrawable;
public ThemeDrawable listAddDrawable; public ThemeDrawable listAddDrawable;
public ThemeDrawable helpDrawable; public ThemeDrawable helpDrawable;
public ThemeDrawable refreshDrawable;
public Theme(String displayName, String name, int resValue, ThemeHelper.PrimaryColor primaryColor) { public Theme(String displayName, String name, int resValue, ThemeHelper.PrimaryColor primaryColor) {
this.displayName = displayName; this.displayName = displayName;
@ -90,6 +91,7 @@ public class Theme {
historyDrawable = new ThemeDrawable(R.drawable.ic_history_black_24dp, 0.54f); historyDrawable = new ThemeDrawable(R.drawable.ic_history_black_24dp, 0.54f);
listAddDrawable = new ThemeDrawable(R.drawable.ic_playlist_add_black_24dp, 0.54f); listAddDrawable = new ThemeDrawable(R.drawable.ic_playlist_add_black_24dp, 0.54f);
helpDrawable = new ThemeDrawable(R.drawable.ic_help_outline_black_24dp, 0.54f); helpDrawable = new ThemeDrawable(R.drawable.ic_help_outline_black_24dp, 0.54f);
refreshDrawable = new ThemeDrawable(R.drawable.ic_refresh_black_24dp, 0.54f);
} }
public void applyFabColor(FloatingActionButton fab) { public void applyFabColor(FloatingActionButton fab) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?><!--
Clover - 4chan browser https://github.com/Floens/Clover/
Copyright (C) 2014 Floens
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/reset"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="top|right"
android:padding="6dp"
tools:ignore="ContentDescription" />
</FrameLayout>
Loading…
Cancel
Save