Skip to content

Commit

Permalink
拆分webview
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Oct 9, 2022
1 parent 9f85686 commit 1c307f5
Show file tree
Hide file tree
Showing 34 changed files with 196 additions and 75 deletions.
35 changes: 22 additions & 13 deletions app/src/main/java/com/hss01248/imageloaderdemo/BaseApp.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package com.hss01248.imageloaderdemo;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.multidex.MultiDexApplication;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.blankj.utilcode.util.Utils;
import com.elvishew.xlog.XLog;
import com.github.piasy.biv.BigImageViewer;
import com.github.piasy.biv.view.BigImageView;
import com.hjq.permissions.XXPermissions;
import com.hss.downloader.BuildConfig;
import com.hss.downloader.DownloadList;
import com.hss.downloader.DownloadUrls;
import com.hss.downloader.ILargeImagesViewer;
import com.hss.downloader.MyDownloader;
import com.hss01248.basewebview.BaseWebviewActivity;
import com.hss01248.basewebview.IDownloader;
import com.hss01248.basewebview.WebConfigger;
import com.hss01248.basewebview.WebviewInit;
import com.hss01248.dialog.MyActyManager;
import com.hss01248.dialog.StyledDialog;

import com.hss01248.dokit.IDokitConfig;
import com.hss01248.dokit.MyDokit;
import com.hss01248.flipper.DBAspect;
Expand All @@ -34,19 +31,15 @@
import com.hss01248.image.config.GlobalConfig;
import com.hss01248.image.config.SingleConfig;
import com.hss01248.image.interfaces.LoadInterceptor;

import com.hss01248.imagelist.album.IViewInit;
import com.hss01248.imagelist.album.ImageListView;
import com.hss01248.imagelist.album.ImageMediaCenterUtil;
import com.hss01248.notifyutil.NotifyUtil;
import com.hss01248.webviewspider.IShowUrls;
import com.hss01248.webviewspider.SpiderWebviewActivity;
import com.hss01248.webviewspider.basewebview.BaseWebviewActivity;
import com.hss01248.webviewspider.basewebview.WebConfigger;
import com.hss01248.webviewspider.basewebview.WebviewInit;


import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -93,6 +86,22 @@ public void report(Object o) {
public Class html5ActivityClass() {
return BaseWebviewActivity.class;
}

@Override
public IDownloader getIDownloader() {
return new IDownloader() {
@Override
public void doDownload(String url, String name,String dir) {
List<DownloadUrls> downloadInfos = new ArrayList<>();
DownloadUrls info = new DownloadUrls();
info.url = url;
info.name = name;
info.dir = dir;//Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
downloadInfos.add(info);
MyDownloader.download(downloadInfos);
}
};
}
});


Expand Down
1 change: 1 addition & 0 deletions baseWebview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions baseWebview/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30

defaultConfig {
minSdkVersion 19
targetSdkVersion 30

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
viewBinding {
enabled = true
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

api 'com.github.Justson.AgentWeb:agentweb-core:v4.1.9-androidx' // (必选)
api 'com.github.hss01248:PageStateManager:3.0.5'
api "androidx.lifecycle:lifecycle-common-java8:2.1.0"
implementation "com.github.hss01248.StartActivityResult:activityresult:1.1.6"
api 'com.github.skyNet2017:webviewdebug:1.2.2-from117'
//api 'com.github.getActivity:TitleBar:9.2'
api 'com.github.hss01248:UI:0.0.1'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

//api 'org.jsoup:jsoup:1.11.2'
api 'com.blankj:utilcodex:1.30.6'
}
Empty file added baseWebview/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions baseWebview/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hss01248.basewebview;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.hss01248.basewebview.test", appContext.getPackageName());
}
}
10 changes: 10 additions & 0 deletions baseWebview/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hss01248.basewebview">

<application>
<activity android:name=".BaseWebviewActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import android.app.Activity;
import android.content.Context;
Expand All @@ -7,7 +7,6 @@
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
Expand All @@ -17,11 +16,8 @@
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -31,12 +27,10 @@

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.hss01248.basewebview.databinding.TitlebarForWebviewBinding;
import com.hss01248.pagestate.PageStateConfig;
import com.hss01248.pagestate.PageStateManager;
import com.hss01248.webviewspider.R;
import com.hss01248.webviewspider.databinding.TitlebarForWebviewBinding;
import com.just.agentweb.AgentWeb;
import com.just.agentweb.AgentWebUIControllerImplBase;
import com.just.agentweb.WebViewClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;

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

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hss01248.webviewspider.R;


public class BaseWebviewActivity extends AppCompatActivity implements ISetWebviewHolder{

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.hss01248.basewebview;

public interface IDownloader {

void doDownload(String url, String name,String dir);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;



Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -19,7 +17,6 @@
import com.blankj.utilcode.util.LogUtils;
import com.hss01248.activityresult.StartActivityUtil;
import com.hss01248.activityresult.TheActivityListener;
import com.hss01248.webviewspider.R;

public class JsCreateNewWinImpl {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import android.content.Context;
import android.os.Build;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.blankj.utilcode.util.NetworkUtils;

import uk.co.alt236.webviewdebug.DebugWebChromeClient;
import uk.co.alt236.webviewdebug.DebugWebViewClient;

public class WebConfigger {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import android.app.Activity;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hss01248.webviewspider.basewebview;
package com.hss01248.basewebview;

import android.Manifest;
import android.app.Activity;
Expand All @@ -11,23 +11,20 @@
import android.webkit.URLUtil;

import androidx.appcompat.app.AlertDialog;
import androidx.core.os.EnvironmentCompat;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.Utils;
import com.hss.downloader.DownloadUrls;
import com.hss.downloader.MyDownloader;
import com.hss.downloader.download.DownloadInfo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class WebviewDownlader implements DownloadListener {

@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
LogUtils.i(url,userAgent,contentDisposition,mimetype,contentLength);
Expand Down Expand Up @@ -86,13 +83,17 @@ public void onClick(DialogInterface dialog, int which) {
}

private void doDownload(String url, String name) {
List<DownloadUrls> downloadInfos = new ArrayList<>();

String dir = subDir(getRightDir(),url);
//Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
WebConfigger.getInit().getIDownloader().doDownload(url, name,dir);
/* List<DownloadUrls> downloadInfos = new ArrayList<>();
DownloadUrls info = new DownloadUrls();
info.url = url;
info.name = name;
info.dir = subDir(getRightDir(),url);//Utils.getApp().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
downloadInfos.add(info);
MyDownloader.download(downloadInfos);
MyDownloader.download(downloadInfos);*/
}

private String subDir(String rightDir, String url) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hss01248.basewebview;

public interface WebviewInit {

Class html5ActivityClass();

IDownloader getIDownloader();

}
Loading

0 comments on commit 1c307f5

Please sign in to comment.