Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/MainScreenFragment.java
Show All 35 Lines | |||||
import android.widget.EditText; | import android.widget.EditText; | ||||
import android.widget.ImageButton; | import android.widget.ImageButton; | ||||
import android.widget.ProgressBar; | import android.widget.ProgressBar; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import com.google.android.material.floatingactionbutton.FloatingActionButton; | import com.google.android.material.floatingactionbutton.FloatingActionButton; | ||||
import java.util.List; | |||||
import java.util.Map; | import java.util.Map; | ||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
import it.reyboz.bustorino.backend.*; | import it.reyboz.bustorino.backend.*; | ||||
import it.reyboz.bustorino.middleware.AppLocationManager; | import it.reyboz.bustorino.middleware.AppLocationManager; | ||||
import it.reyboz.bustorino.middleware.AsyncArrivalsSearcher; | import it.reyboz.bustorino.middleware.AsyncArrivalsSearcher; | ||||
import it.reyboz.bustorino.middleware.AsyncStopsSearcher; | import it.reyboz.bustorino.middleware.AsyncStopsSearcher; | ||||
import it.reyboz.bustorino.middleware.BarcodeScanContract; | import it.reyboz.bustorino.middleware.BarcodeScanContract; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends ScreenBaseFragment implements FragmentListenerMain{ | ||||
/* | /* | ||||
* Search mode | * Search mode | ||||
*/ | */ | ||||
private static final int SEARCH_BY_NAME = 0; | private static final int SEARCH_BY_NAME = 0; | ||||
private static final int SEARCH_BY_ID = 1; | private static final int SEARCH_BY_ID = 1; | ||||
private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12 | private static final int SEARCH_BY_ROUTE = 2; // TODO: implement this -- https://gitpull.it/T12 | ||||
private int searchMode; | private int searchMode; | ||||
//private ImageButton addToFavorites; | //private ImageButton addToFavorites; | ||||
private final ArrivalsFetcher[] arrivalsFetchers = utils.getDefaultArrivalsFetchers(); | |||||
//// HIDDEN BUT IMPORTANT ELEMENTS //// | //// HIDDEN BUT IMPORTANT ELEMENTS //// | ||||
FragmentManager fragMan; | FragmentManager fragMan; | ||||
Handler mainHandler; | Handler mainHandler; | ||||
private final Runnable refreshStop = new Runnable() { | private final Runnable refreshStop = new Runnable() { | ||||
public void run() { | public void run() { | ||||
if(getContext() == null) return; | if(getContext() == null) return; | ||||
List<ArrivalsFetcher> fetcherList = utils.getDefaultArrivalsFetchers(getContext()); | |||||
ArrivalsFetcher[] arrivalsFetchers = new ArrivalsFetcher[fetcherList.size()]; | |||||
arrivalsFetchers = fetcherList.toArray(arrivalsFetchers); | |||||
if (fragMan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | if (fragMan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | ||||
ArrivalsFragment fragment = (ArrivalsFragment) fragMan.findFragmentById(R.id.resultFrame); | ArrivalsFragment fragment = (ArrivalsFragment) fragMan.findFragmentById(R.id.resultFrame); | ||||
if (fragment == null){ | if (fragment == null){ | ||||
//we create a new fragment, which is WRONG | //we create a new fragment, which is WRONG | ||||
Log.e("BusTO-RefreshStop", "Asking for refresh when there is no fragment"); | Log.e("BusTO-RefreshStop", "Asking for refresh when there is no fragment"); | ||||
// AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | // AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | ||||
} else{ | } else{ | ||||
String stopName = fragment.getStopID(); | String stopName = fragment.getStopID(); | ||||
▲ Show 20 Lines • Show All 592 Lines • ▼ Show 20 Lines | public void requestArrivalsForStopID(String ID) { | ||||
return; | return; | ||||
} | } | ||||
final boolean delayedRequest = !(pendingStopID==null); | final boolean delayedRequest = !(pendingStopID==null); | ||||
final FragmentManager framan = getChildFragmentManager(); | final FragmentManager framan = getChildFragmentManager(); | ||||
if (getContext()==null){ | if (getContext()==null){ | ||||
Log.e(DEBUG_TAG, "Asked for arrivals with null context"); | Log.e(DEBUG_TAG, "Asked for arrivals with null context"); | ||||
return; | return; | ||||
} | } | ||||
ArrivalsFetcher[] fetchers = utils.getDefaultArrivalsFetchers(getContext()).toArray(new ArrivalsFetcher[0]); | |||||
if (ID == null || ID.length() <= 0) { | if (ID == null || ID.length() <= 0) { | ||||
// we're still in UI thread, no need to mess with Progress | // we're still in UI thread, no need to mess with Progress | ||||
showToastMessage(R.string.insert_bus_stop_number_error, true); | showToastMessage(R.string.insert_bus_stop_number_error, true); | ||||
toggleSpinner(false); | toggleSpinner(false); | ||||
} else if (framan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | } else if (framan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | ||||
ArrivalsFragment fragment = (ArrivalsFragment) framan.findFragmentById(R.id.resultFrame); | ArrivalsFragment fragment = (ArrivalsFragment) framan.findFragmentById(R.id.resultFrame); | ||||
if (fragment != null && fragment.getStopID() != null && fragment.getStopID().equals(ID)){ | if (fragment != null && fragment.getStopID() != null && fragment.getStopID().equals(ID)){ | ||||
// Run with previous fetchers | // Run with previous fetchers | ||||
//fragment.getCurrentFetchers().toArray() | //fragment.getCurrentFetchers().toArray() | ||||
new AsyncArrivalsSearcher(fragmentHelper,fragment.getCurrentFetchersAsArray(), getContext()).execute(ID); | new AsyncArrivalsSearcher(fragmentHelper,fragment.getCurrentFetchersAsArray(), getContext()).execute(ID); | ||||
} else{ | } else{ | ||||
new AsyncArrivalsSearcher(fragmentHelper, arrivalsFetchers, getContext()).execute(ID); | new AsyncArrivalsSearcher(fragmentHelper, fetchers, getContext()).execute(ID); | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
new AsyncArrivalsSearcher(fragmentHelper,arrivalsFetchers, getContext()).execute(ID); | new AsyncArrivalsSearcher(fragmentHelper,fetchers, getContext()).execute(ID); | ||||
Log.d(DEBUG_TAG, "Started search for arrivals of stop " + ID); | Log.d(DEBUG_TAG, "Started search for arrivals of stop " + ID); | ||||
} | } | ||||
} | } | ||||
/////////// LOCATION METHODS ////////// | /////////// LOCATION METHODS ////////// | ||||
/* | /* | ||||
private void startStopRequest(String provider) { | private void startStopRequest(String provider) { | ||||
Log.d(DEBUG_TAG, "Provider " + provider + " got enabled"); | Log.d(DEBUG_TAG, "Provider " + provider + " got enabled"); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | class NearbyStopsRequester implements Runnable { | ||||
} else if(!haveProviders){ | } else if(!haveProviders){ | ||||
Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION"); | Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
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