]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java
dynamicly set the version in the drawer head
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / LatestTransactions.java
1 package net.ktnx.mobileledger;
2
3 import android.content.pm.PackageInfo;
4 import android.os.Bundle;
5 import android.support.design.widget.FloatingActionButton;
6 import android.support.design.widget.NavigationView;
7 import android.support.design.widget.Snackbar;
8 import android.support.v4.view.GravityCompat;
9 import android.support.v4.widget.DrawerLayout;
10 import android.support.v7.app.ActionBarDrawerToggle;
11 import android.support.v7.app.AppCompatActivity;
12 import android.support.v7.widget.Toolbar;
13 import android.view.Menu;
14 import android.view.MenuItem;
15 import android.view.View;
16
17 public class LatestTransactions extends AppCompatActivity
18         implements NavigationView.OnNavigationItemSelectedListener {
19
20     @Override
21     protected void onCreate(Bundle savedInstanceState) {
22         super.onCreate(savedInstanceState);
23         setContentView(R.layout.activity_latest_transactions);
24         Toolbar toolbar = findViewById(R.id.toolbar);
25         setSupportActionBar(toolbar);
26
27         FloatingActionButton fab = findViewById(R.id.btn_add_transaction);
28         fab.setOnClickListener(new View.OnClickListener() {
29             @Override
30             public void onClick(View view) {
31                 Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
32                         .setAction("Action", null).show();
33             }
34         });
35
36         DrawerLayout drawer = findViewById(R.id.drawer_layout);
37         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
38                 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
39         drawer.addDrawerListener(toggle);
40         toggle.syncState();
41
42         NavigationView navigationView = findViewById(R.id.nav_view);
43         navigationView.setNavigationItemSelectedListener(this);
44
45         android.widget.TextView ver = drawer.findViewById(R.id.drawer_version_text);
46
47         try {
48             PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0);
49             ver.setText(pi.versionName);
50         } catch (Exception e) {
51             ver.setText("version");
52         }
53     }
54
55     @Override
56     public void onBackPressed() {
57         DrawerLayout drawer = findViewById(R.id.drawer_layout);
58         if (drawer.isDrawerOpen(GravityCompat.START)) {
59             drawer.closeDrawer(GravityCompat.START);
60         } else {
61             super.onBackPressed();
62         }
63     }
64
65     @Override
66     public boolean onCreateOptionsMenu(Menu menu) {
67         // Inflate the menu; this adds items to the action bar if it is present.
68         getMenuInflater().inflate(R.menu.latest_transactions, menu);
69         return true;
70     }
71
72     @Override
73     public boolean onOptionsItemSelected(MenuItem item) {
74         // Handle action bar item clicks here. The action bar will
75         // automatically handle clicks on the Home/Up button, so long
76         // as you specify a parent activity in AndroidManifest.xml.
77         int id = item.getItemId();
78
79         //noinspection SimplifiableIfStatement
80         if (id == R.id.action_settings) {
81             return true;
82         }
83
84         return super.onOptionsItemSelected(item);
85     }
86
87     @SuppressWarnings("StatementWithEmptyBody")
88     @Override
89     public boolean onNavigationItemSelected(MenuItem item) {
90         // Handle navigation view item clicks here.
91         int id = item.getItemId();
92
93         if (id == R.id.nav_latest_transactions) {
94             // Handle the camera action
95         } else if (id == R.id.nav_reports) {
96
97         } else if (id == R.id.nav_settings) {
98
99         } else if (id == R.id.nav_exit) {
100
101         }
102
103         DrawerLayout drawer = findViewById(R.id.drawer_layout);
104         drawer.closeDrawer(GravityCompat.START);
105         return true;
106     }
107 }