|
@@ -1,30 +1,34 @@
|
1
|
1
|
package com.rthoni.camotion.ui;
|
2
|
2
|
|
|
3
|
+import android.app.Fragment;
|
3
|
4
|
import android.os.Bundle;
|
4
|
|
-import android.support.design.widget.FloatingActionButton;
|
5
|
|
-import android.util.Log;
|
6
|
|
-import android.view.View;
|
|
5
|
+import android.view.SubMenu;
|
7
|
6
|
import android.support.design.widget.NavigationView;
|
8
|
7
|
import android.support.v4.view.GravityCompat;
|
9
|
8
|
import android.support.v4.widget.DrawerLayout;
|
10
|
9
|
import android.support.v7.app.ActionBarDrawerToggle;
|
11
|
10
|
import android.support.v7.app.AppCompatActivity;
|
12
|
11
|
import android.support.v7.widget.Toolbar;
|
13
|
|
-import android.view.Menu;
|
14
|
12
|
import android.view.MenuItem;
|
|
13
|
+import android.widget.TextView;
|
15
|
14
|
|
16
|
|
-import com.luticate.auth.business.LuticateUsersBusiness;
|
17
|
15
|
import com.luticate.auth.dbo.LuFullLoginDbo;
|
18
|
|
-import com.luticate.utils.business.LuPromise;
|
19
|
16
|
import com.rthoni.camotion.R;
|
20
|
17
|
import com.rthoni.camotion.business.CamotionBusiness;
|
21
|
18
|
import com.rthoni.camotion.dbo.LocationDbo;
|
|
19
|
+import com.rthoni.camotion.ui.fragments.CamerasFragment;
|
22
|
20
|
|
23
|
21
|
import java.util.List;
|
24
|
22
|
|
25
|
23
|
public class MainActivity extends AppCompatActivity
|
26
|
24
|
implements NavigationView.OnNavigationItemSelectedListener {
|
27
|
25
|
|
|
26
|
+ private LuFullLoginDbo _fullLoginDbo = null;
|
|
27
|
+ private LocationDbo _currentLocation = null;
|
|
28
|
+ private TextView _locationNameView;
|
|
29
|
+ private SubMenu _locationsMenu;
|
|
30
|
+ private NavigationView _navigationView;
|
|
31
|
+
|
28
|
32
|
@Override
|
29
|
33
|
protected void onCreate(Bundle savedInstanceState) {
|
30
|
34
|
super.onCreate(savedInstanceState);
|
|
@@ -32,25 +36,7 @@ public class MainActivity extends AppCompatActivity
|
32
|
36
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
33
|
37
|
setSupportActionBar(toolbar);
|
34
|
38
|
|
35
|
|
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
36
|
|
- fab.setOnClickListener(new View.OnClickListener() {
|
37
|
|
- @Override
|
38
|
|
- public void onClick(View view) {
|
39
|
|
- /*LuticateUsersBusiness.loginFull(CamotionBusiness.getConfig(), "user", "test42")
|
40
|
|
- .then(new LuPromise.LuConsumer<LuFullLoginDbo>() {
|
41
|
|
- @Override
|
42
|
|
- public void execute(LuFullLoginDbo data) {
|
43
|
|
- Log.d("Login", data.toString());
|
44
|
|
- }
|
45
|
|
- }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
|
46
|
|
- @Override
|
47
|
|
- public void execute(LuPromise.LuPromiseError error) {
|
48
|
|
- Log.e("Login", error.toString());
|
49
|
|
- }
|
50
|
|
- });*/
|
51
|
|
- //List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
|
52
|
|
- }
|
53
|
|
- });
|
|
39
|
+ _locationNameView = (TextView) findViewById(R.id.location_name_textview);
|
54
|
40
|
|
55
|
41
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
56
|
42
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
|
|
@@ -58,8 +44,51 @@ public class MainActivity extends AppCompatActivity
|
58
|
44
|
drawer.setDrawerListener(toggle);
|
59
|
45
|
toggle.syncState();
|
60
|
46
|
|
61
|
|
- NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
62
|
|
- navigationView.setNavigationItemSelectedListener(this);
|
|
47
|
+ _navigationView = (NavigationView) findViewById(R.id.nav_view);
|
|
48
|
+ _navigationView.setNavigationItemSelectedListener(this);
|
|
49
|
+ _locationsMenu = _navigationView.getMenu().findItem(R.id.location_menu).getSubMenu();
|
|
50
|
+
|
|
51
|
+ init();
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ private void init()
|
|
55
|
+ {
|
|
56
|
+ List<LocationDbo> locations = CamotionBusiness.getLocations(MainActivity.this);
|
|
57
|
+ _locationsMenu.clear();
|
|
58
|
+ if (locations.isEmpty()) {
|
|
59
|
+ return;
|
|
60
|
+ }
|
|
61
|
+ for (final LocationDbo location : locations) {
|
|
62
|
+ MenuItem item = _locationsMenu.add(location.getName());
|
|
63
|
+ item.setIcon(R.mipmap.ic_location);
|
|
64
|
+ item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
65
|
+ @Override
|
|
66
|
+ public boolean onMenuItemClick(MenuItem item) {
|
|
67
|
+ setLocation(location);
|
|
68
|
+ return false;
|
|
69
|
+ }
|
|
70
|
+ });
|
|
71
|
+ }
|
|
72
|
+ // Force drawer update; need a fix
|
|
73
|
+ MenuItem item = _navigationView.getMenu().add("test42");
|
|
74
|
+ _navigationView.getMenu().removeItem(item.getItemId());
|
|
75
|
+ setLocation(locations.get(0));
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ private void setLocation(LocationDbo location)
|
|
79
|
+ {
|
|
80
|
+ _currentLocation = location;
|
|
81
|
+ _locationNameView.setText(_currentLocation.getName());
|
|
82
|
+ showView(R.id.nav_cameras);
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ private void showView(int view)
|
|
86
|
+ {
|
|
87
|
+ Fragment fragment = null;
|
|
88
|
+ if (view == R.id.nav_cameras) {
|
|
89
|
+ fragment = new CamerasFragment();
|
|
90
|
+ }
|
|
91
|
+ getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
|
63
|
92
|
}
|
64
|
93
|
|
65
|
94
|
@Override
|
|
@@ -72,44 +101,17 @@ public class MainActivity extends AppCompatActivity
|
72
|
101
|
}
|
73
|
102
|
}
|
74
|
103
|
|
75
|
|
- @Override
|
76
|
|
- public boolean onCreateOptionsMenu(Menu menu) {
|
77
|
|
- // Inflate the menu; this adds items to the action bar if it is present.
|
78
|
|
- getMenuInflater().inflate(R.menu.menu_main, menu);
|
79
|
|
- return true;
|
80
|
|
- }
|
81
|
|
-
|
82
|
|
- @Override
|
83
|
|
- public boolean onOptionsItemSelected(MenuItem item) {
|
84
|
|
- // Handle action bar item clicks here. The action bar will
|
85
|
|
- // automatically handle clicks on the Home/Up button, so long
|
86
|
|
- // as you specify a parent activity in AndroidManifest.xml.
|
87
|
|
- int id = item.getItemId();
|
88
|
|
-
|
89
|
|
- //noinspection SimplifiableIfStatement
|
90
|
|
- if (id == R.id.action_settings) {
|
91
|
|
- return true;
|
92
|
|
- }
|
93
|
|
-
|
94
|
|
- return super.onOptionsItemSelected(item);
|
95
|
|
- }
|
96
|
|
-
|
97
|
104
|
@SuppressWarnings("StatementWithEmptyBody")
|
98
|
105
|
@Override
|
99
|
106
|
public boolean onNavigationItemSelected(MenuItem item) {
|
100
|
|
- // Handle navigation view item clicks here.
|
101
|
107
|
int id = item.getItemId();
|
102
|
108
|
|
103
|
|
- if (id == R.id.nav_camera) {
|
104
|
|
- // Handle the camera action
|
105
|
|
- } else if (id == R.id.nav_gallery) {
|
106
|
|
-
|
107
|
|
- } else if (id == R.id.nav_slideshow) {
|
108
|
|
-
|
109
|
|
- } else if (id == R.id.nav_share) {
|
110
|
|
-
|
111
|
|
- } else if (id == R.id.nav_send) {
|
112
|
|
-
|
|
109
|
+ if (id == R.id.nav_cameras) {
|
|
110
|
+ showView(id);
|
|
111
|
+ } else if (id == R.id.nav_sensors) {
|
|
112
|
+ showView(id);
|
|
113
|
+ } else if (id == R.id.nav_commands) {
|
|
114
|
+ showView(id);
|
113
|
115
|
}
|
114
|
116
|
|
115
|
117
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|