Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/ArrivalsFragment.java
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
import it.reyboz.bustorino.backend.FiveTAPIFetcher; | import it.reyboz.bustorino.backend.FiveTAPIFetcher; | ||||
import it.reyboz.bustorino.backend.FiveTNormalizer; | import it.reyboz.bustorino.backend.FiveTNormalizer; | ||||
import it.reyboz.bustorino.backend.FiveTScraperFetcher; | import it.reyboz.bustorino.backend.FiveTScraperFetcher; | ||||
import it.reyboz.bustorino.backend.GTTJSONFetcher; | import it.reyboz.bustorino.backend.GTTJSONFetcher; | ||||
import it.reyboz.bustorino.backend.Palina; | import it.reyboz.bustorino.backend.Palina; | ||||
import it.reyboz.bustorino.backend.Passaggio; | import it.reyboz.bustorino.backend.Passaggio; | ||||
import it.reyboz.bustorino.backend.Route; | import it.reyboz.bustorino.backend.Route; | ||||
import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
import it.reyboz.bustorino.backend.utils; | |||||
import it.reyboz.bustorino.data.AppDataProvider; | import it.reyboz.bustorino.data.AppDataProvider; | ||||
import it.reyboz.bustorino.data.NextGenDB; | import it.reyboz.bustorino.data.NextGenDB; | ||||
import it.reyboz.bustorino.data.UserDB; | import it.reyboz.bustorino.data.UserDB; | ||||
import it.reyboz.bustorino.middleware.AsyncStopFavoriteAction; | import it.reyboz.bustorino.middleware.AsyncStopFavoriteAction; | ||||
public class ArrivalsFragment extends ResultListFragment implements LoaderManager.LoaderCallbacks<Cursor> { | public class ArrivalsFragment extends ResultListFragment implements LoaderManager.LoaderCallbacks<Cursor> { | ||||
private final static String KEY_STOP_ID = "stopid"; | private final static String KEY_STOP_ID = "stopid"; | ||||
private final static String KEY_STOP_NAME = "stopname"; | private final static String KEY_STOP_NAME = "stopname"; | ||||
private final static String DEBUG_TAG_ALL = "BUSTOArrivalsFragment"; | private final static String DEBUG_TAG_ALL = "BUSTOArrivalsFragment"; | ||||
private String DEBUG_TAG = DEBUG_TAG_ALL; | private String DEBUG_TAG = DEBUG_TAG_ALL; | ||||
private final static int loaderFavId = 2; | private final static int loaderFavId = 2; | ||||
private final static int loaderStopId = 1; | private final static int loaderStopId = 1; | ||||
private final static ArrivalsFetcher[] defaultFetchers = new ArrivalsFetcher[]{new FiveTAPIFetcher(), new GTTJSONFetcher(), new FiveTScraperFetcher()}; | |||||
static final String STOP_TITLE = "messageExtra"; | static final String STOP_TITLE = "messageExtra"; | ||||
private @Nullable String stopID,stopName; | private @Nullable String stopID,stopName; | ||||
private DBStatusManager prefs; | private DBStatusManager prefs; | ||||
private DBStatusManager.OnDBUpdateStatusChangeListener listener; | private DBStatusManager.OnDBUpdateStatusChangeListener listener; | ||||
private boolean justCreated = false; | private boolean justCreated = false; | ||||
private Palina lastUpdatedPalina = null; | private Palina lastUpdatedPalina = null; | ||||
private boolean needUpdateOnAttach = false; | private boolean needUpdateOnAttach = false; | ||||
private boolean fetchersChangeRequestPending = false; | private boolean fetchersChangeRequestPending = false; | ||||
private boolean stopIsInFavorites = false; | private boolean stopIsInFavorites = false; | ||||
//Views | //Views | ||||
protected ImageButton addToFavorites; | protected ImageButton addToFavorites; | ||||
protected TextView timesSourceTextView; | protected TextView timesSourceTextView; | ||||
private List<ArrivalsFetcher> fetchers = new ArrayList<>(Arrays.asList(defaultFetchers)); | private List<ArrivalsFetcher> fetchers = new ArrayList<>(Arrays.asList(utils.getDefaultArrivalsFetchers())); | ||||
private boolean reloadOnResume = true; | private boolean reloadOnResume = true; | ||||
public static ArrivalsFragment newInstance(String stopID){ | public static ArrivalsFragment newInstance(String stopID){ | ||||
return newInstance(stopID, null); | return newInstance(stopID, null); | ||||
} | } | ||||
public static ArrivalsFragment newInstance(@NonNull String stopID, @Nullable String stopName){ | public static ArrivalsFragment newInstance(@NonNull String stopID, @Nullable String stopName){ | ||||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | protected void showArrivalsSources(Palina p){ | ||||
source_txt = getString(R.string.gttjsonfetcher); | source_txt = getString(R.string.gttjsonfetcher); | ||||
break; | break; | ||||
case FiveTAPI: | case FiveTAPI: | ||||
source_txt = getString(R.string.fivetapifetcher); | source_txt = getString(R.string.fivetapifetcher); | ||||
break; | break; | ||||
case FiveTScraper: | case FiveTScraper: | ||||
source_txt = getString(R.string.fivetscraper); | source_txt = getString(R.string.fivetscraper); | ||||
break; | break; | ||||
case MatoAPI: | |||||
source_txt = getString(R.string.source_mato); | |||||
break; | |||||
case UNDETERMINED: | case UNDETERMINED: | ||||
//Don't show the view | //Don't show the view | ||||
timesSourceTextView.setVisibility(View.GONE); | source_txt = ""; | ||||
return; | break; | ||||
default: | default: | ||||
throw new IllegalStateException("Unexpected value: " + source); | throw new IllegalStateException("Unexpected value: " + source); | ||||
} | } | ||||
int count = 0; | int count = 0; | ||||
if (source!= Passaggio.Source.UNDETERMINED) | |||||
while (source != fetchers.get(0).getSourceForFetcher() && count < 100){ | while (source != fetchers.get(0).getSourceForFetcher() && count < 100){ | ||||
//we need to update the fetcher that is requested | //we need to update the fetcher that is requested | ||||
rotateFetchers(); | rotateFetchers(); | ||||
count++; | count++; | ||||
} | } | ||||
if (count>10) | if (count>10) | ||||
Log.w(DEBUG_TAG, "Tried to update the source fetcher but it didn't work"); | Log.w(DEBUG_TAG, "Tried to update the source fetcher but it didn't work"); | ||||
final String base_message = getString(R.string.times_source_fmt, source_txt); | final String base_message = getString(R.string.times_source_fmt, source_txt); | ||||
▲ Show 20 Lines • Show All 170 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