Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/ArrivalsFragment.java
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | public void onCreate(Bundle savedInstanceState) { | ||||
justCreated = true; | justCreated = true; | ||||
} | } | ||||
@Override | @Override | ||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||
Bundle savedInstanceState) { | Bundle savedInstanceState) { | ||||
View root = inflater.inflate(R.layout.fragment_arrivals, container, false); | View root = inflater.inflate(R.layout.fragment_arrivals, container, false); | ||||
messageTextView = (TextView) root.findViewById(R.id.messageTextView); | messageTextView = root.findViewById(R.id.messageTextView); | ||||
addToFavorites = (ImageButton) root.findViewById(R.id.addToFavorites); | addToFavorites = root.findViewById(R.id.addToFavorites); | ||||
resultsListView = (ListView) root.findViewById(R.id.resultsListView); | resultsListView = root.findViewById(R.id.resultsListView); | ||||
timesSourceTextView = (TextView) root.findViewById(R.id.timesSourceTextView); | timesSourceTextView = root.findViewById(R.id.timesSourceTextView); | ||||
timesSourceTextView.setOnLongClickListener(view -> { | timesSourceTextView.setOnLongClickListener(view -> { | ||||
if(!fetchersChangeRequestPending){ | if(!fetchersChangeRequestPending){ | ||||
rotateFetchers(); | rotateFetchers(); | ||||
//Show we are changing provider | //Show we are changing provider | ||||
timesSourceTextView.setText(R.string.arrival_source_changing); | timesSourceTextView.setText(R.string.arrival_source_changing); | ||||
mListener.requestArrivalsForStopID(stopID); | mListener.requestArrivalsForStopID(stopID); | ||||
fetchersChangeRequestPending = true; | fetchersChangeRequestPending = true; | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | public void setReloadOnResume(boolean reloadOnResume) { | ||||
this.reloadOnResume = reloadOnResume; | this.reloadOnResume = reloadOnResume; | ||||
} | } | ||||
/** | /** | ||||
* Give the fetchers | * Give the fetchers | ||||
* @return the list of the fetchers | * @return the list of the fetchers | ||||
*/ | */ | ||||
public ArrayList<Fetcher> getCurrentFetchers(){ | public ArrayList<Fetcher> getCurrentFetchers(){ | ||||
ArrayList<Fetcher> v = new ArrayList<Fetcher>(); | return new ArrayList<>(this.fetchers); | ||||
for (ArrivalsFetcher fetcher: fetchers){ | |||||
v.add(fetcher); | |||||
} | |||||
return v; | |||||
} | } | ||||
public ArrivalsFetcher[] getCurrentFetchersAsArray(){ | public ArrivalsFetcher[] getCurrentFetchersAsArray(){ | ||||
ArrivalsFetcher[] arr = new ArrivalsFetcher[fetchers.size()]; | ArrivalsFetcher[] arr = new ArrivalsFetcher[fetchers.size()]; | ||||
fetchers.toArray(arr); | fetchers.toArray(arr); | ||||
return arr; | return arr; | ||||
} | } | ||||
private void rotateFetchers(){ | private void rotateFetchers(){ | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | protected void showArrivalsSources(Palina p){ | ||||
case FiveTScraper: | case FiveTScraper: | ||||
source_txt = getString(R.string.fivetscraper); | source_txt = getString(R.string.fivetscraper); | ||||
break; | break; | ||||
case MatoAPI: | case MatoAPI: | ||||
source_txt = getString(R.string.source_mato); | source_txt = getString(R.string.source_mato); | ||||
break; | break; | ||||
case UNDETERMINED: | case UNDETERMINED: | ||||
//Don't show the view | //Don't show the view | ||||
source_txt = ""; | source_txt = getString(R.string.undetermined_source); | ||||
break; | 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) | 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); | ||||
timesSourceTextView.setVisibility(View.VISIBLE); | |||||
timesSourceTextView.setText(base_message); | timesSourceTextView.setText(base_message); | ||||
if (p.getTotalNumberOfPassages() > 0) { | |||||
timesSourceTextView.setVisibility(View.VISIBLE); | |||||
} else { | |||||
timesSourceTextView.setVisibility(View.INVISIBLE); | |||||
} | |||||
fetchersChangeRequestPending = false; | fetchersChangeRequestPending = false; | ||||
} | } | ||||
@Override | @Override | ||||
public void setNewListAdapter(ListAdapter adapter) { | public void setNewListAdapter(ListAdapter adapter) { | ||||
throw new UnsupportedOperationException(); | throw new UnsupportedOperationException(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 160 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