0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

Merge pull request #3930 from timrae/clickable-counts

Make deck picker counts clickable
This commit is contained in:
Houssam Salem 2015-12-03 15:50:39 +11:00
commit 1d1ecf6f47
3 changed files with 61 additions and 34 deletions

View File

@ -196,7 +196,22 @@ public class DeckPicker extends NavigationDrawerActivity implements
long deckId = (long) v.getTag();
Timber.i("DeckPicker:: Selected deck with id %d", deckId);
mActionsMenu.collapse();
handleDeckSelection(deckId);
handleDeckSelection(deckId, false);
if (mFragmented || !CompatHelper.isLollipop()) {
// Calling notifyDataSetChanged() will update the color of the selected deck.
// This interferes with the ripple effect, so we don't do it if lollipop and not tablet view
mDeckListAdapter.notifyDataSetChanged();
}
}
};
private final OnClickListener mCountsClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
long deckId = (long) v.getTag();
Timber.i("DeckPicker:: Selected deck with id %d", deckId);
mActionsMenu.collapse();
handleDeckSelection(deckId, true);
if (mFragmented || !CompatHelper.isLollipop()) {
// Calling notifyDataSetChanged() will update the color of the selected deck.
// This interferes with the ripple effect, so we don't do it if lollipop and not tablet view
@ -389,6 +404,7 @@ public class DeckPicker extends NavigationDrawerActivity implements
// create and set an adapter for the RecyclerView
mDeckListAdapter = new DeckAdapter(getLayoutInflater(), this);
mDeckListAdapter.setDeckClickListener(mDeckClickListener);
mDeckListAdapter.setCountsClickListener(mCountsClickListener);
mDeckListAdapter.setDeckExpanderClickListener(mDeckExpanderClickListener);
mDeckListAdapter.setDeckLongClickListener(mDeckLongClickListener);
mRecyclerView.setAdapter(mDeckListAdapter);
@ -1657,7 +1673,7 @@ public class DeckPicker extends NavigationDrawerActivity implements
}
private void handleDeckSelection(long did) {
private void handleDeckSelection(long did, boolean dontSkipStudyOptions) {
// Forget what the last used deck was in the browser
CardBrowser.clearSelectedDeck();
// Clear the undo history when selecting a new deck
@ -1674,7 +1690,7 @@ public class DeckPicker extends NavigationDrawerActivity implements
Sched.DeckDueTreeNode deckDueTreeNode = mDeckListAdapter.getDeckList().get(pos);
int[] studyOptionsCounts = getCol().getSched().counts();
// Figure out what action to take
if (getCol().getDecks().isDyn(did) || mFragmented) {
if (getCol().getDecks().isDyn(did) || mFragmented || dontSkipStudyOptions) {
// Go to StudyOptions screen when using filtered decks so that it's clearer to the user that it's different
openStudyOptions(false);
} else if (deckDueTreeNode.newCount + deckDueTreeNode.lrnCount + deckDueTreeNode.revCount > 0) {

View File

@ -27,6 +27,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -60,6 +61,7 @@ public class DeckAdapter extends RecyclerView.Adapter<DeckAdapter.ViewHolder> {
private View.OnClickListener mDeckClickListener;
private View.OnClickListener mDeckExpanderClickListener;
private View.OnLongClickListener mDeckLongClickListener;
private View.OnClickListener mCountsClickListener;
private Collection mCol;
@ -74,6 +76,7 @@ public class DeckAdapter extends RecyclerView.Adapter<DeckAdapter.ViewHolder> {
// ViewHolder class to save inflated views for recycling
public class ViewHolder extends RecyclerView.ViewHolder {
public RelativeLayout deckLayout;
public LinearLayout countsLayout;
public ImageButton deckExpander;
public ImageButton indentView;
public TextView deckName;
@ -82,6 +85,7 @@ public class DeckAdapter extends RecyclerView.Adapter<DeckAdapter.ViewHolder> {
public ViewHolder(View v) {
super(v);
deckLayout = (RelativeLayout) v.findViewById(R.id.DeckPickerHoriz);
countsLayout = (LinearLayout) v.findViewById(R.id.counts_layout);
deckExpander = (ImageButton) v.findViewById(R.id.deckpicker_expander);
indentView = (ImageButton) v.findViewById(R.id.deckpicker_indent);
deckName = (TextView) v.findViewById(R.id.deckpicker_name);
@ -123,6 +127,10 @@ public class DeckAdapter extends RecyclerView.Adapter<DeckAdapter.ViewHolder> {
mDeckClickListener = listener;
}
public void setCountsClickListener(View.OnClickListener listener) {
mCountsClickListener = listener;
}
public void setDeckExpanderClickListener(View.OnClickListener listener) {
mDeckExpanderClickListener = listener;
}
@ -200,10 +208,12 @@ public class DeckAdapter extends RecyclerView.Adapter<DeckAdapter.ViewHolder> {
// Store deck ID in layout's tag for easy retrieval in our click listeners
holder.deckLayout.setTag(node.did);
holder.countsLayout.setTag(node.did);
// Set click listeners
holder.deckLayout.setOnClickListener(mDeckClickListener);
holder.deckLayout.setOnLongClickListener(mDeckLongClickListener);
holder.countsLayout.setOnClickListener(mCountsClickListener);
}
@Override

View File

@ -34,7 +34,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/deckpicker_indent"
android:layout_toLeftOf="@+id/deckpicker_new"
android:layout_toLeftOf="@+id/counts_layout"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageButton
@ -56,39 +56,40 @@
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/deckpicker_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/deckpicker_lrn"
android:background="@color/transparent"
android:gravity="center"
android:paddingRight="5dip"
android:textSize="14sp" />
<TextView
android:id="@+id/deckpicker_lrn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toLeftOf="@+id/deckpicker_rev"
android:background="@color/transparent"
android:gravity="center"
android:paddingRight="5dip"
android:textSize="14sp" />
<TextView
android:id="@+id/deckpicker_rev"
<LinearLayout
android:id="@+id/counts_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginRight="6dip"
android:background="@color/transparent"
android:gravity="center"
android:textSize="14sp" />
android:layout_centerVertical="true" >
<TextView
android:id="@+id/deckpicker_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:gravity="center"
android:paddingRight="5dip"
android:textSize="14sp" />
<TextView
android:id="@+id/deckpicker_lrn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/transparent"
android:gravity="center"
android:paddingRight="5dip"
android:textSize="14sp" />
<TextView
android:id="@+id/deckpicker_rev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="6dip"
android:background="@color/transparent"
android:gravity="center"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>