list context menu + tweaks

This commit is contained in:
m2049r 2017-08-28 23:14:53 +02:00
parent b5ded700fe
commit 8ff8be6f60
7 changed files with 61 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -7,7 +7,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginBottom="8sp"
android:orientation="vertical">
<ProgressBar
@ -26,7 +26,7 @@
<TextView
android:id="@+id/tvWalletLabel"
android:layout_width="0dp"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/generate_wallet_label"
@ -36,7 +36,7 @@
<TextView
android:id="@+id/tvWalletPasswordLabel"
android:layout_width="0dp"
android:layout_width="0sp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/generate_password_label"

View File

@ -14,6 +14,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_margin="4sp"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -14,6 +14,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_margin="4sp"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View 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/action_info"
android:title="@string/menu_info" />
</menu>

View File

@ -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" />
</menu>

View File

@ -3,7 +3,7 @@
<string name="login_activity_name">Select Wallet</string>
<string name="wallet_activity_name">Wallet</string>
<string name="menu_info">Info</string>
<string name="menu_info">Details</string>
<string name="prompt_daemon">[&lt;user&gt;:&lt;pass&gt;@]&lt;daemonhost&gt;[:&lt;port&gt;]</string>
<string name="prompt_mainnet">Net Selection</string>