/*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
* This file is part of Mobile-Ledger.
* Mobile-Ledger is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
+import android.widget.TextView;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.model.LedgerAccount;
import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
+import net.ktnx.mobileledger.utils.MLDB;
+
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
public class MainActivity extends AppCompatActivity {
DrawerLayout drawer;
private TransactionListFragment transactionListFragment;
private Fragment currentFragment = null;
private FragmentManager fragmentManager;
+ private TextView tvLastUpdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}
+ tvLastUpdate = findViewById(R.id.transactions_last_update);
+ updateLastUpdateText();
+ long last_update = MLDB.get_option_value(MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
+ Log.d("transactions", String.format("Last update = %d", last_update));
+
+
fragmentManager = getSupportFragmentManager();
onAccountSummaryClicked(null);
startActivity(intent);
}
public void markDrawerItemCurrent(int id) {
- View item = drawer.findViewById(id);
+ TextView item = drawer.findViewById(id);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
}
item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg));
}
+ setTitle(item.getText());
+
@ColorInt int transparent = getResources().getColor(android.R.color.transparent);
LinearLayout actions = drawer.findViewById(R.id.nav_actions);
super.onBackPressed();
}
}
+ public void updateLastUpdateText() {
+ {
+ long last_update = MLDB.get_option_value(MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
+ Log.d("transactions", String.format("Last update = %d", last_update));
+ if (last_update == 0) {
+ tvLastUpdate.setText(getString(R.string.transaction_last_update_never));
+ }
+ else {
+ Date date = new Date(last_update);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ tvLastUpdate.setText(date.toInstant().atZone(ZoneId.systemDefault())
+ .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
+ }
+ else {
+ tvLastUpdate.setText(date.toLocaleString());
+ }
+ }
+ }
+ }
}