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) {
59 public void fab_new_transaction_clicked(View view) {
60 Intent intent = new Intent(this, NewTransactionActivity.class);
61 startActivity(intent);
64 public void nav_exit_clicked(View view) {
65 Log.w("mobileledger", "exiting");
69 public void nav_settings_clicked(View view) {
70 Intent intent = new Intent(this, SettingsActivity.class);
71 startActivity(intent);
75 public void onBackPressed() {
76 DrawerLayout drawer = findViewById(R.id.drawer_layout);
77 if (drawer.isDrawerOpen(GravityCompat.START)) {
78 drawer.closeDrawer(GravityCompat.START);
80 super.onBackPressed();
85 public boolean onCreateOptionsMenu(Menu menu) {
86 // Inflate the menu; this adds items to the action bar if it is present.
87 //getMenuInflater().inflate(R.menu.latest_transactions, menu);
92 public boolean onOptionsItemSelected(MenuItem item) {
93 // Handle action bar item clicks here. The action bar will
94 // automatically handle clicks on the Home/Up button, so long
95 // as you specify a parent activity in AndroidManifest.xml.
96 int id = item.getItemId();
98 //noinspection SimplifiableIfStatement
99 //if (id == R.id.action_settings) {
103 return super.onOptionsItemSelected(item);
106 private void prepare_db() {
107 MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME);
108 MobileLedgerDB.initDB();
110 private void update_accounts() {
113 Activity activity = this;
115 ProgressBar pb = findViewById(R.id.progressBar);
116 TextView pt = findViewById(R.id.textProgress);
117 pb.setIndeterminate(true);
119 RetrieveAccountsTask task = new RetrieveAccountsTask() {
121 protected void onProgressUpdate(Integer... values) {
122 if ( values[0] == 0 )
123 pt.setText(R.string.progress_connecting);
125 pt.setText(String.format(getResources().getString(R.string.progress_N_accounts_loaded), values[0]));
129 protected void onPostExecute(Void result) {
130 pb.setVisibility(GONE);
131 pt.setVisibility(GONE);
133 Snackbar.make(drawer, activity.getResources().getString(this.error), Snackbar.LENGTH_LONG );
137 task.setPref(PreferenceManager.getDefaultSharedPreferences(this));