Skip to content

Commit

Permalink
滑动到对应页添加拦截判断
Browse files Browse the repository at this point in the history
  • Loading branch information
chay committed Jul 17, 2024
1 parent 7da9671 commit d5d9423
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void initListener() {
mBottomBarLayout.showNotify(2);//设置第三个页签显示提示的小红点
mBottomBarLayout.setMsg(3, "NEW");//设置第四个页签显示NEW提示文字

mBottomBarLayout.setOnItemClickInterceptor(position -> {
mBottomBarLayout.setOnPageChangedInterceptor(position -> {
boolean isLogin = false;
if (position == 3 && !isLogin){
//no login intercept to other tab or to LoginActivity
Expand Down
20 changes: 12 additions & 8 deletions library/src/main/java/com/chaychan/library/BottomBarLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

Expand Down Expand Up @@ -136,6 +135,11 @@ public void removeItem(int position) {
}

private void handlePageSelected(int position){
if (onPageChangedInterceptor != null
&& onPageChangedInterceptor.onPageChangedIntercepted(position)){
setCurrentItem(mCurrentItem);
return;
}
resetState();
mItemViews.get(position).refreshTab(true);
int prePos = mCurrentItem;
Expand Down Expand Up @@ -171,8 +175,8 @@ public MyOnClickListener(int i) {
@Override
public void onClick(View v) {
//点击时判断是否需要拦截跳转
if (onItemClickInterceptor != null
&& onItemClickInterceptor.onItemClickIntercepted(currentIndex)){
if (onPageChangedInterceptor != null
&& onPageChangedInterceptor.onPageChangedIntercepted(currentIndex)){
return;
}
if (currentIndex == mCurrentItem) {
Expand Down Expand Up @@ -298,13 +302,13 @@ public void setOnItemSelectedListener(OnItemSelectedListener onItemSelectedListe
this.onItemSelectedListener = onItemSelectedListener;
}

private OnItemClickInterceptor onItemClickInterceptor;
private OnPageChangedInterceptor onPageChangedInterceptor;

public void setOnItemClickInterceptor(OnItemClickInterceptor onItemClickInterceptor) {
this.onItemClickInterceptor = onItemClickInterceptor;
public void setOnPageChangedInterceptor(OnPageChangedInterceptor onPageChangedInterceptor) {
this.onPageChangedInterceptor = onPageChangedInterceptor;
}

public interface OnItemClickInterceptor{
boolean onItemClickIntercepted(int position);
public interface OnPageChangedInterceptor {
boolean onPageChangedIntercepted(int position);
}
}

0 comments on commit d5d9423

Please sign in to comment.