Skip to content

Commit

Permalink
Merge pull request #611 from h4ckm310n/novel-watchlist
Browse files Browse the repository at this point in the history
小说追更列表功能
  • Loading branch information
CeuiLiSA authored Jul 28, 2024
2 parents fce2686 + 48cee17 commit e65ec4b
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 6 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.watchlist:
intent = new Intent(mContext, TemplateActivity.class);
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, "小说书签");
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/ceui/lisa/activities/TemplateActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ protected Fragment createNewFragment() {
return FragmentCollection.newInstance(0);
case "我的小说收藏":
return FragmentCollection.newInstance(1);
case "追更列表":
return FragmentCollection.newInstance(3);
case "我的关注":
return FragmentCollection.newInstance(2);
case "小说书签":
Expand Down
75 changes: 75 additions & 0 deletions app/src/main/java/ceui/lisa/adapters/WatchlistNovelAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package ceui.lisa.adapters

import android.content.Context
import android.content.Intent
import android.view.View
import ceui.lisa.databinding.RecyWatchlistNovelBinding
import ceui.lisa.models.WatchlistNovelItem
import ceui.lisa.R
import ceui.lisa.activities.Shaft
import ceui.lisa.activities.TemplateActivity
import ceui.lisa.activities.UserActivity
import ceui.lisa.utils.GlideUtil
import ceui.lisa.utils.Params
import ceui.lisa.utils.PixivOperate
import com.bumptech.glide.Glide

class WatchlistNovelAdapter(
list: MutableList<WatchlistNovelItem>,
context: Context
) : BaseAdapter<WatchlistNovelItem, RecyWatchlistNovelBinding>(list, context) {
override fun initLayout() {
mLayoutID = R.layout.recy_watchlist_novel
}

override fun bindData(
target: WatchlistNovelItem,
bindView: ViewHolder<RecyWatchlistNovelBinding>,
position: Int
) {
if (isInvalidItem(target)) {
bindView.baseBind.title.text = target.mask_text
bindView.baseBind.author.text = ""
bindView.baseBind.lastDate.text = ""
bindView.baseBind.contentCount.text = ""
bindView.baseBind.readLatest.visibility = View.INVISIBLE
bindView.baseBind.cover.visibility = View.INVISIBLE
bindView.itemView.setOnClickListener {}
bindView.baseBind.author.setOnClickListener {}
bindView.baseBind.userHead.setOnClickListener {}
} else {
bindView.baseBind.title.text = target.title
bindView.baseBind.author.text = target.user!!.name
Glide.with(mContext).load(GlideUtil.getUrl(target.url!!)).into(bindView.baseBind.cover)
bindView.baseBind.lastDate.text = target.last_published_content_datetime!!
bindView.baseBind.contentCount.text = mContext.getString(R.string.episode_number, target.published_content_count)
bindView.itemView.setOnClickListener {
val intent = Intent(mContext, TemplateActivity::class.java)
intent.putExtra(Params.ID, target.id)
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "小说系列详情")
mContext.startActivity(intent)
}
bindView.baseBind.readLatest.setOnClickListener {
PixivOperate.getNovelByID(Shaft.sUserModel, target.latest_content_id!!.toLong(), mContext, null)
}
bindView.baseBind.author.setOnClickListener {
val intent = Intent(mContext, UserActivity::class.java)
intent.putExtra(Params.USER_ID, target.user!!.id)
mContext.startActivity(intent)
}
bindView.baseBind.userHead.setOnClickListener {
val intent = Intent(mContext, UserActivity::class.java)
intent.putExtra(Params.USER_ID, target.user!!.id)
mContext.startActivity(intent)
}
}
Glide.with(mContext).load(GlideUtil.getHead(target.user)).into(bindView.baseBind.userHead)
}

private fun isInvalidItem(target: WatchlistNovelItem): Boolean {
// 表示できない作品です
return (target.title == "" && target.url == null
&& target.mask_text != null && target.user!!.id == 0)
}

}
12 changes: 11 additions & 1 deletion app/src/main/java/ceui/lisa/fragments/FragmentCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class FragmentCollection extends BaseFragment<ViewpagerWithTablayoutBindi
private Fragment[] allPages;
private String[] CHINESE_TITLES;

