mirror of
https://github.com/status-im/syng-client.git
synced 2025-02-23 08:28:07 +00:00
All Dialogs code from BaseActivity moved to GeneralUtil
This commit is contained in:
parent
588ffe72a6
commit
a52b4e8ded
@ -1,25 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="io.syng"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
package="io.syng" >
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
||||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||||
|
|
||||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
@ -27,46 +21,51 @@
|
|||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme" >
|
||||||
|
|
||||||
<!--android:largeHeap="true"-->
|
<!-- android:largeHeap="true" -->
|
||||||
<!--android:hardwareAccelerated="true"-->
|
<!-- android:hardwareAccelerated="true" -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.MainActivity"
|
android:name=".activity.MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:windowSoftInputMode="adjustNothing"
|
android:launchMode="singleTop"
|
||||||
android:launchMode="singleTop">
|
android:windowSoftInputMode="adjustNothing" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<data android:scheme="dapp" />
|
<data android:scheme="dapp" />
|
||||||
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.SettingsActivity"
|
android:name=".activity.SettingsActivity"
|
||||||
android:label="@string/title_activity_settings"
|
android:label="@string/title_activity_settings"
|
||||||
android:parentActivityName=".activity.MainActivity"
|
android:parentActivityName=".activity.MainActivity"
|
||||||
android:theme="@style/SettingsTheme"
|
android:theme="@style/SettingsTheme"
|
||||||
tools:ignore="UnusedAttribute">
|
tools:ignore="UnusedAttribute" >
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activity.MainActivity"/>
|
android:value=".activity.MainActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.EthereumService"
|
android:name=".service.EthereumService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":ethereum_process"/>
|
android:process=":ethereum_process" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activity.LoginActivity"
|
||||||
|
android:label="@string/title_activity_login" >
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -15,9 +15,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
|||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Patterns;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -25,30 +23,19 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.nio.MappedByteBuffer;
|
|
||||||
import java.nio.channels.FileChannel;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.syng.R;
|
import io.syng.R;
|
||||||
import io.syng.adapter.BackgroundArrayAdapter;
|
|
||||||
import io.syng.adapter.DAppDrawerAdapter;
|
import io.syng.adapter.DAppDrawerAdapter;
|
||||||
import io.syng.adapter.DAppDrawerAdapter.OnDAppClickListener;
|
import io.syng.adapter.DAppDrawerAdapter.OnDAppClickListener;
|
||||||
import io.syng.adapter.ProfileDrawerAdapter;
|
import io.syng.adapter.ProfileDrawerAdapter;
|
||||||
@ -57,7 +44,6 @@ import io.syng.entity.Dapp;
|
|||||||
import io.syng.entity.Profile;
|
import io.syng.entity.Profile;
|
||||||
import io.syng.fragment.profile.ProfileDialogFragment;
|
import io.syng.fragment.profile.ProfileDialogFragment;
|
||||||
import io.syng.util.GeneralUtil;
|
import io.syng.util.GeneralUtil;
|
||||||
import io.syng.util.PrefsUtil;
|
|
||||||
import io.syng.util.ProfileManager;
|
import io.syng.util.ProfileManager;
|
||||||
import io.syng.util.ProfileManager.ProfilesChangeListener;
|
import io.syng.util.ProfileManager.ProfilesChangeListener;
|
||||||
|
|
||||||
@ -66,7 +52,7 @@ import static android.view.View.VISIBLE;
|
|||||||
public abstract class BaseActivity extends AppCompatActivity implements
|
public abstract class BaseActivity extends AppCompatActivity implements
|
||||||
OnClickListener, OnDAppClickListener, OnProfileClickListener, OnLongClickListener, ProfilesChangeListener {
|
OnClickListener, OnDAppClickListener, OnProfileClickListener, OnLongClickListener, ProfilesChangeListener {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("SyngApplication");
|
// private static final Logger logger = LoggerFactory.getLogger("SyngApplication");
|
||||||
|
|
||||||
private static final int DRAWER_CLOSE_DELAY_SHORT = 200;
|
private static final int DRAWER_CLOSE_DELAY_SHORT = 200;
|
||||||
private static final int DRAWER_CLOSE_DELAY_LONG = 400;
|
private static final int DRAWER_CLOSE_DELAY_LONG = 400;
|
||||||
@ -156,8 +142,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||||||
populateDApps();
|
populateDApps();
|
||||||
|
|
||||||
mHeaderImageView = (ImageView) findViewById(R.id.iv_header);
|
mHeaderImageView = (ImageView) findViewById(R.id.iv_header);
|
||||||
String currentProfileId = ProfileManager.getCurrentProfile().getId();
|
Glide.with(this).load(ProfileManager.getCurrentProfileBackgroundResourceId()).into(mHeaderImageView);
|
||||||
Glide.with(this).load(PrefsUtil.getBackgroundResourceId(currentProfileId)).into(mHeaderImageView);
|
|
||||||
|
|
||||||
GeneralUtil.showWarningDialogIfNeed(this);
|
GeneralUtil.showWarningDialogIfNeed(this);
|
||||||
ProfileManager.setProfilesChangeListener(this);
|
ProfileManager.setProfilesChangeListener(this);
|
||||||
@ -301,55 +286,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void showProfileCreateDialog() {
|
|
||||||
MaterialDialog dialog = new MaterialDialog.Builder(this)
|
|
||||||
.title("New profile")
|
|
||||||
.positiveText(R.string.dialog_button_create)
|
|
||||||
.negativeText(R.string.dialog_button_cancel)
|
|
||||||
.customView(R.layout.profile_create_dialog, true)
|
|
||||||
.autoDismiss(false)
|
|
||||||
.callback(new MaterialDialog.ButtonCallback() {
|
|
||||||
@Override
|
|
||||||
public void onPositive(MaterialDialog dialog) {
|
|
||||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
|
||||||
EditText pass1 = (EditText) dialog.findViewById(R.id.et_profile_pass_1);
|
|
||||||
EditText pass2 = (EditText) dialog.findViewById(R.id.et_profile_pass_2);
|
|
||||||
|
|
||||||
String nameString = name.getText().toString();
|
|
||||||
String pass1String = pass1.getText().toString();
|
|
||||||
String pass2String = pass2.getText().toString();
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(nameString)) {
|
|
||||||
Toast.makeText(BaseActivity.this, "Profile name can't be empty", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (TextUtils.isEmpty(pass1String) || TextUtils.isEmpty(pass2String)) {
|
|
||||||
Toast.makeText(BaseActivity.this, "Password name can't be empty", Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pass1.getText().toString().equals(pass2.getText().toString())) {
|
|
||||||
Toast.makeText(BaseActivity.this, "Passwords should be the same!", Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
|
||||||
Profile profile = new Profile();
|
|
||||||
profile.setName(name.getText().toString());
|
|
||||||
profile.setPassword(pass1String);
|
|
||||||
ProfileManager.addProfile(profile);
|
|
||||||
GeneralUtil.hideKeyBoard(name, BaseActivity.this);
|
|
||||||
GeneralUtil.hideKeyBoard(pass1, BaseActivity.this);
|
|
||||||
GeneralUtil.hideKeyBoard(pass2, BaseActivity.this);
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNegative(MaterialDialog dialog) {
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
}).show();
|
|
||||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
|
||||||
GeneralUtil.showKeyBoard(name, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void flipDrawer() {
|
private void flipDrawer() {
|
||||||
ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
|
ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
|
||||||
@ -393,105 +330,12 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProfileImport() {
|
public void onProfileImport() {
|
||||||
new MaterialDialog.Builder(this)
|
GeneralUtil.showProfileImportDialog(this);
|
||||||
.title(R.string.wallet_title)
|
|
||||||
.customView(R.layout.wallet_import, true)
|
|
||||||
.positiveText(R.string.sImport)
|
|
||||||
.negativeText(R.string.cancel)
|
|
||||||
.callback(new MaterialDialog.ButtonCallback() {
|
|
||||||
@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);
|
|
||||||
String importPath = importPathEdit.getText().toString();
|
|
||||||
String password = walletPasswordEdit.getText().toString();
|
|
||||||
String fileContents = null;
|
|
||||||
try {
|
|
||||||
File walletFile = new File(importPath);
|
|
||||||
if (walletFile.exists()) {
|
|
||||||
FileInputStream stream = new FileInputStream(walletFile);
|
|
||||||
try {
|
|
||||||
FileChannel fileChannel = stream.getChannel();
|
|
||||||
MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
|
|
||||||
fileContents = Charset.defaultCharset().decode(buffer).toString();
|
|
||||||
} finally {
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Toast.makeText(BaseActivity.this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
|
|
||||||
logger.warn("Wallet file not found: " + importPath);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Toast.makeText(BaseActivity.this, R.string.error_reading_file, Toast.LENGTH_SHORT).show();
|
|
||||||
logger.error("Error reading wallet file", e);
|
|
||||||
}
|
|
||||||
if (importJsonRadio.isChecked()) {
|
|
||||||
Profile profile = ProfileManager.getCurrentProfile();
|
|
||||||
if (profile.importWallet(fileContents, password)) {
|
|
||||||
ProfileManager.updateProfile(profile);
|
|
||||||
ProfileManager.setCurrentProfile(profile);
|
|
||||||
} else {
|
|
||||||
Toast.makeText(BaseActivity.this, R.string.invalid_wallet_password, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Profile profile = ProfileManager.getCurrentProfile();
|
|
||||||
profile.importPrivateKey(fileContents, password);
|
|
||||||
ProfileManager.updateProfile(profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNegative(MaterialDialog dialog) {
|
|
||||||
dialog.hide();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build().show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDAppPress(final Dapp dapp) {
|
public void onDAppPress(final Dapp dapp) {
|
||||||
MaterialDialog dialog = new MaterialDialog.Builder(this)
|
GeneralUtil.showDAppEditDialog(dapp, this);
|
||||||
.title("Edit")
|
|
||||||
.customView(R.layout.dapp_form, true)
|
|
||||||
.positiveText(R.string.save)
|
|
||||||
.negativeText(R.string.cancel)
|
|
||||||
.callback(new MaterialDialog.ButtonCallback() {
|
|
||||||
@Override
|
|
||||||
public void onPositive(MaterialDialog dialog) {
|
|
||||||
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
|
||||||
EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url);
|
|
||||||
CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.dapp_home_icon);
|
|
||||||
boolean homeScreenIcon = checkBox.isChecked();
|
|
||||||
String url = dappUrlEdit.getText().toString();
|
|
||||||
String name = dappNameEdit.getText().toString();
|
|
||||||
if (Patterns.WEB_URL.matcher(url.replace("dapp://", "http://")).matches()) {
|
|
||||||
dapp.setName(name);
|
|
||||||
dapp.setUrl(url);
|
|
||||||
System.out.println(url);
|
|
||||||
ProfileManager.updateDAppInProfile(ProfileManager.getCurrentProfile(), dapp);
|
|
||||||
if (homeScreenIcon) {
|
|
||||||
GeneralUtil.createHomeScreenIcon(BaseActivity.this, name, url);
|
|
||||||
}
|
|
||||||
dialog.hide();
|
|
||||||
} else {
|
|
||||||
Toast.makeText(BaseActivity.this, R.string.invalid_url, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNegative(MaterialDialog dialog) {
|
|
||||||
dialog.hide();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.autoDismiss(false)
|
|
||||||
.build();
|
|
||||||
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
|
||||||
dappNameEdit.setText(dapp.getName());
|
|
||||||
EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url);
|
|
||||||
dappUrlEdit.setText(dapp.getUrl());
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
@ -503,42 +347,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDAppAdd() {
|
public void onDAppAdd() {
|
||||||
Dialog dialog = new MaterialDialog.Builder(this)
|
GeneralUtil.showDAppCreateDialog(this);
|
||||||
.title("Add new DApp")
|
|
||||||
.customView(R.layout.dapp_form, true)
|
|
||||||
.positiveText(R.string.save)
|
|
||||||
.negativeText(R.string.cancel)
|
|
||||||
.callback(new MaterialDialog.ButtonCallback() {
|
|
||||||
@Override
|
|
||||||
public void onPositive(MaterialDialog dialog) {
|
|
||||||
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
|
||||||
EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url);
|
|
||||||
CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.dapp_home_icon);
|
|
||||||
boolean homeScreenIcon = checkBox.isChecked();
|
|
||||||
String url = dappUrlEdit.getText().toString();
|
|
||||||
String name = dappNameEdit.getText().toString();
|
|
||||||
if (Patterns.WEB_URL.matcher(url.replace("dapp://", "http://")).matches()) {
|
|
||||||
Dapp dapp = new Dapp(name);
|
|
||||||
dapp.setUrl(url);
|
|
||||||
ProfileManager.addDAppToProfile(ProfileManager.getCurrentProfile(), dapp);
|
|
||||||
if (homeScreenIcon) {
|
|
||||||
GeneralUtil.createHomeScreenIcon(BaseActivity.this, name, url);
|
|
||||||
}
|
|
||||||
dialog.hide();
|
|
||||||
} else {
|
|
||||||
Toast.makeText(BaseActivity.this, R.string.invalid_url, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNegative(MaterialDialog dialog) {
|
|
||||||
dialog.hide();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.autoDismiss(false)
|
|
||||||
.show();
|
|
||||||
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
|
||||||
GeneralUtil.showKeyBoard(dappNameEdit, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -555,26 +364,13 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewProfile() {
|
public void onNewProfile() {
|
||||||
showProfileCreateDialog();
|
GeneralUtil.showProfileCreateDialog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
if (v.getId() == R.id.drawer_header_item) {
|
if (v.getId() == R.id.drawer_header_item) {
|
||||||
new MaterialDialog.Builder(this)
|
GeneralUtil.showHeaderBackgroundDialog(this);
|
||||||
.adapter(new BackgroundArrayAdapter(this),
|
|
||||||
new MaterialDialog.ListCallback() {
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Override
|
|
||||||
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
|
||||||
BackgroundArrayAdapter adapter = (BackgroundArrayAdapter) dialog.getListView().getAdapter();
|
|
||||||
int imageResourceId = adapter.getImageResourceIdByPosition(which);
|
|
||||||
Glide.with(BaseActivity.this).load(imageResourceId).into(mHeaderImageView);
|
|
||||||
PrefsUtil.setBackgroundResourceId(ProfileManager.getCurrentProfile().getId(), imageResourceId);
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -584,7 +380,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
|||||||
updateCurrentProfileName();
|
updateCurrentProfileName();
|
||||||
populateDApps();
|
populateDApps();
|
||||||
populateProfiles();
|
populateProfiles();
|
||||||
Glide.with(this).load(PrefsUtil.getBackgroundResourceId(ProfileManager.getCurrentProfile().getId())).into(mHeaderImageView);
|
Glide.with(this).load(ProfileManager.getCurrentProfileBackgroundResourceId()).into(mHeaderImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
16
app/src/main/java/io/syng/activity/LoginActivity.java
Normal file
16
app/src/main/java/io/syng/activity/LoginActivity.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package io.syng.activity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import io.syng.R;
|
||||||
|
|
||||||
|
public class LoginActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_login);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,36 @@
|
|||||||
package io.syng.util;
|
package io.syng.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Patterns;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
||||||
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.nio.MappedByteBuffer;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import io.syng.R;
|
import io.syng.R;
|
||||||
|
import io.syng.adapter.BackgroundArrayAdapter;
|
||||||
|
import io.syng.entity.Dapp;
|
||||||
|
import io.syng.entity.Profile;
|
||||||
|
|
||||||
public final class GeneralUtil {
|
public final class GeneralUtil {
|
||||||
|
|
||||||
@ -58,4 +78,214 @@ public final class GeneralUtil {
|
|||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showProfileCreateDialog(final Context context) {
|
||||||
|
MaterialDialog dialog = new MaterialDialog.Builder(context)
|
||||||
|
.title("New profile")
|
||||||
|
.positiveText(R.string.dialog_button_create)
|
||||||
|
.negativeText(R.string.dialog_button_cancel)
|
||||||
|
.customView(R.layout.profile_create_dialog, true)
|
||||||
|
.autoDismiss(false)
|
||||||
|
.callback(new MaterialDialog.ButtonCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPositive(MaterialDialog dialog) {
|
||||||
|
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||||
|
EditText pass1 = (EditText) dialog.findViewById(R.id.et_profile_pass_1);
|
||||||
|
EditText pass2 = (EditText) dialog.findViewById(R.id.et_profile_pass_2);
|
||||||
|
|
||||||
|
String nameString = name.getText().toString();
|
||||||
|
String pass1String = pass1.getText().toString();
|
||||||
|
String pass2String = pass2.getText().toString();
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(nameString)) {
|
||||||
|
Toast.makeText(context, "Profile name can't be empty", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(pass1String) || TextUtils.isEmpty(pass2String)) {
|
||||||
|
Toast.makeText(context, "Password name can't be empty", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pass1.getText().toString().equals(pass2.getText().toString())) {
|
||||||
|
Toast.makeText(context, "Passwords should be the same!", Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
Profile profile = new Profile();
|
||||||
|
profile.setName(name.getText().toString());
|
||||||
|
profile.setPassword(pass1String);
|
||||||
|
ProfileManager.addProfile(profile);
|
||||||
|
GeneralUtil.hideKeyBoard(name, context);
|
||||||
|
GeneralUtil.hideKeyBoard(pass1, context);
|
||||||
|
GeneralUtil.hideKeyBoard(pass2, context);
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative(MaterialDialog dialog) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||||
|
GeneralUtil.showKeyBoard(name, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDAppEditDialog(final Dapp dapp, final Context context) {
|
||||||
|
MaterialDialog dialog = new MaterialDialog.Builder(context)
|
||||||
|
.title("Edit")
|
||||||
|
.customView(R.layout.dapp_form, true)
|
||||||
|
.positiveText(R.string.save)
|
||||||
|
.negativeText(R.string.cancel)
|
||||||
|
.callback(new MaterialDialog.ButtonCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPositive(MaterialDialog dialog) {
|
||||||
|
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
||||||
|
EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url);
|
||||||
|
CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.dapp_home_icon);
|
||||||
|
boolean homeScreenIcon = checkBox.isChecked();
|
||||||
|
String url = dappUrlEdit.getText().toString();
|
||||||
|
String name = dappNameEdit.getText().toString();
|
||||||
|
if (Patterns.WEB_URL.matcher(url.replace("dapp://", "http://")).matches()) {
|
||||||
|
dapp.setName(name);
|
||||||
|
dapp.setUrl(url);
|
||||||
|
System.out.println(url);
|
||||||
|
ProfileManager.updateDAppInProfile(ProfileManager.getCurrentProfile(), dapp);
|
||||||
|
if (homeScreenIcon) {
|
||||||
|
GeneralUtil.createHomeScreenIcon(context, name, url);
|
||||||
|
}
|
||||||
|
dialog.hide();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.invalid_url, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative(MaterialDialog dialog) {
|
||||||
|
dialog.hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.autoDismiss(false)
|
||||||
|
.build();
|
||||||
|
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
||||||
|
dappNameEdit.setText(dapp.getName());
|
||||||
|
EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url);
|
||||||
|
dappUrlEdit.setText(dapp.getUrl());
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDAppCreateDialog(final Context context) {
|
||||||
|
Dialog dialog = new MaterialDialog.Builder(context)
|
||||||
|
.title("Add new DApp")
|
||||||
|
.customView(R.layout.dapp_form, true)
|
||||||
|
.positiveText(R.string.save)
|
||||||
|
.negativeText(R.string.cancel)
|
||||||
|
.callback(new MaterialDialog.ButtonCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPositive(MaterialDialog dialog) {
|
||||||
|
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
||||||
|
EditText dappUrlEdit = (EditText) dialog.findViewById(R.id.dapp_url);
|
||||||
|
CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.dapp_home_icon);
|
||||||
|
boolean homeScreenIcon = checkBox.isChecked();
|
||||||
|
String url = dappUrlEdit.getText().toString();
|
||||||
|
String name = dappNameEdit.getText().toString();
|
||||||
|
if (Patterns.WEB_URL.matcher(url.replace("dapp://", "http://")).matches()) {
|
||||||
|
Dapp dapp = new Dapp(name);
|
||||||
|
dapp.setUrl(url);
|
||||||
|
ProfileManager.addDAppToProfile(ProfileManager.getCurrentProfile(), dapp);
|
||||||
|
if (homeScreenIcon) {
|
||||||
|
GeneralUtil.createHomeScreenIcon(context, name, url);
|
||||||
|
}
|
||||||
|
dialog.hide();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.invalid_url, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative(MaterialDialog dialog) {
|
||||||
|
dialog.hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.autoDismiss(false)
|
||||||
|
.show();
|
||||||
|
EditText dappNameEdit = (EditText) dialog.findViewById(R.id.dapp_name);
|
||||||
|
GeneralUtil.showKeyBoard(dappNameEdit, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showProfileImportDialog(final Context context) {
|
||||||
|
new MaterialDialog.Builder(context)
|
||||||
|
.title(R.string.wallet_title)
|
||||||
|
.customView(R.layout.wallet_import, true)
|
||||||
|
.positiveText(R.string.sImport)
|
||||||
|
.negativeText(R.string.cancel)
|
||||||
|
.callback(new MaterialDialog.ButtonCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPositive(MaterialDialog dialog) {
|
||||||
|
|
||||||
|
Logger logger = LoggerFactory.getLogger("SyngApplication");
|
||||||
|
|
||||||
|
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;
|
||||||
|
try {
|
||||||
|
File walletFile = new File(importPath);
|
||||||
|
if (walletFile.exists()) {
|
||||||
|
FileInputStream stream = new FileInputStream(walletFile);
|
||||||
|
try {
|
||||||
|
FileChannel fileChannel = stream.getChannel();
|
||||||
|
MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
|
||||||
|
fileContents = Charset.defaultCharset().decode(buffer).toString();
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.file_not_found, Toast.LENGTH_SHORT).show();
|
||||||
|
logger.warn("Wallet file not found: " + importPath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(context, R.string.error_reading_file, Toast.LENGTH_SHORT).show();
|
||||||
|
logger.error("Error reading wallet file", e);
|
||||||
|
}
|
||||||
|
if (importJsonRadio.isChecked()) {
|
||||||
|
Profile profile = ProfileManager.getCurrentProfile();
|
||||||
|
if (profile.importWallet(fileContents, password)) {
|
||||||
|
ProfileManager.updateProfile(profile);
|
||||||
|
ProfileManager.setCurrentProfile(profile);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, R.string.invalid_wallet_password, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Profile profile = ProfileManager.getCurrentProfile();
|
||||||
|
profile.importPrivateKey(fileContents, password);
|
||||||
|
ProfileManager.updateProfile(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative(MaterialDialog dialog) {
|
||||||
|
dialog.hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showHeaderBackgroundDialog(final Context context) {
|
||||||
|
new MaterialDialog.Builder(context)
|
||||||
|
.adapter(new BackgroundArrayAdapter(context),
|
||||||
|
new MaterialDialog.ListCallback() {
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@Override
|
||||||
|
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
||||||
|
BackgroundArrayAdapter adapter = (BackgroundArrayAdapter) dialog.getListView().getAdapter();
|
||||||
|
int imageResourceId = adapter.getImageResourceIdByPosition(which);
|
||||||
|
ProfileManager.setCurrentProfileBackgroundResourceId(imageResourceId);
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.syng.util;
|
package io.syng.util;
|
||||||
|
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
@ -81,6 +82,7 @@ public final class ProfileManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return new Profile();
|
return new Profile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +117,15 @@ public final class ProfileManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setCurrentProfileBackgroundResourceId(@DrawableRes int resourceId) {
|
||||||
|
PrefsUtil.setBackgroundResourceId(ProfileManager.getCurrentProfile().getId(), resourceId);
|
||||||
|
notifyListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCurrentProfileBackgroundResourceId() {
|
||||||
|
return PrefsUtil.getBackgroundResourceId(ProfileManager.getCurrentProfile().getId());
|
||||||
|
}
|
||||||
|
|
||||||
public static void setProfilesChangeListener(ProfilesChangeListener listener) {
|
public static void setProfilesChangeListener(ProfilesChangeListener listener) {
|
||||||
getInstance().mProfilesChangeListener = listener;
|
getInstance().mProfilesChangeListener = listener;
|
||||||
}
|
}
|
||||||
@ -128,4 +139,5 @@ public final class ProfileManager {
|
|||||||
getInstance().mProfilesChangeListener.onProfilesChange();
|
getInstance().mProfilesChangeListener.onProfilesChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
12
app/src/main/res/layout/activity_login.xml
Normal file
12
app/src/main/res/layout/activity_login.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context="io.syng.activity.LoginActivity">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_background"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
@ -37,5 +37,9 @@
|
|||||||
<string name="dialog.button.cancel">Cancel</string>
|
<string name="dialog.button.cancel">Cancel</string>
|
||||||
<string name="menu.profile.key.import">Import</string>
|
<string name="menu.profile.key.import">Import</string>
|
||||||
<string name="menu.profile.key.export">Export</string>
|
<string name="menu.profile.key.export">Export</string>
|
||||||
|
<string name="title_activity_login">LoginActivity</string>
|
||||||
|
|
||||||
|
<string name="hello_world">Hello world!</string>
|
||||||
|
<string name="action_settings">Settings</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user