Просмотр исходного кода

Small fixes and improvements here and there.

Iñigo Valentin 8 лет назад
Родитель
Сommit
0e7acab914

+ 54 - 13
app/src/main/java/com/ivalentin/margolariak/ActivityFutureLayout.java

@@ -130,7 +130,18 @@ public class ActivityFutureLayout extends Fragment {
 		cursor.close();
 
 		//Get itinerary
-		Cursor cursorItinerary = db.rawQuery("SELECT activity_itinerary.id, activity_itinerary.name_" + lang + " AS name, description_" + lang + " AS description, start, place.name_" + lang + " AS placename, address_" + lang + " AS address, lat, lon FROM activity_itinerary, place WHERE activity_itinerary.place = place.id AND activity = " + id + ";", null);
+		Cursor cursorItinerary = db.rawQuery("SELECT activity_itinerary.id AS id, activity_itinerary.name_" + lang + " AS name, description_" + lang + " AS description, start, place.name_" + lang + " AS placename, address_" + lang + " AS address, lat, lon, route FROM activity_itinerary, place WHERE activity_itinerary.place = place.id AND activity = " + id + ";", null);
+		/*
+		 * 0: id
+		 * 1: name
+		 * 2: description
+		 * 3: start
+		 * 4: place
+		 * 5: address
+		 * 6: lat
+		 * 7: lon
+		 * 8: route
+		 */
 		if (cursorItinerary.getCount() <= 0){
 			LinearLayout sch = (LinearLayout) view.findViewById(R.id.ll_activity_future_schedule);
 			sch.setVisibility(View.GONE);
@@ -158,20 +169,26 @@ public class ActivityFutureLayout extends Fragment {
 
 				//Set description
 				TextView tvSchDescription = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_description);
-				if (!cursorItinerary.getString(1).equals(cursorItinerary.getString(2))){
+				if (cursorItinerary.getString(1).equals(cursorItinerary.getString(2))){
 					tvSchDescription.setVisibility(View.GONE);
 				}
 				else {
-					tvSchTitle.setText(cursorItinerary.getString(2));
+					tvSchDescription.setText(cursorItinerary.getString(2));
 				}
 
 				//Set place
 				TextView tvSchPlace = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_place);
 				tvSchPlace.setText(cursorItinerary.getString(4));
 
+				// Set route indicator
+				if (cursorItinerary.getString(8) != null && cursorItinerary.getString(8).length() > 0){
+					ImageView ivPinpoint = (ImageView) entry.findViewById(R.id.iv_row_activity_itinerary_pinpoint);
+					ivPinpoint.setImageResource(R.drawable.pinpoint_route);
+				}
+
 				//Set address
 				TextView tvSchAddress = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_address);
-				if (!cursorItinerary.getString(4).equals(cursorItinerary.getString(5))){
+				if (cursorItinerary.getString(4).equals(cursorItinerary.getString(5))){
 					tvSchAddress.setVisibility(View.GONE);
 				}
 				else {
@@ -238,7 +255,7 @@ public class ActivityFutureLayout extends Fragment {
 		//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 id, name_" + lang + ", description_" + lang + ", place, route, start, end, FROM activity_itinerary WHERE activity.id = " + id + " ORDER BY start;", null);
+		Cursor cursor = db.rawQuery("SELECT id, name_" + lang + ", description_" + lang + ", place, route, start, end FROM activity_itinerary WHERE id = " + id + " ORDER BY start;", null);
 		if (cursor.getCount() > 0){
 
 			cursor.moveToNext();
@@ -293,17 +310,15 @@ public class ActivityFutureLayout extends Fragment {
 				Cursor routeCursor = db.rawQuery("SELECT id, c_lat, c_lon, zoom FROM route WHERE id = " + routeId + ";", null);
 				if (routeCursor.moveToNext()) {
 
-					// Configure map route
-					mapController.setZoom(routeCursor.getInt(3));
-					GeoPoint center = new GeoPoint(routeCursor.getDouble(1), routeCursor.getDouble(2));
-					mapController.setCenter(center);
-
 					// Read from route_point and draw the route on the map.
 					Cursor pointCursor = db.rawQuery("SELECT lat_o, lon_o, lat_d, lon_d FROM route_point WHERE route = " + routeId + " ORDER BY part;", null);
 					final ArrayList<GeoPoint> points = new ArrayList<>();
 					GeoPoint lastPoint = new GeoPoint(0.0, 0.0);
+					GeoPoint firstPoint = null;
 					while (pointCursor.moveToNext()){
-
+						if (firstPoint == null){
+							firstPoint = new GeoPoint(pointCursor.getDouble(0), pointCursor.getDouble(1));
+						}
 						points.add(new GeoPoint(pointCursor.getDouble(0), pointCursor.getDouble(1)));
 						lastPoint = new GeoPoint(pointCursor.getDouble(2), pointCursor.getDouble(3));
 					}
@@ -312,12 +327,38 @@ public class ActivityFutureLayout extends Fragment {
 
 					pointCursor.close();
 
-					//Create path
+					// Center map
+					mapController.setCenter(firstPoint);
+					mapController.setZoom(routeCursor.getInt(3));
+
+					// Create path
 					Polyline line = new Polyline();
 					line.setPoints(points);
-					line.setColor(getResources().getColor(R.color.background_menu, null));
+					line.setColor(getResources().getColor(R.color.map_route, null));
+					line.setWidth(30.0f);
 					mapView.getOverlays().add(line);
 
+					// Set markers
+					OverlayItem startOverlay = new OverlayItem(title, title, firstPoint);
+					Drawable startMarker = this.getResources().getDrawable(R.drawable.pinpoint_start, null);
+					startOverlay.setMarker(startMarker);
+					OverlayItem endOverlay = new OverlayItem(title, title, lastPoint);
+					Drawable endMarker = this.getResources().getDrawable(R.drawable.pinpoint_end, null);
+					endOverlay.setMarker(endMarker);
+					final ArrayList<OverlayItem> markers = new ArrayList<>();
+					markers.add(startOverlay);
+					markers.add(endOverlay);
+					ItemizedIconOverlay markersOverlay = new ItemizedIconOverlay<>(markers,
+					  new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
+					        public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
+					                return true;
+					        }
+					        public boolean onItemLongPress(final int index, final OverlayItem item) {
+					                return true;
+					        }
+					  }, getContext());
+					mapView.getOverlays().add(markersOverlay);
+
 				}
 				routeCursor.close();
 

+ 24 - 11
app/src/main/java/com/ivalentin/margolariak/ActivityLayout.java

@@ -72,6 +72,14 @@ public class ActivityLayout extends Fragment{
 
 		//Get data from the database of the future activities
 		cursor = db.rawQuery("SELECT id, date, city, title_" + lang+ " AS title, text_" + lang + " AS text, price FROM activity WHERE date >= date('now') ORDER BY date DESC;", null);
+		/*
+		 * 0: id
+		 * 1: date
+		 * 3: city
+		 * 4: title
+		 * 5: text
+		 * 6: price
+		 */
 		if (cursor.getCount() > 0) {
 			TextView tvNoFuture = (TextView) view.findViewById(R.id.tv_activities_no_future);
 			tvNoFuture.setVisibility(View.GONE);
@@ -126,7 +134,8 @@ public class ActivityLayout extends Fragment{
 						//If the image exists, set it.
 						Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image);
 						iv.setImageBitmap(myBitmap);
-					} else {
+					}
+					else {
 						//If not, create directories and download asynchronously
 						File fpath;
 						fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
@@ -166,7 +175,14 @@ public class ActivityLayout extends Fragment{
 
 		//Get data from the database of the past activities
 		Cursor cursorPast = db.rawQuery("SELECT id, date, city, title_" + lang + " AS title, text_" + lang + " AS text, after_" + lang + " AS after FROM activity WHERE date < date('now') ORDER BY date DESC;", null);
-
+		/*
+		 * 0: id
+		 * 1: date
+		 * 2: city
+		 * 3: title
+		 * 4: text
+		 * 5: after
+		 */
 
 		//Print rows
 		while (cursorPast.moveToNext()) {
@@ -185,15 +201,11 @@ public class ActivityLayout extends Fragment{
 
 			//Set text
 			String text;
-			if (cursorPast.getString(5) == null){
-				text = Html.fromHtml(cursorPast.getString(4)).toString();
+			if (cursorPast.getString(5) != null && cursorPast.getString(5).length() > 0){
+				text = Html.fromHtml(cursorPast.getString(5)).toString();
 			}
-			else {
-				if (cursorPast.getString(5) == null || cursorPast.getString(5).length() < 1) {
-					text = Html.fromHtml(cursorPast.getString(4)).toString();
-				} else {
-					text = Html.fromHtml(cursorPast.getString(5)).toString();
-				}
+			else{
+				text = Html.fromHtml(cursorPast.getString(4)).toString();
 			}
 			TextView tvText = (TextView) entry.findViewById(R.id.tv_row_activity_past_text);
 			tvText.setText(text);
@@ -220,7 +232,8 @@ public class ActivityLayout extends Fragment{
 					//If the image exists, set it.
 					Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image);
 					iv.setImageBitmap(myBitmap);
-				} else {
+				}
+				else {
 					//If not, create directories and download asynchronously
 					File fpath;
 					fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");

+ 2 - 1
app/src/main/java/com/ivalentin/margolariak/GM.java

@@ -929,7 +929,8 @@ final class GM {
 		 * URL of the server.
 		 */
 		//static final String SERVER = "https://margolariak.com";
-		static final String SERVER = "http://192.168.1.101";
+		//static final String SERVER = "http://192.168.1.101";
+		static final String SERVER = "http://47.61.32.194:8101";
 	}
 
 	/**

+ 54 - 16
app/src/main/java/com/ivalentin/margolariak/ScheduleLayout.java

@@ -268,16 +268,29 @@ public class ScheduleLayout extends Fragment{
 		String query;
 
 		if (schedule == GM.SCHEDULE.MARGOLARIAK) {
-			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'";
+			query = "SELECT festival_event_gm.id AS id, title_" + lang + " AS title, description_" + lang + " AS description, place AS place_id, start, end, name_" + lang + " AS place, address_" + lang + " AS address, lat, lon, route 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'";
+			query = "SELECT festival_event_city.id AS id, title_" + lang + " AS title, description_" + lang + " AS description, place AS place_id, start, end, name_" + lang + " AS place, address_" + lang + " AS address, lat, lon, route 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 + "%') ";
 		}
 		query = query + " ORDER BY start;";
 		Cursor cursor = db.rawQuery(query, null);
+		/*
+		 * 0: id
+		 * 1: title
+		 * 2: description
+		 * 3: place_id
+		 * 4: start
+		 * 5: end
+		 * 6: place
+		 * 7: address
+		 * 8: lat
+		 * 9: lon
+		 * 10: route
+		 */
 
 		//Clear the list
 		list = (LinearLayout) view.findViewById(R.id.ll_schedule_list);
@@ -300,7 +313,8 @@ public class ScheduleLayout extends Fragment{
 			tvRowDesc = (TextView) entry.findViewById(R.id.tv_row_schedule_description);
 			if (cursor.getString(2) == null || cursor.getString(2).length() <= 0 || cursor.getString(2).equals(cursor.getString(1))) {
 				tvRowDesc.setVisibility(View.GONE);
-			} else {
+			}
+			else {
 				tvRowDesc.setText(cursor.getString(2));
 			}
 
@@ -312,17 +326,17 @@ public class ScheduleLayout extends Fragment{
 			tvRowAddress = (TextView) entry.findViewById(R.id.tv_row_schedule_address);
 			if (cursor.getString(7) == null || cursor.getString(7).length() <= 0 || cursor.getString(7).equals(cursor.getString(6))) {
 				tvRowAddress.setVisibility(View.GONE);
-			} else {
+			}
+			else {
 				tvRowAddress.setText(cursor.getString(7));
 			}
 
 			//Set icon
-			if (schedule == GM.SCHEDULE.MARGOLARIAK) {
+			if (cursor.getString(10) != null){
 				ImageView pinPoint = (ImageView) entry.findViewById(R.id.iv_row_schedule_pinpoint);
-				pinPoint.setImageResource(getResources().getIdentifier("com.ivalentin.margolariak:drawable/pinpoint_gm", null, null));
+				pinPoint.setImageResource(R.drawable.pinpoint_route);
 			}
 
-
 			//Set time
 			tvRowTime = (TextView) entry.findViewById(R.id.tv_row_schedule_time);
 			String tm = cursor.getString(4).substring(cursor.getString(4).length() - 8, cursor.getString(4).length() - 3);
@@ -391,7 +405,7 @@ public class ScheduleLayout extends Fragment{
 		Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
 		TextView tvOsm = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_osm);
 		MapView mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
-		
+
 		// Basic map configuration
 		mapView.setMultiTouchControls(true);
 		IMapController mapController = mapView.getController();
@@ -543,31 +557,55 @@ public class ScheduleLayout extends Fragment{
 				Cursor routeCursor = db.rawQuery("SELECT id, c_lat, c_lon, zoom FROM route WHERE id = " + routeId + ";", null);
 				if (routeCursor.moveToNext()) {
 
-					// Configure map route
-					mapController.setZoom(routeCursor.getInt(3));
-					GeoPoint center = new GeoPoint(routeCursor.getDouble(1), routeCursor.getDouble(2));
-					mapController.setCenter(center);
-
 					// Read from route_point and draw the route on the map.
 					Cursor pointCursor = db.rawQuery("SELECT lat_o, lon_o, lat_d, lon_d FROM route_point WHERE route = " + routeId + " ORDER BY part;", null);
 					final ArrayList<GeoPoint> points = new ArrayList<>();
 					GeoPoint lastPoint = new GeoPoint(0.0, 0.0);
+					GeoPoint firstPoint = null;
 					while (pointCursor.moveToNext()){
-
 						points.add(new GeoPoint(pointCursor.getDouble(0), pointCursor.getDouble(1)));
 						lastPoint = new GeoPoint(pointCursor.getDouble(2), pointCursor.getDouble(3));
+						if (firstPoint == null){
+							firstPoint = new GeoPoint(pointCursor.getDouble(0), pointCursor.getDouble(1));
+						}
 					}
 					// For the last one, also take destination
 					points.add(lastPoint);
 
 					pointCursor.close();
 
-					//Create path
+					// Center map
+					mapController.setCenter(firstPoint);
+					mapController.setZoom(routeCursor.getInt(3));
+
+					// Create path
 					Polyline line = new Polyline();
 					line.setPoints(points);
-					line.setColor(getResources().getColor(R.color.background_menu, null));
+					line.setColor(getResources().getColor(R.color.map_route, null));
+					line.setWidth(30.0f);
 					mapView.getOverlays().add(line);
 
+					// Set markers
+					OverlayItem startOverlay = new OverlayItem(title, title, firstPoint);
+					Drawable startMarker = this.getResources().getDrawable(R.drawable.pinpoint_start, null);
+					startOverlay.setMarker(startMarker);
+					OverlayItem endOverlay = new OverlayItem(title, title, lastPoint);
+					Drawable endMarker = this.getResources().getDrawable(R.drawable.pinpoint_end, null);
+					endOverlay.setMarker(endMarker);
+					final ArrayList<OverlayItem> markers = new ArrayList<>();
+					markers.add(startOverlay);
+					markers.add(endOverlay);
+                                        ItemizedIconOverlay markersOverlay = new ItemizedIconOverlay<>(markers,
+					  new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
+					  	public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
+							return true;
+						}
+						public boolean onItemLongPress(final int index, final OverlayItem item) {
+							return true;
+						}
+					  }, getContext());
+					mapView.getOverlays().add(markersOverlay);
+
 				}
 				routeCursor.close();
 

BIN
app/src/main/res/drawable-xhdpi/pinpoint_gm.png


BIN
app/src/main/res/drawable-xxhdpi/pinpoint_gm.png


BIN
app/src/main/res/drawable/pinpoint.png


BIN
app/src/main/res/drawable/pinpoint_end.png


BIN
app/src/main/res/drawable/pinpoint_gm.png


BIN
app/src/main/res/drawable/pinpoint_route.png


BIN
app/src/main/res/drawable/pinpoint_start.png


+ 2 - 2
app/src/main/res/layout/fragment_layout_home.xml

@@ -64,7 +64,7 @@
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:contentDescription="@string/app_cdesc"
-                        android:src="@drawable/pinpoint_gm"
+                        android:src="@drawable/pinpoint"
                         android:layout_margin="7dp"
                         android:layout_gravity="center_vertical"/>
 
@@ -748,4 +748,4 @@
 
     </LinearLayout>
 
-</com.ivalentin.margolariak.CustomScrollView>
+</com.ivalentin.margolariak.CustomScrollView>

+ 5 - 5
app/src/main/res/layout/row_activity_schedule.xml

@@ -52,7 +52,7 @@
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_weight=".4">
+        android:layout_weight=".2">
 
         <TextView
             android:layout_width="wrap_content"
@@ -79,11 +79,11 @@
             android:layout_marginBottom="10dp">
 
             <ImageView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
                 android:id="@+id/iv_row_activity_itinerary_pinpoint"
+                android:layout_width="45dp"
+                android:layout_height="45dp"
                 android:contentDescription="@string/app_cdesc"
-                android:src="@drawable/pinpoint_map"
+                android:src="@drawable/pinpoint"
                 android:layout_gravity="center_vertical" />
 
             <LinearLayout
@@ -110,4 +110,4 @@
         </LinearLayout>
 
     </LinearLayout>
-</LinearLayout>
+</LinearLayout>

+ 1 - 1
app/src/main/res/layout/row_schedule.xml

@@ -127,4 +127,4 @@
 
     </LinearLayout>
     
-</LinearLayout>
+</LinearLayout>

+ 2 - 0
app/src/main/res/values/color.xml

@@ -41,9 +41,11 @@
     <!-- Color for maps -->
     <color name="map_border">#0077ff</color>
     <color name="map_background">#ffffff</color>
+    <color name="map_route">#0022aaaa</color>
 
     <!--Colors for album covers -->
     <color name="album_border">#111111</color>
     <color name="album_background">#aaaaaa</color>
 
 </resources>
+

+ 2 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -3,4 +3,5 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+#distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-rc-2-all.zip