package net.ktnx.mobileledger;
+import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.res.Resources;
+import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
+import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.EditText;
+import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TableLayout;
+import android.widget.TableRow;
import android.widget.TextView;
import java.util.Date;
import static android.view.View.GONE;
+import static net.ktnx.mobileledger.MobileLedgerDB.db;
import static net.ktnx.mobileledger.MobileLedgerDB.set_option_value;
public class AccountSummary extends AppCompatActivity {
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.account_summary, menu);
- mRefresh = (MenuItem) menu.findItem(R.id.menu_acc_summary_refresh);
+ mRefresh = menu.findItem(R.id.menu_acc_summary_refresh);
assert mRefresh != null;
return true;
}
String err_text = rm.getString(this.error);
Log.d("visual", String.format("showing snackbar: %s", err_text));
Snackbar.make(drawer, err_text, Snackbar.LENGTH_LONG ).show();
- } else
+ }
+ else {
set_option_value("last_refresh", new Date().getTime() );
+ update_account_table();
+ }
}
};
task.execute();
}
+
+ public int dp2px(float dp) {
+ return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()));
+ }
+
+ @SuppressLint("DefaultLocale")
+ private void update_account_table() {
+ LinearLayout root = findViewById(R.id.account_root);
+ root.removeAllViewsInLayout();
+
+ try (Cursor cursor = db.rawQuery("SELECT name FROM accounts ORDER BY name;", null)) {
+ boolean even = false;
+ while (cursor.moveToNext()) {
+ String acc_name = cursor.getString(0);
+
+ TableLayout t = new TableLayout(this);
+ TableRow r = new TableRow(this);
+ r.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ if (even)
+ r.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
+ even = !even;
+
+ TextView acc_tv = new TextView(this, null, R.style.account_summary_account_name);
+ acc_tv.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 9f));
+ acc_tv.setText(acc_name);
+ r.addView(acc_tv);
+
+ TextView amt_tv = new TextView(this, null, R.style.account_summary_amounts);
+ amt_tv.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
+ amt_tv.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END);
+ amt_tv.setMinWidth(dp2px(40f));
+ StringBuilder amt_text = new StringBuilder();
+ try (Cursor cAmounts = db.rawQuery("SELECT currency, value FROM account_values WHERE account = ?", new String[]{acc_name})) {
+ while (cAmounts.moveToNext()) {
+ String curr = cAmounts.getString(0);
+ Float amt = cAmounts.getFloat(1);
+ if (amt_text.length() != 0) amt_text.append('\n');
+ amt_text.append(String.format("%s %1.2f", curr, amt));
+ }
+ }
+ amt_tv.setText(amt_text.toString());
+
+ r.addView(amt_tv);
+
+ t.addView(r);
+
+ root.addView(t);
+ }
+ }
+ }
}
<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:id="@+id/content_account_summary_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent" />
+ app:layout_constraintStart_toStartOf="parent"
+ tools:ignore="HardcodedText" />
<ProgressBar
android:id="@+id/progressBar"
app:layout_constraintStart_toStartOf="parent" />
<ScrollView
+ android:id="@+id/account_root_scroller"
android:layout_width="match_parent"
- android:layout_height="325dp"
- android:layout_marginTop="8dp"
- android:layout_marginBottom="40dp"
+ android:layout_height="match_parent"
+ android:paddingStart="@dimen/activity_horizontal_margin"
+ android:paddingEnd="@dimen/activity_horizontal_margin"
app:layout_constraintBottom_toTopOf="@+id/textProgress"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
+ android:id="@+id/account_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin">
+ <TableLayout style="@style/account_summary_account_entry_table">
- <LinearLayout
+ <TableRow
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
+ android:layout_height="match_parent"
+ android:background="@color/table_row_even_bg">
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin">
+ <TextView
+ android:id="@+id/textView"
+ style="@style/account_summary_account_name"
+ android:text="TextView" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" />
- </ScrollView>
- </LinearLayout>
- </ScrollView>
+ <TextView
+ android:id="@+id/textView2"
+ style="@style/account_summary_amounts"
+ android:text="123.45" />
+ </TableRow>
+ </TableLayout>
</LinearLayout>
</ScrollView>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item>
</style>
+ <style name="account_summary_account_name">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_weight">9</item>
+ </style>
+
+ <style name="account_summary_amounts">
+ <item name="android:layout_width">wrap_content</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_marginEnd">0dp</item>
+ <item name="android:layout_weight">1</item>
+ <item name="android:width">0dp</item>
+ <item name="android:minWidth">40dp</item>
+ <item name="android:textAlignment">viewEnd</item>
+ </style>
+
+ <style name="account_summary_account_entry_table">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">match_parent</item>
+ </style>
+
</resources>