Skip to content

Commit

Permalink
NClientV2 2.9.6
Browse files Browse the repository at this point in the history
+ Added button to hide the CF fetch
  • Loading branch information
Dar9586 committed Jun 27, 2022
1 parent c38079c commit 71c94f5
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import androidx.annotation.NonNull;

import com.dar.nclientv2.components.activities.GeneralActivity;
import com.dar.nclientv2.components.views.CFTokenView;
import com.dar.nclientv2.settings.Global;
import com.dar.nclientv2.utility.LogUtility;
import com.dar.nclientv2.utility.Utility;
Expand All @@ -17,6 +18,16 @@
public class CookieInterceptor {
private static volatile boolean intercepting = false;
private static final int MAX_RETRIES = 100;
private static volatile boolean webViewHidden=false;

public static void hideWebView(){
webViewHidden=true;
CFTokenView tokenView = GeneralActivity.getLastCFView();
if (tokenView != null){
tokenView.post(() -> tokenView.setVisibility(View.GONE));
}
}

@NonNull
private final Manager manager;
String cookies = null;
Expand All @@ -25,21 +36,22 @@ public CookieInterceptor(@NonNull Manager manager) {
this.manager = manager;
}

private WebView setupWebView() {
WebView webView = GeneralActivity.getLastWebView();
if (webView == null) return null;
webView.post(() -> {
private CFTokenView setupWebView() {
CFTokenView tokenView = GeneralActivity.getLastCFView();
if (tokenView == null) return null;
tokenView.post(() -> {
WebView webView=tokenView.getWebView();
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(Global.getUserAgent());
webView.loadUrl(Utility.getBaseUrl());
});
return webView;
return tokenView;
}

@NonNull
private WebView getWebView() {
WebView web = setupWebView();
private CFTokenView getWebView() {
CFTokenView web = setupWebView();
while (web == null) {
Utility.threadSleep(100);
web = setupWebView();
Expand All @@ -48,8 +60,9 @@ private WebView getWebView() {
}

private void interceptInternal() {
WebView web = getWebView();
web.post(() -> web.setVisibility(View.VISIBLE));
CFTokenView web = getWebView();
if(!webViewHidden)
web.post(() -> web.setVisibility(View.VISIBLE));
CookieManager manager = CookieManager.getInstance();
HashMap<String, String> cookiesMap = new HashMap<>();
int retryCount = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
package com.dar.nclientv2.components.activities;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.dar.nclientv2.R;
import com.dar.nclientv2.components.views.CFTokenView;
import com.dar.nclientv2.settings.Global;

import java.lang.ref.WeakReference;

public abstract class GeneralActivity extends AppCompatActivity {
private boolean isFastScrollerApplied = false;
private static WeakReference<GeneralActivity> lastActivity;
private WebView webView = null;
private CFTokenView tokenView = null;

public static @Nullable
WebView getLastWebView() {
CFTokenView getLastCFView() {
GeneralActivity activity = lastActivity.get();
if (activity != null) {
activity.runOnUiThread(activity::inflateWebView);
return activity.webView;
return activity.tokenView;
}
return null;
}

private void inflateWebView() {
if (webView == null) {
webView = new WebView(this);
if (tokenView == null) {
ViewGroup rootView= (ViewGroup) findViewById(android.R.id.content).getRootView();
ViewGroup v= (ViewGroup) LayoutInflater.from(this).inflate(R.layout.cftoken_layout,rootView,false);
tokenView = new CFTokenView(v);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
webView.setVisibility(View.GONE);
this.addContentView(webView, params);
tokenView.setVisibility(View.GONE);
this.addContentView(v, params);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.dar.nclientv2.components.views;

import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.Button;

import com.dar.nclientv2.R;
import com.dar.nclientv2.components.CookieInterceptor;

public class CFTokenView {

private final ViewGroup masterLayout;
private WebView webView;
private Button button;

public CFTokenView(ViewGroup masterLayout) {
this.masterLayout = masterLayout;
webView=masterLayout.findViewById(R.id.webView);
button=masterLayout.findViewById(R.id.hideWebView);
button.setOnClickListener(v -> CookieInterceptor.hideWebView());
}

public Button getButton() {
return button;
}

public WebView getWebView() {
return webView;
}

public void setVisibility(int visible) {
masterLayout.setVisibility(visible);
}

public void post(Runnable o) {
masterLayout.post(o);
}
}
28 changes: 28 additions & 0 deletions app/src/main/res/layout/cftoken_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:id="@+id/hideWebView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/hide"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<WebView
android:id="@+id/webView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</WebView>
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>أفقي</item>
<item>عمودي</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertikal</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr-rFR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it-rIT/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Orizzontale</item>
<item>Verticale</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Cloudflareトークンを取得しています …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>水平</item>
<item>垂直</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru-rRU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Горизонтальный</item>
<item>Вертикальный</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-tr-rTR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Cloudflare tokeni alınıyor…</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-uk-rUA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Горизонтально</item>
<item>Вертикально</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>水平</item>
<item>垂直</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>水準</item>
<item>垂直</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
<string name="fetching_cloudflare_token">Fetching Cloudflare token …</string>
<string name="exact_title_match_title">Exact tag match only</string>
<string name="exact_title_match_summary">Hide galleries which would appear in the site but doesn\'t contains all the tags searched</string>
<string name="hide">Hide</string>
<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
Expand Down

0 comments on commit 71c94f5

Please sign in to comment.