Skip to content

Commit

Permalink
v1.1.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Dryec committed Oct 19, 2018
1 parent d525cda commit ba6fe0c
Show file tree
Hide file tree
Showing 27 changed files with 1,204 additions and 195 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 27
defaultConfig {
versionCode 38
versionName "1.1.8.1"
versionCode 47
versionName "1.1.9.4"
applicationId "com.eletac.tronwallet"
minSdkVersion 21
targetSdkVersion 27
Expand Down Expand Up @@ -54,6 +54,7 @@ dependencies {
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.google.firebase:firebase-core:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down Expand Up @@ -88,3 +89,5 @@ dependencies {
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
implementation 'com.facebook.stetho:stetho:1.5.0'
}

apply plugin: 'com.google.gms.google-services'
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":38,"versionName":"1.1.8.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":47,"versionName":"1.1.9.4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
34 changes: 34 additions & 0 deletions app/src/main/java/com/eletac/tronwallet/TronWalletApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@
import android.arch.persistence.room.Room;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.arch.lifecycle.ProcessLifecycleOwner;

import com.eletac.tronwallet.block_explorer.BlockExplorerUpdater;
import com.eletac.tronwallet.database.Transaction;
import com.eletac.tronwallet.database.TronWalletDatabase;
import com.eletac.tronwallet.wallet.AccountUpdater;
import com.eletac.tronwallet.wallet.PriceUpdater;
import com.facebook.stetho.Stetho;
import com.google.firebase.analytics.FirebaseAnalytics;

import org.spongycastle.util.encoders.Hex;
import org.tron.common.crypto.Hash;
import org.tron.protos.Protocol;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TronWalletApplication extends Application implements LifecycleObserver{
Expand All @@ -35,6 +45,7 @@ public class TronWalletApplication extends Application implements LifecycleObse
public static final long ACCOUNT_UPDATE_BACKGROUND_INTERVAL = 15000;
public static final long PRICE_UPDATE_INTERVAL = 15000;

private FirebaseAnalytics mFirebaseAnalytics;
private static Context mContext;
private static TronWalletDatabase mDatabase;
private static boolean mIsInForeground;
Expand All @@ -43,6 +54,10 @@ public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);

mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.APP_OPEN, new Bundle());

mContext = getApplicationContext();
mDatabase = Room.databaseBuilder(mContext, TronWalletDatabase.class, DATABASE_FILE_NAME)
.addMigrations(TronWalletDatabase.MIGRATION_1_2)
Expand All @@ -61,6 +76,25 @@ public void onCreate() {

AccountUpdater.init(this, ACCOUNT_UPDATE_FOREGROUND_INTERVAL);
PriceUpdater.init(this, PRICE_UPDATE_INTERVAL);

SharedPreferences sharedPreferences = getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);

if(sharedPreferences.getBoolean("logged_previous_transactions", false))
{
SharedPreferences.Editor editor = sharedPreferences.edit();

List<Transaction> dbTransactions = TronWalletApplication.getDatabase().transactionDao().getAllTransactions();

for(Transaction dbTransaction : dbTransactions) {
Bundle bundle = new Bundle();
bundle.putString("sender_address", dbTransaction.senderAddress);
bundle.putString("hash", Hex.toHexString(Hash.sha256(dbTransaction.transaction.getRawData().toByteArray())));
bundle.putString("contract", Utils.getContractName(dbTransaction.transaction.getRawData().getContract(0)));

mFirebaseAnalytics.logEvent("sent_transaction", bundle);
}
editor.putBoolean("logged_previous_transactions", true);
}
}

public static Context getAppContext() {
Expand Down
71 changes: 71 additions & 0 deletions app/src/main/java/com/eletac/tronwallet/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ public static void saveAccountNet(Context context, String walletName, GrpcAPI.Ac
}
}

