rc
This commit is contained in:
@@ -12,7 +12,7 @@ ext {
|
||||
dependencies = [
|
||||
// androidx
|
||||
androidxappcompat : "androidx.appcompat:appcompat:1.0.2",
|
||||
androidxccorektx : "androidx.core:core-ktx:1.0.2",
|
||||
androidxccorektx : "androidx.core:core-ktx:1.2.0",
|
||||
androidxconstraintlayout : "androidx.constraintlayout:constraintlayout:1.1.3",
|
||||
androidxmultidex : "androidx.multidex:multidex:2.0.1",
|
||||
androidxviewpager2 : "androidx.viewpager2:viewpager2:1.0.0",
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.mvp.MvpFragment;
|
||||
@@ -19,7 +20,6 @@ import com.mogo.service.cardmanager.IMogoCardChangedListener;
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.module.IMogoModuleProvider;
|
||||
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.yarolegovich.discretescrollview.DiscreteScrollView;
|
||||
import java.util.ArrayList;
|
||||
@@ -179,7 +179,13 @@ public class AppNavigatorFragment extends MvpFragment<AppNavigatorView, AppNavig
|
||||
|
||||
@Override
|
||||
public void onCurrentItemChanged(@Nullable RecyclerView.ViewHolder viewHolder, int i) {
|
||||
//AppServiceHandler.getMogoCardManager().invoke(i%CARD_SIZE,"");
|
||||
Logger.d(TAG, "onCurrentItemChanged--position--" + i % CARD_SIZE);
|
||||
int currentPosition = i % CARD_SIZE - 2;
|
||||
if (currentPosition < 0) {
|
||||
currentPosition += CARD_SIZE;
|
||||
}
|
||||
this.currentPosition=currentPosition;
|
||||
AppServiceHandler.getMogoCardManager().invoke(currentPosition, "");
|
||||
}
|
||||
|
||||
@Override public void onScrollStart(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
@@ -196,15 +202,33 @@ public class AppNavigatorFragment extends MvpFragment<AppNavigatorView, AppNavig
|
||||
|
||||
}
|
||||
|
||||
private int currentPosition = 0;
|
||||
|
||||
@Override public void onSwitched(int position, String moduleName) {
|
||||
int index = (position - scroller.getCurrentItem() % CARD_SIZE + 2) % CARD_SIZE;
|
||||
int i = scroller.getCurrentItem() + index;
|
||||
//DiscreteScrollLayoutManager layoutManager =
|
||||
// (DiscreteScrollLayoutManager) scroller.getLayoutManager();
|
||||
//int index = (position - scroller.getCurrentItem() % CARD_SIZE + 2) % CARD_SIZE;
|
||||
//int i = scroller.getCurrentItem() + index;
|
||||
//LinearLayoutManager layoutManager =
|
||||
// (LinearLayoutManager) scroller.getLayoutManager();
|
||||
//
|
||||
//layoutManager.smoothScrollToPosition();
|
||||
|
||||
Logger.d(TAG, "position" + index + "scroll" + i);
|
||||
scroller.smoothScrollToPosition(i);
|
||||
int index = position - currentPosition;
|
||||
|
||||
if (index == 0) {
|
||||
return;
|
||||
}
|
||||
if (index < -2) {
|
||||
index = 1;
|
||||
} else if (index > 2) {
|
||||
index = -1;
|
||||
}
|
||||
//很奇怪,但是位置就是相差
|
||||
if (index == -1) {
|
||||
index = -3;
|
||||
}
|
||||
|
||||
Logger.d(TAG, "position--" + position + "index--" + index);
|
||||
scroller.smoothScrollToPosition(scroller.getCurrentItem() + index);
|
||||
currentPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -14,6 +15,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.accessibility.AccessibilityEventCompat;
|
||||
import androidx.core.view.accessibility.AccessibilityRecordCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearSmoothScroller;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.yarolegovich.discretescrollview.transform.DiscreteScrollItemTransformer;
|
||||
@@ -23,7 +25,7 @@ import java.util.Locale;
|
||||
/**
|
||||
* Created by yarolegovich on 17.02.2017.
|
||||
*/
|
||||
class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
|
||||
class DiscreteScrollLayoutManager extends LinearLayoutManager {
|
||||
|
||||
static final int NO_POSITION = -1;
|
||||
|
||||
@@ -79,6 +81,7 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
|
||||
@NonNull Context c,
|
||||
@NonNull ScrollStateListener scrollStateListener,
|
||||
@NonNull DSVOrientation orientation) {
|
||||
super(c);
|
||||
this.context = c;
|
||||
this.timeForItemSettle = DEFAULT_TIME_FOR_ITEM_SETTLE;
|
||||
this.pendingPosition = NO_POSITION;
|
||||
@@ -355,18 +358,39 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
|
||||
recyclerViewProxy.requestLayout();
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
|
||||
// if (currentPosition == position || pendingPosition != NO_POSITION) {
|
||||
// return;
|
||||
// }
|
||||
// checkTargetPosition(state, position);
|
||||
// if (currentPosition == NO_POSITION) {
|
||||
// //Layout not happened yet
|
||||
// currentPosition = position;
|
||||
// } else {
|
||||
// startSmoothPendingScroll(position);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
@Override
|
||||
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
|
||||
if (currentPosition == position || pendingPosition != NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
checkTargetPosition(state, position);
|
||||
if (currentPosition == NO_POSITION) {
|
||||
//Layout not happened yet
|
||||
currentPosition = position;
|
||||
} else {
|
||||
startSmoothPendingScroll(position);
|
||||
}
|
||||
LinearSmoothScroller smoothScroller =
|
||||
new LinearSmoothScroller(recyclerView.getContext()) {
|
||||
@Override
|
||||
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
|
||||
// 返回:滑过1px时经历的时间(ms)。
|
||||
return 150f / displayMetrics.densityDpi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
|
||||
return boxStart - viewStart;
|
||||
}
|
||||
};
|
||||
|
||||
smoothScroller.setTargetPosition(position);
|
||||
startSmoothScroll(smoothScroller);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -512,6 +536,9 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
|
||||
startSmoothPendingScroll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAutoMeasureEnabled() {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user