Skip to content

Commit

Permalink
Merge pull request #580 from LoxiaLiSA/master
Browse files Browse the repository at this point in the history
web novel
  • Loading branch information
CeuiLiSA authored Mar 1, 2024
2 parents 859a011 + e0177bc commit 7279c6b
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 55 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "ceui.lisa.pixiv"
minSdkVersion 21
targetSdkVersion 33
versionCode 260
versionName "3.3.5"
versionCode 262
versionName "3.3.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/ceui/lisa/activities/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,13 @@ private void updateTheme() {
break;
}
}

protected long tryParseId(String str) {
try {
return Long.parseLong(str);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
}
12 changes: 6 additions & 6 deletions app/src/main/java/ceui/lisa/activities/OutWakeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void initData() {
List<String> pathArray = uri.getPathSegments();
String illustID = pathArray.get(pathArray.size() - 1);
if (!TextUtils.isEmpty(illustID)) {
PixivOperate.getIllustByID(Shaft.sUserModel, Integer.parseInt(illustID), mContext, new Callback<Void>() {
PixivOperate.getIllustByID(Shaft.sUserModel, tryParseId(illustID), mContext, new Callback<Void>() {
@Override
public void doSomething(Void t) {
finish();
Expand All @@ -93,7 +93,7 @@ public void doSomething(Void t) {
List<String> pathArray = uri.getPathSegments();
novelId = pathArray.get(pathArray.size() - 1);
}
PixivOperate.getNovelByID(sUserModel, Integer.parseInt(novelId), mContext, new Callback<Void>() {
PixivOperate.getNovelByID(sUserModel, tryParseId(novelId), mContext, new Callback<Void>() {
@Override
public void doSomething(Void t) {
finish();
Expand Down Expand Up @@ -126,7 +126,7 @@ public void doSomething(Void t) {
String idString = end.split("_")[0];

Common.showLog("end " + end + " idString " + idString);
PixivOperate.getIllustByID(Shaft.sUserModel, Integer.parseInt(idString), mContext, new Callback<Void>() {
PixivOperate.getIllustByID(Shaft.sUserModel, tryParseId(idString), mContext, new Callback<Void>() {
@Override
public void doSomething(Void t) {
finish();
Expand Down Expand Up @@ -158,7 +158,7 @@ public void doSomething(Void t) {

String illustID = uri.getQueryParameter("illust_id");
if (!TextUtils.isEmpty(illustID)) {
PixivOperate.getIllustByID(Shaft.sUserModel, Integer.parseInt(illustID), mContext, new Callback<Void>() {
PixivOperate.getIllustByID(Shaft.sUserModel, tryParseId(illustID), mContext, new Callback<Void>() {
@Override
public void doSomething(Void t) {
finish();
Expand Down Expand Up @@ -262,14 +262,14 @@ public void onClick(QMUIDialog dialog, int index) {

if (host.contains("illusts")) {
String path = uri.getPath();
PixivOperate.getIllustByID(Shaft.sUserModel, Integer.parseInt(path.substring(1)),
PixivOperate.getIllustByID(Shaft.sUserModel, tryParseId(path.substring(1)),
mContext, t -> finish(),null);
return;
}

if (host.contains("novels")) {
String path = uri.getPath();
PixivOperate.getNovelByID(Shaft.sUserModel, Integer.parseInt(path.substring(1)),
PixivOperate.getNovelByID(Shaft.sUserModel, tryParseId(path.substring(1)),
mContext, t -> finish());
return;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/activities/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ else if(Common.isNumeric(trimmedKeyword)){
.create();
tipDialog.show();
//先假定为作品id
PixivOperate.getIllustByID(sUserModel, Integer.parseInt(trimmedKeyword), mContext, new Callback<Void>() {
PixivOperate.getIllustByID(sUserModel, tryParseId(trimmedKeyword), mContext, new Callback<Void>() {
@Override
public void doSomething(Void t) {
PixivOperate.insertSearchHistory(trimmedKeyword, SearchTypeUtil.SEARCH_TYPE_DB_ILLUSTSID);
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/ceui/lisa/core/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public void restore() {
content = new ArrayList<>();
}
for (DownloadingEntity entity : downloadingEntities) {
DownloadItem downloadItem = Shaft.sGson.fromJson(entity.getTaskGson(), DownloadItem.class);
content.add(downloadItem);
try {
DownloadItem downloadItem = Shaft.sGson.fromJson(entity.getTaskGson(), DownloadItem.class);
content.add(downloadItem);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Common.showToast("下载记录恢复成功");
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/ceui/lisa/fragments/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,13 @@ public void finish() {
public void initModel() {

}

protected long tryParseId(String str) {
try {
return Long.parseLong(str);
} catch (Exception ex) {
ex.printStackTrace();
}
return 0;
}
}
15 changes: 11 additions & 4 deletions app/src/main/java/ceui/lisa/fragments/FragmentDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import ceui.lisa.R;
import ceui.lisa.activities.Shaft;
import ceui.lisa.adapters.BaseAdapter;
import ceui.lisa.core.Manager;
import ceui.lisa.database.AppDatabase;
import ceui.lisa.databinding.ViewpagerWithTablayoutBinding;
Expand Down Expand Up @@ -74,13 +75,19 @@ public void onClick(QMUIDialog dialog, int index) {
return true;
} else if (item.getItemId() == R.id.action_start) {
Manager.get().startAll();
if(allPages[0] instanceof FragmentDownloading){
((FragmentDownloading) allPages[0]).mAdapter.notifyDataSetChanged();
if (allPages[0] instanceof FragmentDownloading){
final BaseAdapter<?, ?> adapter = ((FragmentDownloading) allPages[0]).mAdapter;
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
} else if (item.getItemId() == R.id.action_stop) {
Manager.get().stopAll();
if(allPages[0] instanceof FragmentDownloading){
((FragmentDownloading) allPages[0]).mAdapter.notifyDataSetChanged();
if (allPages[0] instanceof FragmentDownloading){
final BaseAdapter<?, ?> adapter = ((FragmentDownloading) allPages[0]).mAdapter;
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
} else if (item.getItemId() == R.id.action_clear) {
if (allPages[0] instanceof FragmentDownloading &&
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/ceui/lisa/fragments/FragmentImageDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,24 @@ private void loadImage() {
baseBind.emptyFrame.setVisibility(View.GONE);
baseBind.progressLayout.getRoot().setVisibility(View.VISIBLE);
String imageUrl;
baseBind.bigImage.setMaxScale(3.5F);
baseBind.bigImage.setDoubleTapZoomScale(2F);
if (mIllustsBean == null && !TextUtils.isEmpty(url)) {
setUpMediumResolutionDoubleTap();
imageUrl = url;
} else {
final String originUrl = IllustDownload.getUrl(mIllustsBean, index);
if (Shaft.getMMKV().decodeBool(originUrl)) {
setUpHighResolutionDoubleTap();
imageUrl = originUrl;
} else {
if (!TextUtils.isEmpty(url)) {
setUpMediumResolutionDoubleTap();
imageUrl = url;
} else {
if (Shaft.sSettings.isShowOriginalImage()) {
setUpHighResolutionDoubleTap();
imageUrl = IllustDownload.getUrl(mIllustsBean, index, Params.IMAGE_RESOLUTION_ORIGINAL);
} else {
setUpMediumResolutionDoubleTap();
imageUrl = IllustDownload.getUrl(mIllustsBean, index, Params.IMAGE_RESOLUTION_LARGE);
}
}
Expand Down Expand Up @@ -156,6 +159,16 @@ protected void onResourceCleared(@Nullable Drawable placeholder) {
});
}

private void setUpHighResolutionDoubleTap() {
baseBind.bigImage.setMaxScale(3.8F);
baseBind.bigImage.setDoubleTapZoomScale(1.8F);
}

private void setUpMediumResolutionDoubleTap() {
baseBind.bigImage.setMaxScale(7F);
baseBind.bigImage.setDoubleTapZoomScale(4F);
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down
27 changes: 17 additions & 10 deletions app/src/main/java/ceui/lisa/fragments/FragmentNovelHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Collections;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import ceui.lisa.R;
Expand Down Expand Up @@ -55,6 +56,9 @@
import gdut.bsx.share2.ShareContentType;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

public class FragmentNovelHolder extends BaseFragment<FragmentNovelHolderBinding> {

Expand Down Expand Up @@ -226,21 +230,24 @@ public void onClick(View v) {
refreshDetail(mNovelDetail);
} else {
baseBind.progressRela.setVisibility(View.VISIBLE);
Retro.getAppApi().getNovelDetail(Shaft.sUserModel.getAccess_token(), novelBean.getId())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new NullCtrl<NovelDetail>() {
Retro.getAppApi().getNovelDetailV2(Shaft.sUserModel.getAccess_token(), novelBean.getId()).enqueue(new retrofit2.Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
baseBind.progressRela.setVisibility(View.INVISIBLE);
new WebNovelParser(response) {
@Override
public void success(NovelDetail novelDetail) {
public void onNovelPrepared(@NonNull NovelDetail novelDetail) {
novelDetail.setParsedChapters(NovelParseHelper.tryParseChapters(novelDetail.getNovel_text()));
refreshDetail(novelDetail);
}
};
}

@Override
public void must(boolean isSuccess) {
baseBind.progressRela.setVisibility(View.INVISIBLE);
}
});
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
baseBind.progressRela.setVisibility(View.INVISIBLE);
}
});
}

baseBind.toolbar.setOnTouchListener(new View.OnTouchListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.ViewDataBinding;

Expand All @@ -23,6 +24,7 @@
import ceui.lisa.core.BaseRepo;
import ceui.lisa.databinding.FragmentNovelSeriesBinding;
import ceui.lisa.download.IllustDownload;
import ceui.lisa.helper.NovelParseHelper;
import ceui.lisa.http.NullCtrl;
import ceui.lisa.http.Retro;
import ceui.lisa.interfaces.Callback;
Expand All @@ -38,6 +40,9 @@
import ceui.lisa.utils.PixivOperate;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

public class FragmentNovelSeriesDetail extends NetListFragment<FragmentNovelSeriesBinding,
ListNovelOfSeries, NovelBean> {
Expand Down Expand Up @@ -69,16 +74,21 @@ public boolean onMenuItemClick(MenuItem item) {
if (novelBean.isLocalSaved()) {
saveNovelToDownload(novelBean, Cache.get().getModel(Params.NOVEL_KEY + novelBean.getId(), NovelDetail.class));
} else {
Retro.getAppApi().getNovelDetail(Shaft.sUserModel.getAccess_token(), novelBean.getId())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new NullCtrl<NovelDetail>() {

Retro.getAppApi().getNovelDetailV2(Shaft.sUserModel.getAccess_token(), novelBean.getId()).enqueue(new retrofit2.Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
new WebNovelParser(response) {
@Override
public void success(NovelDetail novelDetail) {
public void onNovelPrepared(@NonNull NovelDetail novelDetail) {
saveNovelToDownload(novelBean, novelDetail);
}
});
};
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
}
} else if (item.getItemId() == R.id.batch_download_as_one) {
Expand All @@ -94,13 +104,12 @@ public void success(NovelDetail novelDetail) {
saveNovelSeriesToDownload(mResponse.getNovel_series_detail(), content);
}
} else {
Retro.getAppApi().getNovelDetail(Shaft.sUserModel.getAccess_token(), novelBean.getId())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new NullCtrl<NovelDetail>() {

Retro.getAppApi().getNovelDetailV2(Shaft.sUserModel.getAccess_token(), novelBean.getId()).enqueue(new retrofit2.Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
new WebNovelParser(response) {
@Override
public void success(NovelDetail novelDetail) {
public void onNovelPrepared(@NonNull NovelDetail novelDetail) {
String sb = lineSeparator + novelBean.getTitle() + " - " + novelBean.getId() + lineSeparator +
novelDetail.getNovel_text();
taskContainer.put(novelBean.getId(), sb);
Expand All @@ -109,7 +118,13 @@ public void success(NovelDetail novelDetail) {
saveNovelSeriesToDownload(mResponse.getNovel_series_detail(), content);
}
}
});
};
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}
}
}
Expand Down
Loading

0 comments on commit 7279c6b

Please sign in to comment.