From 8ff8be6f609fd8bd107c2f187a6b30a347de286e Mon Sep 17 00:00:00 2001 From: m2049r <30435443+m2049r@users.noreply.github.com> Date: Mon, 28 Aug 2017 23:14:53 +0200 Subject: [PATCH] list context menu + tweaks --- .../com/m2049r/xmrwallet/LoginFragment.java | 47 ++++++++++++++++++- .../main/res/layout/gen_review_fragment.xml | 6 +-- app/src/main/res/layout/login_activity.xml | 1 + app/src/main/res/layout/wallet_activity.xml | 1 + app/src/main/res/menu/list_menu.xml | 8 ++++ app/src/main/res/menu/wallet_menu.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/menu/list_menu.xml diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java index 75e2a93a..0cb557d1 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java @@ -23,8 +23,11 @@ import android.os.Bundle; import android.os.StrictMode; import android.support.design.widget.FloatingActionButton; import android.util.Log; +import android.view.ContextMenu; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; @@ -177,6 +180,7 @@ public class LoginFragment extends Fragment { android.R.layout.simple_list_item_1, android.R.id.text1, this.displayedList); listView.setAdapter(adapter); + registerForContextMenu(listView); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -215,7 +219,7 @@ public class LoginFragment extends Fragment { } }); - listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { +/* listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { // Difference to opening wallet is that we don't need a daemon set @@ -239,6 +243,7 @@ public class LoginFragment extends Fragment { return true; } }); +*/ loadList(); return view; } @@ -386,4 +391,44 @@ public class LoginFragment extends Fragment { mgr.setDaemon(daemonAddress, testnet, username, password); return true; } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + MenuInflater inflater = getActivity().getMenuInflater(); + inflater.inflate(R.menu.list_menu, menu); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); + switch (item.getItemId()) { + case R.id.action_info: + String listItem = (String) listView.getItemAtPosition(info.position); + return showInfo(listItem); + default: + return super.onContextItemSelected(item); + } + } + + private boolean showInfo(String listItem) { + + if (listItem.length() <= (WALLETNAME_PREAMBLE_LENGTH)) { + Toast.makeText(getActivity(), getString(R.string.panic), Toast.LENGTH_LONG).show(); + return true; + } + + String wallet = listItem.substring(WALLETNAME_PREAMBLE_LENGTH); + String x = isMainNet() ? "4" : "9A"; + if (x.indexOf(listItem.charAt(1)) < 0) { + Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show(); + return true; + } + + checkAndSetWalletDaemon("", !isMainNet()); // just set selected net + + activityCallback.onWalletDetails(wallet); + return true; + } } diff --git a/app/src/main/res/layout/gen_review_fragment.xml b/app/src/main/res/layout/gen_review_fragment.xml index a162f4bf..196c8032 100644 --- a/app/src/main/res/layout/gen_review_fragment.xml +++ b/app/src/main/res/layout/gen_review_fragment.xml @@ -7,7 +7,7 @@ diff --git a/app/src/main/res/layout/wallet_activity.xml b/app/src/main/res/layout/wallet_activity.xml index 8290c2bc..48d797bf 100644 --- a/app/src/main/res/layout/wallet_activity.xml +++ b/app/src/main/res/layout/wallet_activity.xml @@ -14,6 +14,7 @@ diff --git a/app/src/main/res/menu/list_menu.xml b/app/src/main/res/menu/list_menu.xml new file mode 100644 index 00000000..1866aac1 --- /dev/null +++ b/app/src/main/res/menu/list_menu.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/wallet_menu.xml b/app/src/main/res/menu/wallet_menu.xml index 58fac060..4e18ba9a 100644 --- a/app/src/main/res/menu/wallet_menu.xml +++ b/app/src/main/res/menu/wallet_menu.xml @@ -6,7 +6,7 @@ android:id="@+id/action_info" android:icon="@drawable/ic_info_black_24dp" android:orderInCategory="100" - android:title="Info" + android:title="@string/menu_info" app:showAsAction="always" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 24d0fba8..b5501cc1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ Select Wallet Wallet - Info + Details [<user>:<pass>@]<daemonhost>[:<port>] Net Selection