public static void saveAccountRes(Context context, String walletName, GrpcAPI.AccountResourceMessage accountRes) {
if (context != null && accountRes != null && WalletManager.existWallet(walletName)) {
SharedPreferences sharedPreferences = context.getSharedPreferences(walletName, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putLong(context.getString(R.string.energy_limit_key), accountRes.getEnergyLimit());
editor.putLong(context.getString(R.string.energy_used_key), accountRes.getEnergyUsed());

editor.apply();
}
}

public static GrpcAPI.AccountResourceMessage getAccountRes(Context context, String walletName) {
if(context != null && WalletManager.existWallet(walletName)) {
SharedPreferences sharedPreferences = context.getSharedPreferences(walletName, Context.MODE_PRIVATE);

GrpcAPI.AccountResourceMessage.Builder accountResMessage = GrpcAPI.AccountResourceMessage.newBuilder();

accountResMessage.setEnergyLimit(sharedPreferences.getLong(context.getString(R.string.energy_limit_key), 0));
accountResMessage.setEnergyUsed(sharedPreferences.getLong(context.getString(R.string.energy_used_key), 0));

return accountResMessage.build();
}
return GrpcAPI.AccountResourceMessage.getDefaultInstance();
}


public static GrpcAPI.AccountNetMessage getAccountNet(Context context, String walletName) {
if(context != null && WalletManager.existWallet(walletName)) {
SharedPreferences sharedPreferences = context.getSharedPreferences(walletName, Context.MODE_PRIVATE);
Expand Down Expand Up @@ -192,4 +219,48 @@ public static double round(double value, int places, RoundingMode mode) {
bd = bd.setScale(places, mode);
return bd.doubleValue();
}


public static String getContractName(Protocol.Transaction.Contract contract) {
if(contract == null)
return "";

switch (contract.getType()) {
case AccountCreateContract:
return "AccountCreateContract";
case TransferContract:
return "TransferContract";
case TransferAssetContract:
return "TransferAssetContract";
case VoteAssetContract:
return "VoteAssetContract";
case VoteWitnessContract:
return "VoteWitnessContract";
case WitnessCreateContract:
return "WitnessCreateContract";
case AssetIssueContract:
return "AssetIssueContract";
case WitnessUpdateContract:
return "WitnessUpdateContract";
case ParticipateAssetIssueContract:
return "ParticipateAssetIssueContract";
case AccountUpdateContract:
return "AccountUpdateContract";
case FreezeBalanceContract:
return "FreezeBalanceContract";
case UnfreezeBalanceContract:
return "UnfreezeBalanceContract";
case WithdrawBalanceContract:
return "WithdrawBalanceContract";
case UnfreezeAssetContract:
return "UnfreezeAssetContract";
case UpdateAssetContract:
return "UpdateAssetContract";
case CustomContract:
return "CustomContract";
case UNRECOGNIZED:
return "UNRECOGNIZED";
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public enum UpdateTask {

private static ExecutorService mExecutorService;

private static List<Protocol.Block> mBlocks;
private static List<Protocol.Transaction> mTransactions;
private static List<GrpcAPI.BlockExtention> mBlocks;
private static List<GrpcAPI.TransactionExtention> mTransactions;
private static List<Protocol.Witness> mWitnesses;
private static List<GrpcAPI.Node> mNodes;
private static List<Contract.AssetIssueContract> mTokens;
Expand Down Expand Up @@ -159,20 +159,20 @@ public void doOnBackground() {
while(!gotSomeBlocks && blockCount > 0) {
// Load Blocks and transactions
try {
GrpcAPI.BlockList result = WalletManager.getBlockByLatestNum(blockCount);
GrpcAPI.BlockListExtention result = WalletManager.getBlockByLatestNum(blockCount);
if (result != null) {
mBlocks.clear();
mBlocks.addAll(result.getBlockList());
Collections.sort(mBlocks, new Comparator<Protocol.Block>() {
Collections.sort(mBlocks, new Comparator<GrpcAPI.BlockExtention>() {
@Override
public int compare(Protocol.Block o1, Protocol.Block o2) {
public int compare(GrpcAPI.BlockExtention o1, GrpcAPI.BlockExtention o2) {
return Long.compare(o1.getBlockHeader().getRawData().getNumber(), o2.getBlockHeader().getRawData().getNumber());
}
});
}

mTransactions.clear();
for (Protocol.Block block : mBlocks) {
for (GrpcAPI.BlockExtention block : mBlocks) {
/*for (Protocol.Transaction transaction : block.getTransactionsList()) {
Protocol.Transaction.Builder builder = transaction.toBuilder();
Protocol.Transaction.raw.Builder rawBuilder = transaction.getRawData().toBuilder();
Expand Down Expand Up @@ -312,7 +312,19 @@ public void doOnBackground() {
GrpcAPI.AssetIssueList result = WalletManager.getAssetIssueList(false);
if(result != null) {
mTokens.clear();
mTokens.addAll(result.getAssetIssueList());

for (Contract.AssetIssueContract token : result.getAssetIssueList())
{
if(!(token.getName().toStringUtf8().equals("TronWatchmarket") ||
token.getName().toStringUtf8().equals("TWM") ||
token.getName().toStringUtf8().equals("TronWatch")||
token.getName().toStringUtf8().equals("Tronwatchmarket")))
{
mTokens.add(token);
}
}

//mTokens.addAll(result.getAssetIssueList());
Collections.sort(mTokens, new Comparator<Contract.AssetIssueContract>() {
@Override
public int compare(Contract.AssetIssueContract o1, Contract.AssetIssueContract o2) {
Expand Down Expand Up @@ -385,11 +397,11 @@ public void doInUIThread() {
}
}

public static List<Protocol.Block> getBlocks() {
public static List<GrpcAPI.BlockExtention> getBlocks() {
return mBlocks;
}

public static List<Protocol.Transaction> getTransactions() {
public static List<GrpcAPI.TransactionExtention> getTransactions() {
return mTransactions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.eletac.tronwallet.R;

import org.tron.api.GrpcAPI;
import org.tron.protos.Protocol;
import org.tron.walletserver.WalletManager;

Expand All @@ -21,7 +22,7 @@
public class BlockItemListAdapter extends RecyclerView.Adapter<BlockItemListAdapter.BlockItemViewHolder> {

private Context mContext;
private List<Protocol.Block> mBlocks;
private List<GrpcAPI.BlockExtention> mBlocks;
private Handler mUpdateElapsedTimeHandler;
private List<BlockItemViewHolder> mViewHolders;
private Runnable mUpdateElapsedTimeRunnable = new Runnable() {
Expand All @@ -43,7 +44,7 @@ public void run() {
}
};

public BlockItemListAdapter(Context context, List<Protocol.Block> blocks) {
public BlockItemListAdapter(Context context, List<GrpcAPI.BlockExtention> blocks) {
mContext = context;
mBlocks = blocks;
mViewHolders = new ArrayList<>();
Expand Down Expand Up @@ -85,7 +86,7 @@ public class BlockItemViewHolder extends RecyclerView.ViewHolder {
private TextView mBlockTransactionsAmount_TextView;
private TextView mBlockProducerAddress_TextView;

private Protocol.Block mBlock;
private GrpcAPI.BlockExtention mBlock;

public BlockItemViewHolder(View itemView) {
super(itemView);
Expand All @@ -97,7 +98,7 @@ public BlockItemViewHolder(View itemView) {
mBlockProducerAddress_TextView = itemView.findViewById(R.id.Block_producer_address_textView);
}

public void bind(Protocol.Block block) {
public void bind(GrpcAPI.BlockExtention block) {
mBlock = block;

String blockNumberStr = "#"+String.valueOf(block.getBlockHeader().getRawData().getNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.eletac.tronwallet.Utils;
import com.eletac.tronwallet.WrapContentLinearLayoutManager;

import org.tron.api.GrpcAPI;
import org.tron.protos.Protocol;
import org.w3c.dom.Text;

Expand All @@ -45,7 +46,7 @@ public class RecentBlocksFragment extends Fragment implements SwipeRefreshLayout

private BlocksUpdatedBroadcastReceiver mBlocksUpdatedBroadcastReceiver;

private List<Protocol.Block> mBlocks;
private List<GrpcAPI.BlockExtention> mBlocks;

public RecentBlocksFragment() {
// Required empty public constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.eletac.tronwallet.R;
import com.eletac.tronwallet.WrapContentLinearLayoutManager;

import org.tron.api.GrpcAPI;
import org.tron.protos.Protocol;

import java.util.ArrayList;
Expand All @@ -36,7 +37,7 @@ public class RecentTransactionsFragment extends Fragment {
private TransactionItemListAdapter mTransactionsItemListAdapter;

private TransactionsUpdatedBroadcastReceiver mTransactionsUpdatedBroadcastReceiver;
private List<Protocol.Transaction> mTransactions;
private List<GrpcAPI.TransactionExtention> mTransactions;

public RecentTransactionsFragment() {
// Required empty public constructor
Expand Down
Loading

0 comments on commit ba6fe0c

Please sign in to comment.