Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/ResultListFragment.java
Show All 33 Lines | |||||
import android.widget.*; | import android.widget.*; | ||||
import com.google.android.material.floatingactionbutton.FloatingActionButton; | import com.google.android.material.floatingactionbutton.FloatingActionButton; | ||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
import it.reyboz.bustorino.backend.FiveTNormalizer; | import it.reyboz.bustorino.backend.FiveTNormalizer; | ||||
import it.reyboz.bustorino.backend.Palina; | import it.reyboz.bustorino.backend.Palina; | ||||
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.middleware.UserDB; | import it.reyboz.bustorino.data.UserDB; | ||||
/** | /** | ||||
* This is a generalized fragment that can be used both for | * This is a generalized fragment that can be used both for | ||||
* | * | ||||
* | * | ||||
*/ | */ | ||||
public class ResultListFragment extends Fragment{ | public class ResultListFragment extends Fragment{ | ||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | ||||
static final String LIST_TYPE = "list-type"; | static final String LIST_TYPE = "list-type"; | ||||
protected static final String LIST_STATE = "list_state"; | protected static final String LIST_STATE = "list_state"; | ||||
protected static final String MESSAGE_TEXT_VIEW = "message_text_view"; | protected static final String MESSAGE_TEXT_VIEW = "message_text_view"; | ||||
private FragmentKind adapterKind; | private FragmentKind adapterKind; | ||||
private boolean adapterSet = false; | private boolean adapterSet = false; | ||||
protected FragmentListener mListener; | protected FragmentListenerMain mListener; | ||||
protected TextView messageTextView; | protected TextView messageTextView; | ||||
protected ListView resultsListView; | protected ListView resultsListView; | ||||
private FloatingActionButton fabutton; | private FloatingActionButton fabutton; | ||||
private ListAdapter mListAdapter = null; | private ListAdapter mListAdapter = null; | ||||
boolean listShown; | boolean listShown; | ||||
private Parcelable mListInstanceState = null; | private Parcelable mListInstanceState = null; | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||
@Override | @Override | ||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||||
/* | /* | ||||
* Casting because of Javamerda | * Casting because of Javamerda | ||||
* @url http://stackoverflow.com/questions/30549485/androids-list-view-parameterized-type-in-adapterview-onitemclicklistener | * @url http://stackoverflow.com/questions/30549485/androids-list-view-parameterized-type-in-adapterview-onitemclicklistener | ||||
*/ | */ | ||||
Stop busStop = (Stop) parent.getItemAtPosition(position); | Stop busStop = (Stop) parent.getItemAtPosition(position); | ||||
mListener.createFragmentForStop(busStop.ID); | mListener.requestArrivalsForStopID(busStop.ID); | ||||
} | } | ||||
}); | }); | ||||
// set the textviewMessage | // set the textviewMessage | ||||
setTextViewMessage(getString(R.string.results)); | setTextViewMessage(getString(R.string.results)); | ||||
break; | break; | ||||
case ARRIVALS: | case ARRIVALS: | ||||
resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | public void onResume() { | ||||
} | } | ||||
mListener.readyGUIfor(adapterKind); | mListener.readyGUIfor(adapterKind); | ||||
} | } | ||||
@Override | @Override | ||||
public void onPause() { | public void onPause() { | ||||
if (adapterKind.equals(FragmentKind.ARRIVALS)) { | if (adapterKind.equals(FragmentKind.ARRIVALS)) { | ||||
SwipeRefreshLayout reflay = (SwipeRefreshLayout) getActivity().findViewById(R.id.listRefreshLayout); | SwipeRefreshLayout reflay = getActivity().findViewById(R.id.listRefreshLayout); | ||||
reflay.setEnabled(false); | reflay.setEnabled(false); | ||||
Log.d("BusTO Fragment " + this.getTag(), "RefreshLayout disabled"); | Log.d("BusTO Fragment " + this.getTag(), "RefreshLayout disabled"); | ||||
} | } | ||||
super.onPause(); | super.onPause(); | ||||
} | } | ||||
@Override | @Override | ||||
public void onAttach(Context context) { | public void onAttach(Context context) { | ||||
super.onAttach(context); | super.onAttach(context); | ||||
if (context instanceof FragmentListener) { | if (context instanceof FragmentListenerMain) { | ||||
mListener = (FragmentListener) context; | mListener = (FragmentListenerMain) context; | ||||
fabutton = (FloatingActionButton) getActivity().findViewById(R.id.floatingActionButton); | fabutton = (FloatingActionButton) getActivity().findViewById(R.id.floatingActionButton); | ||||
} else { | } else { | ||||
throw new RuntimeException(context.toString() | throw new RuntimeException(context.toString() | ||||
+ " must implement ResultFragmentListener"); | + " must implement ResultFragmentListener"); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public class ResultListFragment extends Fragment{ | ||||
* Set the message textView | * Set the message textView | ||||
* @param message the whole message to write in the textView | * @param message the whole message to write in the textView | ||||
*/ | */ | ||||
public void setTextViewMessage(String message) { | public void setTextViewMessage(String message) { | ||||
messageTextView.setText(message); | messageTextView.setText(message); | ||||
messageTextView.setVisibility(View.VISIBLE); | messageTextView.setVisibility(View.VISIBLE); | ||||
} | } | ||||
} | } | ||||
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