Skip to content

Commit

Permalink
Merge pull request #198 from xidaokun/dev_v1.3
Browse files Browse the repository at this point in the history
Dev v1.3
  • Loading branch information
li.fayi authored Apr 28, 2019
2 parents 5ac05b3 + 11c2d1d commit 78e4bab
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = 'com.elastos.wallet'
minSdkVersion 23
targetSdkVersion 27
versionCode 27
versionName "1.2.1"
versionCode 42
versionName "1.3.3"
multiDexEnabled true

// Similar to other properties in the defaultConfig block,
Expand Down
114 changes: 114 additions & 0 deletions app/src/main/java/com/breadwallet/cache/UpgradeHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.breadwallet.cache;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import com.breadwallet.tools.sqlite.BRDataSourceInterface;
import com.breadwallet.tools.sqlite.BRSQLiteHelper;
import com.breadwallet.tools.util.BRConstants;

import static com.breadwallet.tools.sqlite.BRSQLiteHelper.ELA_TX_TABLE_NAME;
import static com.platform.sqlite.PlatformSqliteHelper.KV_STORE_TABLE_NAME;

public class UpgradeHandler implements BRDataSourceInterface {

private static Context mContext;

private static UpgradeHandler mInstance;

private static BRSQLiteHelper dbHelper;

private SQLiteDatabase mDatabase;

private UpgradeHandler(Context context){
this.mContext = context;
}


public static UpgradeHandler getInstance(Context context){
if(mInstance == null) mInstance = new UpgradeHandler(context);
dbHelper = BRSQLiteHelper.getInstance(context);
return mInstance;
}

public SQLiteDatabase getWritable() {
// if (mOpenCounter.incrementAndGet() == 1) {
// Opening new database
// if (ActivityUTILS.isMainThread()) throw new NetworkOnMainThreadException();
if (mDatabase == null || !mDatabase.isOpen())
mDatabase = dbHelper.getWritableDatabase();
dbHelper.setWriteAheadLoggingEnabled(BRConstants.WRITE_AHEAD_LOGGING);
// }
// Log.d(TAG, "getWritable open counter: " + String.valueOf(mOpenCounter.get()));
return mDatabase;
}

public synchronized void deleteAllKVs() {
try {
SQLiteDatabase db = getWritable();
db.execSQL("DROP TABLE IF EXISTS " + KV_STORE_TABLE_NAME);
} catch (SQLException e) {
e.printStackTrace();
} finally {
// dbLock.unlock();
}
}

public static final String ELA_TX_TABLE_NAME = "elaTransactionTable";
public static final String ELA_COLUMN_ID = "_id";
public static final String ELA_COLUMN_ISRECEIVED ="isReceived";//0 false,1 true
public static final String ELA_COLUMN_TIMESTAMP ="timeStamp";
public static final String ELA_COLUMN_BLOCKHEIGHT ="blockHeight";
public static final String ELA_COLUMN_HASH ="hash";
public static final String ELA_COLUMN_TXREVERSED ="txReversed";
public static final String ELA_COLUMN_FEE ="fee";
public static final String ELA_COLUMN_TO ="toAddress";
public static final String ELA_COLUMN_FROM ="fromAddress";
public static final String ELA_COLUMN_BALANCEAFTERTX ="balanceAfterTx";
public static final String ELA_COLUMN_TXSIZE ="txSize";
public static final String ELA_COLUMN_AMOUNT ="amount";
public static final String ELA_COLUMN_MENO ="meno";
public static final String ELA_COLUMN_ISVALID ="isValid";
public static final String ELA_COLUMN_ISVOTE ="isVote";

private static final String ELA_TX_DATABASE_CREATE = "create table if not exists " + ELA_TX_TABLE_NAME + " (" +
ELA_COLUMN_ID + " integer, " +
ELA_COLUMN_ISRECEIVED + " integer, " +
ELA_COLUMN_TIMESTAMP + " integer DEFAULT '0' , " +
ELA_COLUMN_BLOCKHEIGHT + " interger, " +
ELA_COLUMN_HASH + " blob, " +
ELA_COLUMN_TXREVERSED+ " text primary key , " +
ELA_COLUMN_FEE + " real, " +
ELA_COLUMN_TO + " text, " +
ELA_COLUMN_FROM + " text, " +
ELA_COLUMN_BALANCEAFTERTX + " integer, " +
ELA_COLUMN_TXSIZE + " integer, " +
ELA_COLUMN_AMOUNT + " real, " +
ELA_COLUMN_MENO + " text, " +
ELA_COLUMN_ISVALID + " interger, " +
ELA_COLUMN_ISVOTE +" integer);";

public void deleteAllTransactions() {
try {
mDatabase = openDatabase();
// mDatabase.delete(ELA_TX_TABLE_NAME, null, null);
mDatabase.execSQL("DROP TABLE IF EXISTS " + ELA_TX_TABLE_NAME);
mDatabase.execSQL(ELA_TX_DATABASE_CREATE);
} finally {
closeDatabase();
}
}

@Override
public SQLiteDatabase openDatabase() {
if (mDatabase == null || !mDatabase.isOpen())
mDatabase = dbHelper.getWritableDatabase();
dbHelper.setWriteAheadLoggingEnabled(BRConstants.WRITE_AHEAD_LOGGING);
return mDatabase;
}

@Override
public void closeDatabase() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.SslErrorHandler;
Expand Down Expand Up @@ -201,6 +202,19 @@ public void onReceivedError(WebView view, WebResourceRequest request, WebResourc
});
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
WebBackForwardList mWebBackForwardList = webView.copyBackForwardList();
int account = mWebBackForwardList.getCurrentIndex();
if(account > 0){
webView.goBack();
return false;
}
}
return super.onKeyDown(keyCode, event);
}

