Skip to content

Commit

Permalink
Merge pull request #612 from h4ckm310n/marked-novels
Browse files Browse the repository at this point in the history
小说书签功能
  • Loading branch information
CeuiLiSA authored Jul 28, 2024
2 parents c3fc2ff + ff13fbb commit fce2686
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/ceui/lisa/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ public boolean onNavigationItemSelected(MenuItem item) {
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的小说收藏");
intent.putExtra("hideStatusBar", false);
break;
case R.id.novel_markers:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "小说书签");
intent.putExtra("hideStatusBar", false);
break;
case R.id.follow_user:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的关注");
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/ceui/lisa/activities/TemplateActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import ceui.lisa.fragments.FragmentNewNovels;
import ceui.lisa.fragments.FragmentNiceFriend;
import ceui.lisa.fragments.FragmentNovelHolder;
import ceui.lisa.fragments.FragmentNovelMarkers;
import ceui.lisa.fragments.FragmentNovelSeries;
import ceui.lisa.fragments.FragmentNovelSeriesDetail;
import ceui.lisa.fragments.FragmentPopularNovel;
Expand Down Expand Up @@ -235,6 +236,8 @@ protected Fragment createNewFragment() {
return FragmentCollection.newInstance(1);
case "我的关注":
return FragmentCollection.newInstance(2);
case "小说书签":
return new FragmentNovelMarkers();
case "主题颜色":
return new FragmentColors();
case "测试测试":
Expand Down
114 changes: 114 additions & 0 deletions app/src/main/java/ceui/lisa/adapters/NovelMarkersAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package ceui.lisa.adapters;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;
import java.util.Locale;

import ceui.lisa.R;
import ceui.lisa.activities.SearchActivity;
import ceui.lisa.activities.TemplateActivity;
import ceui.lisa.activities.UserActivity;
import ceui.lisa.databinding.RecyNovelMarkersBinding;
import ceui.lisa.models.MarkedNovelItem;
import ceui.lisa.models.TagsBean;
import ceui.lisa.utils.GlideUtil;
import ceui.lisa.utils.Params;
import ceui.lisa.utils.PixivOperate;

public class NovelMarkersAdapter extends BaseAdapter<MarkedNovelItem, RecyNovelMarkersBinding> {
public NovelMarkersAdapter(List<MarkedNovelItem> targetList, Context context) {
super(targetList, context);
}

@Override
public void initLayout() {
mLayoutID = R.layout.recy_novel_markers;
}

@Override
public void bindData(MarkedNovelItem target, ViewHolder<RecyNovelMarkersBinding> bindView, int position) {
if (target.getNovel().getSeries() != null && !TextUtils.isEmpty(target.getNovel().getSeries().getTitle())) {
bindView.baseBind.series.setVisibility(View.VISIBLE);
bindView.baseBind.series.setText(String.format(mContext.getString(R.string.string_184),
target.getNovel().getSeries().getTitle()));
bindView.baseBind.series.setOnClickListener(v -> {
Intent intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(Params.ID, target.getNovel().getSeries().getId());
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "小说系列详情");
mContext.startActivity(intent);
});
} else {
bindView.baseBind.series.setVisibility(View.GONE);
}
bindView.baseBind.title.setText(target.getNovel().getTitle());
bindView.baseBind.novelTag.setAdapter(new TagAdapter<TagsBean>(target.getNovel().getTags()) {
@Override
public View getView(FlowLayout parent, int position, TagsBean s) {
TextView tv = (TextView) LayoutInflater.from(mContext).inflate(R.layout.recy_single_line_text_new,
parent, false);
String tag = s.getName();
tv.setText(tag);
return tv;
}
});
bindView.baseBind.novelTag.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
@Override
public boolean onTagClick(View view, int position, FlowLayout parent) {
Intent intent = new Intent(mContext, SearchActivity.class);
intent.putExtra(Params.KEY_WORD, target.getNovel().getTags().get(position).getName());
intent.putExtra(Params.INDEX, 1);
mContext.startActivity(intent);
return true;
}
});
bindView.baseBind.author.setText(target.getNovel().getUser().getName());
bindView.baseBind.howManyWord.setText(String.format(Locale.getDefault(), "%d字", target.getNovel().getText_length()));
bindView.baseBind.bookmarkCount.setText(String.valueOf(target.getNovel().getTotal_bookmarks()));
Glide.with(mContext).load(GlideUtil.getUrl(target.getNovel().getImage_urls().getMaxImage())).into(bindView.baseBind.cover);
Glide.with(mContext).load(GlideUtil.getHead(target.getNovel().getUser())).into(bindView.baseBind.userHead);

bindView.baseBind.cover.setOnClickListener(v -> {
Intent intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(Params.URL, GlideUtil.getUrl(target.getNovel().getImage_urls().getMaxImage()).toStringUrl());
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "图片详情");
mContext.startActivity(intent);
});

bindView.baseBind.userHead.setOnClickListener(v -> {
Intent intent = new Intent(mContext, UserActivity.class);
intent.putExtra(Params.USER_ID, target.getNovel().getUser().getId());
mContext.startActivity(intent);
});

bindView.baseBind.author.setOnClickListener(v -> {
Intent intent = new Intent(mContext, UserActivity.class);
intent.putExtra(Params.USER_ID, target.getNovel().getUser().getId());
mContext.startActivity(intent);
});

