Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Initial steps to show the JS challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroCarrara committed Jan 22, 2021
1 parent e58ecdf commit b45b1ac
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ public boolean isNotFound() {
return exception instanceof HttpCodeException && ((HttpCodeException) exception).isServerErrorNotFound();
}

public boolean isNotAvailable() {
return exception instanceof HttpCodeException && ((HttpCodeException) exception).code == 503;
}

public int getErrorMessage() {
//by default, a network error has occurred if the exception field is not null
int errorMessage = exception != null ? R.string.thread_load_failed_network : R.string.empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ public void showBoardAndSearch(Loadable catalogLoadable, String searchQuery) {
setBoard(catalogLoadable.board);
}

@Override
public void showChallenge(Loadable loadable) {
ChallengeController c = new ChallengeController(context, loadable);

if (doubleNavigationController != null) {
doubleNavigationController.pushController(c);
} else {
navigationController.pushController(c);
}
}

// Creates or updates the target ViewThreadController
// This controller can be in various places depending on the layout, so we dynamically search for it
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.adamantcheese.chan.ui.controller;

import android.content.Context;
import android.webkit.WebView;

import com.github.adamantcheese.chan.controller.Controller;
import com.github.adamantcheese.chan.core.model.orm.Loadable;

public class ChallengeController extends Controller {
protected Loadable behindChallenge;

public ChallengeController(Context context, Loadable behindChallenge) {
super(context);
this.behindChallenge = behindChallenge;
}

@Override
public void onCreate() {
super.onCreate();

WebView web = new WebView(context);

web.loadUrl(behindChallenge.desktopUrl());
web.getSettings().setJavaScriptEnabled(true);
this.view = web;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.github.adamantcheese.chan.ui.toolbar.ToolbarMenuSubItem;
import com.github.adamantcheese.chan.ui.view.FloatingMenu;
import com.github.adamantcheese.chan.utils.AndroidUtils;
import com.github.adamantcheese.chan.utils.Logger;
import com.github.k1rakishou.fsaf.FileManager;
import com.skydoves.balloon.ArrowConstraints;
import com.skydoves.balloon.ArrowOrientation;
Expand Down Expand Up @@ -226,6 +227,11 @@ public void onEvent(PinMessages.PinsChangedMessage message) {
setPinIconState(true);
}

@Override
public void showChallenge(Loadable loadable) {
// TODO: Implement
}

@Override
public void showThread(final Loadable threadLoadable) {
if (threadLoadable.site instanceof ExternalSiteArchive && !loadable.site.equals(threadLoadable.site)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.github.adamantcheese.chan.ui.view.ThumbnailView;
import com.github.adamantcheese.chan.utils.AndroidUtils;
import com.github.adamantcheese.chan.utils.BackgroundUtils;
import com.github.adamantcheese.chan.utils.Logger;
import com.google.android.material.snackbar.Snackbar;

import java.util.ArrayList;
Expand Down Expand Up @@ -260,6 +261,10 @@ public void postClicked(Post post) {
public void showError(ChanThreadLoader.ChanLoaderException error) {
String errorMessage = getString(error.getErrorMessage());

if (error.isNotAvailable()) {
callback.showChallenge(presenter.getLoadable());
}

if (visible == Visible.THREAD) {
threadListLayout.showError(errorMessage);
} else {
Expand Down Expand Up @@ -764,6 +769,8 @@ public void showHideOrRemoveWholeChainDialog(boolean hide, Post post, int thread
}

public interface ThreadLayoutCallback {
void showChallenge(Loadable loadableBehindChallenge);

void showThread(Loadable threadLoadable);

void showBoard(Loadable catalogLoadable);
Expand Down

0 comments on commit b45b1ac

Please sign in to comment.