Update exchange activity

This commit is contained in:
Tanguy Herbron 2018-07-31 13:16:42 +02:00
parent 93f0a700fb
commit a64aed4729
9 changed files with 260 additions and 2 deletions

Binary file not shown.

View File

@ -0,0 +1,70 @@
package com.herbron.moodl.Activities;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
import com.herbron.moodl.LayoutManagers.ExchangeListAdapter;
import com.herbron.moodl.R;
import java.util.ArrayList;
import java.util.List;
import static com.herbron.moodl.DataManagers.DatabaseManager.BINANCE_TYPE;
import static com.herbron.moodl.DataManagers.DatabaseManager.HITBTC_TYPE;
public class ExchangeListActivity extends AppCompatActivity {
private DatabaseManager databaseManager;
private ListView exchangeListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exchange_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
databaseManager = new DatabaseManager(this);
ArrayList<Exchange> exchangeList = new ArrayList<>();
exchangeList.add(new Exchange(0, "Main account", BINANCE_TYPE, "Account with main balance & trading bot", "0000", "0000"));
exchangeList.add(new Exchange(1, "Hit account", HITBTC_TYPE, "BCN account and HIT", "0001", "0001"));
ExchangeListAdapter exchangeListAdapter = new ExchangeListAdapter(getApplicationContext(), exchangeList);
exchangeListView = findViewById(R.id.exchange_listView);
exchangeListView.setAdapter(exchangeListAdapter);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -6,6 +6,7 @@ import android.app.AlertDialog;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
@ -234,7 +235,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
return false;
Log.d("moodl", "> " + o + " " + preference);
return (boolean) o;
}
});
@ -777,6 +780,17 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
}
});
findPreference("exchange").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent exchangeListIntent = new Intent(getContext(), ExchangeListActivity.class);
startActivity(exchangeListIntent);
return false;
}
});
EditTextPreference editTextPreference = (EditTextPreference) findPreference("minimum_value_displayed");
editTextPreference.setPositiveButtonText(getString(R.string.save));
editTextPreference.setNegativeButtonText(getString(R.string.cancel));
@ -832,6 +846,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
//startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -0,0 +1,31 @@
package com.herbron.moodl.DataManagers.ExchangeManager;
public class Exchange {
protected int id;
protected String name;
protected int type;
protected String description;
protected String publicKey;
protected String privateKey;
public Exchange(int id, String name, int type, String description, String publicKey, String privateKey)
{
this.id = id;
this.name = name;
this.type = type;
this.description = description;
this.publicKey = publicKey;
this.privateKey = privateKey;
}
public String getName()
{
return name;
}
public String getDescription()
{
return description;
}
}

View File

@ -0,0 +1,53 @@
package com.herbron.moodl.LayoutManagers;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.CurrencyData.Trade;
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
import com.herbron.moodl.R;
import java.util.ArrayList;
import static com.herbron.moodl.MoodlBox.getDateFromTimestamp;
public class ExchangeListAdapter extends ArrayAdapter<Exchange> {
private Context context;
public ExchangeListAdapter(Context context, ArrayList<Exchange> exchanges)
{
super(context, android.R.layout.simple_list_item_1, exchanges);
this.context = context;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
Exchange exchange = getItem(position);
if(convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.exchange_cell, parent, false);
}
TextView exchangeNameTextView = convertView.findViewById(R.id.exchange_name);
TextView exchangeDescriptionTextView = convertView.findViewById(R.id.exchange_description);
exchangeNameTextView.setText(exchange.getName());
exchangeDescriptionTextView.setText(exchange.getDescription());
return convertView;
}
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activities.ExchangeListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/gradient_background"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_exchange_list" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_add_white_24dp" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activities.ExchangeListActivity"
tools:showIn="@layout/activity_exchange_list">
<ListView
android:id="@+id/exchange_listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.constraint.ConstraintLayout>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/exchange_icon_imageView"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginEnd="@dimen/margin"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/exchange_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/cardViewTitle"
android:textColor="@color/mainTextViewColor"/>
<TextView
android:id="@+id/exchange_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/cardViewCaption"
android:textColor="@color/captionColor"/>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>

View File

@ -39,7 +39,6 @@
android:title="@string/pref_title_category_synchronization">
<PreferenceScreen
android:fragment="com.herbron.moodl.Activities.SettingsActivity$ExchangePreferenceFragment"
android:title="@string/pref_header_exchange"
android:key="exchange"/>