Skip to content

Commit

Permalink
优化ui和空指针异常
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Aug 28, 2021
1 parent 3a55d2a commit 06659ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.blankj.utilcode.util.Utils;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.hss01248.imagelist.download.db.DaoMaster;
Expand Down Expand Up @@ -37,6 +38,9 @@ static DaoSession getDaoSession() {
if (daoSession == null) {
synchronized (DownloadInfoUtil.class) {
if (daoSession == null) {
if(context == null){
context = Utils.getApp();
}
init(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.ValueCallback;
import android.widget.Button;
import android.widget.TextView;

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

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hss01248.ui.pop.list.PopList;
import com.hss01248.webviewspider.basewebview.BaseQuickWebview;
import com.hss01248.webviewspider.spider.IHtmlParser;
import com.hss01248.webviewspider.spider.ListToDetailImgsInfo;
import com.hss01248.webviewspider.spider.PexelImageParser;
import com.lzf.easyfloat.EasyFloat;
import com.lzf.easyfloat.enums.ShowPattern;

import java.io.File;
import java.io.FileFilter;
Expand Down Expand Up @@ -120,31 +126,43 @@ public void onClick(int position, String str) {

}
});

}

boolean isParsingList;

private void parseListUrlsAndShow() {
if(quickWebview == null){
return;
}
String url = quickWebview.getCurrentUrl();
ProgressDialog dialog = new ProgressDialog(this);
dialog.setCanceledOnTouchOutside(false);
//dialog.setCancelable(false);
dialog.show();
TextView textView = new TextView(this);
textView.setTextColor(Color.WHITE);
textView.setPadding(20,20,20,20);
textView.setBackground(new ColorDrawable(Color.parseColor("#66333333")));
textView.setText("爬取urllist start");
EasyFloat.with(this)
.setTag(url)
.setLayout(textView)
// .setGravity(Gravity.BOTTOM)
.setDragEnable(true)
.setShowPattern(ShowPattern.FOREGROUND)
.show();

quickWebview.loadSource(new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
runOnUiThread(new Runnable() {
@Override
public void run() {
isParsingList = true;
parser.parseListAndDetail(SpiderWebviewActivity.this,quickWebview.getInfo(), new ValueCallback<ListToDetailImgsInfo>() {
@Override
public void onReceiveValue(ListToDetailImgsInfo info) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismiss();
isParsingList = false;
EasyFloat.dismiss(url);
if (info.imagUrls.isEmpty()) {
quickWebview.loadSource(new ValueCallback<String>() {
@Override
Expand All @@ -166,18 +184,17 @@ public void onReceiveValue(String value) {
}, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
dialog.setMessage(value);
textView.setText("爬取urllist: "+value);
}
});
}
});

}
});


}


private String getSaveDir(String folderName, String subFolderName) {

//new File(System.getenv("EXTERNAL_STORAGE"));
Expand Down Expand Up @@ -264,6 +281,10 @@ public void onClick(DialogInterface dialog, int which) {

@Override
public void onBackPressed() {
if(isParsingList){
ToastUtils.showShort("正在爬取list,不可退出当前页面");
return;
}
if(quickWebview == null || !quickWebview.onBackPressed()){
super.onBackPressed();
}
Expand Down

0 comments on commit 06659ca

Please sign in to comment.