diff --git a/app/build.gradle b/app/build.gradle index 657b46d..4a90d61 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,19 +48,13 @@ dependencies { compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:recyclerview-v7:22.2.1' -// compile 'com.android.support:support-v4:22.2.1' compile 'com.android.support:design:22.2.1' - compile 'co.dift.ui.swipetoaction:library:1.1' -// compile 'de.hdodenhof:circleimageview:1.3.0' + compile 'com.android.support:cardview-v7:22.2.1' compile 'com.getbase:floatingactionbutton:1.9.0' -// compile 'com.github.ksoichiro:android-observablescrollview:1.5.2' compile 'com.afollestad:material-dialogs:0.7.7.0' compile 'com.github.bumptech.glide:glide:3.6.1' compile(project(':cordova-android')) { } -// compile 'com.netflix.rxjava:rxjava-android:0.20.7' - debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' - compile 'com.android.support:cardview-v7:22.2.1' } diff --git a/app/src/main/java/io/syng/activity/BaseActivity.java b/app/src/main/java/io/syng/activity/BaseActivity.java index c1effd1..a77b11a 100644 --- a/app/src/main/java/io/syng/activity/BaseActivity.java +++ b/app/src/main/java/io/syng/activity/BaseActivity.java @@ -1,7 +1,6 @@ package io.syng.activity; import android.annotation.SuppressLint; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; @@ -24,13 +23,10 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RadioButton; -import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -62,7 +58,6 @@ import io.syng.entity.Profile; import io.syng.util.GeneralUtil; import io.syng.util.PrefsUtil; -import static android.view.View.GONE; import static android.view.View.VISIBLE; import static org.ethereum.config.SystemProperties.CONFIG; @@ -79,7 +74,6 @@ public abstract class BaseActivity extends AppCompatActivity implements private ActionBarDrawerToggle mDrawerToggle; - private Spinner mAccountSpinner; private EditText mSearchTextView; private RecyclerView mDAppsRecyclerView; private RecyclerView mAccountsRecyclerView; @@ -104,8 +98,6 @@ public abstract class BaseActivity extends AppCompatActivity implements protected abstract void onDAppClick(Dapp dapp); - private SpinnerAdapter spinnerAdapter; - private Profile requestProfile; @SuppressLint("InflateParams") @Override @@ -144,7 +136,6 @@ public abstract class BaseActivity extends AppCompatActivity implements mFrontView = mDrawerLayout.findViewById(R.id.ll_front_view); mBackView = mDrawerLayout.findViewById(R.id.ll_back_view); - mBackView.setVisibility(GONE); mAccountsRecyclerView = (RecyclerView) mBackView.findViewById(R.id.accounts_drawer_recycler_view); RecyclerView.LayoutManager layoutManager2 = new LinearLayoutManager(this); @@ -161,13 +152,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Glide.with(this).load(R.drawable.two).into(header); super.setContentView(mDrawerLayout); - TextView textView = (TextView) findViewById(R.id.tv_name); - if (textView != null) { - textView.setText("Cow"); - } - showWarningDialogIfNeed(); - } private void showWarningDialogIfNeed() { @@ -189,11 +174,11 @@ public abstract class BaseActivity extends AppCompatActivity implements private void initProfiles() { mProfiles = PrefsUtil.getProfiles(); // Add default cow account if not present - if (mProfiles.size() == 0) { + if (mProfiles.isEmpty()) { Profile profile = new Profile(); profile.setName("Cow"); // Add default cow and monkey addresses - List addresses = new ArrayList(); + List addresses = new ArrayList<>(); byte[] cowAddr = HashUtil.sha3("cow".getBytes()); addresses.add(Hex.toHexString(cowAddr)); String secret = CONFIG.coinbaseSecret(); @@ -205,17 +190,19 @@ public abstract class BaseActivity extends AppCompatActivity implements } mAccountDrawerAdapter = new AccountDrawerAdapter(this, mProfiles, this); mAccountsRecyclerView.setAdapter(mAccountDrawerAdapter); - if (SyngApplication.currentProfile == null) { + if (SyngApplication.sCurrentProfile == null) { SyngApplication.changeProfile(mProfiles.get(0)); + updateCurrentProfileName(mProfiles.get(0).getName()); } } private void initDApps() { mDApps = new ArrayList<>(); - if (SyngApplication.currentProfile != null) { - mDApps = SyngApplication.currentProfile.getDapps(); + if (SyngApplication.sCurrentProfile != null) { + mDApps = SyngApplication.sCurrentProfile.getDapps(); } + updateAppList(mSearchTextView.getText().toString()); } @@ -238,9 +225,8 @@ public abstract class BaseActivity extends AppCompatActivity implements } } - protected void requestChangeProfile(Profile profile) { + protected void requestChangeProfile(final Profile profile) { - requestProfile = profile; new MaterialDialog.Builder(BaseActivity.this) .title(R.string.request_profile_password) .customView(R.layout.profile_password, true) @@ -254,13 +240,14 @@ public abstract class BaseActivity extends AppCompatActivity implements .widgetColorRes(R.color.accent) .callback(new MaterialDialog.ButtonCallback() { + @SuppressWarnings("ConstantConditions") @Override public void onPositive(MaterialDialog dialog) { View view = dialog.getCustomView(); EditText passwordInput = (EditText) view.findViewById(R.id.passwordInput); - if (requestProfile.decrypt(passwordInput.getText().toString())) { - changeProfile(requestProfile); + if (profile.decrypt(passwordInput.getText().toString())) { + changeProfile(profile); } else { // dialog.hide(); // mAccountSpinner.setSelection(currentPosition, false); @@ -419,57 +406,6 @@ public abstract class BaseActivity extends AppCompatActivity implements } } - - public class SpinnerAdapter extends ArrayAdapter { - - private Context context; - - private List values; - - public SpinnerAdapter(Context context, int textViewResourceId, List values) { - - super(context, textViewResourceId, values); - this.context = context; - this.values = values; - } - - public int getCount() { - - return values.size(); - } - - public Profile getItem(int position) { - - return values.get(position); - } - - public long getItemId(int position) { - - return position; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - - return getCustomView(position, convertView, parent); - } - - @Override - public View getDropDownView(int position, View convertView, ViewGroup parent) { - - return getCustomView(position, convertView, parent); - } - - public View getCustomView(int position, View convertView, ViewGroup parent) { - - LayoutInflater inflater = getLayoutInflater(); - View row = inflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false); - TextView label = (TextView) row.findViewById(android.R.id.text1); - label.setText(spinnerAdapter.getItem(position).getName()); - return row; - } - } - @Override public void onDAppItemClick(Dapp dapp) { onDAppClick(dapp); @@ -493,9 +429,9 @@ public abstract class BaseActivity extends AppCompatActivity implements @Override public void onPositive(MaterialDialog dialog) { - RadioButton importJsonRadio = (RadioButton)dialog.findViewById(R.id.radio_import_json); - EditText importPathEdit = (EditText)dialog.findViewById(R.id.wallet_import_path); - EditText walletPasswordEdit = (EditText)dialog.findViewById(R.id.wallet_password); + RadioButton importJsonRadio = (RadioButton) dialog.findViewById(R.id.radio_import_json); + EditText importPathEdit = (EditText) dialog.findViewById(R.id.wallet_import_path); + EditText walletPasswordEdit = (EditText) dialog.findViewById(R.id.wallet_password); String importPath = importPathEdit.getText().toString(); String password = walletPasswordEdit.getText().toString(); String fileContents = null; @@ -521,18 +457,18 @@ public abstract class BaseActivity extends AppCompatActivity implements } if (importJsonRadio.isChecked()) { - if (SyngApplication.currentProfile != null) { - if (SyngApplication.currentProfile.importWallet(fileContents, password)) { - PrefsUtil.updateProfile(SyngApplication.currentProfile); - SyngApplication.changeProfile(SyngApplication.currentProfile); + if (SyngApplication.sCurrentProfile != null) { + if (SyngApplication.sCurrentProfile.importWallet(fileContents, password)) { + PrefsUtil.updateProfile(SyngApplication.sCurrentProfile); + SyngApplication.changeProfile(SyngApplication.sCurrentProfile); } else { Toast.makeText(BaseActivity.this, R.string.invalid_wallet_password, Toast.LENGTH_SHORT).show(); } } else { - logger.warn("SyngApplication.currentProfile is null ...?!"); + logger.warn("SyngApplication.sCurrentProfile is null ...?!"); } } else { - SyngApplication.currentProfile.importPrivateKey(fileContents, password); + SyngApplication.sCurrentProfile.importPrivateKey(fileContents, password); } } @@ -603,7 +539,7 @@ public abstract class BaseActivity extends AppCompatActivity implements } } mAccountDrawerAdapter.notifyDataSetChanged(); - if (SyngApplication.currentProfile.getId().equals(profile.getId())) { + if (SyngApplication.sCurrentProfile.getId().equals(profile.getId())) { updateCurrentProfileName(profile.getName()); } } @@ -623,8 +559,8 @@ public abstract class BaseActivity extends AppCompatActivity implements @Override public void onPositive(MaterialDialog dialog) { - EditText dappNameEdit = (EditText)dialog.findViewById(R.id.dapp_name); - EditText dappUrlEdit = (EditText)dialog.findViewById(R.id.dapp_url); + EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name); + EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url); String url = dappUrlEdit.getText().toString(); if (Patterns.WEB_URL.matcher(url.replace("dapp://", "http://")).matches()) { Dapp dapp = new Dapp(dappNameEdit.getText().toString()); diff --git a/app/src/main/java/io/syng/app/SyngApplication.java b/app/src/main/java/io/syng/app/SyngApplication.java index 7076be6..a745fd6 100644 --- a/app/src/main/java/io/syng/app/SyngApplication.java +++ b/app/src/main/java/io/syng/app/SyngApplication.java @@ -23,22 +23,22 @@ public class SyngApplication extends MultiDexApplication implements ConnectorHan private RefWatcher refWatcher; - public static Profile currentProfile; + public static Profile sCurrentProfile; public static void changeProfile(Profile profile) { List privateKeys = profile.getPrivateKeys(); sEthereumConnector.init(privateKeys); - currentProfile = profile; + sCurrentProfile = profile; } public static void addDapp(Dapp dapp) { - currentProfile.addDapp(dapp); - PrefsUtil.updateProfile(currentProfile); + sCurrentProfile.addDapp(dapp); + PrefsUtil.updateProfile(sCurrentProfile); } public static void updateDapp(Dapp dapp) { - currentProfile.updateDapp(dapp); - PrefsUtil.updateProfile(currentProfile); + sCurrentProfile.updateDapp(dapp); + PrefsUtil.updateProfile(sCurrentProfile); } @Override @@ -70,8 +70,8 @@ public class SyngApplication extends MultiDexApplication implements ConnectorHan @Override public void onConnectorConnected() { - if (currentProfile != null) { - sEthereumConnector.init(currentProfile.getPrivateKeys()); + if (sCurrentProfile != null) { + sEthereumConnector.init(sCurrentProfile.getPrivateKeys()); } sEthereumConnector.startJsonRpc(); } diff --git a/app/src/main/res/layout/dapp_form.xml b/app/src/main/res/layout/dapp_form.xml index 55091ab..c9ba37b 100644 --- a/app/src/main/res/layout/dapp_form.xml +++ b/app/src/main/res/layout/dapp_form.xml @@ -1,30 +1,28 @@ - - - - - + - - - - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_back_view.xml b/app/src/main/res/layout/drawer_back_view.xml index fd403a8..2a74012 100644 --- a/app/src/main/res/layout/drawer_back_view.xml +++ b/app/src/main/res/layout/drawer_back_view.xml @@ -3,7 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical"> + android:orientation="vertical" + android:visibility="gone">