|
|
@ -3,7 +3,9 @@ package xyz.fycz.myreader.ui.fragment; |
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.Intent; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
|
|
|
|
import android.os.Parcelable; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
import android.util.Log; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.MenuInflater; |
|
|
|
import android.view.MenuInflater; |
|
|
@ -23,6 +25,8 @@ import com.kongzue.dialogx.dialogs.BottomMenu; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import io.reactivex.Observable; |
|
|
|
import io.reactivex.Observable; |
|
|
@ -50,6 +54,7 @@ import xyz.fycz.myreader.ui.dialog.LoadingDialog; |
|
|
|
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; |
|
|
|
import xyz.fycz.myreader.ui.dialog.MyAlertDialog; |
|
|
|
import xyz.fycz.myreader.util.ShareUtils; |
|
|
|
import xyz.fycz.myreader.util.ShareUtils; |
|
|
|
import xyz.fycz.myreader.util.ToastUtils; |
|
|
|
import xyz.fycz.myreader.util.ToastUtils; |
|
|
|
|
|
|
|
import xyz.fycz.myreader.util.UriFileUtil; |
|
|
|
import xyz.fycz.myreader.util.utils.ClipBoardUtil; |
|
|
|
import xyz.fycz.myreader.util.utils.ClipBoardUtil; |
|
|
|
import xyz.fycz.myreader.util.utils.FileUtils; |
|
|
|
import xyz.fycz.myreader.util.utils.FileUtils; |
|
|
|
import xyz.fycz.myreader.util.utils.GsonExtensionsKt; |
|
|
|
import xyz.fycz.myreader.util.utils.GsonExtensionsKt; |
|
|
@ -67,6 +72,7 @@ import static xyz.fycz.myreader.util.UriFileUtil.getPath; |
|
|
|
* @date 2021/2/10 12:05 |
|
|
|
* @date 2021/2/10 12:05 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DIYSourceFragment extends BaseFragment { |
|
|
|
public class DIYSourceFragment extends BaseFragment { |
|
|
|
|
|
|
|
private static final String TAG = DIYSourceFragment.class.getSimpleName(); |
|
|
|
private FragmentImportSourceBinding binding; |
|
|
|
private FragmentImportSourceBinding binding; |
|
|
|
|
|
|
|
|
|
|
|
private final BookSourceActivity sourceActivity; |
|
|
|
private final BookSourceActivity sourceActivity; |
|
|
@ -182,11 +188,13 @@ public class DIYSourceFragment extends BaseFragment { |
|
|
|
ToastUtils.showError("剪切板内容为空,导入失败"); |
|
|
|
ToastUtils.showError("剪切板内容为空,导入失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (which == 1) { |
|
|
|
} else if (which == 1) { |
|
|
|
ToastUtils.showInfo("请选择书源JSON文件"); |
|
|
|
StoragePermissionUtils.request(this, (permissions, all) -> { |
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
|
|
|
ToastUtils.showInfo("请选择书源文件"); |
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE); |
|
|
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT) |
|
|
|
intent.setType("application/json"); |
|
|
|
.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"text/*", "application/json"}) |
|
|
|
startActivityForResult(intent, APPCONST.REQUEST_IMPORT_BOOK_SOURCE); |
|
|
|
.setType("*/*"); |
|
|
|
|
|
|
|
startActivityForResult(intent, APPCONST.REQUEST_IMPORT_BOOK_SOURCE); |
|
|
|
|
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
String[] url = new String[1]; |
|
|
|
String[] url = new String[1]; |
|
|
|
MyAlertDialog.createInputDia(getContext(), "网络导入", |
|
|
|
MyAlertDialog.createInputDia(getContext(), "网络导入", |
|
|
@ -236,19 +244,19 @@ public class DIYSourceFragment extends BaseFragment { |
|
|
|
refreshSources(); |
|
|
|
refreshSources(); |
|
|
|
ToastUtils.showSuccess(String.format("成功导入%s个书源", size)); |
|
|
|
ToastUtils.showSuccess(String.format("成功导入%s个书源", size)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ToastUtils.showError("格式不对"); |
|
|
|
ToastUtils.showError("书源格式错误,请导入正确的书源"); |
|
|
|
} |
|
|
|
} |
|
|
|
dialog.dismiss(); |
|
|
|
dialog.dismiss(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onError(Throwable e) { |
|
|
|
public void onError(Throwable e) { |
|
|
|
ToastUtils.showError("格式不对"); |
|
|
|
ToastUtils.showError("书源格式错误,请导入正确的书源"); |
|
|
|
dialog.dismiss(); |
|
|
|
dialog.dismiss(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ToastUtils.showError("导入失败"); |
|
|
|
ToastUtils.showError("书源格式错误,请导入正确的书源"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -303,13 +311,35 @@ public class DIYSourceFragment extends BaseFragment { |
|
|
|
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
|
|
|
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
|
|
|
if (resultCode == RESULT_OK) { |
|
|
|
if (resultCode == RESULT_OK) { |
|
|
|
if (requestCode == APPCONST.REQUEST_IMPORT_BOOK_SOURCE) { |
|
|
|
if (requestCode == APPCONST.REQUEST_IMPORT_BOOK_SOURCE) { |
|
|
|
String path = getPath(getContext(), data.getData()); |
|
|
|
LoadingDialog dialog = new LoadingDialog(getContext(), "读取文件", () -> { |
|
|
|
String json = FileUtils.readText(path); |
|
|
|
if (importSourceDis != null) { |
|
|
|
if (!isEmpty(json)) { |
|
|
|
importSourceDis.dispose(); |
|
|
|
importDataS(json); |
|
|
|
} |
|
|
|
} else { |
|
|
|
}); |
|
|
|
ToastUtils.showError("文件读取失败"); |
|
|
|
dialog.show(); |
|
|
|
} |
|
|
|
Single.create((SingleOnSubscribe<String>) emitter -> { |
|
|
|
|
|
|
|
String path = UriFileUtil.getChooseFileResultPath(getContext(), data.getData()); |
|
|
|
|
|
|
|
Log.d(TAG, "filePath:" + path); |
|
|
|
|
|
|
|
emitter.onSuccess(path); |
|
|
|
|
|
|
|
}).compose(RxUtils::toSimpleSingle).subscribe(new MySingleObserver<String>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSubscribe(Disposable d) { |
|
|
|
|
|
|
|
importSourceDis = d; |
|
|
|
|
|
|
|
addDisposable(d); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSuccess(@NonNull String s) { |
|
|
|
|
|
|
|
importDataS(s); |
|
|
|
|
|
|
|
dialog.dismiss(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
|
|
|
ToastUtils.showError("文件读取失败"); |
|
|
|
|
|
|
|
dialog.dismiss(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} else if (requestCode == APPCONST.REQUEST_EDIT_BOOK_SOURCE) { |
|
|
|
} else if (requestCode == APPCONST.REQUEST_EDIT_BOOK_SOURCE) { |
|
|
|
refreshSources(); |
|
|
|
refreshSources(); |
|
|
|
} |
|
|
|
} |
|
|
|