Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityPrincipal.java
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | ||||
private boolean showingMainFragmentFromOther = false; | private boolean showingMainFragmentFromOther = false; | ||||
private boolean onCreateComplete = 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); | ||||
Log.d(DEBUG_TAG, "onCreate, savedInstanceState is: "+savedInstanceState); | |||||
setContentView(R.layout.activity_principal); | setContentView(R.layout.activity_principal); | ||||
final SharedPreferences theShPr = getMainSharedPreferences(); | final SharedPreferences theShPr = getMainSharedPreferences(); | ||||
boolean showingArrivalsFromIntent = 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(); | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
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 (showingArrivalsFromIntent){ | if (showingArrivalsFromIntent){ | ||||
//do nothing but exclude a case | //do nothing but exclude a case | ||||
} | }else if (savedInstanceState==null) { | ||||
else if (vl.equals("map")){ | //we are not restarting the activity from nothing | ||||
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; | onCreateComplete = true; | ||||
//last but not least, set the good default values | //last but not least, set the good default values | ||||
manageDefaultValuesForSettings(); | manageDefaultValuesForSettings(); | ||||
} | } | ||||
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. | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | ||||
// There are 2 signatures and only `onPostCreate(Bundle state)` shows the hamburger icon. | // There are 2 signatures and only `onPostCreate(Bundle state)` shows the hamburger icon. | ||||
@Override | @Override | ||||
protected void onPostCreate(Bundle savedInstanceState) { | protected void onPostCreate(Bundle savedInstanceState) { | ||||
super.onPostCreate(savedInstanceState); | super.onPostCreate(savedInstanceState); | ||||
// Sync the toggle state after onRestoreInstanceState has occurred. | // Sync the toggle state after onRestoreInstanceState has occurred. | ||||
drawerToggle.syncState(); | drawerToggle.syncState(); | ||||
} | } | ||||
@Override | @Override | ||||
public void onConfigurationChanged(@NonNull Configuration newConfig) { | public void onConfigurationChanged(@NonNull Configuration newConfig) { | ||||
super.onConfigurationChanged(newConfig); | super.onConfigurationChanged(newConfig); | ||||
// Pass any configuration change to the drawer toggles | // Pass any configuration change to the drawer toggles | ||||
drawerToggle.onConfigurationChanged(newConfig); | drawerToggle.onConfigurationChanged(newConfig); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | private static void showMainFragment(FragmentManager fraMan, MainScreenFragment fragment, boolean addToBackStack){ | ||||
if (addToBackStack) ft.addToBackStack(null); | if (addToBackStack) ft.addToBackStack(null); | ||||
ft.commit(); | ft.commit(); | ||||
} | } | ||||
/** | /** | ||||
* Show the fragment by adding it to the backstack | * Show the fragment by adding it to the backstack | ||||
* @param fraMan the fragmentManager | * @param fraMan the fragmentManager | ||||
* @param arguments args for the fragment | * @param arguments args for the fragment | ||||
*/ | */ | ||||
private static void createShowMainFragment(FragmentManager fraMan, Bundle arguments, boolean addToBackStack){ | private static void createShowMainFragment(FragmentManager fraMan,@Nullable Bundle arguments, boolean addToBackStack){ | ||||
FragmentTransaction ft = fraMan.beginTransaction() | FragmentTransaction ft = fraMan.beginTransaction() | ||||
.replace(R.id.mainActContentFrame, MainScreenFragment.class, arguments, MainScreenFragment.FRAGMENT_TAG) | .replace(R.id.mainActContentFrame, MainScreenFragment.class, arguments, MainScreenFragment.FRAGMENT_TAG) | ||||
.setReorderingAllowed(false) | .setReorderingAllowed(false) | ||||
/*.setCustomAnimations( | /*.setCustomAnimations( | ||||
R.anim.slide_in, // enter | R.anim.slide_in, // enter | ||||
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 | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | private static void showLinesFragment(@NonNull FragmentManager fragmentManager, boolean addToBackStack, @Nullable Bundle fragArgs){ | ||||
} | } | ||||
if (addToBackStack) | if (addToBackStack) | ||||
ft.addToBackStack("lines"); | ft.addToBackStack("lines"); | ||||
ft.setReorderingAllowed(true) | ft.setReorderingAllowed(true) | ||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) | .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) | ||||
.commit(); | .commit(); | ||||
} | } | ||||
private MainScreenFragment showMainFragment(boolean addToBackStack){ | private void showMainFragment(boolean addToBackStack){ | ||||
FragmentManager fraMan = getSupportFragmentManager(); | FragmentManager fraMan = getSupportFragmentManager(); | ||||
Fragment fragment = fraMan.findFragmentByTag(MainScreenFragment.FRAGMENT_TAG); | Fragment fragment = fraMan.findFragmentByTag(MainScreenFragment.FRAGMENT_TAG); | ||||
final MainScreenFragment mainScreenFragment; | final MainScreenFragment mainScreenFragment; | ||||
if (fragment==null | !(fragment instanceof MainScreenFragment)){ | if (fragment==null | !(fragment instanceof MainScreenFragment)){ | ||||
mainScreenFragment = MainScreenFragment.newInstance(); | createShowMainFragment(fraMan, null, addToBackStack); | ||||
//mainScreenFragment = createAndShowMainFragment(); | |||||
showMainFragment(fraMan, mainScreenFragment, addToBackStack); | |||||
} | } | ||||
else if(!fragment.isVisible()){ | else if(!fragment.isVisible()){ | ||||
mainScreenFragment = (MainScreenFragment) fragment; | mainScreenFragment = (MainScreenFragment) fragment; | ||||
showMainFragment(fraMan, mainScreenFragment, addToBackStack); | showMainFragment(fraMan, mainScreenFragment, addToBackStack); | ||||
Log.d(DEBUG_TAG, "Found the main fragment"); | Log.d(DEBUG_TAG, "Found the main fragment"); | ||||
} else{ | } else{ | ||||
mainScreenFragment = (MainScreenFragment) fragment; | mainScreenFragment = (MainScreenFragment) fragment; | ||||
} | } | ||||
return mainScreenFragment; | //return mainScreenFragment; | ||||
} | } | ||||
@Nullable | @Nullable | ||||
private MainScreenFragment getMainFragmentIfVisible(){ | private MainScreenFragment getMainFragmentIfVisible(){ | ||||
FragmentManager fraMan = getSupportFragmentManager(); | FragmentManager fraMan = getSupportFragmentManager(); | ||||
Fragment fragment = fraMan.findFragmentByTag(MainScreenFragment.FRAGMENT_TAG); | Fragment fragment = fraMan.findFragmentByTag(MainScreenFragment.FRAGMENT_TAG); | ||||
if (fragment!= null && fragment.isVisible()) return (MainScreenFragment) fragment; | if (fragment!= null && fragment.isVisible()) return (MainScreenFragment) fragment; | ||||
else return null; | else return null; | ||||
} | } | ||||
Show All 16 Lines | public void setDrawerSelectedItem(String fragmentTag){ | ||||
case FavoritesFragment.FRAGMENT_TAG: | case FavoritesFragment.FRAGMENT_TAG: | ||||
mNavView.setCheckedItem(R.id.nav_favorites_item); | mNavView.setCheckedItem(R.id.nav_favorites_item); | ||||
break; | break; | ||||
} | } | ||||
}*/ | }*/ | ||||
@Override | @Override | ||||
public void readyGUIfor(FragmentKind fragmentType) { | public void readyGUIfor(FragmentKind fragmentType) { | ||||
MainScreenFragment probableFragment = getMainFragmentIfVisible(); | MainScreenFragment mainFragmentIfVisible = getMainFragmentIfVisible(); | ||||
if (probableFragment!=null){ | if (mainFragmentIfVisible!=null){ | ||||
probableFragment.readyGUIfor(fragmentType); | mainFragmentIfVisible.readyGUIfor(fragmentType); | ||||
} | } | ||||
int titleResId; | int titleResId; | ||||
switch (fragmentType){ | switch (fragmentType){ | ||||
case MAP: | case MAP: | ||||
mNavView.setCheckedItem(R.id.nav_map_item); | mNavView.setCheckedItem(R.id.nav_map_item); | ||||
titleResId = R.string.map; | titleResId = R.string.map; | ||||
break; | break; | ||||
case FAVORITES: | case FAVORITES: | ||||
Show All 38 Lines | public void requestArrivalsForStopID(String ID) { | ||||
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); | probableFragment.requestArrivalsForStopID(ID); | ||||
} else { | } else { | ||||
//createAndShowMainFragment | |||||
// we have no fragment | // we have no fragment | ||||
final Bundle args = new Bundle(); | final Bundle args = new Bundle(); | ||||
args.putString(MainScreenFragment.PENDING_STOP_SEARCH, ID); | args.putString(MainScreenFragment.PENDING_STOP_SEARCH, ID); | ||||
//if onCreate is complete, then we are not asking for the first showing fragment | //if onCreate is complete, then we are not asking for the first showing fragment | ||||
boolean addtobackstack = onCreateComplete; | boolean addtobackstack = onCreateComplete; | ||||
createShowMainFragment(fraMan, args ,addtobackstack); | createShowMainFragment(fraMan, args ,addtobackstack); | ||||
//probableFragment = createAndShowMainFragment(); | |||||
} | } | ||||
} else { | } else { | ||||
//the MainScreeFragment is shown, nothing to do | //the MainScreeFragment is shown, nothing to do | ||||
probableFragment.requestArrivalsForStopID(ID); | probableFragment.requestArrivalsForStopID(ID); | ||||
} | } | ||||
mNavView.setCheckedItem(R.id.nav_arrivals); | mNavView.setCheckedItem(R.id.nav_arrivals); | ||||
} | } | ||||
Show All 9 Lines | public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | ||||
@Override | @Override | ||||
public void enableRefreshLayout(boolean yes) { | public void enableRefreshLayout(boolean yes) { | ||||
MainScreenFragment probableFragment = getMainFragmentIfVisible(); | MainScreenFragment probableFragment = getMainFragmentIfVisible(); | ||||
if (probableFragment!=null){ | if (probableFragment!=null){ | ||||
probableFragment.enableRefreshLayout(yes); | probableFragment.enableRefreshLayout(yes); | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void showMapCenteredOnStop(Stop stop) { | public void showMapCenteredOnStop(Stop stop) { | ||||
createAndShowMapFragment(stop, true); | createAndShowMapFragment(stop, true); | ||||
} | } | ||||
//Map Fragment stuff | //Map Fragment stuff | ||||
void createAndShowMapFragment(@Nullable Stop stop, boolean addToBackStack){ | void createAndShowMapFragment(@Nullable Stop stop, boolean addToBackStack){ | ||||
FragmentManager fm = getSupportFragmentManager(); | FragmentManager fm = getSupportFragmentManager(); | ||||
▲ Show 20 Lines • Show All 65 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