Skip to content

Commit

Permalink
封装TitleView,增加上下滑动隐藏显示标题等功能
Browse files Browse the repository at this point in the history
  • Loading branch information
luern0313 committed Jan 28, 2021
1 parent 38d1615 commit c430dc4
Show file tree
Hide file tree
Showing 92 changed files with 2,560 additions and 3,726 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.luern0313.wristbilibili.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
Expand All @@ -13,14 +14,17 @@
import java.io.IOException;
import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import cn.luern0313.wristbilibili.R;
import cn.luern0313.wristbilibili.adapter.AnimationTimelineAdapter;
import cn.luern0313.wristbilibili.api.AnimationTimelineApi;
import cn.luern0313.wristbilibili.models.AnimationTimelineModel;
import cn.luern0313.wristbilibili.ui.BangumiActivity;
import cn.luern0313.wristbilibili.util.ColorUtil;
import cn.luern0313.wristbilibili.util.ListViewTouchListener;
import cn.luern0313.wristbilibili.util.SharedPreferencesUtil;
import cn.luern0313.wristbilibili.widget.TitleView;
import jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout;

/**
Expand All @@ -31,83 +35,57 @@ public class AnimationTimelineFragment extends Fragment
{
Context ctx;
View rootLayout;
private ListView arListView;
private ListView uiListView;
private WaveSwipeRefreshLayout waveSwipeRefreshLayout;

public static boolean isLogin;
private AnimationTimelineApi animationTimelineApi;
private ArrayList<AnimationTimelineModel> animationTimelineList;
AnimationTimelineAdapter adapter;
private AnimationTimelineAdapter.AnimationTimelineListener adapterListener;
private TitleView.TitleViewListener titleViewListener;

Handler handler = new Handler();
private Runnable runnableUi, runnableNoWeb;

@SuppressLint("ClickableViewAccessibility")
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
ctx = getActivity();
rootLayout = inflater.inflate(R.layout.fragment_aniremind, container, false);
arListView = rootLayout.findViewById(R.id.ar_listview);
uiListView = rootLayout.findViewById(R.id.ar_listview);
waveSwipeRefreshLayout = rootLayout.findViewById(R.id.ar_swipe);
waveSwipeRefreshLayout.setColorSchemeColors(Color.WHITE, Color.WHITE);
//noinspection ConstantConditions
waveSwipeRefreshLayout.setWaveColor(ColorUtil.getColor(R.attr.colorPrimary, getContext()));
waveSwipeRefreshLayout.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener()
{
@Override
public void onRefresh()
waveSwipeRefreshLayout.setWaveColor(ColorUtil.getColor(R.attr.colorPrimary, ctx));
waveSwipeRefreshLayout.setOnRefreshListener(() -> handler.post(() -> {
if(isLogin)
{
handler.post(new Runnable()
{
@Override
public void run()
{
if(isLogin)
{
arListView.setVisibility(View.GONE);
getAnimTimeline();
}
else waveSwipeRefreshLayout.setRefreshing(false);
}
});
uiListView.setVisibility(View.GONE);
getAnimTimeline();
}
});
else waveSwipeRefreshLayout.setRefreshing(false);
}));

adapterListener = new AnimationTimelineAdapter.AnimationTimelineListener()
{
@Override
public void onClick(int viewId, int position)
{
onViewClick(viewId, position);
}
};
adapterListener = this::onViewClick;

runnableUi = new Runnable()
{
@Override
public void run()
{
rootLayout.findViewById(R.id.ar_nologin).setVisibility(View.GONE);
rootLayout.findViewById(R.id.ar_noweb).setVisibility(View.GONE);
adapter = new AnimationTimelineAdapter(inflater, animationTimelineList, arListView, adapterListener);
arListView.setAdapter(adapter);
arListView.setVisibility(View.VISIBLE);
waveSwipeRefreshLayout.setRefreshing(false);
}
runnableUi = () -> {
rootLayout.findViewById(R.id.ar_nologin).setVisibility(View.GONE);
rootLayout.findViewById(R.id.ar_noweb).setVisibility(View.GONE);
adapter = new AnimationTimelineAdapter(inflater, animationTimelineList, uiListView, adapterListener);
uiListView.setAdapter(adapter);
uiListView.setVisibility(View.VISIBLE);
waveSwipeRefreshLayout.setRefreshing(false);
};

runnableNoWeb = new Runnable()
{
@Override
public void run()
{
waveSwipeRefreshLayout.setRefreshing(false);
rootLayout.findViewById(R.id.ar_noweb).setVisibility(View.VISIBLE);
rootLayout.findViewById(R.id.ar_nologin).setVisibility(View.GONE);
}
runnableNoWeb = () -> {
waveSwipeRefreshLayout.setRefreshing(false);
rootLayout.findViewById(R.id.ar_noweb).setVisibility(View.VISIBLE);
rootLayout.findViewById(R.id.ar_nologin).setVisibility(View.GONE);
};

uiListView.setOnTouchListener(new ListViewTouchListener(uiListView, titleViewListener));

isLogin = SharedPreferencesUtil.contains(SharedPreferencesUtil.cookies);
if(isLogin)
{
Expand All @@ -125,22 +103,17 @@ public void run()

private void getAnimTimeline()
{
new Thread(new Runnable()
{
@Override
public void run()
new Thread(() -> {
try
{
animationTimelineApi = new AnimationTimelineApi();
animationTimelineList = animationTimelineApi.getAnimTimelineList();
handler.post(runnableUi);
}
catch (IOException e)
{
try
{
animationTimelineApi = new AnimationTimelineApi();
animationTimelineList = animationTimelineApi.getAnimTimelineList();
handler.post(runnableUi);
}
catch (IOException e)
{
handler.post(runnableNoWeb);
e.printStackTrace();
}
handler.post(runnableNoWeb);
e.printStackTrace();
}
}).start();
}
Expand All @@ -159,4 +132,12 @@ private void onViewClick(int id, int position)
intent.putExtra("season_id", animationTimelineSeasonModel.getSeasonId());
startActivity(intent);
}

@Override
public void onAttach(@NonNull Context context)
{
super.onAttach(context);
if(context instanceof TitleView.TitleViewListener)
titleViewListener = (TitleView.TitleViewListener) context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void onCreate(Bundle savedInstanceState)
}
}

@SuppressLint("ClickableViewAccessibility")
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Expand Down Expand Up @@ -120,14 +121,8 @@ public void onLinkClick(String url)
else if(articleModel.getUpOfficial() == 1)
layoutArticleHeader.findViewById(R.id.article_card_off_2).setVisibility(View.VISIBLE);

layoutArticleHeader.findViewById(R.id.article_card_follow).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
articleDetailFragmentListener.onArticleDetailFragmentViewClick(v.getId());
}
});
layoutArticleHeader.findViewById(R.id.article_card_follow).setOnClickListener(
v -> articleDetailFragmentListener.onArticleDetailFragmentViewClick(v.getId()));

setArticleIcon();

Expand All @@ -137,39 +132,24 @@ public void onClick(View v)
layoutArticleHeader.findViewById(R.id.article_article_bt_fav).setOnClickListener(this);
layoutArticleHeader.findViewById(R.id.article_article_bt_share).setOnClickListener(this);

uiArticleListView.setOnTouchListener(new ListViewTouchListener(uiArticleListView, titleViewListener));

articleAdapter = new ArticleAdapter(inflater, img_width, articleModel.getArticleCardModelList(), uiArticleListView, articleListener);
uiArticleListView.addHeaderView(layoutArticleHeader);
uiArticleListView.addFooterView(layoutArticleFooter);
uiArticleListView.setAdapter(articleAdapter);

layoutArticleFooter.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
uiArticleListView.smoothScrollToPositionFromTop(0, 0, 500);
uiArticleListView.postDelayed(new Runnable()
{
@Override
public void run()
{
uiArticleListView.setSelection(0);
}
}, 500);
}
layoutArticleFooter.setOnClickListener(v -> {
titleViewListener.showTitle();
uiArticleListView.smoothScrollToPositionFromTop(0, 0, 500);
uiArticleListView.postDelayed(() -> uiArticleListView.setSelection(0), 500);
});

layoutArticleHeader.findViewById(R.id.article_card_lay).setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(ctx, UserActivity.class);
intent.putExtra("mid", articleModel.getUpMid());
ArticleDetailFragment.this.startActivity(intent);
}
});
layoutArticleHeader.findViewById(R.id.article_card_lay).setOnClickListener(v -> {
Intent intent = new Intent(ctx, UserActivity.class);
intent.putExtra("mid", articleModel.getUpMid());
ArticleDetailFragment.this.startActivity(intent);
});

return rootLayout;
}
Expand Down Expand Up @@ -253,7 +233,7 @@ public void onEventMainThread(ArticleModel articleModel)
}

@Override
public void onAttach(Context context)
public void onAttach(@NonNull Context context)
{
super.onAttach(context);
if(context instanceof ArticleDetailFragmentListener)
Expand All @@ -274,9 +254,10 @@ public void onArticleDetailActivityLoadingFin()
});
}
else
{
throw new RuntimeException(context.toString() + " must implement OnFragmentInteractionListener");
}

if(context instanceof TitleView.TitleViewListener)
titleViewListener = (TitleView.TitleViewListener) context;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
uiDetailSectionsRecyclerView = rootLayout.findViewById(R.id.bgm_detail_video_other);

((TextView) rootLayout.findViewById(R.id.bgm_detail_title)).setText(bangumiModel.getTitle());
if(bangumiModel.getScore().equals(""))
if(bangumiModel.getScore() == null)
rootLayout.findViewById(R.id.bgm_detail_score).setVisibility(View.GONE);
else
((TextView) rootLayout.findViewById(R.id.bgm_detail_score)).setText(bangumiModel.getScore());
Expand All @@ -115,7 +115,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

setBangumiIcon();

if(bangumiModel.getEpisodes().size() != 0)
if(bangumiModel.getEpisodes() != null && bangumiModel.getEpisodes().size() != 0)
{
rootLayout.findViewById(R.id.bgm_detail_video_part_layout).setVisibility(View.VISIBLE);
((TextView) rootLayout.findViewById(R.id.bgm_detail_video_part_text)).setText(String.format(getString(R.string.bangumi_episodes_title), bangumiModel.getEpisodes().size(), bangumiModel.getTypeEp()));
Expand All @@ -129,7 +129,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
layoutManager.scrollToPositionWithOffset(bangumiModel.getUserProgressPosition(), 0);
}

if(bangumiModel.getSections().size() != 0)
if(bangumiModel.getSections() != null && bangumiModel.getSections().size() != 0)
{
rootLayout.findViewById(R.id.bgm_detail_video_other_layout).setVisibility(View.VISIBLE);
((TextView) rootLayout.findViewById(R.id.bgm_detail_video_other_text)).setText(bangumiModel.getSectionName());
Expand All @@ -143,7 +143,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
layoutManager.scrollToPositionWithOffset(bangumiModel.getUserProgressPosition(), 0);
}

if(bangumiModel.getSeasons().size() > 1)
if(bangumiModel.getSeasons() != null && bangumiModel.getSeasons().size() > 1)
{
rootLayout.findViewById(R.id.bgm_detail_video_season_layout).setVisibility(View.VISIBLE);
LinearLayout episodesLinearLayout = rootLayout.findViewById(R.id.bgm_detail_video_season);
Expand Down Expand Up @@ -251,14 +251,14 @@ private void clickBangumiDetailOther(int position)
private TextView getVideoSeasonButton(final BangumiModel.BangumiSeasonModel season)
{
TextView textView = new TextView(ctx);
textView.setWidth(120);
textView.setWidth(DataProcessUtil.dip2px(80));
textView.setBackgroundResource(seasonId.equals(season.getSeasonId()) ? R.drawable.selector_bg_bangumi_episode_now : R.drawable.selector_bg_bangumi_episode);
textView.setPadding(12, 6, 12, 6);
textView.setText(season.getSeasonTitle());
textView.setLines(1);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setTextSize(14);
textView.setTextColor(getResources().getColor(seasonId.equals(season.getSeasonId()) ? ColorUtil.getColor(R.attr.colorPrimary, textView.getContext()) : R.color.gray_77));
//textView.setTextColor(seasonId.equals(season.getSeasonId()) ? ColorUtil.getColor(R.attr.colorPrimary, textView.getContext()) : getResources().getColor(R.color.gray_77));
textView.setOnClickListener(seasonId.equals(season.getSeasonId()) ? null : (View.OnClickListener) v -> {
Intent intent = new Intent(ctx, BangumiActivity.class);
intent.putExtra("season_id", season.getSeasonId());
Expand Down
Loading

0 comments on commit c430dc4

Please sign in to comment.