mirror of
https://github.com/status-im/syng-client.git
synced 2025-02-22 16:08:11 +00:00
Merge branch 'master' of https://github.com/syng-io/syng-client
This commit is contained in:
commit
27d2327a00
@ -1,26 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
package="io.syng"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<manifest package="io.syng"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_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.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_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.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
|
||||
|
||||
<application
|
||||
android:name=".app.SyngApplication"
|
||||
@ -29,27 +23,34 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<!--android:largeHeap="true"-->
|
||||
<!--android:hardwareAccelerated="true"-->
|
||||
<!-- android:largeHeap="true" -->
|
||||
<!-- android:hardwareAccelerated="true" -->
|
||||
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="adjustNothing"
|
||||
android:launchMode="singleTop">
|
||||
android:name=".activity.LoginActivity"
|
||||
android:theme="@style/AppTheme.Login"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<data android:scheme="dapp" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:windowSoftInputMode="adjustNothing">
|
||||
<intent-filter>
|
||||
<data android:scheme="dapp"/>
|
||||
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.SettingsActivity"
|
||||
android:label="@string/title_activity_settings"
|
||||
|
@ -15,9 +15,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Patterns;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@ -25,30 +23,19 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
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.List;
|
||||
|
||||
import io.syng.R;
|
||||
import io.syng.adapter.BackgroundArrayAdapter;
|
||||
import io.syng.adapter.DAppDrawerAdapter;
|
||||
import io.syng.adapter.DAppDrawerAdapter.OnDAppClickListener;
|
||||
import io.syng.adapter.ProfileDrawerAdapter;
|
||||
@ -57,7 +44,6 @@ import io.syng.entity.Dapp;
|
||||
import io.syng.entity.Profile;
|
||||
import io.syng.fragment.profile.ProfileDialogFragment;
|
||||
import io.syng.util.GeneralUtil;
|
||||
import io.syng.util.PrefsUtil;
|
||||
import io.syng.util.ProfileManager;
|
||||
import io.syng.util.ProfileManager.ProfilesChangeListener;
|
||||
|
||||
@ -66,7 +52,7 @@ import static android.view.View.VISIBLE;
|
||||
public abstract class BaseActivity extends AppCompatActivity implements
|
||||
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_LONG = 400;
|
||||
@ -156,8 +142,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
populateDApps();
|
||||
|
||||
mHeaderImageView = (ImageView) findViewById(R.id.iv_header);
|
||||
String currentProfileId = ProfileManager.getCurrentProfile().getId();
|
||||
Glide.with(this).load(PrefsUtil.getBackgroundResourceId(currentProfileId)).into(mHeaderImageView);
|
||||
Glide.with(this).load(ProfileManager.getCurrentProfileBackgroundResourceId()).into(mHeaderImageView);
|
||||
|
||||
GeneralUtil.showWarningDialogIfNeed(this);
|
||||
ProfileManager.setProfilesChangeListener(this);
|
||||
@ -301,55 +286,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
}
|
||||
|
||||
@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() {
|
||||
ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
|
||||
@ -393,105 +330,12 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
|
||||
@Override
|
||||
public void onProfileImport() {
|
||||
new MaterialDialog.Builder(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();
|
||||
GeneralUtil.showProfileImportDialog(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDAppPress(final Dapp dapp) {
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(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();
|
||||
GeneralUtil.showDAppEditDialog(dapp, this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@ -503,42 +347,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
|
||||
@Override
|
||||
public void onDAppAdd() {
|
||||
Dialog dialog = new MaterialDialog.Builder(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);
|
||||
GeneralUtil.showDAppCreateDialog(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -555,26 +364,13 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
|
||||
@Override
|
||||
public void onNewProfile() {
|
||||
showProfileCreateDialog();
|
||||
GeneralUtil.showProfileCreateDialog(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (v.getId() == R.id.drawer_header_item) {
|
||||
new MaterialDialog.Builder(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();
|
||||
GeneralUtil.showHeaderBackgroundDialog(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -584,7 +380,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
updateCurrentProfileName();
|
||||
populateDApps();
|
||||
populateProfiles();
|
||||
Glide.with(this).load(PrefsUtil.getBackgroundResourceId(ProfileManager.getCurrentProfile().getId())).into(mHeaderImageView);
|
||||
Glide.with(this).load(ProfileManager.getCurrentProfileBackgroundResourceId()).into(mHeaderImageView);
|
||||
}
|
||||
|
||||
}
|
122
app/src/main/java/io/syng/activity/LoginActivity.java
Normal file
122
app/src/main/java/io/syng/activity/LoginActivity.java
Normal file
@ -0,0 +1,122 @@
|
||||
package io.syng.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.syng.R;
|
||||
import io.syng.entity.Profile;
|
||||
import io.syng.util.GeneralUtil;
|
||||
import io.syng.util.PrefsUtil;
|
||||
import io.syng.util.ProfileManager;
|
||||
|
||||
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
ImageView backgroundImageView = (ImageView) findViewById(R.id.iv_background);
|
||||
Glide.with(this).load(R.drawable.console_bg).into(backgroundImageView);
|
||||
|
||||
if (PrefsUtil.isFirstLaunch()) {
|
||||
createAndSetProfile();
|
||||
} else {
|
||||
startNextActivity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void startNextActivity() {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||
}
|
||||
|
||||
private void createAndSetProfile() {
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(LoginActivity.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)
|
||||
.cancelable(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(LoginActivity.this, "Profile name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(pass1String) || TextUtils.isEmpty(pass2String)) {
|
||||
Toast.makeText(LoginActivity.this, "Password name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pass1.getText().toString().equals(pass2.getText().toString())) {
|
||||
Toast.makeText(LoginActivity.this, "Passwords should be the same!", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Profile profile = new Profile();
|
||||
profile.setName(name.getText().toString());
|
||||
profile.setPassword(pass1String);
|
||||
|
||||
List<String> addresses = new ArrayList<>();
|
||||
byte[] addr = HashUtil.sha3(profile.getName().getBytes());
|
||||
addresses.add(Hex.toHexString(addr));
|
||||
String secret = CONFIG.coinbaseSecret();
|
||||
byte[] cbAddr = HashUtil.sha3(secret.getBytes());
|
||||
addresses.add(Hex.toHexString(cbAddr));
|
||||
profile.setPrivateKeys(addresses);
|
||||
|
||||
ProfileManager.addProfile(profile);
|
||||
ProfileManager.setCurrentProfile(profile);
|
||||
GeneralUtil.hideKeyBoard(name, LoginActivity.this);
|
||||
GeneralUtil.hideKeyBoard(pass1, LoginActivity.this);
|
||||
GeneralUtil.hideKeyBoard(pass2, LoginActivity.this);
|
||||
startNextActivity();
|
||||
// dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative(MaterialDialog dialog) {
|
||||
LoginActivity.this.finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
}).show();
|
||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||
GeneralUtil.showKeyBoard(name, LoginActivity.this);
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +1,36 @@
|
||||
package io.syng.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
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.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.adapter.BackgroundArrayAdapter;
|
||||
import io.syng.entity.Dapp;
|
||||
import io.syng.entity.Profile;
|
||||
|
||||
public final class GeneralUtil {
|
||||
|
||||
@ -58,4 +78,214 @@ public final class GeneralUtil {
|
||||
}).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,10 +1,8 @@
|
||||
package io.syng.util;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -12,8 +10,6 @@ import io.syng.app.SyngApplication;
|
||||
import io.syng.entity.Dapp;
|
||||
import io.syng.entity.Profile;
|
||||
|
||||
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||
|
||||
public final class ProfileManager {
|
||||
|
||||
public interface ProfilesChangeListener {
|
||||
@ -55,22 +51,22 @@ public final class ProfileManager {
|
||||
|
||||
public static Profile getCurrentProfile() {
|
||||
// Add default cow account if not present
|
||||
if (ProfileManager.getProfiles().isEmpty()) {
|
||||
Profile profile = new Profile();
|
||||
profile.setName("Cow");
|
||||
// Add default cow and monkey addresses
|
||||
List<String> addresses = new ArrayList<>();
|
||||
byte[] cowAddr = HashUtil.sha3("cow".getBytes());
|
||||
addresses.add(Hex.toHexString(cowAddr));
|
||||
String secret = CONFIG.coinbaseSecret();
|
||||
byte[] cbAddr = HashUtil.sha3(secret.getBytes());
|
||||
addresses.add(Hex.toHexString(cbAddr));
|
||||
profile.setPrivateKeys(addresses);
|
||||
profile.setPassword("qw");
|
||||
ProfileManager.addProfile(profile);
|
||||
ProfileManager.setCurrentProfile(profile);
|
||||
return profile;
|
||||
}
|
||||
// if (ProfileManager.getProfiles().isEmpty()) {
|
||||
// Profile profile = new Profile();
|
||||
// profile.setName("Cow");
|
||||
// // Add default cow and monkey addresses
|
||||
// List<String> addresses = new ArrayList<>();
|
||||
// byte[] cowAddr = HashUtil.sha3("cow".getBytes());
|
||||
// addresses.add(Hex.toHexString(cowAddr));
|
||||
// String secret = CONFIG.coinbaseSecret();
|
||||
// byte[] cbAddr = HashUtil.sha3(secret.getBytes());
|
||||
// addresses.add(Hex.toHexString(cbAddr));
|
||||
// profile.setPrivateKeys(addresses);
|
||||
// profile.setPassword("qw");
|
||||
// ProfileManager.addProfile(profile);
|
||||
// ProfileManager.setCurrentProfile(profile);
|
||||
// return profile;
|
||||
// }
|
||||
|
||||
List<Profile> profiles = ProfileManager.getProfiles();
|
||||
String currentProfileId = PrefsUtil.getCurrentProfileId();
|
||||
@ -81,6 +77,7 @@ public final class ProfileManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new Profile();
|
||||
}
|
||||
|
||||
@ -115,6 +112,15 @@ public final class ProfileManager {
|
||||
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) {
|
||||
getInstance().mProfilesChangeListener = listener;
|
||||
}
|
||||
@ -128,4 +134,5 @@ public final class ProfileManager {
|
||||
getInstance().mProfilesChangeListener.onProfilesChange();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
6
app/src/main/res/anim/fade_in.xml
Normal file
6
app/src/main/res/anim/fade_in.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fromAlpha="0"
|
||||
android:toAlpha="1"
|
||||
android:duration="@android:integer/config_shortAnimTime"
|
||||
/>
|
6
app/src/main/res/anim/fade_out.xml
Normal file
6
app/src/main/res/anim/fade_out.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fromAlpha="1"
|
||||
android:toAlpha="0"
|
||||
android:duration="@android:integer/config_shortAnimTime"
|
||||
/>
|
14
app/src/main/res/layout/activity_login.xml
Normal file
14
app/src/main/res/layout/activity_login.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<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"
|
||||
android:background="@color/login_background_color"
|
||||
tools:context="io.syng.activity.LoginActivity">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
</FrameLayout>
|
@ -11,4 +11,7 @@
|
||||
<color name="fab_dark_color">#cfcfcf</color>
|
||||
<color name="drawer_icon_color">#737373</color>
|
||||
|
||||
|
||||
<color name="login_background_color">#161b2f</color>
|
||||
|
||||
</resources>
|
@ -37,5 +37,9 @@
|
||||
<string name="dialog.button.cancel">Cancel</string>
|
||||
<string name="menu.profile.key.import">Import</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>
|
||||
|
@ -7,6 +7,11 @@
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppTheme.Login" parent="AppTheme">
|
||||
<item name="android:windowBackground">@color/login_background_color</item>
|
||||
</style>
|
||||
|
||||
<style name="SettingsTheme" parent="Theme.AppCompat.Light">
|
||||
</style>
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/pref_running_mode_light_value"
|
||||
android:entries="@array/pref_running_modes_titles"
|
||||
android:entryValues="@array/pref_running_modes_values"
|
||||
android:key="@string/pref_running_mode_key"
|
||||
|
Loading…
x
Reference in New Issue
Block a user