|
|
@@ -47,7 +47,7 @@ import android.widget.TextView;
|
|
|
/**
|
|
|
* Fragment to be inflated showing the festivals schedule.
|
|
|
* Contains a date selector and a ScrollView with all the activities for the day.
|
|
|
- *
|
|
|
+ *
|
|
|
* @author Inigo Valentin
|
|
|
*
|
|
|
*/
|
|
|
@@ -59,24 +59,22 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
private int dateCount = 0;
|
|
|
private int selected = 0;
|
|
|
|
|
|
- //Indicates official schedule
|
|
|
- private int schedule;
|
|
|
-
|
|
|
//Map stuff for the dialog
|
|
|
private MapView mapView;
|
|
|
private GoogleMap map;
|
|
|
private LatLng location;
|
|
|
+ private int route;
|
|
|
private View view;
|
|
|
private String markerName = "";
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Run when the fragment is inflated.
|
|
|
* Assigns views, gets the date and does the first call to the populateSchedule function.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param inflater A LayoutInflater to manage views
|
|
|
* @param container The container View
|
|
|
* @param savedInstanceState Bundle containing the state
|
|
|
- *
|
|
|
+ *
|
|
|
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
|
|
|
*/
|
|
|
@SuppressLint("InflateParams") //Throws unknown error when done properly.
|
|
|
@@ -89,7 +87,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
|
|
|
//Set bundle for the map
|
|
|
bund = savedInstanceState;
|
|
|
-
|
|
|
+
|
|
|
//Load the layout
|
|
|
view = inflater.inflate(R.layout.fragment_layout_schedule, null);
|
|
|
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
|
|
@@ -104,8 +102,8 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
//Get schedule type
|
|
|
TextView title = (TextView) view.findViewById(R.id.tv_schedule_type);
|
|
|
Bundle bundle = this.getArguments();
|
|
|
- schedule = bundle.getInt(GM.SCHEDULE.KEY, GM.SCHEDULE.CITY);
|
|
|
-
|
|
|
+ final int schedule = bundle.getInt(GM.SCHEDULE.KEY, GM.SCHEDULE.CITY);
|
|
|
+
|
|
|
//Set the title
|
|
|
if (schedule == GM.SCHEDULE.CITY) {
|
|
|
((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca_schedule));
|
|
|
@@ -121,10 +119,10 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
|
|
|
Cursor cursor;
|
|
|
if (schedule == GM.SCHEDULE.MARGOLARIAK) {
|
|
|
- cursor = db.rawQuery("SELECT DISTINCT date(start) AS daydate FROM festival_event WHERE strftime('%Y', start) = '" + year + "' AND strftime('%H', start) > '06' AND gm = 1 ORDER BY daydate;", null);
|
|
|
+ cursor = db.rawQuery("SELECT DISTINCT date(start) AS daydate FROM festival_event_gm WHERE strftime('%Y', start) = '" + year + "' AND strftime('%H', start) > '06' ORDER BY daydate;", null);
|
|
|
}
|
|
|
else{
|
|
|
- cursor = db.rawQuery("SELECT DISTINCT date(start) AS daydate FROM festival_event WHERE strftime('%Y', start) = '" + year + "' AND strftime('%H', start) > '06' AND gm = 0 ORDER BY daydate;", null);
|
|
|
+ cursor = db.rawQuery("SELECT DISTINCT date(start) AS daydate FROM festival_event_vity WHERE strftime('%Y', start) = '" + year + "' AND strftime('%H', start) > '06' ORDER BY daydate;", null);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -152,17 +150,17 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
selected --;
|
|
|
- populateSchedule();
|
|
|
+ populateSchedule(schedule);
|
|
|
}
|
|
|
});
|
|
|
btR.setOnClickListener(new OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
selected ++;
|
|
|
- populateSchedule();
|
|
|
+ populateSchedule(schedule);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
//Assign the filter text
|
|
|
EditText etFilter = (EditText) view.findViewById(R.id.et_schedule_filter);
|
|
|
etFilter.addTextChangedListener(new TextWatcher() {
|
|
|
@@ -176,25 +174,25 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
@Override
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
//Repopulate when the text is changed
|
|
|
- populateSchedule();
|
|
|
-
|
|
|
+ populateSchedule(schedule);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
//Populate the activity list
|
|
|
- populateSchedule();
|
|
|
-
|
|
|
+ populateSchedule(schedule);
|
|
|
+
|
|
|
//Return the fragment view
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Populates the list of activities with the ones n the selected day.
|
|
|
- *
|
|
|
+ * Populates the list of activities with the ones in the selected day.
|
|
|
+ *
|
|
|
+ * @param schedule GM.SCHEDULE.GM or GM.SCHEDULE.CITY
|
|
|
*/
|
|
|
@SuppressLint({"InflateParams", "SwitchIntDef"})
|
|
|
//Views are added from a loop: I can't specify the parent when inflating.
|
|
|
- private int populateSchedule() {
|
|
|
+ private int populateSchedule(final int schedule) {
|
|
|
|
|
|
int eventCount = 0;
|
|
|
|
|
|
@@ -280,12 +278,13 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
c.add(Calendar.DATE, 1); // number of days to add
|
|
|
String endDate = sdf.format(c.getTime());
|
|
|
|
|
|
- String query = "SELECT festival_event.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event, place WHERE place = place.id AND start >= '" + dates[selected] + " 06:00:00' AND start < '" + endDate + " 05:59:59' AND ";
|
|
|
+ String query = "";;
|
|
|
|
|
|
if (schedule == GM.SCHEDULE.MARGOLARIAK) {
|
|
|
- query = query + "gm = 1 ";
|
|
|
- } else {
|
|
|
- query = query + "gm = 0 ";
|
|
|
+ query = "SELECT festival_event_gm.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event_gm, place WHERE place = place.id AND start >= '" + dates[selected] + " 06:00:00' AND start < '" + endDate + " 05:59:59'";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ query = "SELECT festival_event_city.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event_city, place WHERE place = place.id AND start >= '" + dates[selected] + " 06:00:00' AND start < '" + endDate + " 05:59:59'";
|
|
|
}
|
|
|
if (filter.length() > 0) {
|
|
|
query = query + "AND (title_" + lang + " like '%" + filter + "%' OR description_" + lang + " like '%" + filter + "%' OR name_" + lang + " like '%" + filter + "%' OR address_" + lang + " like '%" + filter + "%') ";
|
|
|
@@ -348,7 +347,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
public void onClick(View v) {
|
|
|
TextView tvId = (TextView) v.findViewById(R.id.tv_row_schedule_id);
|
|
|
int id = Integer.parseInt(tvId.getText().toString());
|
|
|
- showDialog(id);
|
|
|
+ showDialog(id, schedule);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -371,27 +370,28 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
return eventCount;
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Shows a dialog with info about the selected event.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id The event id
|
|
|
+ * @param schedule GM.SCHEDULE.GM or GM.SCHEDULE.CITY
|
|
|
*/
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
- private void showDialog(final int id){
|
|
|
-
|
|
|
+ private void showDialog(final int id, final int schedule){
|
|
|
+
|
|
|
//Create the dialog
|
|
|
final Dialog dialog = new Dialog(getActivity());
|
|
|
-
|
|
|
+
|
|
|
//Set up dialog window
|
|
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
dialog.setContentView(R.layout.dialog_schedule);
|
|
|
-
|
|
|
+
|
|
|
//Date formatters
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
|
|
SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
|
|
|
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);
|
|
|
-
|
|
|
+
|
|
|
//Set the custom dialog components - text, image and button
|
|
|
TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_title);
|
|
|
TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_description);
|
|
|
@@ -401,18 +401,24 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_place);
|
|
|
TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_address);
|
|
|
Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
|
|
|
-
|
|
|
+
|
|
|
//Get info about the event
|
|
|
SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
|
|
|
String lang = GM.getLang();
|
|
|
- Cursor cursor = db.rawQuery("SELECT festival_event.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host FROM festival_event, place WHERE place = place.id AND festival_event.id = " + id + ";", null);
|
|
|
+ Cursor cursor;
|
|
|
+ if (schedule == GM.SCHEDULE.MARGOLARIAK){
|
|
|
+ cursor = db.rawQuery("SELECT festival_event_gm.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM festival_event_gm, place WHERE place = place.id AND festival_event_gm.id = " + id + ";", null);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cursor = db.rawQuery("SELECT festival_event_city.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host FROM, sponsor festival_event_city, place WHERE place = place.id AND festival_event_city.id = " + id + ";", null);
|
|
|
+ }
|
|
|
if (cursor.getCount() > 0){
|
|
|
cursor.moveToNext();
|
|
|
-
|
|
|
+
|
|
|
//Set title
|
|
|
tvTitle.setText(cursor.getString(1));
|
|
|
markerName = cursor.getString(1);
|
|
|
-
|
|
|
+
|
|
|
//Set description
|
|
|
if (cursor.getString(2) != null && cursor.getString(2).length() > 0) {
|
|
|
tvDescription.setText(cursor.getString(2));
|
|
|
@@ -420,7 +426,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
else{
|
|
|
tvDescription.setVisibility(View.GONE);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//Set host
|
|
|
if (cursor.getString(10) != null){
|
|
|
Cursor hostCursor = db.rawQuery("SELECT name_" + lang + " FROM people WHERE id = " + cursor.getString(10) + ";", null);
|
|
|
@@ -429,11 +435,12 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
tvHost.setText(String.format(getString(R.string.schedule_host), hostCursor.getString(0)));
|
|
|
}
|
|
|
hostCursor.close();
|
|
|
+ // TODO. Add sponsor.
|
|
|
}
|
|
|
else{
|
|
|
tvHost.setVisibility(View.GONE);
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
//Set date
|
|
|
try{
|
|
|
Date day = dateFormat.parse(cursor.getString(4));
|
|
|
@@ -441,17 +448,16 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
//If the event is today, show "Today" instead of the date
|
|
|
if (dayFormat.format(day).equals(dayFormat.format(date)))
|
|
|
tvDate.setText(dialog.getContext().getString(R.string.today));
|
|
|
-
|
|
|
else{
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(date);
|
|
|
cal.add(Calendar.HOUR_OF_DAY, 24);
|
|
|
-
|
|
|
+
|
|
|
//If the event is tomorrow, show "Tomorrow" instead of the date
|
|
|
if (dayFormat.format(cal.getTime()).equals(dayFormat.format(date))){
|
|
|
tvDate.setText(dialog.getContext().getString(R.string.tomorrow));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//Else, show the date
|
|
|
else{
|
|
|
SimpleDateFormat printFormat;
|
|
|
@@ -478,7 +484,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
catch (Exception ex){
|
|
|
Log.e("Error parsing date", ex.toString());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//Set time
|
|
|
try{
|
|
|
if (cursor.getString(5) == null || cursor.getString(5).length() == 0) {
|
|
|
@@ -492,28 +498,29 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
catch (ParseException ex){
|
|
|
Log.e("Error parsing time", ex.toString());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//Set the place
|
|
|
tvPlace.setText(cursor.getString(6));
|
|
|
tvAddress.setText(cursor.getString(7));
|
|
|
-
|
|
|
+
|
|
|
//Set up map
|
|
|
+ // TODO if route...
|
|
|
location = new LatLng(Double.parseDouble(cursor.getString(8)), Double.parseDouble(cursor.getString(9)));
|
|
|
mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
|
|
|
mapView.onCreate(bund);
|
|
|
-
|
|
|
+
|
|
|
//Close the db connection
|
|
|
cursor.close();
|
|
|
db.close();
|
|
|
-
|
|
|
- //Set close button
|
|
|
- btClose.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- dialog.dismiss();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
+
|
|
|
+ //Set close button
|
|
|
+ btClose.setOnClickListener(new OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
//Actions to take when the dialog is cancelled
|
|
|
dialog.setOnCancelListener(new OnCancelListener(){
|
|
|
@Override
|
|
|
@@ -524,12 +531,12 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
}
|
|
|
}
|
|
|
if (mapView != null){
|
|
|
- mapView.onResume();
|
|
|
- mapView.onDestroy();
|
|
|
- }
|
|
|
+ mapView.onResume();
|
|
|
+ mapView.onDestroy();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
//Show the dialog
|
|
|
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
|
|
lp.copyFrom(dialog.getWindow().getAttributes());
|
|
|
@@ -541,7 +548,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
|
|
|
//Show dialog
|
|
|
dialog.show();
|
|
|
-
|
|
|
+
|
|
|
//Start the map
|
|
|
startMap();
|
|
|
mapView.onResume();
|
|
|
@@ -551,24 +558,24 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
public void onShow(DialogInterface dialog) {
|
|
|
// Gets to GoogleMap from the MapView and does initialization stuff
|
|
|
startMap();
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Starts the map in the dialog.
|
|
|
*/
|
|
|
private void startMap(){
|
|
|
mapView.getMapAsync(this);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Called when the fragment is brought back into the foreground.
|
|
|
+ * Called when the fragment is brought back into the foreground.
|
|
|
* Resumes the map and the location manager.
|
|
|
- *
|
|
|
+ *
|
|
|
* @see android.app.Fragment#onResume()
|
|
|
*/
|
|
|
@Override
|
|
|
@@ -584,9 +591,9 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Called when the fragment is destroyed.
|
|
|
- * Finishes the map.
|
|
|
- *
|
|
|
+ * Called when the fragment is destroyed.
|
|
|
+ * Finishes the map.
|
|
|
+ *
|
|
|
* @see android.app.Fragment#onDestroy()
|
|
|
*/
|
|
|
@Override
|
|
|
@@ -607,11 +614,11 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * Called when the fragment is paused.
|
|
|
- * Finishes the map.
|
|
|
- *
|
|
|
+ * Called when the fragment is paused.
|
|
|
+ * Finishes the map.
|
|
|
+ *
|
|
|
* @see android.app.Fragment#onPause()
|
|
|
*/
|
|
|
@Override
|
|
|
@@ -640,7 +647,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
/**
|
|
|
* Called in a situation of low memory.
|
|
|
* Lets the map handle this situation.
|
|
|
- *
|
|
|
+ *
|
|
|
* @see android.app.Fragment#onLowMemory()
|
|
|
*/
|
|
|
@Override
|
|
|
@@ -653,17 +660,17 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Called when the map is ready to be displayed.
|
|
|
+ * Called when the map is ready to be displayed.
|
|
|
* Sets the map options and a marker for the map.
|
|
|
- *
|
|
|
+ *
|
|
|
* @param googleMap The map to be shown
|
|
|
- *
|
|
|
+ *
|
|
|
* @see com.google.android.gms.maps.OnMapReadyCallback#onMapReady(com.google.android.gms.maps.GoogleMap)
|
|
|
*/
|
|
|
@Override
|
|
|
public void onMapReady(GoogleMap googleMap) {
|
|
|
this.map = googleMap;
|
|
|
-
|
|
|
+
|
|
|
map.getUiSettings().setMyLocationButtonEnabled(false);
|
|
|
if (!(ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
|
|
map.setMyLocationEnabled(true);
|
|
|
@@ -682,7 +689,7 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
|
|
|
mo.title(markerName);
|
|
|
mo.position(location);
|
|
|
map.addMarker(mo);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|