Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/ResultListFragment.java
Show All 14 Lines | BusTO - Fragments components | ||||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
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.os.Bundle; | import android.os.Bundle; | ||||
import android.os.Parcelable; | import android.os.Parcelable; | ||||
import android.support.annotation.Nullable; | import android.support.annotation.Nullable; | ||||
import android.support.v4.app.Fragment; | import android.support.v4.app.Fragment; | ||||
import android.support.v4.widget.SwipeRefreshLayout; | import android.support.v4.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; | ||||
import android.widget.*; | import android.widget.*; | ||||
import android.support.design.widget.FloatingActionButton; | import android.support.design.widget.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; | |||||
/** | /** | ||||
* 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"; | ||||
private static final String STOP_TITLE = "messageExtra"; | private static final String STOP_TITLE = "messageExtra"; | ||||
protected static final String LIST_STATE = "list_state"; | protected static final String LIST_STATE = "list_state"; | ||||
private static final String MESSAGE_TEXT_VIEW = "message_text_view"; | private 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 FragmentListener mListener; | ||||
private TextView messageTextView; | private TextView messageTextView; | ||||
private ImageButton addToFavorites; | |||||
private FloatingActionButton fabutton; | private FloatingActionButton fabutton; | ||||
private ListView resultsListView; | private ListView resultsListView; | ||||
private ListAdapter mListAdapter = null; | private ListAdapter mListAdapter = null; | ||||
boolean listShown; | boolean listShown; | ||||
private Parcelable mListInstanceState = null; | private Parcelable mListInstanceState = null; | ||||
public ResultListFragment() { | public ResultListFragment() { | ||||
Show All 29 Lines | public class ResultListFragment extends Fragment{ | ||||
@Override | @Override | ||||
public void onCreate(Bundle savedInstanceState) { | public void onCreate(Bundle savedInstanceState) { | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
if (getArguments() != null) { | if (getArguments() != null) { | ||||
adapterKind = (FragmentKind) getArguments().getSerializable(LIST_TYPE); | adapterKind = (FragmentKind) getArguments().getSerializable(LIST_TYPE); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Check if the last Bus Stop is in the favorites | |||||
* @return | |||||
*/ | |||||
public boolean isStopInFavorites(String busStopId) { | |||||
boolean found = false; | |||||
// no stop no party | |||||
if(busStopId != null) { | |||||
SQLiteDatabase userDB = new UserDB(getContext()).getReadableDatabase(); | |||||
found = UserDB.isStopInFavorites(userDB, busStopId); | |||||
} | |||||
return found; | |||||
} | |||||
@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_list_view, container, false); | View root = inflater.inflate(R.layout.fragment_list_view, container, false); | ||||
messageTextView = (TextView) root.findViewById(R.id.messageTextView); | messageTextView = (TextView) root.findViewById(R.id.messageTextView); | ||||
addToFavorites = (ImageButton) root.findViewById(R.id.addToFavorites); | |||||
if (adapterKind != null) { | if (adapterKind != null) { | ||||
resultsListView = (ListView) root.findViewById(R.id.resultsListView); | resultsListView = (ListView) root.findViewById(R.id.resultsListView); | ||||
switch (adapterKind) { | switch (adapterKind) { | ||||
case STOPS: | case STOPS: | ||||
resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||||
@Override | @Override | ||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||||
▲ Show 20 Lines • Show All 151 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); | ||||
switch (adapterKind) { | switch (adapterKind) { | ||||
case ARRIVALS: | case ARRIVALS: | ||||
messageTextView.setClickable(true); | addToFavorites.setClickable(true); | ||||
messageTextView.setOnClickListener(new View.OnClickListener() { | addToFavorites.setOnClickListener(new View.OnClickListener() { | ||||
@Override | @Override | ||||
public void onClick(View v) { | public void onClick(View v) { | ||||
// add/remove the stop in the favorites | // add/remove the stop in the favorites | ||||
mListener.toggleLastStopToFavorites(); | mListener.toggleLastStopToFavorites(); | ||||
} | } | ||||
}); | }); | ||||
break; | break; | ||||
case STOPS: | case STOPS: | ||||
messageTextView.setClickable(false); | addToFavorites.setClickable(false); | ||||
break; | break; | ||||
} | } | ||||
messageTextView.setVisibility(View.VISIBLE); | messageTextView.setVisibility(View.VISIBLE); | ||||
} | } | ||||
} |
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