bindView.itemView.setOnClickListener(v -> {
Intent intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(Params.CONTENT, target.getNovel());
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "小说详情");
intent.putExtra("hideStatusBar", true);
mContext.startActivity(intent);
});

bindView.baseBind.mark.setOnClickListener(v ->
PixivOperate.postNovelMarker(target.getNovel_marker(),
target.getNovel().getId(),
bindView.baseBind.mark));

}
}
25 changes: 25 additions & 0 deletions app/src/main/java/ceui/lisa/fragments/FragmentNovelMarkers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ceui.lisa.fragments

import androidx.databinding.ViewDataBinding
import ceui.lisa.R
import ceui.lisa.adapters.BaseAdapter
import ceui.lisa.adapters.NovelMarkersAdapter
import ceui.lisa.core.BaseRepo
import ceui.lisa.databinding.FragmentBaseListBinding
import ceui.lisa.model.ListNovelMarkers
import ceui.lisa.models.MarkedNovelItem
import ceui.lisa.repo.NovelMarkersRepo

class FragmentNovelMarkers: NetListFragment<FragmentBaseListBinding, ListNovelMarkers, MarkedNovelItem>() {
override fun adapter(): BaseAdapter<*, out ViewDataBinding> {
return NovelMarkersAdapter(allItems, mContext)
}

override fun repository(): BaseRepo {
return NovelMarkersRepo()
}

override fun getToolbarTitle(): String {
return getString(R.string.core_string_novel_marker)
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/fragments/WebNovelParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class WebNovelParser(response: Response<ResponseBody>) {
novel_text = webNovel.text
series_next = webNovel.seriesNavigation?.nextNovel
series_prev = webNovel.seriesNavigation?.prevNovel
novel_marker = webNovel.marker
novel_marker = if (webNovel.marker == null) NovelDetail.NovelMarkerBean() else webNovel.marker
}, webNovel)
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/ceui/lisa/http/AppApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ceui.lisa.model.ListMangaOfSeries;
import ceui.lisa.model.ListMangaSeries;
import ceui.lisa.model.ListNovel;
import ceui.lisa.model.ListNovelMarkers;
import ceui.lisa.model.ListNovelOfSeries;
import ceui.lisa.model.ListNovelSeries;
import ceui.lisa.model.ListSimpleUser;
Expand Down Expand Up @@ -531,4 +532,12 @@ Observable<NullResponse> postDeleteNovelMarker(@Header("Authorization") String t
@GET("v1/user/related?filter=for_android")
Observable<ListUser> getRelatedUsers(@Header("Authorization") String token,
@Query("seed_user_id") int seed_user_id);

// 小说书签
@GET("v2/novel/markers")
Observable<ListNovelMarkers> getNovelMarkers(@Header("Authorization") String token);

@GET
Observable<ListNovelMarkers> getNextNovelMarkers(@Header("Authorization") String token,
@Url String next_url);
}
20 changes: 20 additions & 0 deletions app/src/main/java/ceui/lisa/model/ListNovelMarkers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ceui.lisa.model;

import java.util.List;

import ceui.lisa.interfaces.ListShow;
import ceui.lisa.models.MarkedNovelItem;

public class ListNovelMarkers implements ListShow<MarkedNovelItem> {
private String next_url;
private List<MarkedNovelItem> marked_novels;
@Override
public List<MarkedNovelItem> getList() {
return marked_novels;
}

@Override
public String getNextUrl() {
return next_url;
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/ceui/lisa/repo/NovelMarkersRepo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ceui.lisa.repo

import ceui.lisa.core.RemoteRepo
import ceui.lisa.http.Retro
import ceui.lisa.model.ListNovelMarkers
import io.reactivex.Observable

class NovelMarkersRepo: RemoteRepo<ListNovelMarkers>() {
override fun initApi(): Observable<out ListNovelMarkers> {
return Retro.getAppApi().getNovelMarkers(token())
}

override fun initNextApi(): Observable<out ListNovelMarkers> {
return Retro.getAppApi().getNextNovelMarkers(token(), nextUrl)
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/ceui/lisa/utils/PixivOperate.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import ceui.lisa.models.FramesBean;
import ceui.lisa.models.GifResponse;
import ceui.lisa.models.IllustSearchResponse;
import ceui.lisa.models.MarkedNovelItem;
import ceui.lisa.models.NovelBean;
import ceui.lisa.models.NovelDetail;
import ceui.lisa.models.NovelSearchResponse;
Expand Down Expand Up @@ -875,4 +876,40 @@ public void next(NullResponse nullResponse) {
});
}
}

// For markers page
public static void postNovelMarker(MarkedNovelItem.NovelMarker marker, int novelId, View view) {
int page = marker.getPage();
if (marker.isCancelled()) {
marker.setCancelled(false);
Retro.getAppApi().postAddNovelMarker(
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)));
}
Common.showToast(getString(R.string.string_368, page));
}
});
} else {
marker.setCancelled(true);
Retro.getAppApi().postDeleteNovelMarker(
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)));
}
Common.showToast(getString(R.string.string_369));
}
});
}
}
}
Loading

0 comments on commit fce2686

Please sign in to comment.