Files
assistant-android/app/src/main/java/com/gh/gamecenter/collection/ToolsFragment.java
叶子维 31d7dd903e feat: APP内容配置重构-换一批—客户端 https://jira.shanqu.cc/browse/GHZS-4256
feat: APP内容配置重构-刷新轮换—客户端 https://jira.shanqu.cc/browse/GHZS-4257
feat: APP内容配置重构-其他组件:搜索栏—客户端 https://jira.shanqu.cc/browse/GHZS-4073
feat: APP内容配置重构-页面:多tab导航页—客户端 https://jira.shanqu.cc/browse/GHZS-4080
feat: APP内容配置重构-其他组件:下拉推送—客户端 https://jira.shanqu.cc/browse/GHZS-4070
feat: APP内容配置重构-页面:多tab导航页—客户端 https://jira.shanqu.cc/browse/GHZS-4080
feat: APP内容配置重构-底部tab—客户端 https://jira.shanqu.cc/browse/GHZS-4025
2024-03-11 16:35:07 +08:00

97 lines
3.5 KiB
Java

package com.gh.gamecenter.collection;
import static com.gh.common.constant.Config.URL_ARTICLE;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.gh.common.util.CollectionUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.WebActivity;
import com.gh.gamecenter.common.baselist.ListAdapter;
import com.gh.gamecenter.common.baselist.ListFragment;
import com.gh.gamecenter.common.baselist.LoadType;
import com.gh.gamecenter.common.baselist.NormalListViewModel;
import com.gh.gamecenter.common.entity.ToolBoxEntity;
import com.gh.gamecenter.common.view.CustomDividerItemDecoration;
import com.gh.gamecenter.eventbus.EBCollectionChanged;
import com.gh.gamecenter.login.user.UserManager;
import com.gh.gamecenter.newsdetail.NewsDetailActivity;
import com.gh.gamecenter.retrofit.RetrofitManager;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.List;
import io.reactivex.Observable;
/**
* Created by khy on 18/07/17.
*/
public class ToolsFragment extends ListFragment<ToolBoxEntity, NormalListViewModel> {
private ToolsAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.ui_surface));
}
@Override
protected ListAdapter provideListAdapter() {
return mAdapter == null ? mAdapter = new ToolsAdapter(getContext(), this) : mAdapter;
}
@Override
public Observable<List<ToolBoxEntity>> provideDataObservable(int page) {
return RetrofitManager.getInstance().getApi().getCollectionTools(UserManager.getInstance().getUserId(), page);
}
// 收藏事件
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBCollectionChanged changed) {
if (changed.getCollectionType().equals(CollectionUtils.CollectionType.TOOLKIT)) {
mListViewModel.load(LoadType.REFRESH);
}
}
@Override
public void onListClick(View view, int position, Object data) {
ToolBoxEntity toolBoxEntity = (ToolBoxEntity) data;
String url = toolBoxEntity.getUrl();
if (url != null && url.contains(URL_ARTICLE)) {
String newsId = url.substring(url.lastIndexOf("/") + 1, url.length() - 5);
Intent intent = NewsDetailActivity.getIntentById(getContext(), newsId, true, "(收藏:工具箱)");
startActivity(intent);
} else {
startActivity(WebActivity.getWebByCollectionTools(getContext(), toolBoxEntity, true));
}
}
@Override
protected RecyclerView.ItemDecoration getItemDecoration() {
Drawable insetDivider = ContextCompat.getDrawable(requireContext(), R.drawable.divider_item_line_space_16);
CustomDividerItemDecoration itemDecoration = new CustomDividerItemDecoration(requireContext(), false, false, true, false);
itemDecoration.setDrawable(insetDivider);
return itemDecoration;
}
@Override
protected void onDarkModeChanged() {
super.onDarkModeChanged();
mCachedView.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.ui_surface));
if (mListRv != null && mListRv.getItemDecorationCount() > 0) {
mListRv.removeItemDecorationAt(0);
mListRv.addItemDecoration(getItemDecoration());
}
}
}