Skip to content

Commit

Permalink
Merge pull request #614 from Lostin-Tianyi/master
Browse files Browse the repository at this point in the history
Just add some comments
  • Loading branch information
CeuiLiSA authored Jul 28, 2024
2 parents 0fec5c2 + 56eb6d7 commit c3fc2ff
Showing 1 changed file with 50 additions and 36 deletions.
86 changes: 50 additions & 36 deletions app/src/main/java/ceui/lisa/utils/PixivOperate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Integer,Back> sBack = new HashMap<>();
private static final Map<Integer, Back> sBack = new HashMap<>();
private static final Map<Integer, Long> gifEncodingWorkSet = new HashMap<>();
private static final long reEncodeTimeThresholdMillis = 60 * 1000;

Expand All @@ -94,7 +97,7 @@ public static void refreshUserData(UserModel userModel, Callback<UserModel> 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<NullResponse>() {
Expand All @@ -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<NullResponse>() {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -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)) {
Expand All @@ -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<IllustSearchResponse>() {


/**
*
* @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);
}

Expand All @@ -314,7 +330,7 @@ public void must() {
}

public static void getIllustByID(UserModel userModel, long illustID, Context context,
ceui.lisa.interfaces.Callback<Void> success,ceui.lisa.interfaces.Callback<Void> fail) {
ceui.lisa.interfaces.Callback<Void> success, ceui.lisa.interfaces.Callback<Void> fail) {
Retro.getAppApi().getIllustByID(userModel.getAccess_token(), illustID)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -356,7 +373,7 @@ public void must() {
}

public static void getNovelByID(UserModel userModel, long novel, Context context,
ceui.lisa.interfaces.Callback<Void> callback) {
ceui.lisa.interfaces.Callback<Void> callback) {
Retro.getAppApi().getNovelByID(userModel.getAccess_token(), novel)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand All @@ -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<Void>() {
@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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}

Expand All @@ -832,29 +846,29 @@ 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<NullResponse>() {
@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));
}
});
} else {
novelMarkerBean.setPage(0);
Retro.getAppApi().postDeleteNovelMarker(
sUserModel.getAccess_token(), novelId)
sUserModel.getAccess_token(), novelId)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new ErrorCtrl<NullResponse>() {
@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));
}
Expand Down

0 comments on commit c3fc2ff

Please sign in to comment.