Skip to content

Commit

Permalink
修改拦截器命名,更新README
Browse files Browse the repository at this point in the history
  • Loading branch information
chay committed Jul 17, 2024
1 parent 9b40b64 commit 1a4daae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
22 changes: 14 additions & 8 deletions README-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@

#### 跳转前拦截
```
mBottomBarLayout.setOnPageChangedIntercepagetor(position -> {
mBottomBarLayout.setOnPageChangeInterceptor(position -> {
boolean isLogin = false; //模拟没有登录
if (position == TAB_POSITION_ME && !isLogin){
//no login intercept to other tab or to LoginActivity
Expand All @@ -265,16 +265,22 @@

#### 设置条目选中的监听
```
mBottomBarLayout.setOnItemSelectedListener((bottomBarItem, previousPosition, currentPosition) -> {
//do something
});
mBottomBarLayout.setOnItemSelectedListener((bottomBarItem, previousPosition, currentPosition) -> {
//do something
});
```

#### 设置同个tab重复点击是否回调setOnItemSelectedListener
```
app:sameTabClickCallBack="true" //默认为false
```

#### 显示未读数、提示小红点、提示消息
```
mBottomBarLayout.setUnread(0,20);//设置第一个页签的未读数为20
mBottomBarLayout.setUnread(1,101);//设置第二个页签的未读数
mBottomBarLayout.showNotify(2);//设置第三个页签显示提示的小红点
mBottomBarLayout.setMsg(3,"NEW");//设置第四个页签显示NEW提示文字
mBottomBarLayout.setUnread(0,20);//设置第一个页签的未读数为20
mBottomBarLayout.setUnread(1,101);//设置第二个页签的未读数
mBottomBarLayout.showNotify(2);//设置第三个页签显示提示的小红点
mBottomBarLayout.setMsg(3,"NEW");//设置第四个页签显示NEW提示文字
```
当设置的未读数小于或等于0时,消失未读数的小红点将会消失;
当未读数为1-99时,则显示对应的数字;
Expand Down
2 changes: 1 addition & 1 deletion README-en-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ The effect after opening is as follows:

#### Intercept before jump
```
mBottomBarLayout.setOnPageChangedIntercepagetor(position -> {
mBottomBarLayout.setOnPageChangeInterceptor(position -> {
boolean isLogin = false; //Simulate no login
if (position == TAB_POSITION_ME && !isLogin){
//no login intercept to other tab or to LoginActivity
Expand Down
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ The effect after opening is as follows:

#### Intercept before jump
```
mBottomBarLayout.setOnPageChangedIntercepagetor(position -> {
mBottomBarLayout.setOnPageChangeInterceptor(position -> {
boolean isLogin = false; //Simulate no login
if (position == TAB_POSITION_ME && !isLogin){
//no login intercept to other tab or to LoginActivity
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@

#### 跳转前拦截
```
mBottomBarLayout.setOnPageChangedIntercepagetor(position -> {
mBottomBarLayout.setOnPageChangeInterceptor(position -> {
if(position == TAB_POSITION_ADD){
//中间凸起图标的位置
Toast.makeText(ViewPager2DemoActivity.this, "可以跳转别的页面,比如发布页", Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.chaychan.bottombarlayout;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
Expand All @@ -18,7 +17,6 @@
import com.chaychan.library.TabData;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -84,7 +82,7 @@ public void initListener() {
mBottomBarLayout.showNotify(3);//设置第三个页签显示提示的小红点
mBottomBarLayout.setMsg(4, "NEW");//设置第四个页签显示NEW提示文字

mBottomBarLayout.setOnPageChangedIntercepagetor(position -> {
mBottomBarLayout.setOnPageChangeInterceptor(position -> {
if(position == 2){
//中间凸起图标的位置
Toast.makeText(ViewPager2DemoActivity.this, "可以跳转别的页面,比如发布页", Toast.LENGTH_SHORT).show();
Expand Down
23 changes: 9 additions & 14 deletions library/src/main/java/com/chaychan/library/BottomBarLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
Expand All @@ -14,11 +12,8 @@
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;

Expand Down Expand Up @@ -277,8 +272,8 @@ public void removeItem(int position) {

private void handlePageSelected(int position){
//滑动时判断是否需要拦截跳转
if (onPageChangedIntercepagetor != null
&& onPageChangedIntercepagetor.onPageChangedIntercepted(position)){
if (mOnPageChangeInterceptor != null
&& mOnPageChangeInterceptor.onIntercepted(position)){
setCurrentItem(mCurrentItem);
return;
}
Expand Down Expand Up @@ -317,8 +312,8 @@ public MyOnClickListener(int i) {
@Override
public void onClick(View v) {
//点击时判断是否需要拦截跳转
if (onPageChangedIntercepagetor != null
&& onPageChangedIntercepagetor.onPageChangedIntercepted(currentIndex)){
if (mOnPageChangeInterceptor != null
&& mOnPageChangeInterceptor.onIntercepted(currentIndex)){
return;
}
if (currentIndex == mCurrentItem) {
Expand Down Expand Up @@ -444,13 +439,13 @@ public void setOnItemSelectedListener(OnItemSelectedListener onItemSelectedListe
this.onItemSelectedListener = onItemSelectedListener;
}

private OnItemClickInterceptor onPageChangedIntercepagetor;
private OnPageChangeInterceptor mOnPageChangeInterceptor;

public void setOnPageChangedIntercepagetor(OnItemClickInterceptor onPageChangedIntercepagetor) {
this.onPageChangedIntercepagetor = onPageChangedIntercepagetor;
public void setOnPageChangeInterceptor(OnPageChangeInterceptor onPageChangedInterceptor) {
mOnPageChangeInterceptor = onPageChangedInterceptor;
}

public interface OnItemClickInterceptor{
boolean onPageChangedIntercepted(int position);
public interface OnPageChangeInterceptor {
boolean onIntercepted(int position);
}
}

0 comments on commit 1a4daae

Please sign in to comment.