Skip to content

Commit

Permalink
feat: add detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao-yiwen committed Jul 20, 2024
1 parent 8ca7633 commit 1b2fc37
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.haoyiwen.jinritoutiao.presenter;

import io.github.haoyiwen.jinritoutiao.base.BasePresenter;
import io.github.haoyiwen.jinritoutiao.presenter.view.INewsListView;

public class NewsDetailPresenter extends BasePresenter<INewsListView> {
public NewsDetailPresenter(INewsListView view) {
super(view);
}

public void getNewsDetail(String mDetailUrl) {
}

public void getComment(String mGroupId, String mItemId, int i) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.github.haoyiwen.jinritoutiao.ui.activities;

import android.content.Intent;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.viewbinding.ViewBinding;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.github.nukc.stateview.StateView;

import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import io.github.haoyiwen.jinritoutiao.R;
import io.github.haoyiwen.jinritoutiao.base.BaseActivity;
import io.github.haoyiwen.jinritoutiao.base.BasePresenter;
import io.github.haoyiwen.jinritoutiao.model.entity.CommentData;
import io.github.haoyiwen.jinritoutiao.model.response.CommentResponse;
import io.github.haoyiwen.jinritoutiao.presenter.NewsDetailPresenter;
import io.github.haoyiwen.jinritoutiao.presenter.view.INewsListView;
import io.github.haoyiwen.jinritoutiao.ui.adapter.CommentAdapter;
import io.github.haoyiwen.jinritoutiao.ui.widget.NewsDetailHeaderView;
import io.github.haoyiwen.uikit.powerfulrecyclerview.PowerfulRecyclerView;

public abstract class NewsDetailBaseActivity extends BaseActivity<NewsDetailPresenter, ViewBinding> implements INewsListView, BaseQuickAdapter.RequestLoadMoreListener {
public static final String CHANNEL_CODE = "channelCode";

public static final String VIDEO_URL = "videoUrl";

public static final String PROGRESS = "progress";

public static final String POSITION = "position";

public static final String DETAIL_URL = "detailUrl";

public static final String GROUP_ID = "groupId";

public static final String ITEM_ID = "itemId";

FrameLayout mFlContent;

PowerfulRecyclerView mRvComment;

TextView mTvCommentCount;

private List<CommentData> commentList = new ArrayList<>();

protected StateView mStateView;

private CommentAdapter mCommentAdapter;

protected NewsDetailHeaderView mHeaderView;

private String mDetailUrl;

private String mGroupId;

private String mItemId;

protected CommentResponse mCommentResponse;

protected String mChannelCode;

protected int mPosition;


protected abstract ViewBinding initViewBinding();

@Override
protected NewsDetailPresenter createPresenter() {
return new NewsDetailPresenter(this);
}

@Override
public void initView() {
mStateView = StateView.inject(mFlContent);
mStateView.setLoadingResource(io.github.haoyiwen.uikit.R.layout.page_loading);
mStateView.setRetryResource(io.github.haoyiwen.uikit.R.layout.page_net_error);
}

@Override
public void initData() {
Intent intent = getIntent();

mChannelCode = intent.getStringExtra(CHANNEL_CODE);
mPosition = intent.getIntExtra(POSITION, 0);
mDetailUrl = intent.getStringExtra(DETAIL_URL);
mGroupId = intent.getStringExtra(GROUP_ID);
mItemId = intent.getStringExtra(ITEM_ID);
mItemId = mItemId.replace("i", "");

mPresenter.getNewsDetail(mDetailUrl);
loadCommentData();
}

private void loadCommentData() {
mStateView.showLoading();
mPresenter.getComment(mGroupId, mItemId, 1);
}

@Override
public void initListener() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.haoyiwen.jinritoutiao.ui.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import io.github.haoyiwen.jinritoutiao.model.entity.CommentData;

public class CommentAdapter extends BaseQuickAdapter<CommentData, BaseViewHolder> {
public CommentAdapter(int layoutResId, @Nullable List<CommentData> data) {
super(layoutResId, data);
}

@Override
protected void convert(BaseViewHolder baseViewHolder, CommentData commentDatam) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.haoyiwen.jinritoutiao.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class NewsDetailHeaderView extends FrameLayout {
public NewsDetailHeaderView(@NonNull Context context) {
super(context);
}

public NewsDetailHeaderView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public NewsDetailHeaderView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
112 changes: 68 additions & 44 deletions uikit/src/main/java/io/github/haoyiwen/uikit/LoadingFlashView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.media.Image;
import android.util.AttributeSet;
import android.view.LayoutInflater;
Expand All @@ -21,92 +23,114 @@
public class LoadingFlashView extends FrameLayout {

private View mFlashView;

private ImageView mload1;

private ImageView mload2;

private ImageView mload3;

private ImageView mload4;

private ImageView mLoad1;
private ImageView mLoad2;
private ImageView mLoad3;
private ImageView mLoad4;
private AnimatorSet mAnimatorSet;

public LoadingFlashView(@NonNull Context context) {
super(context);
public LoadingFlashView(Context context) {
this(context, null);
}

public LoadingFlashView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
public LoadingFlashView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public LoadingFlashView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public LoadingFlashView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context, attrs, defStyleAttr);
}

public LoadingFlashView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public void initView(Context context,AttributeSet attrs,int defStyleAttr){
private void initView(Context context, AttributeSet attrs, int defStyleAttr) {
mFlashView = LayoutInflater.from(context).inflate(R.layout.loading_flush_view, this);
}

@Override
protected void onFinishInflate() {
super.onFinishInflate();
mload1 = findViewById(R.id.load1);
mload2 = findViewById(R.id.load2);
mload3 = findViewById(R.id.load3);
mload4 = findViewById(R.id.load4);
mLoad1 = ((ImageView) findViewById(R.id.load1));
mLoad2 = ((ImageView) findViewById(R.id.load2));
mLoad3 = ((ImageView) findViewById(R.id.load3));
mLoad4 = ((ImageView) findViewById(R.id.load4));
showLoading();
}

private void showLoading() {
if(getVisibility() != View.VISIBLE){
public void showLoading() {
if (getVisibility() != View.VISIBLE)
return;
}
if(mAnimatorSet == null){
if (mAnimatorSet == null)
initAnimation();
}
if(mAnimatorSet.isRunning() || mAnimatorSet.isStarted()){
if (mAnimatorSet.isRunning() || mAnimatorSet.isStarted())
return;
}
mAnimatorSet.start();
}

public void hideLoading() {
if (mAnimatorSet == null)
return;
if ((!mAnimatorSet.isRunning()) && (!mAnimatorSet.isStarted()))
return;
mAnimatorSet.removeAllListeners();
mAnimatorSet.cancel();
mAnimatorSet.end();
}


private void initAnimation() {
mAnimatorSet = new AnimatorSet();

List<ImageView> imageViewList = Arrays.asList(mload1, mload2, mload3, mload4);

List<ImageView> imageViewList = Arrays.asList(mLoad1, mLoad2, mLoad3, mLoad4);
List<Animator> animatorList = new ArrayList<>();
for (int i = 0; i < 4; i++) {
ObjectAnimator loadAnimator = ObjectAnimator.ofFloat(imageViewList.get(i), "alpha", 1.0f, 0.4f);
loadAnimator.setDuration(100 * i);
ObjectAnimator loadAnimator = ObjectAnimator.ofFloat(imageViewList.get(i), "alpha", new float[]{1.0F, 0.5F}).setDuration(500L);
loadAnimator.setStartDelay(100 * i);
loadAnimator.setRepeatMode(ObjectAnimator.REVERSE);
loadAnimator.setRepeatCount(-1);
animatorList.add(loadAnimator);
}
mAnimatorSet.playTogether(animatorList);


// ObjectAnimator loadAnimator1 = ObjectAnimator.ofFloat(mLoad1, "alpha", new float[]{1.0F, 0.5F}).setDuration(500L);
// ObjectAnimator loadAnimator2 = ObjectAnimator.ofFloat(mLoad2, "alpha", new float[]{1.0F, 0.5F}).setDuration(500L);
// ObjectAnimator loadAnimator3 = ObjectAnimator.ofFloat(mLoad3, "alpha", new float[]{1.0F, 0.5F}).setDuration(500L);
// ObjectAnimator loadAnimator4 = ObjectAnimator.ofFloat(mLoad4, "alpha", new float[]{1.0F, 0.5F}).setDuration(500L);
// loadAnimator1.setStartDelay(0L);
// loadAnimator2.setStartDelay(100L);
// loadAnimator3.setStartDelay(200L);
// loadAnimator4.setStartDelay(300L);
// loadAnimator1.setRepeatMode(ObjectAnimator.REVERSE);
// loadAnimator2.setRepeatMode(ObjectAnimator.REVERSE);
// loadAnimator3.setRepeatMode(ObjectAnimator.REVERSE);
// loadAnimator4.setRepeatMode(ObjectAnimator.REVERSE);
// loadAnimator1.setRepeatCount(-1);
// loadAnimator2.setRepeatCount(-1);
// loadAnimator3.setRepeatCount(-1);
// loadAnimator4.setRepeatCount(-1);
// mAnimatorSet.playTogether(new Animator[]{loadAnimator1, loadAnimator2, loadAnimator3, loadAnimator4});
}

private void hideLoading() {
if(mAnimatorSet == null){
return;
}
if((!mAnimatorSet.isRunning()) && (!mAnimatorSet.isStarted())){
return;
public void setLoadingTheme(boolean isNight) {
if (isNight) {
PorterDuffColorFilter localPorterDuffColorFilter = new PorterDuffColorFilter(getResources().getColor(R.color.subscribe_category_bar_bg_night), PorterDuff.Mode.SRC_ATOP);
mLoad1.setColorFilter(localPorterDuffColorFilter);
mLoad2.setColorFilter(localPorterDuffColorFilter);
mLoad3.setColorFilter(localPorterDuffColorFilter);
mLoad4.setColorFilter(localPorterDuffColorFilter);
} else {
mLoad1.setColorFilter(null);
mLoad2.setColorFilter(null);
mLoad3.setColorFilter(null);
mLoad4.setColorFilter(null);
}
mAnimatorSet.removeAllListeners();
mAnimatorSet.cancel();
mAnimatorSet.end();
}

@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if(visibility!=VISIBLE){
if (visibility != VISIBLE)
hideLoading();
}
}
}

0 comments on commit 1b2fc37

Please sign in to comment.