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.InputType;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@ -344,6 +345,13 @@ public class GenerateFragment extends Fragment {
bGenerate.setVisibility(View.VISIBLE);
}
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onPause()");
activityCallback.setTitle(getString(R.string.generate_title));
}
GenerateFragment.Listener activityCallback;
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);
File getStorageRoot();
void setTitle(String title);
}
@Override

View File

@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
@ -55,6 +56,8 @@ public class LoginActivity extends AppCompatActivity
static final int DAEMON_TIMEOUT = 500; // deamon must respond in 500ms
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -63,8 +66,7 @@ public class LoginActivity extends AppCompatActivity
return;
}
Toolbar toolbar = (Toolbar) findViewById(R.id.tbLogin);
toolbar.setTitle(R.string.login_activity_name);
toolbar = (Toolbar) findViewById(R.id.tbLogin);
setSupportActionBar(toolbar);
if (Helper.getWritePermission(this)) {
@ -77,9 +79,6 @@ public class LoginActivity extends AppCompatActivity
@Override
public void onWalletSelected(final String walletName) {
Log.d(TAG, "selected wallet is ." + walletName + ".");
if (walletName.equals(':' + getString(R.string.generate_title))) {
startGenerateFragment();
} else {
// now it's getting real, check if wallet exists
String walletPath = Helper.getWalletPath(this, walletName);
if (WalletManager.getInstance().walletExists(walletPath)) {
@ -93,7 +92,6 @@ public class LoginActivity extends AppCompatActivity
Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onWalletDetails(final String walletName) {
@ -111,6 +109,11 @@ public class LoginActivity extends AppCompatActivity
}
}
@Override
public void onAddWallet() {
startGenerateFragment();
}
AlertDialog passwordDialog = null; // for preventing multiple clicks in wallet list
void promptPassword(final String wallet, final PasswordAction action) {
@ -203,9 +206,13 @@ public class LoginActivity extends AppCompatActivity
@Override
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.os.Bundle;
import android.os.StrictMode;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -68,6 +69,7 @@ public class LoginFragment extends Fragment {
ToggleButton tbMainNet;
EditText etDaemonAddress;
FloatingActionButton fabAdd;
Listener activityCallback;
@ -81,7 +83,12 @@ public class LoginFragment extends Fragment {
void onWalletDetails(final String wallet);
void onAddWallet();
void setTitle(String title);
void setSubtitle(String subtitle);
}
@Override
@ -102,6 +109,13 @@ public class LoginFragment extends Fragment {
super.onPause();
}
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onPause()");
activityCallback.setTitle(getString(R.string.login_activity_name));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -111,6 +125,16 @@ public class LoginFragment extends Fragment {
tbMainNet = (ToggleButton) view.findViewById(R.id.tbMainNet);
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());
etDaemonAddress.setOnClickListener(new View.OnClickListener() {
@ -139,14 +163,14 @@ public class LoginFragment extends Fragment {
} else {
setDaemon(daemonTestNet);
}
activityCallback.setTitle(getString(R.string.app_name) + " " +
getString(mainnet ? R.string.connect_mainnet : R.string.connect_testnet));
activityCallback.setSubtitle(getString(mainnet ? R.string.connect_mainnet : R.string.connect_testnet));
filterList();
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
}
});
loadPrefs();
activityCallback.setSubtitle(getString(isMainNet()? R.string.connect_mainnet : R.string.connect_testnet));
listView = (ListView) view.findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
@ -187,7 +211,6 @@ public class LoginFragment extends Fragment {
savePrefs();
String wallet = itemValue.substring(WALLETNAME_PREAMBLE_LENGTH);
if (itemValue.charAt(1) == '-') wallet = ':' + wallet;
activityCallback.onWalletSelected(wallet);
}
});
@ -204,30 +227,18 @@ public class LoginFragment extends Fragment {
}
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";
if (x.indexOf(itemValue.charAt(1)) < 0) {
Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
return true;
}
if (!checkAndSetWalletDaemon("", !isMainNet())) {
Toast.makeText(getActivity(), getString(R.string.warn_daemon_unavailable), Toast.LENGTH_SHORT).show();
return true;
}
checkAndSetWalletDaemon("", !isMainNet()); // just set selected net
activityCallback.onWalletDetails(wallet);
return true;
}
});
activityCallback.setTitle(getString(R.string.app_name) + " " +
getString(isMainNet() ? R.string.connect_mainnet : R.string.connect_testnet));
loadList();
return view;
}
@ -239,7 +250,6 @@ public class LoginFragment extends Fragment {
// Log.d(TAG, "filtering " + s);
if (x.indexOf(s.charAt(1)) >= 0) displayedList.add(s);
}
displayedList.add(WALLETNAME_PREAMBLE + getString(R.string.generate_title));
}
private void loadList() {
@ -261,7 +271,6 @@ public class LoginFragment extends Fragment {
}
boolean isMainNet() {
return tbMainNet.isChecked();
}

View File

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

View File

@ -17,35 +17,49 @@
android:textOff="@string/connect_testnet"
android:textOn="@string/connect_mainnet"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</ToggleButton>
app:layout_constraintTop_toTopOf="parent"></ToggleButton>
<EditText
android:id="@+id/etDaemonAddress"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:hint="@string/prompt_daemon"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimary"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:gravity="center"
android:hint="@string/prompt_daemon"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="1"
android:textIsSelectable="true"
android:textSize="15sp"
android:maxLines="1"
android:imeOptions="actionDone"
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>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="4dp">
</ListView>
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>

View File

@ -57,7 +57,7 @@
<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="generate_title">Generate Wallet</string>
<string name="generate_title">Create Wallet</string>
<string name="generate_name_hint">Wallet Name</string>
<string name="generate_password_hint">Wallet Password</string>
<string name="generate_buttonGenerate">Make me a wallet already!</string>