Add menu to the entries to rename
This commit is contained in:
parent
76fd504c46
commit
3ddd8788c7
6 changed files with 64 additions and 27 deletions
|
@ -25,8 +25,11 @@ package org.shadowice.flocke.andotp;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
@ -138,27 +141,49 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
|
|||
|
||||
protected TextView OTPValue;
|
||||
protected TextView OTPLabel;
|
||||
protected ImageView editButton;
|
||||
protected LinearLayout customPeriodLayout;
|
||||
protected TextView customPeriod;
|
||||
protected ImageView menuButton;
|
||||
|
||||
public EntryViewHolder(View v) {
|
||||
public EntryViewHolder(final View v) {
|
||||
super(v);
|
||||
|
||||
OTPValue = (TextView) v.findViewById(R.id.textViewOTP);
|
||||
OTPLabel = (TextView) v.findViewById(R.id.textViewLabel);
|
||||
editButton = (ImageView) v.findViewById(R.id.editImage);
|
||||
customPeriodLayout = (LinearLayout) v.findViewById(R.id.customPeriodLayout);
|
||||
customPeriod = (TextView) v.findViewById(R.id.customPeriod);
|
||||
menuButton = (ImageView) v.findViewById(R.id.menuButton);
|
||||
|
||||
editButton.setOnClickListener(new View.OnClickListener() {
|
||||
menuButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
eventCallback.onEditButtonClicked(getAdapterPosition());
|
||||
showPopupMenu(view);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showPopupMenu(View view) {
|
||||
View menuItemView = view.findViewById(R.id.menuButton);
|
||||
PopupMenu popup = new PopupMenu(view.getContext(), menuItemView);
|
||||
MenuInflater inflate = popup.getMenuInflater();
|
||||
inflate.inflate(R.menu.menu_popup, popup.getMenu());
|
||||
|
||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.editLabel) {
|
||||
eventCallback.onEditButtonClicked(getAdapterPosition());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
popup.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected() {
|
||||
if (eventCallback != null)
|
||||
|
@ -176,6 +201,6 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
|
|||
void onMoveEventStart();
|
||||
void onMoveEventStop();
|
||||
|
||||
void onEditButtonClicked(int pos);
|
||||
void onEditButtonClicked(final int pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -332,7 +332,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onEditButtonClicked(int pos) {
|
||||
public void onEditButtonClicked(final int pos) {
|
||||
editEntryLabel(pos);
|
||||
}
|
||||
});
|
||||
|
@ -464,15 +464,12 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
if (id == R.id.action_export) {
|
||||
exportJSONWithWarning();
|
||||
|
||||
return true;
|
||||
} else if (id == R.id.action_import) {
|
||||
importJSONWithPermissions();
|
||||
|
||||
return true;
|
||||
} else if (id == R.id.action_about){
|
||||
showAbout();
|
||||
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
9
app/src/main/res/drawable/ic_more_vert_gray.xml
Normal file
9
app/src/main/res/drawable/ic_more_vert_gray.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="#FF727272"
|
||||
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>
|
|
@ -23,31 +23,20 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textViewOTP">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textViewOTP"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/editImage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/activity_horizontal_margin"
|
||||
android:src="@drawable/ic_edit_gray" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/customPeriodLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_toStartOf="@+id/menuButton"
|
||||
android:layout_marginEnd="@dimen/activity_horizontal_margin"
|
||||
android:visibility="gone"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
|
@ -63,6 +52,14 @@
|
|||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/menuButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:src="@drawable/ic_more_vert_gray"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
8
app/src/main/res/menu/menu_popup.xml
Normal file
8
app/src/main/res/menu/menu_popup.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/editLabel"
|
||||
android:title="@string/menu_edit_label" />
|
||||
|
||||
</menu>
|
|
@ -10,6 +10,7 @@
|
|||
<string name="format_custom_period">%d s</string>
|
||||
|
||||
<string name="menu_about">About</string>
|
||||
<string name="menu_edit_label">Edit label</string>
|
||||
<string name="menu_export">Export (JSON)</string>
|
||||
<string name="menu_import">Import (JSON)</string>
|
||||
<string name="menu_submenu_backup">Import / Export</string>
|
||||
|
|
Loading…
Reference in a new issue