Skip to content

Commit

Permalink
1. fix some bugs
Browse files Browse the repository at this point in the history
2. adjust the structure
  • Loading branch information
lorne committed Nov 3, 2017
1 parent 926c5cf commit bb1da5c
Show file tree
Hide file tree
Showing 24 changed files with 541 additions and 586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@

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;
import com.bitshares.bitshareswallet.wallet.graphene.chain.asset_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.object_id;

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


/**
Expand Down Expand Up @@ -145,8 +138,9 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public void onShow() {
super.onShow();
public void onResume() {
super.onResume();

WalletViewModel walletViewModel = ViewModelProviders.of(getActivity()).get(WalletViewModel.class);
walletViewModel.getBalanceData().observe(
this, resourceBalanceList -> {
Expand All @@ -163,6 +157,11 @@ public void onShow() {
});
}

@Override
public void onShow() {
super.onShow();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down
30 changes: 21 additions & 9 deletions app/src/main/java/com/bitshares/bitshareswallet/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.ListPreferenceDialogFragmentCompat;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.widget.Toolbar;
import android.util.Pair;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
Expand All @@ -47,6 +38,9 @@
import android.widget.TextView;
import android.widget.Toast;

import com.bitshares.bitshareswallet.room.BitsharesAsset;
import com.bitshares.bitshareswallet.room.BitsharesDao;
import com.bitshares.bitshareswallet.room.BitsharesOperationHistory;
import com.bitshares.bitshareswallet.viewmodel.QuotationViewModel;
import com.bitshares.bitshareswallet.viewmodel.WalletViewModel;
import com.bitshares.bitshareswallet.wallet.BitsharesWalletWraper;
Expand All @@ -55,6 +49,11 @@
import com.bitshares.bitshareswallet.wallet.fc.crypto.sha256_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.signed_transaction;
import com.bitshares.bitshareswallet.wallet.graphene.chain.utils;
import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.schedulers.Schedulers;



public class MainActivity extends AppCompatActivity
Expand All @@ -78,6 +77,7 @@ public class MainActivity extends AppCompatActivity
private TextView mTxtTitle;
private LinearLayout mLayoutTitle;
private BottomNavigationView mBottomNavigation;
private Handler mHandler = new Handler();

private static final int REQUEST_CODE_SETTINGS = 1;

Expand Down Expand Up @@ -344,6 +344,18 @@ private void processLogout() {
builder.setPositiveButton(R.string.log_out_dialog_confirm_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Flowable.just(0)
.subscribeOn(Schedulers.io())
.map(integer -> {
BitsharesDao bitsharesDao = BitsharesApplication.getInstance().getBitsharesDatabase().getBitsharesDao();;
List<BitsharesAsset> bitsharesAssetList = bitsharesDao.queryBalanceList();
List<BitsharesOperationHistory> bitsharesOperationHistoryList = bitsharesDao.queryOperationHistoryList();
bitsharesDao.deleteBalance(bitsharesAssetList);
bitsharesDao.deleteOperationHistory(bitsharesOperationHistoryList);

return 0;
}).subscribe();

BitsharesWalletWraper.getInstance().reset();
Intent intent = new Intent(MainActivity.this, SignUpButtonActivity.class);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.RecyclerView;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bitshares.bitshareswallet.market.MarketTicker;
import com.bitshares.bitshareswallet.room.BitsharesMarketTicker;
import com.bitshares.bitshareswallet.wallet.BitshareData;
import com.bitshares.bitshareswallet.wallet.BitsharesWalletWraper;
import com.bitshares.bitshareswallet.wallet.graphene.chain.asset_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.bucket_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.object_id;
import com.bitshares.bitshareswallet.wallet.graphene.chain.utils;

import java.text.DecimalFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.bitshares.bitshareswallet.market.MarketStat;
import com.bitshares.bitshareswallet.data.HistoryPrice;
import com.bitshares.bitshareswallet.market.MarketTicker;
import com.bitshares.bitshareswallet.viewmodel.QuotationViewModel;
import com.github.mikephil.charting.charts.CandleStickChart;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void onValueSelected(Entry e, Highlight h) {
TextView textViewLow = (TextView) mviewLayoutSelected.findViewById(R.id.textViewLow);
TextView textViewChange = (TextView) mviewLayoutSelected.findViewById(R.id.textViewChange);

MarketStat.HistoryPrice historyPrice = (MarketStat.HistoryPrice) candleEntry.getData();
HistoryPrice historyPrice = (HistoryPrice) candleEntry.getData();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd HH:mm");
textViewDate.setText(simpleDateFormat.format(historyPrice.date));

Expand Down Expand Up @@ -277,11 +276,11 @@ public void onHide() {
super.onHide();
}

private void updateChartData(List<MarketStat.HistoryPrice> historyPriceList) {
private void updateChartData(List<HistoryPrice> historyPriceList) {
class xAxisValueFormater implements IAxisValueFormatter {
private List<MarketStat.HistoryPrice> mListPrices;
private List<HistoryPrice> mListPrices;

public xAxisValueFormater(List<MarketStat.HistoryPrice> listPrices) {
public xAxisValueFormater(List<HistoryPrice> listPrices) {
mListPrices = listPrices;
}
@Override
Expand All @@ -303,12 +302,12 @@ public String getFormattedValue(float value, AxisBase axis) {
mChart.getXAxis().setValueFormatter(xvalueFormater);
}

private void initializeData(List<MarketStat.HistoryPrice> listHistoryPrice) {
private void initializeData(List<HistoryPrice> listHistoryPrice) {
mviewLayoutSelected.setVisibility(View.INVISIBLE);
List<CandleEntry> candleEntryList = new ArrayList<>();
List<BarEntry> barEntryList = new ArrayList<>();
int i = 0;
for (MarketStat.HistoryPrice price : listHistoryPrice) {
for (HistoryPrice price : listHistoryPrice) {
int nPosition = i++;
CandleEntry candleEntry = new CandleEntry(nPosition, (float)price.high, (float)price.low, (float)price.open, (float)price.close, price);
candleEntryList.add(candleEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
import com.bitshares.bitshareswallet.room.BitsharesAssetObject;
import com.bitshares.bitshareswallet.room.BitsharesBalanceAsset;
import com.bitshares.bitshareswallet.viewmodel.SendViewModel;
import com.bitshares.bitshareswallet.wallet.BitshareData;
import com.bitshares.bitshareswallet.wallet.BitsharesWalletWraper;
import com.bitshares.bitshareswallet.wallet.account_object;
import com.bitshares.bitshareswallet.wallet.asset;
import com.bitshares.bitshareswallet.wallet.common.ErrorCode;
import com.bitshares.bitshareswallet.wallet.exception.ErrorCodeException;
import com.bitshares.bitshareswallet.wallet.exception.NetworkStatusException;
import com.bitshares.bitshareswallet.wallet.fc.crypto.sha256_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.asset_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.signed_transaction;
import com.bituniverse.utils.NumericUtil;
import com.kaopiz.kprogresshud.KProgressHUD;
Expand All @@ -48,7 +46,6 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Flowable;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.schedulers.Schedulers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.PreferenceManager;
Expand All @@ -26,23 +25,21 @@
import android.widget.Toast;

import com.bitshares.bitshareswallet.market.MarketStat;
import com.bitshares.bitshareswallet.room.BitsharesAsset;
import com.bitshares.bitshareswallet.viewmodel.SellBuyViewModel;
import com.bitshares.bitshareswallet.wallet.BitshareData;
import com.bitshares.bitshareswallet.wallet.BitsharesWalletWraper;
import com.bitshares.bitshareswallet.wallet.Broadcast;
import com.bitshares.bitshareswallet.wallet.asset;
import com.bitshares.bitshareswallet.wallet.graphene.chain.asset_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.global_property_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.object_id;
import com.bitshares.bitshareswallet.wallet.graphene.chain.utils;
import com.bituniverse.network.Status;
import com.bituniverse.utils.NumericUtil;
import com.kaopiz.kprogresshud.KProgressHUD;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;


Expand Down Expand Up @@ -195,12 +192,15 @@ public void onShow() {
viewModel.changeBalanceAsset(quoteAsset);
}

viewModel.getAvaliableBalance().observe(this, bitsharesAsset -> {
if (bitsharesAsset != null) {
DecimalFormat decimalFormat = new DecimalFormat("#.####");
balanceText.setText(decimalFormat.format((double) bitsharesAsset.amount / bitsharesAsset.precision));
} else {
balanceText.setText("0");
viewModel.getAvaliableBalance().observe(this, bitsharesAssetResource -> {
if (bitsharesAssetResource.status == Status.SUCCESS) {
BitsharesAsset bitsharesAsset = bitsharesAssetResource.data;
if (bitsharesAsset != null) {
DecimalFormat decimalFormat = new DecimalFormat("#.####");
balanceText.setText(decimalFormat.format((double) bitsharesAsset.amount / bitsharesAsset.precision));
} else {
balanceText.setText("0");
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
Expand All @@ -21,9 +20,6 @@

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.graphene.chain.signed_transaction;

import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -105,8 +101,8 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public void onShow() {
super.onShow();
public void onResume() {
super.onResume();

WalletViewModel walletViewModel = ViewModelProviders.of(getActivity()).get(WalletViewModel.class);
walletViewModel.getBalanceData().observe(
Expand All @@ -127,6 +123,11 @@ public void onShow() {
});
}

@Override
public void onShow() {
super.onShow();
}

@Override
public void onHide() {
super.onHide();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bitshares.bitshareswallet.data;

import java.util.Date;

/**
* Created by lorne on 03/11/2017.
*/
public class HistoryPrice {
public double high;
public double low;
public double open;
public double close;
public double volume;
public Date date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.bitshares.bitshareswallet.livedata;

import android.arch.lifecycle.LiveData;
import android.util.Pair;

import com.bitshares.bitshareswallet.wallet.BitsharesWalletWraper;
import com.bitshares.bitshareswallet.wallet.graphene.chain.asset_object;
import com.bitshares.bitshareswallet.wallet.graphene.chain.object_id;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Created by lorne on 03/11/2017.
*/

public class MarketChangeLiveData extends LiveData<List<Pair<object_id<asset_object>, object_id<asset_object>>>> {
private BitsharesWalletWraper.BitsharesDataObserver bitsharesDataObserver = new BitsharesWalletWraper.BitsharesDataObserver() {
@Override
public void onDisconnect() {
}

@Override
public void onMarketFillUpdate(object_id<asset_object> base, object_id<asset_object> quote) {
postValue(Collections.singletonList(new Pair<>(base, quote)));
}

@Override
public void onAccountChanged() {

}
};

public MarketChangeLiveData() {
setValue(new ArrayList<>());
}

@Override
protected void onInactive() {
super.onInactive();
BitsharesWalletWraper.getInstance().unregisterDataObserver(bitsharesDataObserver);
}

@Override
protected void onActive() {
super.onActive();
BitsharesWalletWraper.getInstance().registerDataObserver(bitsharesDataObserver);
}
}
Loading

0 comments on commit bb1da5c

Please sign in to comment.