Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityPrincipal.java
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
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 it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
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.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; | ||||
import static it.reyboz.bustorino.backend.utils.openIceweasel; | import static it.reyboz.bustorino.backend.utils.openIceweasel; | ||||
public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | public class ActivityPrincipal extends GeneralActivity implements FragmentListenerMain { | ||||
private DrawerLayout mDrawer; | private DrawerLayout mDrawer; | ||||
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; | ||||
@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(); | ||||
//database check | |||||
GtfsDatabase gtfsDB = GtfsDatabase.Companion.getGtfsDatabase(this); | |||||
final int db_version = gtfsDB.getOpenHelper().getReadableDatabase().getVersion(); | |||||
boolean dataUpdateRequested = false; | |||||
final int old_version = PreferencesHolder.getGtfsDBVersion(theShPr); | |||||
Log.d(DEBUG_TAG, "GTFS Database: old version is "+old_version+ ", new version is "+db_version); | |||||
if (old_version < db_version){ | |||||
//request db update | |||||
dataUpdateRequested = true; | |||||
DatabaseUpdate.requestDBUpdateWithWork(this, true, true); | |||||
PreferencesHolder.setGtfsDBVersion(theShPr, db_version); | |||||
} | |||||
Toolbar mToolbar = findViewById(R.id.default_toolbar); | Toolbar mToolbar = findViewById(R.id.default_toolbar); | ||||
setSupportActionBar(mToolbar); | setSupportActionBar(mToolbar); | ||||
if (getSupportActionBar()!=null) | if (getSupportActionBar()!=null) | ||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||||
else Log.w(DEBUG_TAG, "NO ACTION BAR"); | else Log.w(DEBUG_TAG, "NO ACTION BAR"); | ||||
mToolbar.setOnMenuItemClickListener(new ToolbarItemClickListener(this)); | mToolbar.setOnMenuItemClickListener(new ToolbarItemClickListener(this)); | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
} | } | ||||
} else { | } else { | ||||
// If you are here an intent has worked successfully | // If you are here an intent has worked successfully | ||||
//setBusStopSearchByIDEditText(busStopID); | //setBusStopSearchByIDEditText(busStopID); | ||||
requestArrivalsForStopID(busStopID); | requestArrivalsForStopID(busStopID); | ||||
} | } | ||||
//Try (hopefully) database update | //Try (hopefully) database update | ||||
if(!dataUpdateRequested) | |||||
DatabaseUpdate.requestDBUpdateWithWork(this, false, false); | DatabaseUpdate.requestDBUpdateWithWork(this, false, false); | ||||
/* | /* | ||||
Watch for database update | Watch for database update | ||||
*/ | */ | ||||
final WorkManager workManager = WorkManager.getInstance(this); | final WorkManager workManager = WorkManager.getInstance(this); | ||||
workManager.getWorkInfosForUniqueWorkLiveData(DBUpdateWorker.DEBUG_TAG) | workManager.getWorkInfosForUniqueWorkLiveData(DBUpdateWorker.DEBUG_TAG) | ||||
.observe(this, workInfoList -> { | .observe(this, workInfoList -> { | ||||
// If there are no matching work info, do nothing | // If there are no matching work info, do nothing | ||||
if (workInfoList == null || workInfoList.isEmpty()) { | if (workInfoList == null || workInfoList.isEmpty()) { | ||||
▲ Show 20 Lines • Show All 425 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