Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityPrincipal.java
Show All 26 Lines | |||||
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.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
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.fragments.FavoritesFragment; | import it.reyboz.bustorino.fragments.FavoritesFragment; | ||||
import it.reyboz.bustorino.fragments.FragmentKind; | import it.reyboz.bustorino.fragments.FragmentKind; | ||||
import it.reyboz.bustorino.fragments.FragmentListenerMain; | import it.reyboz.bustorino.fragments.FragmentListenerMain; | ||||
import it.reyboz.bustorino.fragments.MainScreenFragment; | import it.reyboz.bustorino.fragments.MainScreenFragment; | ||||
import it.reyboz.bustorino.fragments.MapFragment; | |||||
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; | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | private void setupDrawerContent(NavigationView navigationView) { | ||||
ft.addToBackStack(null); | ft.addToBackStack(null); | ||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | ||||
ft.commit(); | ft.commit(); | ||||
return true; | return true; | ||||
} else if(menuItem.getItemId() == R.id.nav_arrivals){ | } else if(menuItem.getItemId() == R.id.nav_arrivals){ | ||||
closeDrawerIfOpen(); | closeDrawerIfOpen(); | ||||
showMainFragment(); | showMainFragment(); | ||||
return true; | return true; | ||||
} else if(menuItem.getItemId() == R.id.nav_map_item){ | |||||
closeDrawerIfOpen(); | |||||
createAndShowMapFragment(null); | |||||
return true; | |||||
} | } | ||||
//selectDrawerItem(menuItem); | //selectDrawerItem(menuItem); | ||||
Log.d(DEBUG_TAG, "pressed item "+menuItem.toString()); | Log.d(DEBUG_TAG, "pressed item "+menuItem.toString()); | ||||
return true; | return true; | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | private MainScreenFragment getMainFragmentIfVisible(){ | ||||
else return null; | else return null; | ||||
} | } | ||||
@Override | @Override | ||||
public void showFloatingActionButton(boolean yes) { | public void showFloatingActionButton(boolean yes) { | ||||
//TODO | //TODO | ||||
} | } | ||||
/* | |||||
public void setDrawerSelectedItem(String fragmentTag){ | |||||
switch (fragmentTag){ | |||||
case MainScreenFragment.FRAGMENT_TAG: | |||||
mNavView.setCheckedItem(R.id.nav_arrivals); | |||||
break; | |||||
case MapFragment.FRAGMENT_TAG: | |||||
break; | |||||
case FavoritesFragment.FRAGMENT_TAG: | |||||
mNavView.setCheckedItem(R.id.nav_favorites_item); | |||||
break; | |||||
} | |||||
}*/ | |||||
@Override | @Override | ||||
public void readyGUIfor(FragmentKind fragmentType) { | public void readyGUIfor(FragmentKind fragmentType) { | ||||
MainScreenFragment probableFragment = getMainFragmentIfVisible(); | MainScreenFragment probableFragment = getMainFragmentIfVisible(); | ||||
if (probableFragment!=null){ | if (probableFragment!=null){ | ||||
probableFragment.readyGUIfor(fragmentType); | probableFragment.readyGUIfor(fragmentType); | ||||
} | } | ||||
switch (fragmentType){ | |||||
case MAP: | |||||
mNavView.setCheckedItem(R.id.nav_map_item); | |||||
break; | |||||
case FAVORITES: | |||||
mNavView.setCheckedItem(R.id.nav_favorites_item); | |||||
break; | |||||
case ARRIVALS: | |||||
case NEARBY_STOPS: | |||||
case STOPS: | |||||
case MAIN_SCREEN_FRAGMENT: | |||||
case NEARBY_ARRIVALS: | |||||
mNavView.setCheckedItem(R.id.nav_arrivals); | |||||
break; | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
public void requestArrivalsForStopID(String ID) { | public void requestArrivalsForStopID(String ID) { | ||||
//register if the request came from the main fragment or not | //register if the request came from the main fragment or not | ||||
MainScreenFragment probableFragment = getMainFragmentIfVisible(); | MainScreenFragment probableFragment = getMainFragmentIfVisible(); | ||||
showingMainFragmentFromOther = (probableFragment==null); | showingMainFragmentFromOther = (probableFragment==null); | ||||
Show All 26 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); | ||||
} | } | ||||
} | } | ||||
//Map Fragment stuff | |||||
void createAndShowMapFragment(@Nullable Stop stop){ | |||||
FragmentManager fm = getSupportFragmentManager(); | |||||
FragmentTransaction ft = fm.beginTransaction(); | |||||
MapFragment fragment = stop == null? MapFragment.getInstance(): MapFragment.getInstance(stop); | |||||
ft.replace(R.id.mainActContentFrame, fragment, MapFragment.FRAGMENT_TAG); | |||||
ft.addToBackStack(null); | |||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); | |||||
ft.commit(); | |||||
} | |||||
class ToolbarItemClickListener implements Toolbar.OnMenuItemClickListener{ | class ToolbarItemClickListener implements Toolbar.OnMenuItemClickListener{ | ||||
@Override | @Override | ||||
public boolean onMenuItemClick(MenuItem item) { | public boolean onMenuItemClick(MenuItem item) { | ||||
switch (item.getItemId()) { | switch (item.getItemId()) { | ||||
case R.id.action_about: | case R.id.action_about: | ||||
startActivity(new Intent(ActivityPrincipal.this, ActivityAbout.class)); | startActivity(new Intent(ActivityPrincipal.this, ActivityAbout.class)); | ||||
return true; | return true; | ||||
Show All 15 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