[6.6.0]
[fea] [选择线路封装为view]
This commit is contained in:
@@ -2,10 +2,7 @@
|
||||
package="com.mogo.och.shuttle.weaknet">
|
||||
|
||||
<application>
|
||||
<activity android:name="com.mogo.och.weaknet.ui.BusSwitchLineActivity"
|
||||
android:theme="@style/SwitchLineDialogStyle"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="landscape" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -40,6 +40,20 @@ public class BusQueryLinesResponse extends BaseData {
|
||||
public boolean haveTask;
|
||||
|
||||
public List<BusQueryLineTaskResponse.Result> taskList;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Result result = (Result) o;
|
||||
return lineId == result.lineId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Long.hashCode(lineId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.weaknet.constant.BusConst
|
||||
import com.mogo.och.weaknet.presenter.BusPresenter
|
||||
import com.mogo.och.weaknet.ui.BusStationCommonItem
|
||||
import com.mogo.och.weaknet.ui.BusSwitchLineActivity
|
||||
import com.mogo.och.weaknet.ui.taskrunning.RunningTaskManager
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
@@ -516,8 +515,9 @@ class ShuttleFragment : BaseShuttleTabFragment<ShuttleFragment?, BusPresenter?>(
|
||||
return
|
||||
}
|
||||
if (mSwitchLine!!.tag as Int == 0) { //切换路线
|
||||
val intent = Intent(context, BusSwitchLineActivity::class.java)
|
||||
ActivityUtils.startActivity(intent)
|
||||
context?.let {
|
||||
RunningTaskManager.showSwitchLineWindow(it)
|
||||
}
|
||||
} else { //结束任务
|
||||
val builder = OCHCommitDialog.Builder()
|
||||
val closeLineConfirmDialog = builder
|
||||
|
||||
@@ -46,7 +46,6 @@ import com.mogo.och.weaknet.database.transform.FRetryWithTime11
|
||||
import com.mogo.och.weaknet.database.transform.TransformTask
|
||||
import com.mogo.och.weaknet.database.transform.transform4DataBase
|
||||
import com.mogo.och.weaknet.net.OrderServiceManager
|
||||
import com.mogo.och.weaknet.ui.BusSwitchLineActivity
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.disposables.Disposable
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
@@ -68,6 +67,8 @@ object BusLineModel {
|
||||
// 展示上一次刷新时间
|
||||
const val executableChangeTime = "executablechangetime"
|
||||
|
||||
const val LASTCOMMITLINEID = "lastcommitlineid"
|
||||
|
||||
var currentTask: TaskDataBean?=null
|
||||
|
||||
// 当前任务的站点列表
|
||||
@@ -251,7 +252,7 @@ object BusLineModel {
|
||||
object : TaskRepository.TaskStatusCallback {
|
||||
override fun startSuccess() {
|
||||
SharedPrefsMgr.getInstance()
|
||||
.putLong(BusSwitchLineActivity.LASTCOMMITLINEID, line.lineId)
|
||||
.putLong(LASTCOMMITLINEID, line.lineId)
|
||||
EventRepository.saveEventTaskStart(task.id,line.lineId,task.taskStartTime,line.name)
|
||||
mBusLinesCallback?.onChangeLineIdSuccess()
|
||||
}
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
package com.mogo.och.weaknet.presenter
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.mogo.commons.mvp.Presenter
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse
|
||||
import com.mogo.och.weaknet.callback.IBusLinesCallback
|
||||
import com.mogo.och.weaknet.model.BusLineModel
|
||||
import com.mogo.och.weaknet.model.BusLineModel.executableChangeTime
|
||||
import com.mogo.och.weaknet.model.BusLineModel.queryBusLineTasksById
|
||||
import com.mogo.och.weaknet.model.BusLineModel.setBusLinesCallback
|
||||
import com.mogo.och.weaknet.model.OrderModel
|
||||
import com.mogo.och.weaknet.model.OrderModel.clearBusStationDatas
|
||||
import com.mogo.och.weaknet.ui.BusSwitchLineView
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/2/9
|
||||
*/
|
||||
class BusLinePresenter(view: BusSwitchLineView?) : Presenter<BusSwitchLineView?>(view),
|
||||
IBusLinesCallback {
|
||||
private var subscribe: Disposable? = null
|
||||
|
||||
init {
|
||||
BusLineModel.init()
|
||||
OrderModel.init()
|
||||
}
|
||||
|
||||
override fun onCreate(owner: LifecycleOwner) {
|
||||
super.onCreate(owner)
|
||||
initListener()
|
||||
initData()
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
BusLineModel.refreshTask()
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
setBusLinesCallback(this)
|
||||
}
|
||||
|
||||
override fun onBusLinesChange(data: List<BusQueryLinesResponse.Result>) {
|
||||
mView?.onBusLinesChange(data)
|
||||
}
|
||||
|
||||
override fun onChangeLineIdSuccess() {
|
||||
clearBusStationDatas()
|
||||
UiThreadHandler.post({
|
||||
mView?.startTaskState(true)
|
||||
mView?.onChangeLineIdSuccess()
|
||||
}, UiThreadHandler.MODE.QUEUE)
|
||||
}
|
||||
|
||||
fun queryBusLines() {
|
||||
BusLineModel.queryBusLines()
|
||||
}
|
||||
|
||||
fun queryBusLineTasks(lineId: Long, position: Int, close: Boolean) {
|
||||
if (subscribe != null && !subscribe!!.isDisposed) {
|
||||
subscribe!!.dispose()
|
||||
}
|
||||
if (close) {
|
||||
return
|
||||
}
|
||||
queryBusLineTasksById(lineId, position, false)
|
||||
subscribe = Observable.interval(3, TimeUnit.MINUTES).subscribe { aLong: Long? ->
|
||||
queryBusLineTasksById(lineId, position, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun commitSwitchLineId(taskId: BusQueryLineTaskResponse.Result, lineId: BusQueryLinesResponse.Result) {
|
||||
BusLineModel.commitSwitchLineId(taskId, lineId)
|
||||
}
|
||||
|
||||
fun removeListener() {
|
||||
setBusLinesCallback(null)
|
||||
}
|
||||
|
||||
fun queryBusRoutes() {
|
||||
OrderModel.queryBusRoutes()
|
||||
}
|
||||
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
super.onDestroy(owner)
|
||||
if (subscribe != null && !subscribe!!.isDisposed) {
|
||||
subscribe!!.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onBusLineTasks(
|
||||
o: List<BusQueryLineTaskResponse.Result>,
|
||||
position: Int,
|
||||
autoRefresh: Boolean
|
||||
) {
|
||||
mView?.onBusLineTasks(o, position, autoRefresh)
|
||||
}
|
||||
|
||||
override fun onRefreshSuccess(currentTimeStamp: Long) {
|
||||
mView?.refreshDate(DateTimeUtil.formatLongToString(currentTimeStamp,DateTimeUtil.yyyy_MM_dd_HH_mm_ss))
|
||||
}
|
||||
|
||||
override fun onChangeLineIdFail() {
|
||||
mView?.startTaskState(false)
|
||||
}
|
||||
|
||||
fun refreshTask() {
|
||||
BusLineModel.refreshTask()
|
||||
}
|
||||
|
||||
fun setRefreshTime() {
|
||||
val lastUpdateTime = SharedPrefsMgr.getInstance().getLong(executableChangeTime, -1)
|
||||
if(lastUpdateTime>0){
|
||||
onRefreshSuccess(lastUpdateTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.mogo.och.weaknet.ui;
|
||||
|
||||
import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse;
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/2/10
|
||||
*/
|
||||
public interface BusSwitchLineView extends IView {
|
||||
|
||||
void onBusLinesChange(List<BusQueryLinesResponse.Result> data);
|
||||
void onChangeLineIdSuccess();
|
||||
|
||||
void onBusLineTasks(List<BusQueryLineTaskResponse.Result> o, int position,boolean autoRefresh);
|
||||
|
||||
void refreshDate(@Nullable String formatLongToString);
|
||||
|
||||
void startTaskState(boolean b);
|
||||
}
|
||||
|
||||
@@ -1,643 +0,0 @@
|
||||
package com.mogo.och.weaknet.ui.adapter;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.TimeInterpolator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.view.View;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This implementation of {@link RecyclerView.ItemAnimator} provides basic
|
||||
* animations on remove, add, and move events that happen to the items in
|
||||
* a RecyclerView. RecyclerView uses a DefaultItemAnimator by default.
|
||||
*
|
||||
* @see RecyclerView#setItemAnimator(RecyclerView.ItemAnimator)
|
||||
*/
|
||||
public class OpenItemAnimator extends DefaultItemAnimator {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static TimeInterpolator sDefaultInterpolator;
|
||||
|
||||
private final ArrayList<RecyclerView.ViewHolder> mPendingRemovals = new ArrayList<>();
|
||||
private final ArrayList<RecyclerView.ViewHolder> mPendingAdditions = new ArrayList<>();
|
||||
private final ArrayList<MoveInfo> mPendingMoves = new ArrayList<>();
|
||||
private final ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>();
|
||||
|
||||
ArrayList<ArrayList<RecyclerView.ViewHolder>> mAdditionsList = new ArrayList<>();
|
||||
ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
|
||||
ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
|
||||
|
||||
ArrayList<RecyclerView.ViewHolder> mAddAnimations = new ArrayList<>();
|
||||
ArrayList<RecyclerView.ViewHolder> mMoveAnimations = new ArrayList<>();
|
||||
ArrayList<RecyclerView.ViewHolder> mRemoveAnimations = new ArrayList<>();
|
||||
ArrayList<RecyclerView.ViewHolder> mChangeAnimations = new ArrayList<>();
|
||||
|
||||
private static class MoveInfo {
|
||||
public RecyclerView.ViewHolder holder;
|
||||
public int fromX, fromY, toX, toY;
|
||||
|
||||
MoveInfo(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
|
||||
this.holder = holder;
|
||||
this.fromX = fromX;
|
||||
this.fromY = fromY;
|
||||
this.toX = toX;
|
||||
this.toY = toY;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChangeInfo {
|
||||
public RecyclerView.ViewHolder oldHolder, newHolder;
|
||||
public int fromX, fromY, toX, toY;
|
||||
private ChangeInfo(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder) {
|
||||
this.oldHolder = oldHolder;
|
||||
this.newHolder = newHolder;
|
||||
}
|
||||
|
||||
ChangeInfo(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
|
||||
int fromX, int fromY, int toX, int toY) {
|
||||
this(oldHolder, newHolder);
|
||||
this.fromX = fromX;
|
||||
this.fromY = fromY;
|
||||
this.toX = toX;
|
||||
this.toY = toY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChangeInfo{"
|
||||
+ "oldHolder=" + oldHolder
|
||||
+ ", newHolder=" + newHolder
|
||||
+ ", fromX=" + fromX
|
||||
+ ", fromY=" + fromY
|
||||
+ ", toX=" + toX
|
||||
+ ", toY=" + toY
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runPendingAnimations() {
|
||||
boolean removalsPending = !mPendingRemovals.isEmpty();
|
||||
boolean movesPending = !mPendingMoves.isEmpty();
|
||||
boolean changesPending = !mPendingChanges.isEmpty();
|
||||
boolean additionsPending = !mPendingAdditions.isEmpty();
|
||||
if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
|
||||
// nothing to animate
|
||||
return;
|
||||
}
|
||||
// First, remove stuff
|
||||
for (RecyclerView.ViewHolder holder : mPendingRemovals) {
|
||||
animateRemoveImpl(holder);
|
||||
}
|
||||
mPendingRemovals.clear();
|
||||
// Next, move stuff
|
||||
if (movesPending) {
|
||||
final ArrayList<MoveInfo> moves = new ArrayList<>(mPendingMoves);
|
||||
mMovesList.add(moves);
|
||||
mPendingMoves.clear();
|
||||
Runnable mover = () -> {
|
||||
for (MoveInfo moveInfo : moves) {
|
||||
animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY,
|
||||
moveInfo.toX, moveInfo.toY);
|
||||
}
|
||||
moves.clear();
|
||||
mMovesList.remove(moves);
|
||||
};
|
||||
if (removalsPending) {
|
||||
View view = moves.get(0).holder.itemView;
|
||||
ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
|
||||
} else {
|
||||
mover.run();
|
||||
}
|
||||
}
|
||||
// Next, change stuff, to run in parallel with move animations
|
||||
if (changesPending) {
|
||||
final ArrayList<ChangeInfo> changes = new ArrayList<>(mPendingChanges);
|
||||
mChangesList.add(changes);
|
||||
mPendingChanges.clear();
|
||||
Runnable changer = () -> {
|
||||
for (ChangeInfo change : changes) {
|
||||
animateChangeImpl(change);
|
||||
}
|
||||
changes.clear();
|
||||
mChangesList.remove(changes);
|
||||
};
|
||||
if (removalsPending) {
|
||||
RecyclerView.ViewHolder holder = changes.get(0).oldHolder;
|
||||
ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
|
||||
} else {
|
||||
changer.run();
|
||||
}
|
||||
}
|
||||
// Next, add stuff
|
||||
if (additionsPending) {
|
||||
final ArrayList<RecyclerView.ViewHolder> additions = new ArrayList<>(mPendingAdditions);
|
||||
mAdditionsList.add(additions);
|
||||
mPendingAdditions.clear();
|
||||
Runnable adder = () -> {
|
||||
for (RecyclerView.ViewHolder holder : additions) {
|
||||
animateAddImpl(holder);
|
||||
}
|
||||
additions.clear();
|
||||
mAdditionsList.remove(additions);
|
||||
};
|
||||
if (removalsPending || movesPending || changesPending) {
|
||||
long removeDuration = removalsPending ? getRemoveDuration() : 0;
|
||||
long moveDuration = movesPending ? getMoveDuration() : 0;
|
||||
long changeDuration = changesPending ? getChangeDuration() : 0;
|
||||
long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
|
||||
View view = additions.get(0).itemView;
|
||||
ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
|
||||
} else {
|
||||
adder.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean animateRemove(final RecyclerView.ViewHolder holder) {
|
||||
resetAnimation(holder);
|
||||
mPendingRemovals.add(holder);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
|
||||
final View view = holder.itemView;
|
||||
final ViewPropertyAnimator animation = view.animate();
|
||||
mRemoveAnimations.add(holder);
|
||||
animation.setDuration(getRemoveDuration()).alpha(0).setListener(
|
||||
new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
dispatchRemoveStarting(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
animation.setListener(null);
|
||||
view.setAlpha(1);
|
||||
dispatchRemoveFinished(holder);
|
||||
mRemoveAnimations.remove(holder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean animateAdd(final RecyclerView.ViewHolder holder) {
|
||||
resetAnimation(holder);
|
||||
holder.itemView.setAlpha(0);
|
||||
mPendingAdditions.add(holder);
|
||||
return true;
|
||||
}
|
||||
|
||||
void animateAddImpl(final RecyclerView.ViewHolder holder) {
|
||||
final View view = holder.itemView;
|
||||
final ViewPropertyAnimator animation = view.animate();
|
||||
mAddAnimations.add(holder);
|
||||
animation.alpha(1).setDuration(getAddDuration())
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
dispatchAddStarting(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
view.setAlpha(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
animation.setListener(null);
|
||||
dispatchAddFinished(holder);
|
||||
mAddAnimations.remove(holder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
|
||||
int toX, int toY) {
|
||||
final View view = holder.itemView;
|
||||
fromX += (int) holder.itemView.getTranslationX();
|
||||
fromY += (int) holder.itemView.getTranslationY();
|
||||
resetAnimation(holder);
|
||||
int deltaX = toX - fromX;
|
||||
int deltaY = toY - fromY;
|
||||
if (deltaX == 0 && deltaY == 0) {
|
||||
dispatchMoveFinished(holder);
|
||||
return false;
|
||||
}
|
||||
if (deltaX != 0) {
|
||||
view.setTranslationX(-deltaX);
|
||||
}
|
||||
if (deltaY != 0) {
|
||||
view.setTranslationY(-deltaY);
|
||||
}
|
||||
mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
|
||||
return true;
|
||||
}
|
||||
|
||||
void animateMoveImpl(final RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
|
||||
final View view = holder.itemView;
|
||||
final int deltaX = toX - fromX;
|
||||
final int deltaY = toY - fromY;
|
||||
if (deltaX != 0) {
|
||||
view.animate().translationX(0);
|
||||
}
|
||||
if (deltaY != 0) {
|
||||
view.animate().translationY(0);
|
||||
}
|
||||
// TODO: make EndActions end listeners instead, since end actions aren't called when
|
||||
// vpas are canceled (and can't end them. why?)
|
||||
// need listener functionality in VPACompat for this. Ick.
|
||||
final ViewPropertyAnimator animation = view.animate();
|
||||
mMoveAnimations.add(holder);
|
||||
animation.setDuration(getMoveDuration()).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
dispatchMoveStarting(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
if (deltaX != 0) {
|
||||
view.setTranslationX(0);
|
||||
}
|
||||
if (deltaY != 0) {
|
||||
view.setTranslationY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
animation.setListener(null);
|
||||
dispatchMoveFinished(holder);
|
||||
mMoveAnimations.remove(holder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
|
||||
int fromX, int fromY, int toX, int toY) {
|
||||
if (oldHolder == newHolder) {
|
||||
// Don't know how to run change animations when the same view holder is re-used.
|
||||
// run a move animation to handle position changes.
|
||||
return animateMove(oldHolder, fromX, fromY, toX, toY);
|
||||
}
|
||||
final float prevTranslationX = oldHolder.itemView.getTranslationX();
|
||||
final float prevTranslationY = oldHolder.itemView.getTranslationY();
|
||||
final float prevAlpha = oldHolder.itemView.getAlpha();
|
||||
resetAnimation(oldHolder);
|
||||
int deltaX = (int) (toX - fromX - prevTranslationX);
|
||||
int deltaY = (int) (toY - fromY - prevTranslationY);
|
||||
// recover prev translation state after ending animation
|
||||
oldHolder.itemView.setTranslationX(prevTranslationX);
|
||||
oldHolder.itemView.setTranslationY(prevTranslationY);
|
||||
oldHolder.itemView.setAlpha(prevAlpha);
|
||||
if (newHolder != null) {
|
||||
// carry over translation values
|
||||
resetAnimation(newHolder);
|
||||
newHolder.itemView.setTranslationX(-deltaX);
|
||||
newHolder.itemView.setTranslationY(-deltaY);
|
||||
newHolder.itemView.setAlpha(0);
|
||||
}
|
||||
mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
|
||||
return true;
|
||||
}
|
||||
|
||||
void animateChangeImpl(final ChangeInfo changeInfo) {
|
||||
final RecyclerView.ViewHolder holder = changeInfo.oldHolder;
|
||||
final View view = holder == null ? null : holder.itemView;
|
||||
final RecyclerView.ViewHolder newHolder = changeInfo.newHolder;
|
||||
final View newView = newHolder != null ? newHolder.itemView : null;
|
||||
if (view != null) {
|
||||
final ViewPropertyAnimator oldViewAnim = view.animate().setDuration(
|
||||
getChangeDuration());
|
||||
mChangeAnimations.add(changeInfo.oldHolder);
|
||||
oldViewAnim.translationX((float)(changeInfo.toX - changeInfo.fromX));
|
||||
oldViewAnim.translationY((float)(changeInfo.toY - changeInfo.fromY));
|
||||
oldViewAnim.alpha(0).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
dispatchChangeStarting(changeInfo.oldHolder, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
oldViewAnim.setListener(null);
|
||||
view.setAlpha(1);
|
||||
view.setTranslationX(0);
|
||||
view.setTranslationY(0);
|
||||
dispatchChangeFinished(changeInfo.oldHolder, true);
|
||||
mChangeAnimations.remove(changeInfo.oldHolder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
if (newView != null) {
|
||||
final ViewPropertyAnimator newViewAnimation = newView.animate();
|
||||
mChangeAnimations.add(changeInfo.newHolder);
|
||||
newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration())
|
||||
.alpha(1).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
dispatchChangeStarting(changeInfo.newHolder, false);
|
||||
}
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
newViewAnimation.setListener(null);
|
||||
newView.setAlpha(1);
|
||||
newView.setTranslationX(0);
|
||||
newView.setTranslationY(0);
|
||||
dispatchChangeFinished(changeInfo.newHolder, false);
|
||||
mChangeAnimations.remove(changeInfo.newHolder);
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
private void endChangeAnimation(List<ChangeInfo> infoList, RecyclerView.ViewHolder item) {
|
||||
for (int i = infoList.size() - 1; i >= 0; i--) {
|
||||
ChangeInfo changeInfo = infoList.get(i);
|
||||
if (endChangeAnimationIfNecessary(changeInfo, item)) {
|
||||
if (changeInfo.oldHolder == null && changeInfo.newHolder == null) {
|
||||
infoList.remove(changeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void endChangeAnimationIfNecessary(ChangeInfo changeInfo) {
|
||||
if (changeInfo.oldHolder != null) {
|
||||
endChangeAnimationIfNecessary(changeInfo, changeInfo.oldHolder);
|
||||
}
|
||||
if (changeInfo.newHolder != null) {
|
||||
endChangeAnimationIfNecessary(changeInfo, changeInfo.newHolder);
|
||||
}
|
||||
}
|
||||
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
|
||||
boolean oldItem = false;
|
||||
if (changeInfo.newHolder == item) {
|
||||
changeInfo.newHolder = null;
|
||||
} else if (changeInfo.oldHolder == item) {
|
||||
changeInfo.oldHolder = null;
|
||||
oldItem = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
item.itemView.setAlpha(1);
|
||||
item.itemView.setTranslationX(0);
|
||||
item.itemView.setTranslationY(0);
|
||||
dispatchChangeFinished(item, oldItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endAnimation(RecyclerView.ViewHolder item) {
|
||||
final View view = item.itemView;
|
||||
// this will trigger end callback which should set properties to their target values.
|
||||
view.animate().cancel();
|
||||
// TODO if some other animations are chained to end, how do we cancel them as well?
|
||||
for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
|
||||
MoveInfo moveInfo = mPendingMoves.get(i);
|
||||
if (moveInfo.holder == item) {
|
||||
view.setTranslationY(0);
|
||||
view.setTranslationX(0);
|
||||
dispatchMoveFinished(item);
|
||||
mPendingMoves.remove(i);
|
||||
}
|
||||
}
|
||||
endChangeAnimation(mPendingChanges, item);
|
||||
if (mPendingRemovals.remove(item)) {
|
||||
view.setAlpha(1);
|
||||
dispatchRemoveFinished(item);
|
||||
}
|
||||
if (mPendingAdditions.remove(item)) {
|
||||
view.setAlpha(1);
|
||||
dispatchAddFinished(item);
|
||||
}
|
||||
|
||||
for (int i = mChangesList.size() - 1; i >= 0; i--) {
|
||||
ArrayList<ChangeInfo> changes = mChangesList.get(i);
|
||||
endChangeAnimation(changes, item);
|
||||
if (changes.isEmpty()) {
|
||||
mChangesList.remove(i);
|
||||
}
|
||||
}
|
||||
for (int i = mMovesList.size() - 1; i >= 0; i--) {
|
||||
ArrayList<MoveInfo> moves = mMovesList.get(i);
|
||||
for (int j = moves.size() - 1; j >= 0; j--) {
|
||||
MoveInfo moveInfo = moves.get(j);
|
||||
if (moveInfo.holder == item) {
|
||||
view.setTranslationY(0);
|
||||
view.setTranslationX(0);
|
||||
dispatchMoveFinished(item);
|
||||
moves.remove(j);
|
||||
if (moves.isEmpty()) {
|
||||
mMovesList.remove(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
|
||||
ArrayList<RecyclerView.ViewHolder> additions = mAdditionsList.get(i);
|
||||
if (additions.remove(item)) {
|
||||
view.setAlpha(1);
|
||||
dispatchAddFinished(item);
|
||||
if (additions.isEmpty()) {
|
||||
mAdditionsList.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// animations should be ended by the cancel above.
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mRemoveAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mRemoveAnimations list");
|
||||
}
|
||||
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mAddAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mAddAnimations list");
|
||||
}
|
||||
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mChangeAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mChangeAnimations list");
|
||||
}
|
||||
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (mMoveAnimations.remove(item) && DEBUG) {
|
||||
throw new IllegalStateException("after animation is cancelled, item should not be in "
|
||||
+ "mMoveAnimations list");
|
||||
}
|
||||
dispatchFinishedWhenDone();
|
||||
}
|
||||
|
||||
private void resetAnimation(RecyclerView.ViewHolder holder) {
|
||||
if (sDefaultInterpolator == null) {
|
||||
sDefaultInterpolator = new ValueAnimator().getInterpolator();
|
||||
}
|
||||
holder.itemView.animate().setInterpolator(sDefaultInterpolator);
|
||||
endAnimation(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return (!mPendingAdditions.isEmpty()
|
||||
|| !mPendingChanges.isEmpty()
|
||||
|| !mPendingMoves.isEmpty()
|
||||
|| !mPendingRemovals.isEmpty()
|
||||
|| !mMoveAnimations.isEmpty()
|
||||
|| !mRemoveAnimations.isEmpty()
|
||||
|| !mAddAnimations.isEmpty()
|
||||
|| !mChangeAnimations.isEmpty()
|
||||
|| !mMovesList.isEmpty()
|
||||
|| !mAdditionsList.isEmpty()
|
||||
|| !mChangesList.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the state of currently pending and running animations. If there are none
|
||||
* pending/running, call {@link #dispatchAnimationsFinished()} to notify any
|
||||
* listeners.
|
||||
*/
|
||||
void dispatchFinishedWhenDone() {
|
||||
if (!isRunning()) {
|
||||
dispatchAnimationsFinished();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endAnimations() {
|
||||
int count = mPendingMoves.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
MoveInfo item = mPendingMoves.get(i);
|
||||
View view = item.holder.itemView;
|
||||
view.setTranslationY(0);
|
||||
view.setTranslationX(0);
|
||||
dispatchMoveFinished(item.holder);
|
||||
mPendingMoves.remove(i);
|
||||
}
|
||||
count = mPendingRemovals.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
RecyclerView.ViewHolder item = mPendingRemovals.get(i);
|
||||
dispatchRemoveFinished(item);
|
||||
mPendingRemovals.remove(i);
|
||||
}
|
||||
count = mPendingAdditions.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
RecyclerView.ViewHolder item = mPendingAdditions.get(i);
|
||||
item.itemView.setAlpha(1);
|
||||
dispatchAddFinished(item);
|
||||
mPendingAdditions.remove(i);
|
||||
}
|
||||
count = mPendingChanges.size();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
endChangeAnimationIfNecessary(mPendingChanges.get(i));
|
||||
}
|
||||
mPendingChanges.clear();
|
||||
if (!isRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int listCount = mMovesList.size();
|
||||
for (int i = listCount - 1; i >= 0; i--) {
|
||||
ArrayList<MoveInfo> moves = mMovesList.get(i);
|
||||
count = moves.size();
|
||||
for (int j = count - 1; j >= 0; j--) {
|
||||
MoveInfo moveInfo = moves.get(j);
|
||||
RecyclerView.ViewHolder item = moveInfo.holder;
|
||||
View view = item.itemView;
|
||||
view.setTranslationY(0);
|
||||
view.setTranslationX(0);
|
||||
dispatchMoveFinished(moveInfo.holder);
|
||||
moves.remove(j);
|
||||
if (moves.isEmpty()) {
|
||||
mMovesList.remove(moves);
|
||||
}
|
||||
}
|
||||
}
|
||||
listCount = mAdditionsList.size();
|
||||
for (int i = listCount - 1; i >= 0; i--) {
|
||||
ArrayList<RecyclerView.ViewHolder> additions = mAdditionsList.get(i);
|
||||
count = additions.size();
|
||||
for (int j = count - 1; j >= 0; j--) {
|
||||
RecyclerView.ViewHolder item = additions.get(j);
|
||||
View view = item.itemView;
|
||||
view.setAlpha(1);
|
||||
dispatchAddFinished(item);
|
||||
additions.remove(j);
|
||||
if (additions.isEmpty()) {
|
||||
mAdditionsList.remove(additions);
|
||||
}
|
||||
}
|
||||
}
|
||||
listCount = mChangesList.size();
|
||||
for (int i = listCount - 1; i >= 0; i--) {
|
||||
ArrayList<ChangeInfo> changes = mChangesList.get(i);
|
||||
count = changes.size();
|
||||
for (int j = count - 1; j >= 0; j--) {
|
||||
endChangeAnimationIfNecessary(changes.get(j));
|
||||
if (changes.isEmpty()) {
|
||||
mChangesList.remove(changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cancelAll(mRemoveAnimations);
|
||||
cancelAll(mMoveAnimations);
|
||||
cancelAll(mAddAnimations);
|
||||
cancelAll(mChangeAnimations);
|
||||
|
||||
dispatchAnimationsFinished();
|
||||
}
|
||||
|
||||
void cancelAll(List<RecyclerView.ViewHolder> viewHolders) {
|
||||
for (int i = viewHolders.size() - 1; i >= 0; i--) {
|
||||
viewHolders.get(i).itemView.animate().cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* If the payload list is not empty, DefaultItemAnimator returns <code>true</code>.
|
||||
* When this is the case:
|
||||
* <ul>
|
||||
* <li>If you override {@link #animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)}, both
|
||||
* ViewHolder arguments will be the same instance.
|
||||
* </li>
|
||||
* <li>
|
||||
* If you are not overriding {@link #animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)},
|
||||
* then DefaultItemAnimator will call {@link #animateMove(RecyclerView.ViewHolder, int, int, int, int)} and
|
||||
* run a move animation instead.
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHolder,
|
||||
@NonNull List<Object> payloads) {
|
||||
return !payloads.isEmpty() || super.canReuseUpdatedViewHolder(viewHolder, payloads);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.och.weaknet.ui.adapter
|
||||
package com.mogo.och.weaknet.ui.switchline
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
@@ -7,20 +7,21 @@ import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.DiffUtil.Callback
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse
|
||||
import com.mogo.och.weaknet.ui.adapter.SwitchLineAdapter.SwitchLineViewHolder
|
||||
import com.mogo.och.weaknet.ui.switchline.SwitchLineAdapter.SwitchLineViewHolder
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import kotlin.text.StringBuilder
|
||||
|
||||
/**
|
||||
* 路线列表adapter
|
||||
*/
|
||||
class SwitchLineAdapter(
|
||||
private val mContext: Context,
|
||||
private val mData: List<BusQueryLinesResponse.Result>
|
||||
val mData: MutableList<BusQueryLinesResponse.Result>
|
||||
) : RecyclerView.Adapter<SwitchLineViewHolder>() {
|
||||
companion object{
|
||||
const val TAG = "SwitchLineAdapter"
|
||||
@@ -29,6 +30,19 @@ class SwitchLineAdapter(
|
||||
private var mItemClickListener: LineItemClickListener? = null
|
||||
var checkLine:BusQueryLinesResponse.Result? = null
|
||||
var checkTask: BusQueryLineTaskResponse.Result? = null
|
||||
|
||||
fun setDataList(dataList: List<BusQueryLinesResponse.Result>) {
|
||||
if (this.mData == dataList) {
|
||||
// 如果新旧列表一致,则直接返回
|
||||
return
|
||||
}
|
||||
|
||||
val diffResult = DiffUtil.calculateDiff(MyDiffCallback(this.mData, dataList))
|
||||
this.mData.clear()
|
||||
this.mData.addAll(dataList)
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(
|
||||
parent: ViewGroup,
|
||||
viewType: Int
|
||||
@@ -169,4 +183,28 @@ class SwitchLineAdapter(
|
||||
interface LineItemClickListener {
|
||||
fun onItemClick(position: Int,close:Boolean)
|
||||
}
|
||||
|
||||
inner class MyDiffCallback(private val oldData:List<BusQueryLinesResponse.Result>, private val newData:List<BusQueryLinesResponse.Result>):
|
||||
Callback(){
|
||||
override fun getOldListSize(): Int {
|
||||
return oldData.size
|
||||
}
|
||||
|
||||
override fun getNewListSize(): Int {
|
||||
return newData.size
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
val oldItem = oldData[oldItemPosition]
|
||||
val newItem = newData[newItemPosition]
|
||||
return oldItem == newItem
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
val oldItem = oldData[oldItemPosition]
|
||||
val newItem = newData[newItemPosition]
|
||||
return oldItem == newItem
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.och.weaknet.ui.adapter
|
||||
package com.mogo.och.weaknet.ui.switchline
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
@@ -8,7 +8,7 @@ import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.eagle.core.utilcode.util.TimeUtils
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.ui.adapter.SwitchLineTaskAdapter.SwitchLineTaskViewHolder
|
||||
import com.mogo.och.weaknet.ui.switchline.SwitchLineTaskAdapter.SwitchLineTaskViewHolder
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
|
||||
/**
|
||||
@@ -1,106 +1,99 @@
|
||||
package com.mogo.och.weaknet.ui
|
||||
package com.mogo.och.weaknet.ui.switchline
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.Point
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.commons.mvp.MvpActivity
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import com.mogo.eagle.core.utilcode.mogo.view.SpacesItemDecoration
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.och.common.module.utils.ResourcesUtils
|
||||
import com.mogo.och.common.module.wigets.WindowRelativeLayout
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse
|
||||
import com.mogo.och.weaknet.presenter.BusLinePresenter
|
||||
import com.mogo.och.weaknet.ui.adapter.OpenItemAnimator
|
||||
import com.mogo.och.weaknet.ui.adapter.SwitchLineAdapter
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.aciv_refresh_task
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.actv_last_refresh_date
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.pb_start_task
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.tv_start_task
|
||||
import com.mogo.och.weaknet.model.BusLineModel
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.no_order_data_view
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.aciv_refresh_task
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.actv_last_refresh_date
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.pb_start_task
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.switch_line_btn_commit
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.switch_line_close
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.switch_line_rv
|
||||
import kotlinx.android.synthetic.main.shuttle_weak_switch_line.view.tv_start_task
|
||||
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/2/8
|
||||
*/
|
||||
class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>(),
|
||||
View.OnClickListener, BusSwitchLineView {
|
||||
class SwitchLineView: WindowRelativeLayout, SwtichLineModel.SwtichLineViewCallback {
|
||||
|
||||
companion object{
|
||||
const val LASTCOMMITLINEID = "lastcommitlineid"
|
||||
|
||||
constructor(context: Context?) : super(context)
|
||||
|
||||
constructor(context: Context?, attributeSet: AttributeSet) : super(context, attributeSet)
|
||||
|
||||
constructor(context: Context?, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr)
|
||||
|
||||
constructor(context: Context?, attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attributeSet, defStyleAttr, defStyleRes)
|
||||
|
||||
|
||||
companion object {
|
||||
const val TAG = "BadCaseManagerView"
|
||||
}
|
||||
|
||||
private lateinit var mClose: ImageView
|
||||
private lateinit var mNoDatasView: ConstraintLayout
|
||||
private lateinit var mLinesListView: RecyclerView
|
||||
private lateinit var mLineCommitBtn: LinearLayout
|
||||
private var clickListener:ClickListener?=null
|
||||
private var viewModel:SwtichLineModel?=null
|
||||
|
||||
private lateinit var mAdapter: SwitchLineAdapter
|
||||
private lateinit var linearLayoutManager:LinearLayoutManager
|
||||
private val mData: MutableList<BusQueryLinesResponse.Result> = ArrayList()
|
||||
|
||||
private var animator:ObjectAnimator?=null
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.shuttle_weak_switch_line
|
||||
}
|
||||
|
||||
override fun createPresenter(): BusLinePresenter {
|
||||
return BusLinePresenter(this)
|
||||
}
|
||||
private lateinit var linearLayoutManager:LinearLayoutManager
|
||||
|
||||
override fun initViews() {
|
||||
initWH()
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.shuttle_weak_switch_line, this, true)
|
||||
initView()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
initDatas()
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化view
|
||||
*/
|
||||
private fun initView() {
|
||||
mClose = findViewById(R.id.switch_line_close)
|
||||
mClose.setOnClickListener(this)
|
||||
mNoDatasView = findViewById(R.id.no_order_data_view)
|
||||
mLineCommitBtn = findViewById(R.id.switch_line_btn_commit)
|
||||
mLineCommitBtn.setOnClickListener(this)
|
||||
mLinesListView = findViewById(R.id.switch_line_rv)
|
||||
linearLayoutManager = LinearLayoutManager(this)
|
||||
mLinesListView.setLayoutManager(linearLayoutManager)
|
||||
mLinesListView.setItemAnimator(OpenItemAnimator())
|
||||
mAdapter = SwitchLineAdapter(applicationContext, mData)
|
||||
mLinesListView.addItemDecoration(
|
||||
private fun initView(){
|
||||
switch_line_close.onClick {
|
||||
clickListener?.onClose()
|
||||
}
|
||||
switch_line_btn_commit.onClick {
|
||||
if(mAdapter.checkLine!=null&&mAdapter.checkTask!=null){
|
||||
viewModel?.let {
|
||||
it.commitSwitchLineId(mAdapter.checkTask!!,mAdapter.checkLine!!)
|
||||
startTaskLoading()
|
||||
}
|
||||
}else{
|
||||
ToastUtils.showLong("请选择任务")
|
||||
}
|
||||
}
|
||||
linearLayoutManager = LinearLayoutManager(context)
|
||||
switch_line_rv.setLayoutManager(linearLayoutManager)
|
||||
mAdapter = SwitchLineAdapter(context, mutableListOf())
|
||||
switch_line_rv.addItemDecoration(
|
||||
SpacesItemDecoration(
|
||||
4
|
||||
)
|
||||
)
|
||||
mLinesListView.setAdapter(mAdapter)
|
||||
switch_line_rv.setAdapter(mAdapter)
|
||||
//设置item 点击事件
|
||||
mAdapter.setOnLineItemClickListener(object : SwitchLineAdapter.LineItemClickListener{
|
||||
override fun onItemClick(position: Int, close: Boolean) {
|
||||
mPresenter?.queryBusLineTasks(mData[position].lineId, position, close)
|
||||
viewModel?.queryBusLineTasks(mAdapter.mData[position].lineId, position, close)
|
||||
}
|
||||
})
|
||||
|
||||
aciv_refresh_task.onClick {
|
||||
mPresenter?.refreshTask()
|
||||
viewModel?.refreshTask()
|
||||
if(animator==null) {
|
||||
animator = ObjectAnimator.ofFloat(aciv_refresh_task, "rotation", 0f, 360f)
|
||||
animator?.setDuration(1000) // 设置动画持续时间
|
||||
@@ -110,51 +103,64 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
animator?.start()
|
||||
}
|
||||
pb_start_task.progressTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局宽高
|
||||
*/
|
||||
private fun initWH() {
|
||||
val window = window
|
||||
val params = window.attributes
|
||||
val windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
|
||||
val point = Point()
|
||||
windowManager.defaultDisplay.getSize(point) //用于获取屏幕高度
|
||||
params.width = (point.x * 0.375).toInt()
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
window.attributes = params
|
||||
window.setGravity(Gravity.START or Gravity.BOTTOM)
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
private fun initDatas() {
|
||||
mPresenter?.queryBusLines()
|
||||
mPresenter?.setRefreshTime()
|
||||
viewModel?.queryBusLines()
|
||||
viewModel?.setRefreshTime()
|
||||
}
|
||||
|
||||
fun setOnClickListener(clickListener: ClickListener) {
|
||||
this.clickListener = clickListener
|
||||
}
|
||||
|
||||
|
||||
interface ClickListener {
|
||||
fun onClose()
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
viewModel = ViewModelProvider(this).get(SwtichLineModel::class.java)
|
||||
viewModel?.setDistanceCallback(this)
|
||||
initDatas()
|
||||
}
|
||||
|
||||
fun startTaskLoading(){
|
||||
pb_start_task.visibility = View.VISIBLE
|
||||
tv_start_task.text = "创建中"
|
||||
}
|
||||
|
||||
override fun startTaskState(success: Boolean) {
|
||||
pb_start_task.visibility = View.GONE
|
||||
if(success){
|
||||
tv_start_task.text = "创建成功"
|
||||
}else{
|
||||
tv_start_task.text = "创建失败"
|
||||
UiThreadHandler.postDelayed({
|
||||
tv_start_task.text = "确定"
|
||||
},1_000)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询返回绑定路线集合
|
||||
* @param data
|
||||
*/
|
||||
override fun onBusLinesChange(data: MutableList<BusQueryLinesResponse.Result>?) {
|
||||
if (data.isNullOrEmpty()) {
|
||||
showNoData(true)
|
||||
return
|
||||
}
|
||||
val lastCommitLineid = SharedPrefsMgr.getInstance().getLong(LASTCOMMITLINEID, -1)
|
||||
val lastCommitLineid = SharedPrefsMgr.getInstance().getLong(BusLineModel.LASTCOMMITLINEID, -1)
|
||||
if (data.size > 0) {
|
||||
showNoData(false)
|
||||
mData.clear()
|
||||
mData.addAll(data)
|
||||
mAdapter.notifyDataSetChanged()
|
||||
mAdapter.setDataList(data)
|
||||
if(lastCommitLineid>0){
|
||||
mData.forEachIndexed { index, line ->
|
||||
mAdapter.mData.forEachIndexed { index, line ->
|
||||
if(line.lineId==lastCommitLineid){
|
||||
line.open = true
|
||||
mPresenter?.queryBusLineTasks(line.lineId,index,false)
|
||||
viewModel?.queryBusLineTasks(line.lineId,index,false)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -164,16 +170,31 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 有无数据UI显示
|
||||
* @param b
|
||||
*/
|
||||
private fun showNoData(b: Boolean) {
|
||||
if (b) {
|
||||
switch_line_rv.visibility = View.GONE
|
||||
switch_line_btn_commit.visibility = View.GONE
|
||||
no_order_data_view.visibility = View.VISIBLE
|
||||
} else {
|
||||
switch_line_rv.visibility = View.VISIBLE
|
||||
switch_line_btn_commit.visibility = View.VISIBLE
|
||||
no_order_data_view.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onChangeLineIdSuccess() {
|
||||
ToastUtils.showLong(resources.getString(R.string.bus_change_line_commit_tip_s))
|
||||
mPresenter?.queryBusRoutes()
|
||||
viewModel?.queryBusRoutes()
|
||||
mAdapter.setOnLineItemClickListener(null)
|
||||
mPresenter?.removeListener()
|
||||
finish()
|
||||
clickListener?.onClose()
|
||||
}
|
||||
|
||||
override fun onBusLineTasks(lineTaskInfo: List<BusQueryLineTaskResponse.Result>, position: Int, autoRefresh:Boolean) {
|
||||
val result = mData[position]
|
||||
val result = mAdapter.mData[position]
|
||||
if (result.taskList == null) {
|
||||
result.taskList = ArrayList()
|
||||
}
|
||||
@@ -202,8 +223,9 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
}
|
||||
// 打开操作
|
||||
mAdapter.notifyItemChanged(position)
|
||||
linearLayoutManager.stackFromEnd = (position==mData.size-1||position==mData.size-2)&&mData.size>6
|
||||
mLinesListView.smoothScrollToPosition(position)
|
||||
linearLayoutManager.stackFromEnd =
|
||||
(position == mAdapter.itemCount - 1 || position == mAdapter.itemCount - 2) && mAdapter.itemCount > 6
|
||||
switch_line_rv.smoothScrollToPosition(position)
|
||||
}else if(lineTaskInfo.isEmpty()){
|
||||
mAdapter.notifyItemChanged(position)
|
||||
}
|
||||
@@ -221,62 +243,7 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 有无数据UI显示
|
||||
* @param b
|
||||
*/
|
||||
private fun showNoData(b: Boolean) {
|
||||
if (b) {
|
||||
mLinesListView.visibility = View.GONE
|
||||
mLineCommitBtn.visibility = View.GONE
|
||||
mNoDatasView.visibility = View.VISIBLE
|
||||
} else {
|
||||
mLinesListView.visibility = View.VISIBLE
|
||||
mLineCommitBtn.visibility = View.VISIBLE
|
||||
mNoDatasView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
//关闭dialog
|
||||
if (v.id == R.id.switch_line_close) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
//切换路线提交
|
||||
if (v.id == R.id.switch_line_btn_commit) {
|
||||
if(mAdapter.checkLine!=null&&mAdapter.checkTask!=null){
|
||||
mPresenter?.let {
|
||||
it.commitSwitchLineId(mAdapter.checkTask!!,mAdapter.checkLine!!)
|
||||
startTaskLoading()
|
||||
}
|
||||
}else{
|
||||
ToastUtils.showLong("请选择任务")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun startTaskState(success: Boolean) {
|
||||
pb_start_task.visibility = View.GONE
|
||||
if(success){
|
||||
tv_start_task.text = "创建成功"
|
||||
}else{
|
||||
tv_start_task.text = "创建失败"
|
||||
UiThreadHandler.postDelayed({
|
||||
tv_start_task.text = "确定"
|
||||
},1_000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun startTaskLoading(){
|
||||
pb_start_task.visibility = View.VISIBLE
|
||||
tv_start_task.text = "创建中"
|
||||
}
|
||||
|
||||
|
||||
override fun onDestroy() {
|
||||
mPresenter!!.removeListener()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.mogo.och.weaknet.ui.switchline
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.common.module.utils.RxUtils
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse
|
||||
import com.mogo.och.weaknet.bean.WaitUploadLine
|
||||
import com.mogo.och.weaknet.callback.IBusLinesCallback
|
||||
import com.mogo.och.weaknet.model.BusLineModel
|
||||
import com.mogo.och.weaknet.model.BusLineModel.executableChangeTime
|
||||
import com.mogo.och.weaknet.model.BusLineModel.queryBusLineTasksById
|
||||
import com.mogo.och.weaknet.model.EventModel
|
||||
import com.mogo.och.weaknet.model.OrderModel
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
* @description BadCase录包管理页面
|
||||
* @since: 2022/12/15
|
||||
*/
|
||||
class SwtichLineModel : ViewModel(), IBusLinesCallback {
|
||||
|
||||
private val TAG = SwtichLineModel::class.java.simpleName
|
||||
|
||||
private var viewCallback:SwtichLineViewCallback?=null
|
||||
|
||||
private var subscribe: Disposable? = null
|
||||
|
||||
override fun onCleared() {
|
||||
RxUtils.disposeSubscribe(subscribe)
|
||||
BusLineModel.setBusLinesCallback(null)
|
||||
}
|
||||
|
||||
fun setDistanceCallback(viewCallback:SwtichLineViewCallback){
|
||||
this.viewCallback = viewCallback
|
||||
BusLineModel.setBusLinesCallback(this)
|
||||
}
|
||||
|
||||
fun queryBusLines() {
|
||||
BusLineModel.queryBusLines()
|
||||
}
|
||||
|
||||
fun setRefreshTime() {
|
||||
val lastUpdateTime = SharedPrefsMgr.getInstance().getLong(executableChangeTime, -1)
|
||||
if(lastUpdateTime>0){
|
||||
this.onRefreshSuccess(lastUpdateTime)
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshTask() {
|
||||
BusLineModel.refreshTask()
|
||||
}
|
||||
|
||||
fun queryBusLineTasks(lineId: Long, position: Int, close: Boolean) {
|
||||
if (subscribe != null && !subscribe!!.isDisposed) {
|
||||
subscribe!!.dispose()
|
||||
}
|
||||
if (close) {
|
||||
return
|
||||
}
|
||||
queryBusLineTasksById(lineId, position, false)
|
||||
subscribe = Observable.interval(3, TimeUnit.MINUTES).subscribe { aLong: Long? ->
|
||||
queryBusLineTasksById(lineId, position, true)
|
||||
}
|
||||
}
|
||||
|
||||
fun commitSwitchLineId(taskId: BusQueryLineTaskResponse.Result, lineId: BusQueryLinesResponse.Result) {
|
||||
BusLineModel.commitSwitchLineId(taskId, lineId)
|
||||
}
|
||||
|
||||
fun queryBusRoutes() {
|
||||
OrderModel.queryBusRoutes()
|
||||
}
|
||||
|
||||
interface SwtichLineViewCallback{
|
||||
fun startTaskState(success: Boolean)
|
||||
fun onBusLinesChange(data: MutableList<BusQueryLinesResponse.Result>?)
|
||||
fun onChangeLineIdSuccess()
|
||||
fun onBusLineTasks(
|
||||
lineTaskInfo: List<BusQueryLineTaskResponse.Result>,
|
||||
position: Int,
|
||||
autoRefresh: Boolean
|
||||
)
|
||||
|
||||
fun refreshDate(formatLongToString: String?)
|
||||
}
|
||||
|
||||
override fun onBusLinesChange(data: MutableList<BusQueryLinesResponse.Result>?) {
|
||||
viewCallback?.onBusLinesChange(data)
|
||||
}
|
||||
|
||||
override fun onChangeLineIdSuccess() {
|
||||
ThreadUtils.runOnUiThread( {
|
||||
viewCallback?.onChangeLineIdSuccess()
|
||||
},ThreadUtils.MODE.QUEUE)
|
||||
}
|
||||
|
||||
override fun onBusLineTasks(
|
||||
o: MutableList<BusQueryLineTaskResponse.Result>,
|
||||
position: Int,
|
||||
autoRefresh: Boolean
|
||||
) {
|
||||
viewCallback?.onBusLineTasks(o,position,autoRefresh)
|
||||
}
|
||||
|
||||
override fun onRefreshSuccess(currentTimeStamp: Long) {
|
||||
viewCallback?.refreshDate(
|
||||
DateTimeUtil.formatLongToString(currentTimeStamp, DateTimeUtil.yyyy_MM_dd_HH_mm_ss)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onChangeLineIdFail() {
|
||||
viewCallback?.startTaskState(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ import android.widget.TextView
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.DiffUtil.Callback
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.mogo.eagle.core.function.business.travelreality.EventDrawBean
|
||||
import com.mogo.eagle.core.utilcode.util.TimeUtils
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.ui.adapter.SwitchLineTaskAdapter.SwitchLineTaskViewHolder
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.weaknet.bean.WaitUploadLine
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.mogo.eagle.core.utilcode.kotlin.lifeCycleOwner
|
||||
import com.mogo.eagle.core.utilcode.reminder.Reminder
|
||||
import com.mogo.eagle.core.utilcode.reminder.api.impl.PopupWindowReminder
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
import com.mogo.och.weaknet.ui.switchline.SwitchLineView
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
import kotlin.math.abs
|
||||
|
||||
@@ -58,6 +59,27 @@ object RunningTaskManager : LifecycleEventObserver{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示BadCase配置页面
|
||||
*/
|
||||
fun showSwitchLineWindow(context: Context) {
|
||||
val badCaseConfigView = SwitchLineView(context)
|
||||
badCaseConfigView.setOnClickListener(object : SwitchLineView.ClickListener {
|
||||
override fun onClose() {
|
||||
hideFloat?.invoke()
|
||||
hideFloat = null
|
||||
}
|
||||
})
|
||||
enqueuePop(
|
||||
badCaseConfigView,
|
||||
AutoSizeUtils.dp2px(context, 960f),
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
key = "BadCaseConfigView"
|
||||
).also {
|
||||
hideFloat = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStateChanged(source: LifecycleOwner, event: Event) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.mogo.och.weaknet.ui.taskrunning
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@@ -13,10 +11,8 @@ import com.mogo.och.common.module.utils.ResourcesUtils
|
||||
import com.mogo.och.common.module.wigets.WindowRelativeLayout
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.weaknet.bean.WaitUploadLine
|
||||
import com.mogo.och.weaknet.ui.adapter.OpenItemAnimator
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.aciv_show_data
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.actvCurrentDate
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.clLayout
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.ivTaskRunningClose
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.no_order_data_view
|
||||
import kotlinx.android.synthetic.main.shuttle_wadk_task_running.view.rvDataLiet
|
||||
@@ -62,7 +58,6 @@ class RunningTaskManagerView: WindowRelativeLayout, RunningTastViewModel.Running
|
||||
|
||||
linearLayoutManager = LinearLayoutManager(context)
|
||||
rvDataLiet.setLayoutManager(linearLayoutManager)
|
||||
rvDataLiet.setItemAnimator(OpenItemAnimator())
|
||||
mAdapter = RunningTaskAdapter(context, mutableListOf())
|
||||
rvDataLiet.addItemDecoration(
|
||||
BottomDecoration(
|
||||
|
||||
Reference in New Issue
Block a user