Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/ResultListFragment.java
Show All 17 Lines | |||||
package it.reyboz.bustorino.fragments; | package it.reyboz.bustorino.fragments; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.database.sqlite.SQLiteDatabase; | import android.database.sqlite.SQLiteDatabase; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.os.Parcelable; | import android.os.Parcelable; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; | ||||
import android.util.Log; | import android.util.Log; | ||||
import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||
import android.view.View; | import android.view.View; | ||||
import android.view.ViewGroup; | import android.view.ViewGroup; | ||||
Show All 16 Lines | 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; | |||||
protected FragmentListenerMain mListener; | protected FragmentListenerMain mListener; | ||||
protected TextView messageTextView; | protected TextView messageTextView; | ||||
protected ListView resultsListView; | protected ListView resultsListView; | ||||
private FloatingActionButton fabutton; | |||||
private ListAdapter mListAdapter = null; | private ListAdapter mListAdapter = null; | ||||
boolean listShown; | boolean listShown; | ||||
private Parcelable mListInstanceState = null; | private Parcelable mListInstanceState = null; | ||||
public ResultListFragment() { | public ResultListFragment() { | ||||
// Required empty public constructor | // Required empty public constructor | ||||
} | } | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | public void onResume() { | ||||
} | } | ||||
if (mListInstanceState != null) { | if (mListInstanceState != null) { | ||||
Log.d("resultsListView", "trying to restore instance state"); | Log.d("resultsListView", "trying to restore instance state"); | ||||
resultsListView.onRestoreInstanceState(mListInstanceState); | resultsListView.onRestoreInstanceState(mListInstanceState); | ||||
} | } | ||||
switch (adapterKind) { | switch (adapterKind) { | ||||
case ARRIVALS: | case ARRIVALS: | ||||
resultsListView.setOnScrollListener(new CommonScrollListener(mListener, true)); | resultsListView.setOnScrollListener(new CommonScrollListener(mListener, true)); | ||||
fabutton.show(); | mListener.showFloatingActionButton(true); | ||||
break; | break; | ||||
case STOPS: | case STOPS: | ||||
resultsListView.setOnScrollListener(new CommonScrollListener(mListener, false)); | resultsListView.setOnScrollListener(new CommonScrollListener(mListener, false)); | ||||
break; | break; | ||||
default: | default: | ||||
//NONE | //NONE | ||||
} | } | ||||
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 = 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(@NonNull Context context) { | ||||
super.onAttach(context); | super.onAttach(context); | ||||
if (context instanceof FragmentListenerMain) { | if (context instanceof FragmentListenerMain) { | ||||
mListener = (FragmentListenerMain) context; | mListener = (FragmentListenerMain) context; | ||||
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"); | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void onDetach() { | public void onDetach() { | ||||
mListener.showFloatingActionButton(false); | |||||
mListener = null; | mListener = null; | ||||
if (fabutton != null) | |||||
fabutton.show(); | |||||
super.onDetach(); | super.onDetach(); | ||||
} | } | ||||
@Override | @Override | ||||
public void onDestroyView() { | public void onDestroyView() { | ||||
resultsListView = null; | resultsListView = null; | ||||
//Log.d(getString(R.string.list_fragment_debug), "called onDestroyView"); | //Log.d(getString(R.string.list_fragment_debug), "called onDestroyView"); | ||||
Show All 28 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