Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
670848654 committed Jan 25, 2021
1 parent d45f8e5 commit c27ea1c
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ public static String queryAllIndex(String fid) {
}

/**
* 查询用户收藏的番剧
* 分页查询用户收藏的番剧
*/
public static List<AnimeListBean> queryAllFavorite() {
public static List<AnimeListBean> queryFavoriteByLimit(int offset, int limit) {
List<AnimeListBean> list = new ArrayList<>();
Cursor c = db.rawQuery("select * from f_favorite order by id desc", null);
// Cursor c = db.rawQuery("select * from f_favorite order by id desc", null);
String parameter = "%s,%s";
Cursor c = db.query("f_favorite", null, null, null,null,null,"id DESC",
String.format(parameter, offset, limit));
while (c.moveToNext()) {
AnimeListBean bean = new AnimeListBean();
bean.setTitle(c.getString(1));
Expand All @@ -140,6 +143,19 @@ public static List<AnimeListBean> queryAllFavorite() {
return list;
}

/**
* 查询用户收藏总数
* @return
*/
public static int queryFavoriteCount() {
int count;
String QueryCount = "select * from f_favorite";
Cursor cursor = db.rawQuery(QueryCount, null);
count = cursor.getCount();
cursor.close();
return count;
}

/**
* 收藏or删除收藏
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import my.project.sakuraproject.R;
import my.project.sakuraproject.adapter.FavoriteListAdapter;
import my.project.sakuraproject.bean.AnimeListBean;
import my.project.sakuraproject.custom.CustomLoadMoreView;
import my.project.sakuraproject.database.DatabaseUtil;
import my.project.sakuraproject.main.base.BaseActivity;
import my.project.sakuraproject.main.desc.DescActivity;
Expand All @@ -39,15 +40,20 @@ public class FavoriteActivity extends BaseActivity<FavoriteContract.View, Favori
private List<AnimeListBean> favoriteList = new ArrayList<>();
@BindView(R.id.msg)
CoordinatorLayout msg;
private int limit = 100;
private int videosCount = 0;
private boolean isMain = true;
protected boolean isErr = true;

@Override
protected FavoritePresenter createPresenter() {
return new FavoritePresenter(this);
return new FavoritePresenter(favoriteList.size(), limit, this);
}

@Override
protected void loadData() {
mPresenter.loadData(true);
videosCount = DatabaseUtil.queryFavoriteCount();
mPresenter.loadData(isMain);
}

@Override
Expand Down Expand Up @@ -110,10 +116,30 @@ public void initAdapter() {
popupMenu.show();
return true;
});
adapter.setLoadMoreView(new CustomLoadMoreView());
adapter.setOnLoadMoreListener(() -> mRecyclerView.postDelayed(() -> {
if (favoriteList.size() >= videosCount) {
adapter.loadMoreEnd();
} else {
if (isErr) {
isMain = false;
mPresenter = createPresenter();
loadData();
} else {
isErr = true;
adapter.loadMoreFail();
}
}
}, 500), mRecyclerView);
if (Utils.checkHasNavigationBar(this)) mRecyclerView.setPadding(0,0,0, Utils.getNavigationBarHeight(this));
mRecyclerView.setAdapter(adapter);
}

public void setLoadState(boolean loadState) {
isErr = loadState;
adapter.loadMoreComplete();
}

/**
* 移除收藏
*/
Expand All @@ -131,20 +157,25 @@ private void removeFavorite(int position) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 200 && requestCode == 3000) {
mPresenter.loadData(true);
isMain = true;
favoriteList.clear();
mPresenter = createPresenter();
loadData();
}
}

@Override
public void showLoadingView() {
favoriteList.clear();
adapter.setNewData(favoriteList);
}

@Override
public void showLoadErrorView(String msg) {
errorTitle.setText(msg);
adapter.setEmptyView(errorView);
setLoadState(false);
if (isMain) {
errorTitle.setText(msg);
adapter.setEmptyView(errorView);
}
}

@Override
Expand All @@ -159,7 +190,11 @@ public void showLog(String url) {

@Override
public void showSuccessView(List<AnimeListBean> list) {
favoriteList = list;
adapter.setNewData(favoriteList);
setLoadState(true);
if (isMain) {
favoriteList = list;
adapter.setNewData(favoriteList);
} else
adapter.addData(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface FavoriteContract {
interface Model {
void getData(LoadDataCallback callback);
void getData(int offset, int limit, LoadDataCallback callback);
}

interface View extends BaseView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
public class FavoriteModel implements FavoriteContract.Model {

@Override
public void getData(FavoriteContract.LoadDataCallback callback) {
List<AnimeListBean> list = DatabaseUtil.queryAllFavorite();
public void getData(int offset, int limit, FavoriteContract.LoadDataCallback callback) {
List<AnimeListBean> list = DatabaseUtil.queryFavoriteByLimit(offset, limit);
if (list.size() > 0)
callback.success(list);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
public class FavoritePresenter extends Presenter<FavoriteContract.View> implements BasePresenter, FavoriteContract.LoadDataCallback {
private FavoriteContract.View view;
private FavoriteModel model;
private int offset;
private int limit;

public FavoritePresenter(FavoriteContract.View view) {
public FavoritePresenter(int offset, int limit, FavoriteContract.View view) {
super(view);
this.view = view;
this.offset = offset;
this.limit = limit;
model = new FavoriteModel();
}

Expand All @@ -22,7 +26,7 @@ public void loadData(boolean isMain) {
view.showLoadingView();
view.showEmptyVIew();
}
model.getData(this);
model.getData(offset, limit, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package my.project.sakuraproject.main.tag;

import android.util.Log;

import com.chad.library.adapter.base.entity.MultiItemEntity;

import org.jsoup.Jsoup;
Expand Down Expand Up @@ -49,8 +47,6 @@ public void onResponse(Call call, Response response) {
else {
Elements tagTitles = doc.select("div.dtit");
Elements tagItems = doc.select("div.link");
Log.e("size1", tagTitles.size()+"");
Log.e("size2", tagItems.size()+"");
if (tagTitles.size() == tagItems.size()) {
setTagData(tagTitles, tagItems);
callback.success(list);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<string name="down">下载</string>
<string name="open_in_browser">通过浏览器打开</string>
<!-- 收藏相关文本 -->
<string name="favorite_title">我的追番</string>
<string name="favorite_title">追番列表</string>
<string name="empty_favorite">空空如也呢(-∀=)</string>
<string name="favorite">追番</string>
<string name="remove_favorite">弃番</string>
Expand Down

0 comments on commit c27ea1c

Please sign in to comment.