Captcha work

multisite
Floens 8 years ago
parent 7dc977eedf
commit 5fec88804f
  1. 19
      Clover/app/src/main/java/org/floens/chan/core/presenter/ReplyPresenter.java
  2. 2
      Clover/app/src/main/java/org/floens/chan/core/site/Site.java
  3. 10
      Clover/app/src/main/java/org/floens/chan/core/site/SiteAuthentication.java
  4. 17
      Clover/app/src/main/java/org/floens/chan/core/site/sites/chan4/Chan4.java
  5. 2
      Clover/app/src/main/java/org/floens/chan/ui/captcha/CaptchaCallback.java
  6. 2
      Clover/app/src/main/java/org/floens/chan/ui/captcha/CaptchaLayout.java
  7. 2
      Clover/app/src/main/java/org/floens/chan/ui/captcha/CaptchaLayoutInterface.java
  8. 3
      Clover/app/src/main/java/org/floens/chan/ui/captcha/LegacyCaptchaLayout.java
  9. 23
      Clover/app/src/main/java/org/floens/chan/ui/layout/ReplyLayout.java
  10. 4
      Clover/app/src/main/res/layout/layout_captcha_legacy.xml

@ -32,13 +32,14 @@ import org.floens.chan.core.model.Post;
import org.floens.chan.core.model.SavedReply;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.core.site.Site;
import org.floens.chan.core.site.SiteAuthentication;
import org.floens.chan.core.site.http.HttpCall;
import org.floens.chan.core.site.http.HttpCallManager;
import org.floens.chan.core.site.http.ReplyResponse;
import org.floens.chan.core.site.http.Reply;
import org.floens.chan.ui.helper.ImagePickDelegate;
import org.floens.chan.ui.layout.CaptchaCallback;
import org.floens.chan.ui.layout.CaptchaLayoutInterface;
import org.floens.chan.ui.captcha.CaptchaCallback;
import org.floens.chan.ui.captcha.CaptchaLayoutInterface;
import java.io.File;
import java.nio.charset.Charset;
@ -55,7 +56,7 @@ import static org.floens.chan.utils.AndroidUtils.getString;
public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImagePickCallback, Site.PostListener {
public enum Page {
INPUT,
CAPTCHA,
AUTHENTICATION,
LOADING
}
@ -149,7 +150,7 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP
public boolean onBack() {
if (page == Page.LOADING) {
return true;
} else if (page == Page.CAPTCHA) {
} else if (page == Page.AUTHENTICATION) {
switchPage(Page.INPUT, true);
return true;
} else if (moreOpen) {
@ -200,10 +201,10 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP
draft.spoilerImage = draft.spoilerImage && board.spoilers;
draft.captchaResponse = null;
if (loadable.getSite().isLoggedIn()) {
makeSubmitCall();
if (loadable.getSite().authentication().requireAuthentication(SiteAuthentication.AuthenticationRequestType.POSTING)) {
switchPage(Page.AUTHENTICATION, true);
} else {
switchPage(Page.CAPTCHA, true);
makeSubmitCall();
}
}
@ -346,8 +347,8 @@ public class ReplyPresenter implements CaptchaCallback, ImagePickDelegate.ImageP
case INPUT:
callback.setPage(Page.INPUT, animate);
break;
case CAPTCHA:
callback.setPage(Page.CAPTCHA, true);
case AUTHENTICATION:
callback.setPage(Page.AUTHENTICATION, true);
if (!captchaInited) {
captchaInited = true;

@ -117,6 +117,8 @@ public interface Site {
SiteRequestModifier requestModifier();
SiteAuthentication authentication();
BoardsType boardsType();
String desktopUrl(Loadable loadable, @Nullable Post post);

@ -0,0 +1,10 @@
package org.floens.chan.core.site;
public interface SiteAuthentication {
enum AuthenticationRequestType {
POSTING
}
boolean requireAuthentication(AuthenticationRequestType type);
}

@ -34,6 +34,7 @@ import org.floens.chan.core.model.Post;
import org.floens.chan.core.settings.StringSetting;
import org.floens.chan.core.site.Boards;
import org.floens.chan.core.site.Site;
import org.floens.chan.core.site.SiteAuthentication;
import org.floens.chan.core.site.SiteEndpoints;
import org.floens.chan.core.site.SiteRequestModifier;
import org.floens.chan.core.site.http.DeleteRequest;
@ -230,6 +231,17 @@ public class Chan4 implements Site {
}
};
private SiteAuthentication authentication = new SiteAuthentication() {
@Override
public boolean requireAuthentication(AuthenticationRequestType type) {
if (type == AuthenticationRequestType.POSTING) {
return !isLoggedIn();
}
return false;
}
};
// Legacy settings that were global before
private final StringSetting passUser;
private final StringSetting passPass;
@ -334,6 +346,11 @@ public class Chan4 implements Site {
return siteRequestModifier;
}
@Override
public SiteAuthentication authentication() {
return authentication;
}
@Override
public void boards(final BoardsListener listener) {
requestQueue.add(new Chan4BoardsRequest(this, new Response.Listener<List<Board>>() {

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
package org.floens.chan.ui.captcha;
public interface CaptchaCallback {
void captchaLoaded(CaptchaLayoutInterface captchaLayout);

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
package org.floens.chan.ui.captcha;
import android.annotation.SuppressLint;
import android.content.Context;

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
package org.floens.chan.ui.captcha;
public interface CaptchaLayoutInterface {
void initCaptcha(String baseUrl, String siteKey, boolean lightTheme, CaptchaCallback callback);

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.layout;
package org.floens.chan.ui.captcha;
import android.annotation.SuppressLint;
import android.content.Context;
@ -54,7 +54,6 @@ public class LegacyCaptchaLayout extends LinearLayout implements CaptchaLayoutIn
private String challenge;
public LegacyCaptchaLayout(Context context) {
super(context);
}

@ -41,6 +41,9 @@ import org.floens.chan.core.site.http.Reply;
import org.floens.chan.core.presenter.ReplyPresenter;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.activity.StartActivity;
import org.floens.chan.ui.captcha.CaptchaCallback;
import org.floens.chan.ui.captcha.CaptchaLayout;
import org.floens.chan.ui.captcha.CaptchaLayoutInterface;
import org.floens.chan.ui.drawable.DropdownArrowDrawable;
import org.floens.chan.ui.helper.HintPopup;
import org.floens.chan.ui.helper.ImagePickDelegate;
@ -67,7 +70,7 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
private View replyInputLayout;
private FrameLayout captchaContainer;
private ImageView captchaHardReset;
private CaptchaLayoutInterface captchaLayout;
private CaptchaLayoutInterface authenticationLayout;
private boolean openingName;
private boolean blockSelectionChange = false;
@ -209,7 +212,7 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
}/* else if (v == preview) {
// TODO
}*/ else if (v == captchaHardReset) {
captchaLayout.hardReset();
authenticationLayout.hardReset();
}
}
@ -228,14 +231,14 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
case INPUT:
setView(replyInputLayout);
break;
case CAPTCHA:
if (captchaLayout == null) {
case AUTHENTICATION:
if (authenticationLayout == null) {
if (newCaptcha) {
captchaLayout = new CaptchaLayout(getContext());
authenticationLayout = new CaptchaLayout(getContext());
} else {
captchaLayout = (CaptchaLayoutInterface) LayoutInflater.from(getContext()).inflate(R.layout.layout_captcha_legacy, captchaContainer, false);
authenticationLayout = (CaptchaLayoutInterface) LayoutInflater.from(getContext()).inflate(R.layout.layout_captcha_legacy, captchaContainer, false);
}
captchaContainer.addView((View) captchaLayout, 0);
captchaContainer.addView((View) authenticationLayout, 0);
}
if (newCaptcha) {
@ -250,13 +253,13 @@ public class ReplyLayout extends LoadView implements View.OnClickListener, Anima
@Override
public void initCaptcha(String baseUrl, String siteKey, CaptchaCallback callback) {
captchaLayout.initCaptcha(baseUrl, siteKey, ThemeHelper.getInstance().getTheme().isLightTheme, callback);
captchaLayout.reset();
authenticationLayout.initCaptcha(baseUrl, siteKey, ThemeHelper.getInstance().getTheme().isLightTheme, callback);
authenticationLayout.reset();
}
@Override
public void resetCaptcha() {
captchaLayout.reset();
authenticationLayout.reset();
}
@Override

@ -15,7 +15,7 @@ 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/>.
-->
<org.floens.chan.ui.layout.LegacyCaptchaLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.floens.chan.ui.captcha.LegacyCaptchaLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@ -50,4 +50,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</LinearLayout>
</org.floens.chan.ui.layout.LegacyCaptchaLayout>
</org.floens.chan.ui.captcha.LegacyCaptchaLayout>

Loading…
Cancel
Save