Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/FragmentHelper.java
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | public class FragmentHelper { | ||||
} | } | ||||
/** | /** | ||||
* Called when you need to create a fragment for a specified Palina | * Called when you need to create a fragment for a specified Palina | ||||
* @param p the Stop that needs to be displayed | * @param p the Stop that needs to be displayed | ||||
*/ | */ | ||||
public void createOrUpdateStopFragment(Palina p, boolean addToBackStack){ | public void createOrUpdateStopFragment(Palina p, boolean addToBackStack){ | ||||
boolean sameFragment; | boolean sameFragment; | ||||
ArrivalsFragment arrivalsFragment; | ArrivalsFragment arrivalsFragment = null; | ||||
if(managerWeakRef.get()==null || shouldHaltAllActivities) { | if(managerWeakRef.get()==null || shouldHaltAllActivities) { | ||||
//SOMETHING WENT VERY WRONG | //SOMETHING WENT VERY WRONG | ||||
Log.e(DEBUG_TAG, "We are asked for a new stop but we can't show anything"); | Log.e(DEBUG_TAG, "We are asked for a new stop but we can't show anything"); | ||||
return; | return; | ||||
} | } | ||||
FragmentManager fm = managerWeakRef.get(); | FragmentManager fm = managerWeakRef.get(); | ||||
if(fm.findFragmentById(primaryFrameLayout) instanceof ArrivalsFragment) { | if(fm.findFragmentById(primaryFrameLayout) instanceof ArrivalsFragment) { | ||||
arrivalsFragment = (ArrivalsFragment) fm.findFragmentById(primaryFrameLayout); | arrivalsFragment = (ArrivalsFragment) fm.findFragmentById(primaryFrameLayout); | ||||
//Log.d(DEBUG_TAG, "Arrivals are for fragment with same stop?"); | //Log.d(DEBUG_TAG, "Arrivals are for fragment with same stop?"); | ||||
assert arrivalsFragment != null; | if (arrivalsFragment == null) sameFragment = false; | ||||
sameFragment = arrivalsFragment.isFragmentForTheSameStop(p); | else sameFragment = arrivalsFragment.isFragmentForTheSameStop(p); | ||||
} else { | } else { | ||||
sameFragment = false; | sameFragment = false; | ||||
Log.d(DEBUG_TAG, "We aren't showing an ArrivalsFragment"); | Log.d(DEBUG_TAG, "We aren't showing an ArrivalsFragment"); | ||||
} | } | ||||
setLastSuccessfullySearchedBusStop(p); | setLastSuccessfullySearchedBusStop(p); | ||||
if (sameFragment){ | |||||
Log.d("BusTO", "Same bus stop, accessing existing fragment"); | |||||
arrivalsFragment = (ArrivalsFragment) fm.findFragmentById(primaryFrameLayout); | |||||
if (arrivalsFragment == null) sameFragment = false; | |||||
} | |||||
if(!sameFragment) { | if(!sameFragment) { | ||||
//set the String to be displayed on the fragment | //set the String to be displayed on the fragment | ||||
String displayName = p.getStopDisplayName(); | String displayName = p.getStopDisplayName(); | ||||
String displayStuff; | |||||
if (displayName != null && displayName.length() > 0) { | if (displayName != null && displayName.length() > 0) { | ||||
arrivalsFragment = ArrivalsFragment.newInstance(p.ID,displayName); | arrivalsFragment = ArrivalsFragment.newInstance(p.ID,displayName); | ||||
} else { | } else { | ||||
arrivalsFragment = ArrivalsFragment.newInstance(p.ID); | arrivalsFragment = ArrivalsFragment.newInstance(p.ID); | ||||
} | } | ||||
String probableTag = ResultListFragment.getFragmentTag(p); | String probableTag = ResultListFragment.getFragmentTag(p); | ||||
attachFragmentToContainer(fm,arrivalsFragment,new AttachParameters(probableTag, true, addToBackStack)); | attachFragmentToContainer(fm,arrivalsFragment,new AttachParameters(probableTag, true, addToBackStack)); | ||||
} else { | |||||
Log.d("BusTO", "Same bus stop, accessing existing fragment"); | |||||
arrivalsFragment = (ArrivalsFragment) fm.findFragmentById(primaryFrameLayout); | |||||
} | } | ||||
// DO NOT CALL `setListAdapter` ever on arrivals fragment | // DO NOT CALL `setListAdapter` ever on arrivals fragment | ||||
arrivalsFragment.updateFragmentData(p); | arrivalsFragment.updateFragmentData(p); | ||||
// enable fragment auto refresh | // enable fragment auto refresh | ||||
arrivalsFragment.setReloadOnResume(true); | arrivalsFragment.setReloadOnResume(true); | ||||
listenerMain.hideKeyboard(); | listenerMain.hideKeyboard(); | ||||
toggleSpinner(false); | toggleSpinner(false); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | protected void attachFragmentToContainer(FragmentManager fm,Fragment fragment, AttachParameters parameters){ | ||||
ft.commit(); | ft.commit(); | ||||
//fm.executePendingTransactions(); | //fm.executePendingTransactions(); | ||||
} | } | ||||
public synchronized void setBlockAllActivities(boolean shouldI) { | public synchronized void setBlockAllActivities(boolean shouldI) { | ||||
this.shouldHaltAllActivities = shouldI; | this.shouldHaltAllActivities = shouldI; | ||||
} | } | ||||
public void stopLastRequestIfNeeded(){ | public void stopLastRequestIfNeeded(boolean interruptIfRunning){ | ||||
if(lastTaskRef == null) return; | if(lastTaskRef == null) return; | ||||
AsyncDataDownload task = lastTaskRef.get(); | AsyncDataDownload task = lastTaskRef.get(); | ||||
if(task!=null){ | if(task!=null){ | ||||
task.cancel(false); | task.cancel(interruptIfRunning); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Wrapper to show the errors/status that happened | * Wrapper to show the errors/status that happened | ||||
* @param res result from Fetcher | * @param res result from Fetcher | ||||
*/ | */ | ||||
public void showErrorMessage(Fetcher.Result res){ | public void showErrorMessage(Fetcher.Result res){ | ||||
▲ Show 20 Lines • Show All 59 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