Add delete menu item for TimerViewHolder
This commit is contained in:
parent
f9b09f29a1
commit
5d5002a6d7
@ -57,6 +57,10 @@ public class TimerController {
|
||||
// Prompts a reload of the list data, so the list will reflect this modified timer
|
||||
}
|
||||
|
||||
public void deleteTimer() {
|
||||
mUpdateHandler.asyncDelete(mTimer);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
mUpdateHandler.asyncUpdate(mTimer.getId(), mTimer);
|
||||
}
|
||||
|
||||
@ -5,7 +5,9 @@ import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
@ -36,6 +38,7 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
||||
private final Drawable mStartIcon;
|
||||
private final Drawable mPauseIcon;
|
||||
private final FragmentManager mFragmentManager;
|
||||
private final PopupMenu mPopupMenu;
|
||||
|
||||
@Bind(R.id.label) TextView mLabel;
|
||||
@Bind(R.id.duration) CountdownChronometer mChronometer;
|
||||
@ -43,6 +46,7 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
||||
@Bind(R.id.add_one_minute) TextView mAddOneMinute;
|
||||
@Bind(R.id.start_pause) ImageButton mStartPause;
|
||||
@Bind(R.id.stop) ImageButton mStop;
|
||||
@Bind(R.id.menu) ImageButton mMenuButton;
|
||||
|
||||
public TimerViewHolder(ViewGroup parent, OnListItemInteractionListener<Timer> listener,
|
||||
AsyncTimersTableUpdateHandler asyncTimersTableUpdateHandler) {
|
||||
@ -66,6 +70,21 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
||||
Log.i(TAG, "Restoring add label callback");
|
||||
labelDialog.setOnLabelSetListener(newOnLabelSetListener());
|
||||
}
|
||||
|
||||
// The item layout is inflated in the super ctor, so we can safely reference our views.
|
||||
mPopupMenu = new PopupMenu(getContext(), mMenuButton);
|
||||
mPopupMenu.inflate(R.menu.menu_timer_viewholder);
|
||||
mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_delete:
|
||||
mController.deleteTimer();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,6 +121,11 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
||||
dialog.show(mFragmentManager, TAG_ADD_LABEL_DIALOG);
|
||||
}
|
||||
|
||||
@OnClick(R.id.menu)
|
||||
void openMenu() {
|
||||
mPopupMenu.show();
|
||||
}
|
||||
|
||||
private void bindLabel(String label) {
|
||||
if (!label.isEmpty()) {
|
||||
mLabel.setText(label);
|
||||
|
||||
9
app/src/main/res/drawable/ic_overflow_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_overflow_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
||||
@ -46,6 +46,16 @@
|
||||
android:layout_alignParentEnd="true"
|
||||
style="@style/TimerAction"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/menu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_overflow_24dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="@dimen/cardview_action_icon_margin"
|
||||
style="@style/TimerAction"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
@ -47,6 +47,16 @@
|
||||
android:layout_alignParentEnd="true"
|
||||
style="@style/TimerAction"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/menu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_overflow_24dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="@dimen/cardview_action_icon_margin"
|
||||
style="@style/TimerAction"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
7
app/src/main/res/menu/menu_timer_viewholder.xml
Normal file
7
app/src/main/res/menu/menu_timer_viewholder.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/action_delete"
|
||||
android:title="@string/delete"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
Loading…
Reference in New Issue
Block a user