action button for create wallet + setting activity title in LoginActivity

This commit is contained in:
m2049r 2017-08-26 22:28:53 +02:00
parent a82a90575d
commit 191aa6ac22
6 changed files with 100 additions and 60 deletions

View File

@ -22,6 +22,7 @@ import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -344,6 +345,13 @@ public class GenerateFragment extends Fragment {
bGenerate.setVisibility(View.VISIBLE); bGenerate.setVisibility(View.VISIBLE);
} }
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onPause()");
activityCallback.setTitle(getString(R.string.generate_title));
}
GenerateFragment.Listener activityCallback; GenerateFragment.Listener activityCallback;
public interface Listener { public interface Listener {
@ -354,6 +362,9 @@ public class GenerateFragment extends Fragment {
void onGenerate(String name, String password, String address, String viewKey, String spendKey, long height); void onGenerate(String name, String password, String address, String viewKey, String spendKey, long height);
File getStorageRoot(); File getStorageRoot();
void setTitle(String title);
} }
@Override @Override

View File

@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
@ -55,6 +56,8 @@ public class LoginActivity extends AppCompatActivity
static final int DAEMON_TIMEOUT = 500; // deamon must respond in 500ms static final int DAEMON_TIMEOUT = 500; // deamon must respond in 500ms
Toolbar toolbar;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -63,8 +66,7 @@ public class LoginActivity extends AppCompatActivity
return; return;
} }
Toolbar toolbar = (Toolbar) findViewById(R.id.tbLogin); toolbar = (Toolbar) findViewById(R.id.tbLogin);
toolbar.setTitle(R.string.login_activity_name);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
if (Helper.getWritePermission(this)) { if (Helper.getWritePermission(this)) {
@ -77,21 +79,17 @@ public class LoginActivity extends AppCompatActivity
@Override @Override
public void onWalletSelected(final String walletName) { public void onWalletSelected(final String walletName) {
Log.d(TAG, "selected wallet is ." + walletName + "."); Log.d(TAG, "selected wallet is ." + walletName + ".");
if (walletName.equals(':' + getString(R.string.generate_title))) { // now it's getting real, check if wallet exists
startGenerateFragment(); String walletPath = Helper.getWalletPath(this, walletName);
} else { if (WalletManager.getInstance().walletExists(walletPath)) {
// now it's getting real, check if wallet exists promptPassword(walletName, new PasswordAction() {
String walletPath = Helper.getWalletPath(this, walletName); @Override
if (WalletManager.getInstance().walletExists(walletPath)) { public void action(String walletName, String password) {
promptPassword(walletName, new PasswordAction() { startWallet(walletName, password);
@Override }
public void action(String walletName, String password) { });
startWallet(walletName, password); } else { // this cannot really happen as we prefilter choices
} Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
});
} else { // this cannot really happen as we prefilter choices
Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
}
} }
} }
@ -111,6 +109,11 @@ public class LoginActivity extends AppCompatActivity
} }
} }
@Override
public void onAddWallet() {
startGenerateFragment();
}
AlertDialog passwordDialog = null; // for preventing multiple clicks in wallet list AlertDialog passwordDialog = null; // for preventing multiple clicks in wallet list
void promptPassword(final String wallet, final PasswordAction action) { void promptPassword(final String wallet, final PasswordAction action) {
@ -203,9 +206,13 @@ public class LoginActivity extends AppCompatActivity
@Override @Override
public void setTitle(String title) { public void setTitle(String title) {
super.setTitle(title); toolbar.setTitle(title);
} }
@Override
public void setSubtitle(String subtitle) {
toolbar.setSubtitle(subtitle);
}
//////////////////////////////////////// ////////////////////////////////////////
//////////////////////////////////////// ////////////////////////////////////////

View File

@ -21,6 +21,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.StrictMode; import android.os.StrictMode;
import android.support.design.widget.FloatingActionButton;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -68,6 +69,7 @@ public class LoginFragment extends Fragment {
ToggleButton tbMainNet; ToggleButton tbMainNet;
EditText etDaemonAddress; EditText etDaemonAddress;
FloatingActionButton fabAdd;
Listener activityCallback; Listener activityCallback;
@ -81,7 +83,12 @@ public class LoginFragment extends Fragment {
void onWalletDetails(final String wallet); void onWalletDetails(final String wallet);
void onAddWallet();
void setTitle(String title); void setTitle(String title);
void setSubtitle(String subtitle);
} }
@Override @Override
@ -102,6 +109,13 @@ public class LoginFragment extends Fragment {
super.onPause(); super.onPause();
} }
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onPause()");
activityCallback.setTitle(getString(R.string.login_activity_name));
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -111,6 +125,16 @@ public class LoginFragment extends Fragment {
tbMainNet = (ToggleButton) view.findViewById(R.id.tbMainNet); tbMainNet = (ToggleButton) view.findViewById(R.id.tbMainNet);
etDaemonAddress = (EditText) view.findViewById(R.id.etDaemonAddress); etDaemonAddress = (EditText) view.findViewById(R.id.etDaemonAddress);
fabAdd = (FloatingActionButton) view.findViewById(R.id.fabAdd);
fabAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checkAndSetWalletDaemon("", !isMainNet());
activityCallback.onAddWallet();
}
});
Helper.hideKeyboard(getActivity()); Helper.hideKeyboard(getActivity());
etDaemonAddress.setOnClickListener(new View.OnClickListener() { etDaemonAddress.setOnClickListener(new View.OnClickListener() {
@ -139,14 +163,14 @@ public class LoginFragment extends Fragment {
} else { } else {
setDaemon(daemonTestNet); setDaemon(daemonTestNet);
} }
activityCallback.setTitle(getString(R.string.app_name) + " " + activityCallback.setSubtitle(getString(mainnet ? R.string.connect_mainnet : R.string.connect_testnet));
getString(mainnet ? R.string.connect_mainnet : R.string.connect_testnet));
filterList(); filterList();
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged(); ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
} }
}); });
loadPrefs(); loadPrefs();
activityCallback.setSubtitle(getString(isMainNet()? R.string.connect_mainnet : R.string.connect_testnet));
listView = (ListView) view.findViewById(R.id.list); listView = (ListView) view.findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
@ -187,7 +211,6 @@ public class LoginFragment extends Fragment {
savePrefs(); savePrefs();
String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH); String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH);
if (itemValue.charAt(1) == '-') wallet = ':' + wallet;
activityCallback.onWalletSelected(wallet); activityCallback.onWalletSelected(wallet);
} }
}); });
@ -204,30 +227,18 @@ public class LoginFragment extends Fragment {
} }
String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH); String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH);
if (itemValue.charAt(1) == '-') {
Toast.makeText(getActivity(), getString(R.string.bad_wallet), Toast.LENGTH_LONG).show();
return true;
}
String x = isMainNet() ? "4" : "9A"; String x = isMainNet() ? "4" : "9A";
if (x.indexOf(itemValue.charAt(1)) < 0) { if (x.indexOf(itemValue.charAt(1)) < 0) {
Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
return true; return true;
} }
if (!checkAndSetWalletDaemon("", !isMainNet())) { checkAndSetWalletDaemon("", !isMainNet()); // just set selected net
Toast.makeText(getActivity(), getString(R.string.warn_daemon_unavailable), Toast.LENGTH_SHORT).show();
return true;
}
activityCallback.onWalletDetails(wallet); activityCallback.onWalletDetails(wallet);
return true; return true;
} }
}); });
activityCallback.setTitle(getString(R.string.app_name) + " " +
getString(isMainNet() ? R.string.connect_mainnet : R.string.connect_testnet));
loadList(); loadList();
return view; return view;
} }
@ -239,7 +250,6 @@ public class LoginFragment extends Fragment {
// Log.d(TAG, "filtering " + s); // Log.d(TAG, "filtering " + s);
if (x.indexOf(s.charAt(1)) >= 0) displayedList.add(s); if (x.indexOf(s.charAt(1)) >= 0) displayedList.add(s);
} }
displayedList.add(WALLETNAME_PREAMBLE + getString(R.string.generate_title));
} }
private void loadList() { private void loadList() {
@ -261,7 +271,6 @@ public class LoginFragment extends Fragment {
} }
boolean isMainNet() { boolean isMainNet() {
return tbMainNet.isChecked(); return tbMainNet.isChecked();
} }

View File

@ -35,7 +35,6 @@ import android.widget.Toast;
import com.m2049r.xmrwallet.model.PendingTransaction; import com.m2049r.xmrwallet.model.PendingTransaction;
import com.m2049r.xmrwallet.model.TransactionInfo; import com.m2049r.xmrwallet.model.TransactionInfo;
import com.m2049r.xmrwallet.model.Wallet; import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.service.WalletService; import com.m2049r.xmrwallet.service.WalletService;
import com.m2049r.xmrwallet.util.TxData; import com.m2049r.xmrwallet.util.TxData;
@ -46,7 +45,7 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
public static final String REQUEST_ID = "id"; public static final String REQUEST_ID = "id";
public static final String REQUEST_PW = "pw"; public static final String REQUEST_PW = "pw";
Toolbar tbWallet; Toolbar toolbar;
private boolean synced = false; private boolean synced = false;
@ -115,10 +114,10 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
return; return;
} }
tbWallet = (Toolbar) findViewById(R.id.tbWallet); toolbar = (Toolbar) findViewById(R.id.tbWallet);
tbWallet.setTitle(R.string.app_name); toolbar.setTitle(R.string.app_name);
setSupportActionBar(tbWallet); setSupportActionBar(toolbar);
tbWallet.setOnClickListener(new View.OnClickListener() { toolbar.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onWalletDetails(); onWalletDetails();
@ -268,12 +267,12 @@ public class WalletActivity extends AppCompatActivity implements WalletFragment.
@Override @Override
public void setTitle(String title) { public void setTitle(String title) {
tbWallet.setTitle(title); toolbar.setTitle(title);
} }
@Override @Override
public void setSubtitle(String subtitle) { public void setSubtitle(String subtitle) {
tbWallet.setSubtitle(subtitle); toolbar.setSubtitle(subtitle);
} }
@Override @Override

View File

@ -17,35 +17,49 @@
android:textOff="@string/connect_testnet" android:textOff="@string/connect_testnet"
android:textOn="@string/connect_mainnet" android:textOn="@string/connect_mainnet"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent"></ToggleButton>
</ToggleButton>
<EditText <EditText
android:id="@+id/etDaemonAddress" android:id="@+id/etDaemonAddress"
android:layout_height="wrap_content"
android:layout_width="0dp" android:layout_width="0dp"
android:gravity="center" android:layout_height="wrap_content"
android:hint="@string/prompt_daemon"
android:backgroundTint="@color/colorPrimary" android:backgroundTint="@color/colorPrimary"
android:clickable="true"
android:focusable="true" android:focusable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:clickable="true" android:gravity="center"
android:hint="@string/prompt_daemon"
android:imeOptions="actionDone"
android:inputType="text" android:inputType="text"
android:maxLines="1"
android:textIsSelectable="true" android:textIsSelectable="true"
android:textSize="15sp" android:textSize="15sp"
android:maxLines="1"
android:imeOptions="actionDone"
app:layout_constraintBaseline_toBaselineOf="@+id/tbMainNet" app:layout_constraintBaseline_toBaselineOf="@+id/tbMainNet"
app:layout_constraintRight_toLeftOf="@+id/tbMainNet" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintLeft_toLeftOf="parent" /> app:layout_constraintRight_toLeftOf="@+id/tbMainNet" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
<ListView <FrameLayout
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_marginTop="4dp"> android:layout_height="match_parent">
</ListView>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"/>
<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fabAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16sp"
android:src="@android:drawable/ic_input_add"
app:elevation="6dp"
app:fabSize="auto"
app:pressedTranslationZ="12dp" />
</FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -57,7 +57,7 @@
<string name="message_strorage_not_writable">External Storage is not writable! Panic!</string> <string name="message_strorage_not_writable">External Storage is not writable! Panic!</string>
<string name="message_strorage_not_permitted">We really need those External Storage permissions!</string> <string name="message_strorage_not_permitted">We really need those External Storage permissions!</string>
<string name="generate_title">Generate Wallet</string> <string name="generate_title">Create Wallet</string>
<string name="generate_name_hint">Wallet Name</string> <string name="generate_name_hint">Wallet Name</string>
<string name="generate_password_hint">Wallet Password</string> <string name="generate_password_hint">Wallet Password</string>
<string name="generate_buttonGenerate">Make me a wallet already!</string> <string name="generate_buttonGenerate">Make me a wallet already!</string>