Merge remote-tracking branch 'origin/master'

This commit is contained in:
henry 2017-11-07 22:21:20 -04:00
commit 10798b8e0c
9 changed files with 343 additions and 1 deletions

View file

@ -27,6 +27,8 @@
</activity>
<activity android:name=".activities.SendTransactionActivity" >
</activity>
<activity android:name=".activities.GeneralSettingsActivity" >
</activity>
<service android:name=".service.CrystalWalletService"
android:exported="false"/>
</application>

View file

@ -1,5 +1,6 @@
package cy.agorise.crystalwallet.activities;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@ -7,9 +8,11 @@ import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageButton;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.fragments.BalanceFragment;
import cy.agorise.crystalwallet.fragments.ContactsFragment;
@ -24,6 +27,9 @@ public class BoardActivity extends AppCompatActivity {
@BindView(R.id.pager)
public ViewPager mPager;
@BindView(R.id.btnGeneralSettings)
public ImageButton btnGeneralSettings;
public BoardPagerAdapter boardAdapter;
@Override
@ -36,6 +42,12 @@ public class BoardActivity extends AppCompatActivity {
mPager.setAdapter(boardAdapter);
}
@OnClick(R.id.btnGeneralSettings)
public void onBtnGeneralSettingsClick(){
Intent intent = new Intent(this, GeneralSettingsActivity.class);
startActivity(intent);
}
private class BoardPagerAdapter extends FragmentStatePagerAdapter {
public BoardPagerAdapter(FragmentManager fm) {
super(fm);

View file

@ -0,0 +1,129 @@
package cy.agorise.crystalwallet.activities;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Currency;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnItemSelected;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.models.GrapheneAccount;
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter;
public class GeneralSettingsActivity extends AppCompatActivity {
@BindView(R.id.spPreferedCountry)
Spinner spPreferedCountry;
private GeneralSettingListViewModel generalSettingListViewModel;
private LiveData<List<GeneralSetting>> generalSettingListLiveData;
private HashMap<String,String> countriesMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.general_settings);
ButterKnife.bind(this);
this.generalSettingListViewModel = ViewModelProviders.of(this).get(GeneralSettingListViewModel.class);
generalSettingListLiveData = generalSettingListViewModel.getGeneralSettingList();
// Initializes the countries spinner
countriesMap = new HashMap<String, String>();
String[] countryCodeList = Locale.getISOCountries();
ArrayList<String> countryAndCurrencyList = new ArrayList<String>();
String countryAndCurrencyLabel = "";
for (String countryCode : countryCodeList) {
Locale locale = new Locale("", countryCode);
try {
Currency currency = Currency.getInstance(locale);
countryAndCurrencyLabel = locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";
countryAndCurrencyList.add(countryAndCurrencyLabel);
countriesMap.put(countryCode, countryAndCurrencyLabel);
countriesMap.put(countryAndCurrencyLabel, countryCode);
} catch (Exception e) {
}
}
Collections.sort(countryAndCurrencyList);
countryAndCurrencyList.add(0,"SELECT COUNTRY");
ArrayAdapter<String> countryAdapter = new ArrayAdapter<String>(this.getApplicationContext(), android.R.layout.simple_spinner_item, countryAndCurrencyList);
spPreferedCountry.setAdapter(countryAdapter);
//Observes the general settings data
generalSettingListLiveData.observe(this, new Observer<List<GeneralSetting>>() {
@Override
public void onChanged(@Nullable List<GeneralSetting> generalSettings) {
loadSettings(generalSettings);
}
});
}
public GeneralSetting getSetting(String name){
for (GeneralSetting generalSetting:this.generalSettingListLiveData.getValue()) {
if (generalSetting.getName().equals(name)) {
return generalSetting;
}
}
return null;
}
@OnItemSelected(R.id.spPreferedCountry)
void onItemSelected(int position) {
if (position != 0) {
GeneralSetting generalSettingCountryCode = this.getSetting(GeneralSetting.SETTING_NAME_PREFERED_COUNTRY);
GeneralSetting generalSettingCurrency = this.getSetting(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY);
if (generalSettingCountryCode == null){
generalSettingCountryCode = new GeneralSetting();
generalSettingCountryCode.setName(GeneralSetting.SETTING_NAME_PREFERED_COUNTRY);
}
if (generalSettingCurrency == null){
generalSettingCurrency = new GeneralSetting();
generalSettingCurrency.setName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY);
}
String countryCode = countriesMap.get((String) spPreferedCountry.getSelectedItem());
Locale locale = new Locale("", countryCode);
Currency currency = Currency.getInstance(locale);
generalSettingCountryCode.setValue(countryCode);
generalSettingCurrency.setValue(currency.getCurrencyCode());
this.generalSettingListViewModel.saveGeneralSettings(generalSettingCountryCode, generalSettingCurrency);
}
}
public void loadSettings(List<GeneralSetting> generalSettings){
for (GeneralSetting generalSetting:generalSettings) {
if (generalSetting.getName().equals(GeneralSetting.SETTING_NAME_PREFERED_COUNTRY)){
String preferedCountryCode = generalSetting.getValue();
spPreferedCountry.setSelection(((ArrayAdapter<String>)spPreferedCountry.getAdapter()).getPosition(countriesMap.get(preferedCountryCode)));
}
}
}
}