private synchronized void loadUrl(String url){
Log.i("schemeLoadurl", "url:"+url);
if(StringUtil.isNullOrEmpty(url)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public void onClick(View v) {

BigDecimal balance = BRSharedPrefs.getCachedBalance(getContext(), "ELA");
String candidatesStr = BRSharedPrefs.getCandidate(getContext());
String iso = BRSharedPrefs.getCurrentWalletIso(getContext());
if(StringUtil.isNullOrEmpty(iso) || !iso.equalsIgnoreCase("ELA")){
mAutoVoteCb.setVisibility(View.GONE);
}
if(balance.longValue()<1 || StringUtil.isNullOrEmpty(candidatesStr)){
mAutoVoteCb.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static BRSQLiteHelper getInstance(Context context) {
}

public static final String DATABASE_NAME = "breadwallet.db";
private static final int DATABASE_VERSION = 16;
private static final int DATABASE_VERSION = 17;

/**
* DID author table
Expand Down Expand Up @@ -218,7 +218,11 @@ public void onCreate(SQLiteDatabase database) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

db.execSQL("DROP TABLE IF EXISTS " + ELA_TX_TABLE_NAME);
if((newVersion!=oldVersion) && newVersion==17) {
db.execSQL("DROP TABLE IF EXISTS " + ELA_TX_TABLE_NAME);
db.execSQL(ELA_TX_DATABASE_CREATE);
}

if (/*oldVersion < 13 && (newVersion >= 13)*/ newVersion==16) {
boolean migrationNeeded = !tableExists(MB_TABLE_NAME, db);
onCreate(db); //create new db tables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,7 @@ public synchronized String sendElaRawTx(final String transaction){
JSONObject jsonObject = new JSONObject(tmp);
result = jsonObject.getString("result");
if(result==null || result.contains("ERROR") || result.contains(" ")) {
if(result.contains("Duplicate")) {
toast(mActivity.getString(R.string.double_spend));
}
if(mActivity!=null) toast(mActivity.getString(R.string.double_spend));
// toast(result);
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_send.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
android:layout_marginStart="16dp"
android:background="@android:color/transparent"
android:cursorVisible="false"
android:maxLength="50"
android:maxLength="256"
android:hint="@string/Send.descriptionLabel"/>

<View
Expand Down

0 comments on commit 78e4bab

Please sign in to comment.