diff --git a/app/src/main/java/ceui/lisa/utils/PixivOperate.java b/app/src/main/java/ceui/lisa/utils/PixivOperate.java index f67907141..a17e185b2 100644 --- a/app/src/main/java/ceui/lisa/utils/PixivOperate.java +++ b/app/src/main/java/ceui/lisa/utils/PixivOperate.java @@ -65,6 +65,7 @@ import ceui.lisa.models.IllustsBean; import ceui.lisa.viewmodel.AppLevelViewModel; import ceui.loxia.ObjectPool; +import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import retrofit2.Call; @@ -74,10 +75,12 @@ import static com.blankj.utilcode.util.ColorUtils.getColor; import static com.blankj.utilcode.util.StringUtils.getString; - +/** + * A class about Pixiv operations. + */ public class PixivOperate { - private static final Map sBack = new HashMap<>(); + private static final Map sBack = new HashMap<>(); private static final Map gifEncodingWorkSet = new HashMap<>(); private static final long reEncodeTimeThresholdMillis = 60 * 1000; @@ -94,7 +97,7 @@ public static void refreshUserData(UserModel userModel, Callback call public static void postFollowUser(int userID, String followType) { String pendingFollowType = Shaft.sSettings.isPrivateStar() ? Params.TYPE_PRIVATE : followType; Retro.getAppApi().postFollow( - sUserModel.getAccess_token(), userID, pendingFollowType) + sUserModel.getAccess_token(), userID, pendingFollowType) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new ErrorCtrl() { @@ -120,7 +123,7 @@ public void next(NullResponse nullResponse) { public static void postUnFollowUser(int userID) { Retro.getAppApi().postUnFollow( - sUserModel.getAccess_token(), userID) + sUserModel.getAccess_token(), userID) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new ErrorCtrl() { @@ -140,7 +143,7 @@ public void next(NullResponse nullResponse) { public static void postLikeDefaultStarType(IllustsBean illustsBean) { if (Shaft.sSettings.isPrivateStar()) { postLike(illustsBean, Params.TYPE_PRIVATE, false, 0); - } else{ + } else { postLike(illustsBean, Params.TYPE_PUBLIC, false, 0); } } @@ -229,7 +232,7 @@ public void next(NullResponse nullResponse) { intent.putExtra(Params.IS_LIKED, false); LocalBroadcastManager.getInstance(Shaft.getContext()).sendBroadcast(intent); - if(view instanceof Button){ + if (view instanceof Button) { ((Button) view).setText(getString(R.string.string_180)); } Common.showToast(getString(R.string.cancel_like_illust)); @@ -249,7 +252,7 @@ public void next(NullResponse nullResponse) { intent.putExtra(Params.IS_LIKED, true); LocalBroadcastManager.getInstance(Shaft.getContext()).sendBroadcast(intent); - if(view instanceof Button){ + if (view instanceof Button) { ((Button) view).setText(getString(R.string.string_179)); } if (Params.TYPE_PUBLIC.equals(pendingType)) { @@ -262,32 +265,45 @@ public void next(NullResponse nullResponse) { } } + /** + * @param userModel The model of current user + * @param illustID The id of illustration user searching for + * @param context (In doubt)The current activity + */ public static void getIllustByID(UserModel userModel, long illustID, Context context) { QMUITipDialog tipDialog = new QMUITipDialog.Builder(context) .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING) .setTipWord(getString(R.string.string_429)) .create(); tipDialog.show(); - Retro.getAppApi().getIllustByID(userModel.getAccess_token(), illustID) + Retro.getAppApi() + .getIllustByID(userModel.getAccess_token(), illustID) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new NullCtrl() { + + + /** + * + * @param illustSearchResponse The response message returned by {@link NullCtrl} + * In case that the illustration information conveyed by illustSearchResponse is null + */ @Override public void success(IllustSearchResponse illustSearchResponse) { IllustsBean illust = illustSearchResponse.getIllust(); if (illust == null) { return; } - + //Update the illustration object in ObjectPool ObjectPool.INSTANCE.updateIllust(illust); - + //Check the permission to view the illustration if (illust.getId() == 0 || !illust.isVisible()) { Common.showToast(R.string.string_206); return; } - + //Get the user who posts the illustration UserBean user = illust.getUser(); - if(user != null){ + if (user != null) { Shaft.appViewModel.updateFollowUserStatus(user.getId(), user.isIs_followed() ? AppLevelViewModel.FollowUserStatus.FOLLOWED : AppLevelViewModel.FollowUserStatus.NOT_FOLLOW); } @@ -314,7 +330,7 @@ public void must() { } public static void getIllustByID(UserModel userModel, long illustID, Context context, - ceui.lisa.interfaces.Callback success,ceui.lisa.interfaces.Callback fail) { + ceui.lisa.interfaces.Callback success, ceui.lisa.interfaces.Callback fail) { Retro.getAppApi().getIllustByID(userModel.getAccess_token(), illustID) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -324,7 +340,7 @@ public void success(IllustSearchResponse illustSearchResponse) { IllustsBean illust = illustSearchResponse.getIllust(); if (illust != null) { UserBean user = illust.getUser(); - if(user != null){ + if (user != null) { Shaft.appViewModel.updateFollowUserStatus(user.getId(), user.isIs_followed() ? AppLevelViewModel.FollowUserStatus.FOLLOWED : AppLevelViewModel.FollowUserStatus.NOT_FOLLOW); } @@ -342,9 +358,10 @@ public void success(IllustSearchResponse illustSearchResponse) { } } } + @Override public void must(boolean isSuccess) { - if(!isSuccess&&fail!=null) fail.doSomething(null); + if (!isSuccess && fail != null) fail.doSomething(null); } @Override @@ -356,7 +373,7 @@ public void must() { } public static void getNovelByID(UserModel userModel, long novel, Context context, - ceui.lisa.interfaces.Callback callback) { + ceui.lisa.interfaces.Callback callback) { Retro.getAppApi().getNovelByID(userModel.getAccess_token(), novel) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -532,7 +549,7 @@ public static void insertNovelViewHistory(NovelBean novelBean) { } public static void insertSearchHistory(String key, int searchType) { - if(TextUtils.isEmpty(key)){ + if (TextUtils.isEmpty(key)) { return; } SearchEntity searchEntity = new SearchEntity(); @@ -549,7 +566,7 @@ public static void insertSearchHistory(String key, int searchType) { } public static void insertPinnedSearchHistory(String key, int searchType, boolean pinned) { - if(TextUtils.isEmpty(key)){ + if (TextUtils.isEmpty(key)) { return; } SearchEntity searchEntity = new SearchEntity(); @@ -563,7 +580,7 @@ public static void insertPinnedSearchHistory(String key, int searchType, boolean AppDatabase.getAppDatabase(Shaft.getContext()).searchDao().insert(searchEntity); } - public static SearchEntity getSearchHistory(String key, int searchType){ + public static SearchEntity getSearchHistory(String key, int searchType) { int id = key.hashCode() + searchType; return AppDatabase.getAppDatabase(Shaft.getContext()).searchDao().getSearchEntity(id); } @@ -642,12 +659,11 @@ public int compare(File o1, File o2) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//这个参数设置为true才有效, BitmapFactory.decodeFile(allFiles.get(0).getPath(), options);//这里的bitmap是个空 - int outHeight=options.outHeight; - int outWidth= options.outWidth; + int outHeight = options.outHeight; + int outWidth = options.outWidth; Common.showLog("通过Options获取到的图片大小" + "width:" + outWidth + " height: " + outHeight); - gifEncoder.init(outWidth, outHeight, gifFile.getPath(), GifEncoder.EncodingType.ENCODING_TYPE_NORMAL_LOW_MEMORY); @@ -689,8 +705,6 @@ public int compare(File o1, File o2) { Common.showLog("allFiles size " + allFiles.size()); - - gifEncoder.close(); Common.showLog("gifFile gifFile " + FileUtils.getSize(gifFile)); @@ -703,13 +717,13 @@ public int compare(File o1, File o2) { }, new TryCatchObserverImpl<>()); } - public static void encodeGifV2(Context context, File parentFile, IllustsBean illustsBean, boolean autoSave){ + public static void encodeGifV2(Context context, File parentFile, IllustsBean illustsBean, boolean autoSave) { RxRun.runOn(new RxRunnable() { @Override public Void execute() throws Exception { long currentTimeMillis = System.currentTimeMillis(); - if(gifEncodingWorkSet.containsKey(illustsBean.getId()) - && (currentTimeMillis - gifEncodingWorkSet.get(illustsBean.getId())) < reEncodeTimeThresholdMillis){ + if (gifEncodingWorkSet.containsKey(illustsBean.getId()) + && (currentTimeMillis - gifEncodingWorkSet.get(illustsBean.getId())) < reEncodeTimeThresholdMillis) { return null; } gifEncodingWorkSet.put(illustsBean.getId(), currentTimeMillis); @@ -787,8 +801,8 @@ public int compare(File o1, File o2) { outStream.write(bos.toByteArray()); outStream.close(); - if(autoSave){ - OutPut.outPutGif(context, gifFile,illustsBean); + if (autoSave) { + OutPut.outPutGif(context, gifFile, illustsBean); } Common.showLog("gifFile gifFile " + FileUtils.getSize(gifFile)); @@ -823,7 +837,7 @@ public static void setBack(int illustId, Back back) { sBack.put(illustId, back); } - public static void clearBack(){ + public static void clearBack() { sBack.clear(); } @@ -832,14 +846,14 @@ public static void postNovelMarker(NovelDetail.NovelMarkerBean novelMarkerBean, if (currentMarkPage == 0 || (currentMarkPage > 0 && currentMarkPage != page)) { novelMarkerBean.setPage(page); Retro.getAppApi().postAddNovelMarker( - sUserModel.getAccess_token(), novelId, page) + sUserModel.getAccess_token(), novelId, page) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new ErrorCtrl() { @Override public void next(NullResponse nullResponse) { - if(view instanceof ImageView){ - ((ImageView)view).setImageTintList(ColorStateList.valueOf(getColor(R.color.novel_marker_add))); + if (view instanceof ImageView) { + ((ImageView) view).setImageTintList(ColorStateList.valueOf(getColor(R.color.novel_marker_add))); } Common.showToast(getString(R.string.string_368, page)); } @@ -847,14 +861,14 @@ public void next(NullResponse nullResponse) { } else { novelMarkerBean.setPage(0); Retro.getAppApi().postDeleteNovelMarker( - sUserModel.getAccess_token(), novelId) + sUserModel.getAccess_token(), novelId) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new ErrorCtrl() { @Override public void next(NullResponse nullResponse) { - if(view instanceof ImageView){ - ((ImageView)view).setImageTintList(ColorStateList.valueOf(getColor(R.color.novel_marker_none))); + if (view instanceof ImageView) { + ((ImageView) view).setImageTintList(ColorStateList.valueOf(getColor(R.color.novel_marker_none))); } Common.showToast(getString(R.string.string_369)); }