Skip to content

Commit

Permalink
1. use google live data, room and mvvm architecture
Browse files Browse the repository at this point in the history
2. add some features and fix bugs
  • Loading branch information
lorne committed Nov 3, 2017
1 parent f35c1ad commit 926c5cf
Show file tree
Hide file tree
Showing 111 changed files with 5,877 additions and 1,436 deletions.
65 changes: 49 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,55 @@ apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
google()
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.bitshares.bitshareswallet"
minSdkVersion 15
targetSdkVersion 25
versionCode 10000021
versionName "1.0.0.21"
versionCode 10201001
versionName "1.2.1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":
"$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled true
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
versionNameSuffix '-DEBUG'
}
}

configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}

lintOptions {
disable 'MissingTranslation'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
Expand Down Expand Up @@ -72,28 +94,39 @@ dependencies {
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:preference-v7:25.3.1'
compile 'com.android.support:preference-v14:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:preference-v7:26.1.0'
compile 'com.android.support:preference-v14:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.google.guava:guava:23.0-android'
compile 'com.madgag.spongycastle:core:1.51.0.0'
compile 'com.madgag.spongycastle:prov:1.51.0.0'
compile 'com.madgag.spongycastle:core:1.56.0.0'
compile 'com.madgag.spongycastle:prov:1.56.0.0'
compile 'com.madgag.spongycastle:pkix:1.51.0.0'
compile 'com.madgag.spongycastle:pg:1.51.0.0'
compile 'org.slf4j:slf4j-android:1.7.25'
compile 'com.google.protobuf:protobuf-java:3.4.0'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.okhttp3:okhttp:3.9.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.1'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.kaopiz:kprogresshud:1.0.2'
compile 'com.google.firebase:firebase-perf:11.0.2'
compile 'com.google.firebase:firebase-core:11.0.2'
compile 'com.wang.avi:library:2.1.3'
compile 'com.google.firebase:firebase-core:11.4.2'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'android.arch.persistence.room:runtime:1.0.0-rc1'
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-rc1"
implementation 'android.arch.lifecycle:extensions:1.0.0-rc1'
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-rc1"
testCompile 'junit:junit:4.12'
compile project(':graphenej:graphenej')
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation project(':graphenej:graphenej')
}

apply plugin: 'com.google.gms.google-services'
24 changes: 14 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,31 @@
android:theme="@style/ActivityTheme" />
<activity
android:name=".SignUpActivity"
android:theme="@style/ActivityTheme"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:theme="@style/ActivityTheme" />
<activity
android:name=".ImportActivty"
android:theme="@style/ActivityTheme"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:theme="@style/ActivityTheme" />
<activity
android:name=".ModelSelectActivity"
android:theme="@style/ActivityTheme"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:theme="@style/ActivityTheme" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="1516f2abc1f71a4a06a0b84c26caaa01398302fb" />

<activity android:name=".SettingsActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".SettingsActivity"
android:screenOrientation="portrait" />
<activity
android:name=".AboutActivity"
android:theme="@style/ActivityTheme"
android:screenOrientation="portrait"></activity>
android:screenOrientation="portrait"
android:theme="@style/ActivityTheme" />
<activity android:name=".CreateAccountActivity"
android:screenOrientation="portrait"
android:theme="@style/ActivityTheme" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bitshares.bitshareswallet;

import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -11,6 +12,8 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.bitshares.bitshareswallet.room.BitsharesBalanceAsset;
import com.bitshares.bitshareswallet.viewmodel.WalletViewModel;
import com.bitshares.bitshareswallet.wallet.BitshareData;
import com.bitshares.bitshareswallet.wallet.BitsharesWalletWraper;
import com.bitshares.bitshareswallet.wallet.asset;
Expand Down Expand Up @@ -65,66 +68,46 @@ public BalanceItemViewHolder(View itemView) {
}

class BalancesAdapter extends RecyclerView.Adapter<BalanceItemViewHolder> {
private BitshareData mBitsharesData;
private Map<object_id<asset_object>, asset_object> mMapId2AssetObject;
private List<asset> mListAsset = new ArrayList<>();
private asset_object mAssetObjectBase;
private final LayoutInflater mLayoutInflater;
public BalancesAdapter(Context context) {
mLayoutInflater = LayoutInflater.from(context);
}
private List<BitsharesBalanceAsset> bitsharesBalanceAssetList;

@Override
public BalanceItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mLayoutInflater.inflate(R.layout.recyclerview_item_balances, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item_balances, parent, false);
return new BalanceItemViewHolder(view);
}

@Override
public void onBindViewHolder(BalanceItemViewHolder holder, int position) {
asset assetBalance = mListAsset.get(position);
asset_object assetObject = mMapId2AssetObject.get(assetBalance.asset_id);

asset_object.asset_object_legible assetObjectLegible = assetObject.get_legible_asset_object(assetBalance.amount);
double fResult = (double)assetObjectLegible.lDecimal / assetObjectLegible.scaled_precision + assetObjectLegible.lCount;

BitsharesBalanceAsset bitsharesBalanceAsset = bitsharesBalanceAssetList.get(position);
String strBalances = String.format(
Locale.ENGLISH,
"%.4f",
fResult
(float)bitsharesBalanceAsset.amount / bitsharesBalanceAsset.quote_precision
);

holder.viewNumber.setText(strBalances);
holder.viewUnit.setText(assetObjectLegible.symbol);
if (assetObject.is_base_asset_object() == false) {
asset assetAmount = mBitsharesData.convert_asset_to_base(assetBalance, mAssetObjectBase);
//long lBaseAmount = assetObject.convert_exchange_to_base(assetBalance.amount);

assetObjectLegible = mAssetObjectBase.get_legible_asset_object(assetAmount.amount);
fResult = (double)assetObjectLegible.lDecimal / assetObjectLegible.scaled_precision + assetObjectLegible.lCount;
int nResult = (int)Math.rint(fResult);
holder.viewUnit.setText(bitsharesBalanceAsset.quote);
if (bitsharesBalanceAsset.quote.compareTo("BTS") != 0) {
int nResult = (int)Math.rint(bitsharesBalanceAsset.total / bitsharesBalanceAsset.base_precision);

holder.viewEqual.setText("=");
holder.viewConvertNumber.setText(Integer.valueOf(nResult).toString());
holder.viewConvertUnit.setText(assetObjectLegible.symbol);
holder.viewConvertUnit.setText("BTS");
}

}

@Override
public int getItemCount() {
if (mListAsset == null) {
if (bitsharesBalanceAssetList == null) {
return 0;
} else {
return mListAsset.size();
return bitsharesBalanceAssetList.size();
}
}

public void notifyBalancesDataChanged(BitshareData bitshareData) {
mBitsharesData = bitshareData;
mListAsset = bitshareData.listBalances;
mMapId2AssetObject = bitshareData.mapId2AssetObject;
mAssetObjectBase = mMapId2AssetObject.get(new object_id<asset_object>(0, asset_object.class));
public void notifyBalancesDataChanged(List<BitsharesBalanceAsset> bitsharesBalanceAssetList) {
this.bitsharesBalanceAssetList = bitsharesBalanceAssetList;

notifyDataSetChanged();
}
Expand Down Expand Up @@ -164,11 +147,20 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onShow() {
super.onShow();
BitshareData bitshareData = BitsharesWalletWraper.getInstance().getBitshareData();

if (bitshareData != null) {
mBalancesAdapter.notifyBalancesDataChanged(bitshareData);
}
WalletViewModel walletViewModel = ViewModelProviders.of(getActivity()).get(WalletViewModel.class);
walletViewModel.getBalanceData().observe(
this, resourceBalanceList -> {
switch (resourceBalanceList.status) {
case SUCCESS:
mBalancesAdapter.notifyBalancesDataChanged(resourceBalanceList.data);
break;
case LOADING:
if (resourceBalanceList.data != null) {
mBalancesAdapter.notifyBalancesDataChanged(resourceBalanceList.data);
}
break;
}
});
}

@Override
Expand All @@ -178,7 +170,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
View view = inflater.inflate(R.layout.fragment_balances, container, false);
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mBalancesAdapter = new BalancesAdapter(getActivity());
mBalancesAdapter = new BalancesAdapter();
recyclerView.setAdapter(mBalancesAdapter);

return view;
Expand Down Expand Up @@ -225,9 +217,6 @@ public interface OnFragmentInteractionListener {

@Override
public void notifyUpdate() {
BitshareData bitshareData = BitsharesWalletWraper.getInstance().getBitshareData();
if (bitshareData != null && mBalancesAdapter != null) {
mBalancesAdapter.notifyBalancesDataChanged(bitshareData);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.bitshares.bitshareswallet;

import android.app.Application;
import android.arch.persistence.room.Room;
import android.support.multidex.MultiDexApplication;

import com.bitshares.bitshareswallet.room.BitsharesDatabase;
import com.crashlytics.android.Crashlytics;

import org.spongycastle.jce.provider.BouncyCastleProvider;
Expand All @@ -14,6 +15,7 @@

public class BitsharesApplication extends MultiDexApplication {
private static BitsharesApplication theApp;
private BitsharesDatabase bitsharesDatabase;
/*
* 是否需要把涨跌的颜色互换
*/
Expand All @@ -25,10 +27,22 @@ public BitsharesApplication() {
theApp = this;
}

public BitsharesDatabase getBitsharesDatabase() {
return bitsharesDatabase;
}

@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
Security.insertProviderAt(new BouncyCastleProvider(), 1);

bitsharesDatabase = Room.databaseBuilder(
this,
BitsharesDatabase.class,
"bitshares.db"
).build();

// 注册回调,保证数据更新
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.view.View;
import android.widget.TextView;


public class ConfirmOrderDialog {
private Activity mActivity;
private AlertDialog.Builder mDialogBuilder;
Expand Down Expand Up @@ -131,14 +130,14 @@ public ConfirmOrderDialog(Activity mActivity, ConfirmOrderData confirmOrderData)
TextView txtSrcCoin = (TextView)view.findViewById(R.id.dco_txt_src_coin);
txtSrcCoin.setText(confirmOrderData.getTotal());

TextView txtSrcCoinName = (TextView)view.findViewById(R.id.dco_txt_src_coin_name);
txtSrcCoinName.setText(confirmOrderData.getTotalType() + ":");
//TextView txtSrcCoinName = (TextView)view.findViewById(R.id.dco_txt_src_coin_name);
//txtSrcCoinName.setText(confirmOrderData.getTotalType() + ":");

TextView txtTargetCoin = (TextView)view.findViewById(R.id.dco_txt_target_coin);
txtTargetCoin.setText(confirmOrderData.getQuantity());

TextView txtTargetCoinName = (TextView)view.findViewById(R.id.dco_txt_target_coin_name);
txtTargetCoinName.setText(confirmOrderData.getQuantityType() + ":");
//TextView txtTargetCoinName = (TextView)view.findViewById(R.id.dco_txt_target_coin_name);
//txtTargetCoinName.setText(confirmOrderData.getQuantityType() + ":");

TextView txtExpiration = (TextView)view.findViewById(R.id.dco_txt_expiration);
txtExpiration.setText(confirmOrderData.getTimeExpiration());
Expand Down
Loading

0 comments on commit 926c5cf

Please sign in to comment.