captcha: replace instance check for reset and destroy to interface methods.

dev
Floens 6 years ago
parent 1ea9810826
commit ee7ffb6ad1
  1. 4
      Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java
  2. 4
      Clover/app/src/main/java/org/floens/chan/ui/captcha/AuthenticationLayoutInterface.java
  3. 9
      Clover/app/src/main/java/org/floens/chan/ui/captcha/CaptchaLayout.java
  4. 10
      Clover/app/src/main/java/org/floens/chan/ui/captcha/GenericWebViewAuthenticationLayout.java
  5. 10
      Clover/app/src/main/java/org/floens/chan/ui/captcha/LegacyCaptchaLayout.java
  6. 9
      Clover/app/src/main/java/org/floens/chan/ui/captcha/v1/CaptchaNojsLayoutV1.java
  7. 18
      Clover/app/src/main/java/org/floens/chan/ui/captcha/v2/CaptchaNoJsLayoutV2.java
  8. 7
      Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java

@ -37,7 +37,6 @@ import org.floens.chan.core.site.http.Reply;
import org.floens.chan.core.site.http.ReplyResponse;
import org.floens.chan.ui.captcha.AuthenticationLayoutCallback;
import org.floens.chan.ui.captcha.AuthenticationLayoutInterface;
import org.floens.chan.ui.captcha.v2.CaptchaNoJsLayoutV2;
import org.floens.chan.ui.helper.ImagePickDelegate;
import org.floens.chan.utils.Logger;
@ -283,8 +282,7 @@ public class ReplyPresenter implements AuthenticationLayoutCallback, ImagePickDe
// we don't need this to be called for new captcha window.
// Otherwise "Request captcha request is already in progress" message will be shown
if (!(authenticationLayout instanceof CaptchaNoJsLayoutV2)) {
// should this be called here?
if (authenticationLayout.requireResetAfterComplete()) {
authenticationLayout.reset();
}

@ -24,5 +24,9 @@ public interface AuthenticationLayoutInterface {
void reset();
boolean requireResetAfterComplete();
void hardReset();
void onDestroy();
}

@ -121,6 +121,15 @@ public class CaptchaLayout extends WebView implements AuthenticationLayoutInterf
loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null);
}
@Override
public boolean requireResetAfterComplete() {
return true;
}
@Override
public void onDestroy() {
}
private void onCaptchaLoaded() {
}

@ -80,6 +80,16 @@ public class GenericWebViewAuthenticationLayout extends WebView implements Authe
public void hardReset() {
}
@Override
public boolean requireResetAfterComplete() {
return true;
}
@Override
public void onDestroy() {
}
private void checkText() {
loadUrl("javascript:WebInterface.onAllText(document.documentElement.textContent)");
}

@ -142,6 +142,16 @@ public class LegacyCaptchaLayout extends LinearLayout implements AuthenticationL
input.requestFocus();
}
@Override
public boolean requireResetAfterComplete() {
return true;
}
@Override
public void onDestroy() {
}
private void submitCaptcha() {
AndroidUtils.hideKeyboard(this);
callback.onAuthenticationComplete(this, challenge, input.getText().toString());

@ -133,11 +133,20 @@ public class CaptchaNojsLayoutV1 extends WebView implements AuthenticationLayout
hardReset();
}
@Override
public boolean requireResetAfterComplete() {
return true;
}
@Override
public void hardReset() {
loadRecaptchaAndSetWebViewData();
}
@Override
public void onDestroy() {
}
private void loadRecaptchaAndSetWebViewData() {
final String recaptchaUrl = "https://www.google.com/recaptcha/api/fallback?k=" + siteKey;

@ -152,6 +152,17 @@ public class CaptchaNoJsLayoutV2 extends FrameLayout
}
}
@Override
public boolean requireResetAfterComplete() {
return false;
}
@Override
public void onDestroy() {
adapter.onDestroy();
presenter.onDestroy();
}
@Override
public void onCaptchaInfoParsed(CaptchaInfo captchaInfo) {
// called on a background thread
@ -171,8 +182,8 @@ public class CaptchaNoJsLayoutV2 extends FrameLayout
callback.onAuthenticationComplete(this, null, verificationToken);
});
}
// Called when we got response from re-captcha but could not parse some part of it
@Override
public void onCaptchaInfoParseError(Throwable error) {
// called on a background thread
@ -289,9 +300,4 @@ public class CaptchaNoJsLayoutV2 extends FrameLayout
onCaptchaInfoParseError(error);
}
}
public void onDestroy() {
adapter.onDestroy();
presenter.onDestroy();
}
}

@ -365,12 +365,7 @@ public class ReplyLayout extends LoadView implements
return;
}
if (!(authenticationLayout instanceof CaptchaNoJsLayoutV2)) {
return;
}
// cleanup resources when switching from the new to the old captcha view
((CaptchaNoJsLayoutV2) authenticationLayout).onDestroy();
authenticationLayout.onDestroy();
captchaContainer.removeView((CaptchaNoJsLayoutV2) authenticationLayout);
authenticationLayout = null;
}

Loading…
Cancel
Save