Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityPrincipal.java
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | ||||
private NavigationView mNavView; | private NavigationView mNavView; | ||||
private ActionBarDrawerToggle drawerToggle; | private ActionBarDrawerToggle drawerToggle; | ||||
private final static String DEBUG_TAG="BusTO Act Principal"; | private final static String DEBUG_TAG="BusTO Act Principal"; | ||||
private final static String TAG_FAVORITES="favorites_frag"; | private final static String TAG_FAVORITES="favorites_frag"; | ||||
private Snackbar snackbar; | private Snackbar snackbar; | ||||
private boolean showingMainFragmentFromOther = false; | private boolean showingMainFragmentFromOther = false; | ||||
private boolean onCreateComplete = false; | |||||
@Override | @Override | ||||
protected void onCreate(@Nullable Bundle savedInstanceState) { | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_principal); | setContentView(R.layout.activity_principal); | ||||
final SharedPreferences theShPr = getMainSharedPreferences(); | final SharedPreferences theShPr = getMainSharedPreferences(); | ||||
boolean showingArrivalsForStop = false; | boolean showingArrivalsFromIntent = false; | ||||
//database check | //database check | ||||
GtfsDatabase gtfsDB = GtfsDatabase.Companion.getGtfsDatabase(this); | GtfsDatabase gtfsDB = GtfsDatabase.Companion.getGtfsDatabase(this); | ||||
final int db_version = gtfsDB.getOpenHelper().getReadableDatabase().getVersion(); | final int db_version = gtfsDB.getOpenHelper().getReadableDatabase().getVersion(); | ||||
boolean dataUpdateRequested = false; | boolean dataUpdateRequested = false; | ||||
final int old_version = PreferencesHolder.getGtfsDBVersion(theShPr); | final int old_version = PreferencesHolder.getGtfsDBVersion(theShPr); | ||||
Log.d(DEBUG_TAG, "GTFS Database: old version is "+old_version+ ", new version is "+db_version); | Log.d(DEBUG_TAG, "GTFS Database: old version is "+old_version+ ", new version is "+db_version); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
//---------------------------- START INTENT CHECK QUEUE ------------------------------------ | //---------------------------- START INTENT CHECK QUEUE ------------------------------------ | ||||
// Intercept calls from URL intent | // Intercept calls from URL intent | ||||
boolean tryedFromIntent = false; | boolean tryedFromIntent = false; | ||||
String busStopID = null; | String busStopID = null; | ||||
Uri data = getIntent().getData(); | Uri data = getIntent().getData(); | ||||
if (data != null) { | if (data != null) { | ||||
busStopID = getBusStopIDFromUri(data); | busStopID = getBusStopIDFromUri(data); | ||||
Log.d(DEBUG_TAG, "Opening Intent: busStopID: "+busStopID); | |||||
tryedFromIntent = true; | tryedFromIntent = true; | ||||
} | } | ||||
// Intercept calls from other activities | // Intercept calls from other activities | ||||
if (!tryedFromIntent) { | if (!tryedFromIntent) { | ||||
Bundle b = getIntent().getExtras(); | Bundle b = getIntent().getExtras(); | ||||
if (b != null) { | if (b != null) { | ||||
busStopID = b.getString("bus-stop-ID"); | busStopID = b.getString("bus-stop-ID"); | ||||
Show All 18 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
// This shows a luser warning | // This shows a luser warning | ||||
Toast.makeText(getApplicationContext(), | Toast.makeText(getApplicationContext(), | ||||
R.string.insert_bus_stop_number_error, Toast.LENGTH_SHORT).show(); | R.string.insert_bus_stop_number_error, Toast.LENGTH_SHORT).show(); | ||||
} | } | ||||
} else { | } else { | ||||
// If you are here an intent has worked successfully | // If you are here an intent has worked successfully | ||||
//setBusStopSearchByIDEditText(busStopID); | //setBusStopSearchByIDEditText(busStopID); | ||||
//Log.d(DEBUG_TAG, "Requesting arrivals for stop "+busStopID+" from intent"); | |||||
requestArrivalsForStopID(busStopID); | requestArrivalsForStopID(busStopID); //this shows the fragment, too | ||||
showingArrivalsForStop = true; | showingArrivalsFromIntent = true; | ||||
} | } | ||||
//Try (hopefully) database update | //Try (hopefully) database update | ||||
if(!dataUpdateRequested) | if(!dataUpdateRequested) | ||||
DatabaseUpdate.requestDBUpdateWithWork(this, false, false); | DatabaseUpdate.requestDBUpdateWithWork(this, false, false); | ||||
/* | /* | ||||
Watch for database update | Watch for database update | ||||
*/ | */ | ||||
Show All 26 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
}); | }); | ||||
// show the main fragment | // show the main fragment | ||||
Fragment f = getSupportFragmentManager().findFragmentById(R.id.mainActContentFrame); | Fragment f = getSupportFragmentManager().findFragmentById(R.id.mainActContentFrame); | ||||
Log.d(DEBUG_TAG, "OnCreate the fragment is "+f); | Log.d(DEBUG_TAG, "OnCreate the fragment is "+f); | ||||
String vl = PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsFragment.PREF_KEY_STARTUP_SCREEN, ""); | String vl = PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsFragment.PREF_KEY_STARTUP_SCREEN, ""); | ||||
//if (vl.length() == 0 || vl.equals("arrivals")) { | //if (vl.length() == 0 || vl.equals("arrivals")) { | ||||
// showMainFragment(); | // showMainFragment(); | ||||
Log.d(DEBUG_TAG, "The default screen to open is: "+vl); | Log.d(DEBUG_TAG, "The default screen to open is: "+vl); | ||||
if(showingArrivalsForStop){ | if (showingArrivalsFromIntent){ | ||||
showMainFragment(false); | //do nothing but exclude a case | ||||
} else if (vl.equals("map")){ | } | ||||
else if (vl.equals("map")){ | |||||
requestMapFragment(false); | requestMapFragment(false); | ||||
} else if(vl.equals("favorites")){ | } else if(vl.equals("favorites")){ | ||||
checkAndShowFavoritesFragment(getSupportFragmentManager(), false); | checkAndShowFavoritesFragment(getSupportFragmentManager(), false); | ||||
} else if(vl.equals("lines")){ | } else if(vl.equals("lines")){ | ||||
showLinesFragment(getSupportFragmentManager(), false, null); | showLinesFragment(getSupportFragmentManager(), false, null); | ||||
} else{ | } else { | ||||
showMainFragment(false); | showMainFragment(false); | ||||
} | } | ||||
onCreateComplete = true; | |||||
} | } | ||||
private ActionBarDrawerToggle setupDrawerToggle(Toolbar toolbar) { | private ActionBarDrawerToggle setupDrawerToggle(Toolbar toolbar) { | ||||
// NOTE: Make sure you pass in a valid toolbar reference. ActionBarDrawToggle() does not require it | // NOTE: Make sure you pass in a valid toolbar reference. ActionBarDrawToggle() does not require it | ||||
// and will not render the hamburger icon without it. | // and will not render the hamburger icon without it. | ||||
return new ActionBarDrawerToggle(this, mDrawer, toolbar, R.string.drawer_open, R.string.drawer_close); | return new ActionBarDrawerToggle(this, mDrawer, toolbar, R.string.drawer_open, R.string.drawer_close); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | private static void showMainFragment(FragmentManager fraMan, MainScreenFragment fragment, boolean addToBackStack){ | ||||
R.anim.fade_out, // exit | R.anim.fade_out, // exit | ||||
R.anim.fade_in, // popEnter | R.anim.fade_in, // popEnter | ||||
R.anim.slide_out // popExit | R.anim.slide_out // popExit | ||||
)*/ | )*/ | ||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | ||||
if (addToBackStack) ft.addToBackStack(null); | if (addToBackStack) ft.addToBackStack(null); | ||||
ft.commit(); | ft.commit(); | ||||
} | } | ||||
/** | |||||
* Show the fragment by adding it to the backstack | |||||
* @param fraMan the fragmentManager | |||||
* @param arguments args for the fragment | |||||
*/ | |||||
private static void createShowMainFragment(FragmentManager fraMan, Bundle arguments, boolean addToBackStack){ | |||||
FragmentTransaction ft = fraMan.beginTransaction() | |||||
.replace(R.id.mainActContentFrame, MainScreenFragment.class, arguments, MainScreenFragment.FRAGMENT_TAG) | |||||
.setReorderingAllowed(false) | |||||
/*.setCustomAnimations( | |||||
R.anim.slide_in, // enter | |||||
R.anim.fade_out, // exit | |||||
R.anim.fade_in, // popEnter | |||||
R.anim.slide_out // popExit | |||||
)*/ | |||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | |||||
if (addToBackStack) ft.addToBackStack(null); | |||||
ft.commit(); | |||||
} | |||||
private void requestMapFragment(final boolean allowReturn){ | private void requestMapFragment(final boolean allowReturn){ | ||||
final String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE; | final String permission = Manifest.permission.WRITE_EXTERNAL_STORAGE; | ||||
int result = askForPermissionIfNeeded(permission, STORAGE_PERMISSION_REQ); | int result = askForPermissionIfNeeded(permission, STORAGE_PERMISSION_REQ); | ||||
switch (result) { | switch (result) { | ||||
case PERMISSION_OK: | case PERMISSION_OK: | ||||
createAndShowMapFragment(null, allowReturn); | createAndShowMapFragment(null, allowReturn); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | public void requestArrivalsForStopID(String ID) { | ||||
Fragment fragment = fraMan.findFragmentByTag(MainScreenFragment.FRAGMENT_TAG); | Fragment fragment = fraMan.findFragmentByTag(MainScreenFragment.FRAGMENT_TAG); | ||||
Log.d(DEBUG_TAG, "Requested main fragment, not visible. Search by TAG: "+fragment); | Log.d(DEBUG_TAG, "Requested main fragment, not visible. Search by TAG: "+fragment); | ||||
if(fragment!=null){ | if(fragment!=null){ | ||||
//the fragment is there but not shown | //the fragment is there but not shown | ||||
probableFragment = (MainScreenFragment) fragment; | probableFragment = (MainScreenFragment) fragment; | ||||
// set the flag | // set the flag | ||||
probableFragment.setSuppressArrivalsReload(true); | probableFragment.setSuppressArrivalsReload(true); | ||||
showMainFragment(fraMan, probableFragment, true); | showMainFragment(fraMan, probableFragment, true); | ||||
probableFragment.requestArrivalsForStopID(ID); | |||||
} else { | } else { | ||||
//createAndShowMainFragment | //createAndShowMainFragment | ||||
// we have no fragment | // we have no fragment | ||||
probableFragment = MainScreenFragment.newInstance(); | final Bundle args = new Bundle(); | ||||
showMainFragment(fraMan, probableFragment,true); | args.putString(MainScreenFragment.PENDING_STOP_SEARCH, ID); | ||||
//if onCreate is complete, then we are not asking for the first showing fragment | |||||
boolean addtobackstack = onCreateComplete; | |||||
createShowMainFragment(fraMan, args ,addtobackstack); | |||||
//probableFragment = createAndShowMainFragment(); | //probableFragment = createAndShowMainFragment(); | ||||
} | } | ||||
} | } | ||||
probableFragment.requestArrivalsForStopID(ID); | |||||
mNavView.setCheckedItem(R.id.nav_arrivals); | mNavView.setCheckedItem(R.id.nav_arrivals); | ||||
} | } | ||||
@Override | @Override | ||||
public void toggleSpinner(boolean state) { | public void toggleSpinner(boolean state) { | ||||
MainScreenFragment probableFragment = getMainFragmentIfVisible(); | MainScreenFragment probableFragment = getMainFragmentIfVisible(); | ||||
if (probableFragment!=null){ | if (probableFragment!=null){ | ||||
probableFragment.toggleSpinner(state); | probableFragment.toggleSpinner(state); | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register