|
@@ -9,7 +9,6 @@ import android.support.design.widget.NavigationView;
|
9
|
9
|
import android.support.multidex.MultiDex;
|
10
|
10
|
import android.support.v4.app.FragmentManager;
|
11
|
11
|
import android.support.v4.widget.DrawerLayout;
|
12
|
|
-import android.support.v7.app.ActionBar;
|
13
|
12
|
import android.support.v7.app.ActionBarDrawerToggle;
|
14
|
13
|
import android.support.v7.app.AlertDialog;
|
15
|
14
|
import android.support.v7.app.AppCompatActivity;
|
|
@@ -60,8 +59,7 @@ import butterknife.ButterKnife;
|
60
|
59
|
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
61
|
60
|
|
62
|
61
|
public static int ADD_FAVOURITE_STOP_REQUEST_CODE = 1;
|
63
|
|
-
|
64
|
|
- private boolean _goToHome = false;
|
|
62
|
+ public static int SEARCH_STOP_REQUEST_CODE = 2;
|
65
|
63
|
|
66
|
64
|
@BindView(R.id.fab)
|
67
|
65
|
FloatingActionMenu _fab;
|
|
@@ -85,10 +83,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
85
|
83
|
|
86
|
84
|
private CallbackManager _callbackManager;
|
87
|
85
|
|
88
|
|
- private ActionBar _actionBar;
|
89
|
|
-
|
90
|
86
|
private FragmentManager _fragmentManager;
|
91
|
87
|
|
|
88
|
+ private DrawerLayout _drawer;
|
|
89
|
+
|
|
90
|
+ private Runnable _onResumeAction;
|
|
91
|
+
|
92
|
92
|
@Override
|
93
|
93
|
protected void onCreate(Bundle savedInstanceState) {
|
94
|
94
|
super.onCreate(savedInstanceState);
|
|
@@ -108,10 +108,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
108
|
108
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
109
|
109
|
setSupportActionBar(toolbar);
|
110
|
110
|
|
111
|
|
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
111
|
+ _drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
112
|
112
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
113
|
|
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
114
|
|
- drawer.setDrawerListener(toggle);
|
|
113
|
+ this, _drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
|
114
|
+ _drawer.addDrawerListener(toggle);
|
115
|
115
|
toggle.syncState();
|
116
|
116
|
|
117
|
117
|
_navigationView.setNavigationItemSelectedListener(this);
|
|
@@ -184,8 +184,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
184
|
184
|
}
|
185
|
185
|
});
|
186
|
186
|
|
187
|
|
- _actionBar = getSupportActionBar();
|
188
|
|
-
|
189
|
187
|
updateLoginState();
|
190
|
188
|
goToHome();
|
191
|
189
|
}
|
|
@@ -207,9 +205,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
207
|
205
|
|
208
|
206
|
@Override
|
209
|
207
|
protected void onResume() {
|
210
|
|
- if (_goToHome) {
|
211
|
|
- _goToHome = false;
|
212
|
|
- goToHome();
|
|
208
|
+ if (_onResumeAction != null) {
|
|
209
|
+ _onResumeAction.run();
|
213
|
210
|
}
|
214
|
211
|
super.onResume();
|
215
|
212
|
}
|
|
@@ -241,17 +238,48 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
241
|
238
|
|
242
|
239
|
public void goToAddStop(boolean map)
|
243
|
240
|
{
|
|
241
|
+ _fab.close(true);
|
244
|
242
|
Intent intent = new Intent(this, StopPickerActivity.class);
|
245
|
243
|
intent.putExtra(StopPickerActivity.MAP_EXTRA_NAME, map);
|
246
|
244
|
startActivityForResult(intent, ADD_FAVOURITE_STOP_REQUEST_CODE);
|
247
|
245
|
}
|
248
|
246
|
|
|
247
|
+ public void goToSearchStop(boolean map)
|
|
248
|
+ {
|
|
249
|
+ _fab.close(true);
|
|
250
|
+ Intent intent = new Intent(this, StopPickerActivity.class);
|
|
251
|
+ intent.putExtra(StopPickerActivity.MAP_EXTRA_NAME, map);
|
|
252
|
+ intent.putExtra(StopPickerActivity.SELECT_ROUTES_EXTRA_NAME, false);
|
|
253
|
+ startActivityForResult(intent, SEARCH_STOP_REQUEST_CODE);
|
|
254
|
+ }
|
|
255
|
+
|
|
256
|
+ public void goToSearchStop()
|
|
257
|
+ {
|
|
258
|
+ final int item[] = new int[1];
|
|
259
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
260
|
+ String[] array = new String[]{getString(R.string.stop_add_map), getString(R.string.stop_add_list)};
|
|
261
|
+ builder.setSingleChoiceItems(array, 0, new DialogInterface.OnClickListener() {
|
|
262
|
+ @Override
|
|
263
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
264
|
+ item[0] = which;
|
|
265
|
+ }
|
|
266
|
+ });
|
|
267
|
+ builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
268
|
+ @Override
|
|
269
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
270
|
+ dialog.dismiss();
|
|
271
|
+ goToSearchStop(item[0] == 0);
|
|
272
|
+ }
|
|
273
|
+ });
|
|
274
|
+ builder.show();
|
|
275
|
+ }
|
|
276
|
+
|
249
|
277
|
@Override
|
250
|
278
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
251
|
279
|
if (requestCode == ADD_FAVOURITE_STOP_REQUEST_CODE && resultCode == RESULT_OK) {
|
252
|
280
|
UserFavouriteStopsDbo favouriteStopDbo = new UserFavouriteStopsDbo();
|
253
|
281
|
try {
|
254
|
|
- JSONObject obj = new JSONObject(data.getStringExtra(StopPickerActivity.STOP_EXTRA_NAME));
|
|
282
|
+ JSONObject obj = new JSONObject(data.getStringExtra(StopPickerActivity.FAVOURITE_STOP_EXTRA_NAME));
|
255
|
283
|
favouriteStopDbo.fromJson(obj);
|
256
|
284
|
} catch (JSONException e) {
|
257
|
285
|
e.printStackTrace();
|
|
@@ -260,7 +288,28 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
260
|
288
|
List<UserFavouriteStopsDbo> favouriteStopDbos = STSBusiness.getFavouriteStops(this);
|
261
|
289
|
favouriteStopDbos.add(favouriteStopDbo);
|
262
|
290
|
STSBusiness.setFavouriteStops(this, favouriteStopDbos);
|
263
|
|
- _goToHome = true;
|
|
291
|
+ _onResumeAction = new Runnable() {
|
|
292
|
+ @Override
|
|
293
|
+ public void run() {
|
|
294
|
+ goToHome();
|
|
295
|
+ }
|
|
296
|
+ };
|
|
297
|
+ }
|
|
298
|
+ else if (requestCode == SEARCH_STOP_REQUEST_CODE && resultCode == RESULT_OK) {
|
|
299
|
+ final StopsDbo stopDbo = new StopsDbo();
|
|
300
|
+ try {
|
|
301
|
+ JSONObject obj = new JSONObject(data.getStringExtra(StopPickerActivity.STOP_EXTRA_NAME));
|
|
302
|
+ stopDbo.fromJson(obj);
|
|
303
|
+ } catch (JSONException e) {
|
|
304
|
+ e.printStackTrace();
|
|
305
|
+ return;
|
|
306
|
+ }
|
|
307
|
+ _onResumeAction = new Runnable() {
|
|
308
|
+ @Override
|
|
309
|
+ public void run() {
|
|
310
|
+ goToStop(stopDbo);
|
|
311
|
+ }
|
|
312
|
+ };
|
264
|
313
|
}
|
265
|
314
|
else {
|
266
|
315
|
_callbackManager.onActivityResult(requestCode, resultCode, data);
|
|
@@ -270,7 +319,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
270
|
319
|
|
271
|
320
|
@Override
|
272
|
321
|
public boolean onNavigationItemSelected(MenuItem item) {
|
273
|
|
- if (item.getItemId() == R.id.nav_restore) {
|
|
322
|
+ if (item.getItemId() == R.id.nav_search_stop) {
|
|
323
|
+ goToSearchStop();
|
|
324
|
+ }
|
|
325
|
+ else if (item.getItemId() == R.id.nav_restore) {
|
274
|
326
|
restoreSettings();
|
275
|
327
|
}
|
276
|
328
|
else if (item.getItemId() == R.id.nav_backup) {
|
|
@@ -284,6 +336,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
284
|
336
|
else {
|
285
|
337
|
return false;
|
286
|
338
|
}
|
|
339
|
+ _drawer.closeDrawers();
|
287
|
340
|
return true;
|
288
|
341
|
}
|
289
|
342
|
|
|
@@ -292,9 +345,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
292
|
345
|
UserDbo user = STSBusiness.getLoggedUser(this);
|
293
|
346
|
_btnLogin.setVisibility(user == null ? View.VISIBLE : View.GONE);
|
294
|
347
|
Menu menu = _navigationView.getMenu();
|
295
|
|
- for (int i = 0; i < menu.size(); i++) {
|
296
|
|
- menu.getItem(i).setVisible(user != null);
|
297
|
|
- }
|
|
348
|
+ menu.findItem(R.id.nav_restore).setVisible(user != null);
|
|
349
|
+ menu.findItem(R.id.nav_backup).setVisible(user != null);
|
|
350
|
+ menu.findItem(R.id.nav_logout).setVisible(user != null);
|
298
|
351
|
_textUserName.setText(user == null ? "" : user.getName());
|
299
|
352
|
_textUserName.setVisibility(user == null ? View.GONE : View.VISIBLE);
|
300
|
353
|
_textUserEmail.setText(user == null ? "" : user.getEmail());
|