View file

@ -14,6 +14,7 @@ import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
/**
@ -29,7 +30,8 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
CryptoCoinBalance.class,
GrapheneAccountInfo.class,
BitsharesAssetInfo.class,
CryptoCurrencyEquivalence.class
CryptoCurrencyEquivalence.class,
GeneralSetting.class
}, version = 2)
@TypeConverters({Converters.class})
public abstract class CrystalDatabase extends RoomDatabase {
@ -44,6 +46,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
public abstract CryptoCurrencyDao cryptoCurrencyDao();
public abstract BitsharesAssetDao bitsharesAssetDao();
public abstract CryptoCurrencyEquivalenceDao cryptoCurrencyEquivalenceDao();
public abstract GeneralSettingDao generalSettingDao();
public static CrystalDatabase getAppDatabase(Context context) {
if (instance == null) {

View file

@ -0,0 +1,32 @@
package cy.agorise.crystalwallet.dao;
import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import java.util.List;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.GeneralSetting;
/**
* Created by Henry Varona on 10/9/2017.
*/
@Dao
public interface GeneralSettingDao {
@Query("SELECT * FROM general_setting")
LiveData<List<GeneralSetting>> getAll();
@Query("SELECT * FROM general_setting WHERE name = :name")
LiveData<GeneralSetting> getByName(String name);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertGeneralSettings(GeneralSetting... generalSettings);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long insertGeneralSetting(GeneralSetting generalSetting);
}

View file

@ -0,0 +1,89 @@
package cy.agorise.crystalwallet.models;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import android.support.v7.recyclerview.extensions.DiffCallback;
import cy.agorise.crystalwallet.enums.SeedType;
/**
* Created by Henry Varona on 6/11/2017.
*/
@Entity(tableName = "general_setting")
public class GeneralSetting {
public final static String SETTING_NAME_PREFERED_COUNTRY = "PREFERED_COUNTRY";
public final static String SETTING_NAME_PREFERED_CURRENCY = "PREFERED_CURRENCY";
/**
* The id on the database
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
private long mId;
/**
* The name of this setting
*/
@ColumnInfo(name = "name")
private String mName;
/**
* The value of this setting
*/
@ColumnInfo(name = "value")
private String mValue;
public long getId() {
return mId;
}
public void setId(long id){
this.mId = id;
}
public String getName() {
return mName;
}
public void setName(String mName) {
this.mName = mName;
}
public String getValue() {
return mValue;
}
public void setValue(String mValue) {
this.mValue = mValue;
}
public static final DiffCallback<GeneralSetting> DIFF_CALLBACK = new DiffCallback<GeneralSetting>() {
@Override
public boolean areItemsTheSame(
@NonNull GeneralSetting oldSetting, @NonNull GeneralSetting newSetting) {
return oldSetting.getId() == newSetting.getId();
}
@Override
public boolean areContentsTheSame(
@NonNull GeneralSetting oldSetting, @NonNull GeneralSetting newSetting) {
return oldSetting.equals(newSetting);
}
};
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GeneralSetting that = (GeneralSetting) o;
if (mId != that.mId) return false;
if (mName != that.mName) return false;
return mValue.equals(that.mValue);
}
}

View file

@ -0,0 +1,40 @@
package cy.agorise.crystalwallet.viewmodels;
import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.LiveData;
import android.arch.paging.PagedList;
import java.util.List;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.GeneralSetting;
/**
* Created by Henry Varona on 6/11/2017.
*/
public class GeneralSettingListViewModel extends AndroidViewModel {
private LiveData<List<GeneralSetting>> generalSettingList;
private CrystalDatabase db;
public GeneralSettingListViewModel(Application application) {
super(application);
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
generalSettingList = this.db.generalSettingDao().getAll();
}
public LiveData<List<GeneralSetting>> getGeneralSettingList(){
return this.generalSettingList;
}
public void saveGeneralSetting(GeneralSetting generalSetting){
this.db.generalSettingDao().insertGeneralSetting(generalSetting);
}
public void saveGeneralSettings(GeneralSetting... generalSettings){
this.db.generalSettingDao().insertGeneralSettings(generalSettings);
}
}

View file

@ -7,4 +7,18 @@
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white">
<ImageButton
android:id="@+id/btnGeneralSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/icon_setting" />
</RelativeLayout>
</RelativeLayout>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_country"/>
<Spinner
android:id="@+id/spPreferedCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>