Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityPrincipal.java
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||
import androidx.work.WorkInfo; | import androidx.work.WorkInfo; | ||||
import androidx.work.WorkManager; | import androidx.work.WorkManager; | ||||
import com.google.android.material.navigation.NavigationView; | import com.google.android.material.navigation.NavigationView; | ||||
import com.google.android.material.snackbar.Snackbar; | import com.google.android.material.snackbar.Snackbar; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.HashSet; | |||||
import java.util.Set; | |||||
import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
import it.reyboz.bustorino.backend.utils; | |||||
import it.reyboz.bustorino.data.DBUpdateWorker; | import it.reyboz.bustorino.data.DBUpdateWorker; | ||||
import it.reyboz.bustorino.data.DatabaseUpdate; | import it.reyboz.bustorino.data.DatabaseUpdate; | ||||
import it.reyboz.bustorino.data.PreferencesHolder; | import it.reyboz.bustorino.data.PreferencesHolder; | ||||
import it.reyboz.bustorino.data.gtfs.GtfsDatabase; | import it.reyboz.bustorino.data.gtfs.GtfsDatabase; | ||||
import it.reyboz.bustorino.fragments.*; | import it.reyboz.bustorino.fragments.*; | ||||
import it.reyboz.bustorino.middleware.GeneralActivity; | import it.reyboz.bustorino.middleware.GeneralActivity; | ||||
import static it.reyboz.bustorino.backend.utils.getBusStopIDFromUri; | import static it.reyboz.bustorino.backend.utils.getBusStopIDFromUri; | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
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 | |||||
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. | ||||
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 360 Lines • ▼ Show 20 Lines | public void requestArrivalsForStopID(String ID) { | ||||
// 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(); | //probableFragment = createAndShowMainFragment(); | ||||
} | } | ||||
} else { | |||||
//the MainScreeFragment is shown, nothing to do | |||||
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(); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | class ToolbarItemClickListener implements Toolbar.OnMenuItemClickListener{ | ||||
return true; | return true; | ||||
case R.id.action_experiments: | case R.id.action_experiments: | ||||
startActivity(new Intent(ActivityPrincipal.this, ActivityExperiments.class)); | startActivity(new Intent(ActivityPrincipal.this, ActivityExperiments.class)); | ||||
default: | default: | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Adjust setting to match the default ones | |||||
*/ | |||||
private void manageDefaultValuesForSettings(){ | |||||
SharedPreferences mainSharedPref = PreferenceManager.getDefaultSharedPreferences(this); | |||||
SharedPreferences.Editor editor = mainSharedPref.edit(); | |||||
//Main fragment to show | |||||
String screen = mainSharedPref.getString(SettingsFragment.PREF_KEY_STARTUP_SCREEN, ""); | |||||
boolean edit = false; | |||||
if (screen.isEmpty()){ | |||||
editor.putString(SettingsFragment.PREF_KEY_STARTUP_SCREEN, "arrivals"); | |||||
edit=true; | |||||
} | |||||
//Fetchers | |||||
final Set<String> setSelected = mainSharedPref.getStringSet(SettingsFragment.KEY_ARRIVALS_FETCHERS_USE, new HashSet<>()); | |||||
if (setSelected.isEmpty()){ | |||||
String[] defaultVals = getResources().getStringArray(R.array.arrivals_sources_values_default); | |||||
editor.putStringSet(SettingsFragment.KEY_ARRIVALS_FETCHERS_USE, utils.convertArrayToSet(defaultVals)); | |||||
edit=true; | |||||
} | |||||
if (edit){ | |||||
editor.commit(); | |||||
} | |||||
} | |||||
} | } |
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