private int type; //0插画收藏,1小说收藏,2关注
private int type; //0插画收藏,1小说收藏,2关注, 3追更列表
private final static Set<Integer> filterType = new HashSet<>(Arrays.asList(0,1));

public static FragmentCollection newInstance(int type) {
Expand Down Expand Up @@ -87,6 +87,14 @@ public void initView() {
Shaft.getContext().getString(R.string.public_like_user),
Shaft.getContext().getString(R.string.private_like_user)
};
} else if (type == 3) {
// TODO: manga watchlist
allPages = new Fragment[]{
new FragmentWatchlistNovel()
};
CHINESE_TITLES = new String[]{
Shaft.getContext().getString(R.string.type_novel)
};
}

if (type == 0) {
Expand All @@ -95,6 +103,8 @@ public void initView() {
baseBind.toolbarTitle.setText(R.string.string_320);
} else if (type == 2) {
baseBind.toolbarTitle.setText(R.string.string_321);
} else if (type == 3) {
baseBind.toolbarTitle.setText(R.string.watchlist);
}
baseBind.toolbar.setNavigationOnClickListener(v -> mActivity.finish());
baseBind.toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/ceui/lisa/fragments/FragmentWatchlistNovel.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.adapters.BaseAdapter
import ceui.lisa.adapters.WatchlistNovelAdapter
import ceui.lisa.core.BaseRepo
import ceui.lisa.databinding.FragmentBaseListBinding
import ceui.lisa.model.ListWatchlistNovel
import ceui.lisa.models.WatchlistNovelItem
import ceui.lisa.repo.WatchlistNovelRepo

class FragmentWatchlistNovel:
NetListFragment<FragmentBaseListBinding, ListWatchlistNovel, WatchlistNovelItem>() {
override fun adapter(): BaseAdapter<*, out ViewDataBinding> {
return WatchlistNovelAdapter(allItems, mContext)
}

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

override fun showToolbar(): Boolean {
return false
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/ceui/lisa/http/AppApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ceui.lisa.model.ListTag;
import ceui.lisa.model.ListTrendingtag;
import ceui.lisa.model.ListUser;
import ceui.lisa.model.ListWatchlistNovel;
import ceui.lisa.model.RecmdIllust;
import ceui.lisa.models.CommentHolder;
import ceui.lisa.models.GifResponse;
Expand Down Expand Up @@ -533,6 +534,13 @@ Observable<NullResponse> postDeleteNovelMarker(@Header("Authorization") String t
Observable<ListUser> getRelatedUsers(@Header("Authorization") String token,
@Query("seed_user_id") int seed_user_id);

// 小说追更列表
@GET("v1/watchlist/novel")
Observable<ListWatchlistNovel> getWatchlistNovel(@Header("Authorization") String token);

@GET
Observable<ListWatchlistNovel> getNextWatchlistNovel(@Header("Authorization") String token,
@Url String next_url);
// 小说书签
@GET("v2/novel/markers")
Observable<ListNovelMarkers> getNovelMarkers(@Header("Authorization") String token);
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/ceui/lisa/model/ListWatchlistNovel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ceui.lisa.model;

import java.util.List;

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

public class ListWatchlistNovel implements ListShow<WatchlistNovelItem> {
private String next_url;
private List<WatchlistNovelItem> series;

@Override
public List<WatchlistNovelItem> getList() {
return series;
}

@Override
public String getNextUrl() {
return next_url;
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/ceui/lisa/repo/WatchlistNovelRepo.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.ListWatchlistNovel
import io.reactivex.Observable

class WatchlistNovelRepo: RemoteRepo<ListWatchlistNovel>() {
override fun initApi(): Observable<out ListWatchlistNovel> {
return Retro.getAppApi().getWatchlistNovel(token())
}

override fun initNextApi(): Observable<out ListWatchlistNovel> {
return Retro.getAppApi().getNextWatchlistNovel(token(), nextUrl)
}
}
137 changes: 137 additions & 0 deletions app/src/main/res/layout/recy_watchlist_novel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

</data>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/cover"
android:layout_width="90dp"
android:layout_height="120dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/eight_dp"
android:layout_marginEnd="@dimen/eight_dp"
android:layout_marginBottom="@dimen/eight_dp"
android:scaleType="centerCrop"
app:riv_border_width="0dp"
app:riv_corner_radius="@dimen/eight_dp">
</com.makeramen.roundedimageview.RoundedImageView>

<RelativeLayout
android:layout_width="match_parent"
android:id="@+id/top_rela"
android:layout_marginEnd="@dimen/eight_dp"
android:layout_toStartOf="@+id/cover"
android:layout_height="wrap_content">

<ImageView
android:layout_width="2dp"
android:background="?attr/colorPrimary"
android:layout_alignTop="@+id/title"
android:layout_alignBottom="@+id/title"
android:layout_height="wrap_content">

</ImageView>

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/eight_dp"
android:layout_marginTop="@dimen/eight_dp"
android:layout_marginBottom="@dimen/eight_dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/rank_text_color"
android:textSize="16sp">

</TextView>
</RelativeLayout>

<TextView
android:id="@+id/last_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top_rela"
android:layout_marginStart="@dimen/eight_dp"
android:layout_marginEnd="@dimen/eight_dp"
android:layout_toStartOf="@+id/cover"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?attr/colorPrimary"
android:textSize="15sp">
</TextView>

<TextView
android:id="@+id/content_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/last_date"
android:layout_marginStart="@dimen/eight_dp"
android:layout_marginEnd="@dimen/eight_dp"
android:layout_toStartOf="@+id/cover"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?attr/colorPrimary"
android:textSize="15sp">
</TextView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/content_count"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/four_dp"
android:layout_toStartOf="@id/cover"
android:orientation="horizontal">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_head"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center_vertical"
android:layout_marginVertical="0dp"
android:layout_marginStart="@dimen/eight_dp"
android:layout_marginEnd="@dimen/four_dp"
app:civ_border_color="@color/dark_bg"
app:civ_border_width="1dp" />

<TextView
android:id="@+id/author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginVertical="0dp"
android:layout_marginTop="14dp"
android:layout_marginEnd="@dimen/eight_dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:shadowColor="@android:color/black"
android:textColor="@color/rank_text_color"
android:textSize="13sp"
android:textStyle="bold" />

<Button
android:id="@+id/read_latest"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/read_latest_episode"
android:textColor="?attr/colorPrimary">
</Button>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</layout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/activity_main_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
android:icon="@drawable/ic_baseline_menu_book_24"
android:title="@string/string_320" />

<item
android:id="@+id/watchlist"
android:icon="@drawable/ic_fiber_new_black_24dp"
android:title="@string/watchlist" />

<item
android:id="@+id/novel_markers"
android:icon="@drawable/ic_baseline_bookmark_24"
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="file_path">path:</string>
<string name="add_account">Add accounts</string>
<string name="add_account">Add accounts</string>
<string name="read_latest_episode">Read latest episode</string>
<string name="watchlist">Watchlist</string>
<string name="episode_number">%d ep</string>
<string name="string_1">Mask Setting</string>
<string name="string_2">Developer Preview</string>
<string name="string_3">share</string>
Expand Down Expand Up @@ -606,7 +609,7 @@
<string name="string_452">Download limit type</string>
<string name="string_453">Do not auto start</string>
<string name="string_454">Share first image</string>
<string name="string_455">AI works download to another directory</string>
<string name="string_455">AI works download to another directory</string>
<string name="refresh">Refresh</string>
<string name="now_loading">Loading…</string>
<string name="retry">Retry</string>
Expand Down
Loading

0 comments on commit e65ec4b

Please sign in to comment.