Show activated download label

This commit is contained in:
seven332 committed 2015-08-24 17:31:05 +08:00
1 parent 7b95c21030
commit 5f5a8d026b
6 files changed
+103 -32

No files matched your search

@@ -23,7 +23,6 @@ import android.content.Intent;
import android.content.res.Resources;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.ViewGroup;
@@ -200,6 +199,7 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
mRightDrawerView.setPlusVisibility(View.GONE);
mRightDrawerView.setHelper(this);
mRightDrawerView.showRecyclerView(false);
mRightDrawerView.addOnChildAttachStateChangeListener(new DownloadLabelStateChangeListener());
updateTitle();
@@ -372,23 +372,16 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
@Override
public void onClick(View v) {
Log.d("TAG", "mDeleteListener 1");
if (mRecyclerView.inCustomChoice()) {
return;
}
Log.d("TAG", "mDeleteListener 2");
int position = getAdapterPosition(v);
if (position >= 0) {
// Add to cache
DownloadInfo info = mDownloadInfos.get(position);
mGidPositionMap.add(info.galleryBase.gid, position);
Log.d("TAG", "mDeleteListener 3");
// Delete
DownloadManager.getInstance().deleteDownloadInfo(info);
}
@@ -415,6 +408,20 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
return position;
}
private void updateActivated() {
EasyRecyclerView recyclerView = mRightDrawerView.getRecyclerView();
for (int i = 0, n = recyclerView.getChildCount(); i < n; i++) {
View view = recyclerView.getChildAt(i);
int position = recyclerView.getChildAdapterPosition(view);
if (mActivatedLabelPosition >= 0 && mActivatedLabelPosition == position) {
view.setActivated(true);
} else {
view.setActivated(false);
}
}
}
@Override
public void onReceive(int id, Object obj) {
if (id == Constants.MESSENGER_ID_UPDATE_DOWNLOAD) {
@@ -487,6 +494,7 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
mActivatedLabel = LABEL_DEFAULT;
mActivatedLabelPosition = INDEX_DEFAULT;
updateTitle();
updateActivated();
mDownloadInfos = DownloadManager.getInstance().getDownloadList(null);
mGidPositionMap.clear();
@@ -511,6 +519,7 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
// Update activated info
if (fromPosition == mActivatedLabelPosition) {
mActivatedLabelPosition = toPosition;
updateActivated();
}
}
break;
@@ -914,6 +923,7 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
mDownloadInfos = DownloadManager.getInstance().getDownloadList(mActivatedLabel);
}
updateTitle();
updateActivated();
mGidPositionMap.clear();
mAdapter.notifyDataSetChanged();
@@ -956,4 +966,22 @@ public class DownloadScene extends AppbarScene implements DrawerProvider,
return mLabels == null ? 0 : mLabels.size();
}
}
public class DownloadLabelStateChangeListener implements RecyclerView.OnChildAttachStateChangeListener {
@Override
public void onChildViewAttachedToWindow(View view) {
int position = mRightDrawerView.getChildAdapterPosition(view);
if (position == mActivatedLabelPosition) {
view.setActivated(true);
} else {
view.setActivated(false);
}
}
@Override
public void onChildViewDetachedFromWindow(View view) {
}
}
}
@@ -113,6 +113,10 @@ public class AppbarRecyclerView extends LinearLayout implements View.OnClickList
mRecyclerView.setAdapter(adapter);
}
public void addOnChildAttachStateChangeListener(RecyclerView.OnChildAttachStateChangeListener listener) {
mRecyclerView.addOnChildAttachStateChangeListener(listener);
}
public void showTip(boolean animation) {
mViewTransition.showView(0, animation);
}
@@ -125,6 +129,14 @@ public class AppbarRecyclerView extends LinearLayout implements View.OnClickList
mRecyclerView.setOnItemClickListener(listener);
}
public int getChildAdapterPosition(View view) {
return mRecyclerView.getChildAdapterPosition(view);
}
public EasyRecyclerView getRecyclerView() {
return mRecyclerView;
}
public void setFitPaddingBottom(int fitPaddingBottom) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
mRecyclerView.getPaddingRight(), mOriginalPaddingBottom + fitPaddingBottom);
@@ -110,8 +110,6 @@ public class EasyRecyclerView extends RecyclerView {
private SparseBooleanArray mTempCheckStates;
private FixCheckedHelper mFixCheckedHelper;
/**
* Running count of how many items are currently checked
*/
@@ -415,6 +413,18 @@ public class EasyRecyclerView extends RecyclerView {
}
}
@Override
public void onChildAttachedToWindow(View child) {
super.onChildAttachedToWindow(child);
if (mCheckStates != null) {
int position = getChildAdapterPosition(child);
if (position >= 0) {
setViewChecked(child, mCheckStates.get(position));
}
}
}
/**
* Returns the number of items currently selected. This will only be valid
* if the choice mode is not {@link #CHOICE_MODE_NONE} (default).
@@ -676,10 +686,6 @@ public class EasyRecyclerView extends RecyclerView {
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
mCheckedIdStates = new LongSparseArray<>(0);
}
if (mFixCheckedHelper == null) {
mFixCheckedHelper = new FixCheckedHelper();
addOnChildAttachStateChangeListener(mFixCheckedHelper);
}
// Modal multi-choice mode only has choices when the mode is active. Clear them.
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
clearChoices();
@@ -1352,22 +1358,6 @@ public class EasyRecyclerView extends RecyclerView {
boolean beforeDrawSelector(int position);
}
public class FixCheckedHelper implements OnChildAttachStateChangeListener {
@Override
public void onChildViewAttachedToWindow(View view) {
int position = getChildAdapterPosition(view);
if (position >= 0) {
setViewChecked(view, mCheckStates.get(position));
}
}
@Override
public void onChildViewDetachedFromWindow(View view) {
}
}
/**
* A MultiChoiceModeListener receives events for {@link android.widget.AbsListView#CHOICE_MODE_MULTIPLE_MODAL}.
* It acts as the {@link android.support.v7.view.ActionMode.Callback} for the selection mode and also receives