1 package net.ktnx.mobileledger;
3 import android.app.Activity;
4 import android.content.Intent;
5 import android.content.pm.PackageInfo;
6 import android.os.Bundle;
7 import android.preference.PreferenceManager;
8 import android.support.design.widget.Snackbar;
9 import android.support.v4.view.GravityCompat;
10 import android.support.v4.widget.DrawerLayout;
11 import android.support.v7.app.ActionBarDrawerToggle;
12 import android.support.v7.app.AppCompatActivity;
13 import android.support.v7.widget.Toolbar;
14 import android.util.Log;
15 import android.view.Menu;
16 import android.view.MenuItem;
17 import android.view.View;
18 import android.widget.ProgressBar;
19 import android.widget.TextView;
21 import java.util.Date;
23 import static android.view.View.GONE;
24 import static net.ktnx.mobileledger.MobileLedgerDB.db;
26 public class LatestTransactions extends AppCompatActivity {
29 private static Date account_list_last_updated;
30 private static boolean account_list_needs_update = true;
31 public static void preferences_changed() {
32 account_list_needs_update = true;
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38 setContentView(R.layout.activity_latest_transactions);
39 Toolbar toolbar = findViewById(R.id.toolbar);
40 setSupportActionBar(toolbar);
42 drawer = findViewById(R.id.drawer_layout);
43 ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
44 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
45 drawer.addDrawerListener(toggle);
48 android.widget.TextView ver = drawer.findViewById(R.id.drawer_version_text);
51 PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0);
52 ver.setText(pi.versionName);
53 } catch (Exception e) {
60 public void fab_new_transaction_clicked(View view) {
61 Intent intent = new Intent(this, NewTransactionActivity.class);
62 startActivity(intent);
65 public void nav_exit_clicked(View view) {
66 Log.w("mobileledger", "exiting");
70 public void nav_settings_clicked(View view) {
71 Intent intent = new Intent(this, SettingsActivity.class);
72 startActivity(intent);
76 public void onBackPressed() {
77 DrawerLayout drawer = findViewById(R.id.drawer_layout);
78 if (drawer.isDrawerOpen(GravityCompat.START)) {
79 drawer.closeDrawer(GravityCompat.START);
81 super.onBackPressed();
86 public boolean onCreateOptionsMenu(Menu menu) {
87 // Inflate the menu; this adds items to the action bar if it is present.
88 //getMenuInflater().inflate(R.menu.latest_transactions, menu);
93 public boolean onOptionsItemSelected(MenuItem item) {
94 // Handle action bar item clicks here. The action bar will
95 // automatically handle clicks on the Home/Up button, so long
96 // as you specify a parent activity in AndroidManifest.xml.
97 int id = item.getItemId();
99 //noinspection SimplifiableIfStatement
100 //if (id == R.id.action_settings) {
104 return super.onOptionsItemSelected(item);
107 private void prepare_db() {
108 MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME);
109 MobileLedgerDB.initDB();
111 private void update_accounts() {
114 Activity activity = this;
116 ProgressBar pb = findViewById(R.id.progressBar);
117 TextView pt = findViewById(R.id.textProgress);
118 pb.setIndeterminate(true);
120 RetrieveAccountsTask task = new RetrieveAccountsTask() {
122 protected void onProgressUpdate(Integer... values) {
123 if ( values[0] == 0 )
124 pt.setText(R.string.progress_connecting);
126 pt.setText(String.format(getResources().getString(R.string.progress_N_accounts_loaded), values[0]));
130 protected void onPostExecute(Void result) {
131 pb.setVisibility(GONE);
132 pt.setVisibility(GONE);
134 Snackbar.make(drawer, activity.getResources().getString(this.error), Snackbar.LENGTH_LONG );
138 task.setPref(PreferenceManager.getDefaultSharedPreferences(this));