소스 검색

Added backup configuration.
Permissions check for location.
Code simplifications.
Code optimizations.

seavenois 10 년 전
부모
커밋
661e234290
34개의 변경된 파일342개의 추가작업 그리고 591개의 파일을 삭제
  1. 3 3
      app/build.gradle
  2. 4 7
      app/src/main/AndroidManifest.xml
  3. 30 11
      app/src/main/java/com/ivalentin/margolariak/ActivityFutureLayout.java
  4. 1 2
      app/src/main/java/com/ivalentin/margolariak/ActivityLayout.java
  5. 0 1
      app/src/main/java/com/ivalentin/margolariak/ActivityPastLayout.java
  6. 0 1
      app/src/main/java/com/ivalentin/margolariak/BlogLayout.java
  7. 4 10
      app/src/main/java/com/ivalentin/margolariak/Distance.java
  8. 3 11
      app/src/main/java/com/ivalentin/margolariak/DownloadImage.java
  9. 0 257
      app/src/main/java/com/ivalentin/margolariak/Event.java
  10. 1 1
      app/src/main/java/com/ivalentin/margolariak/FetchURL.java
  11. 2 7
      app/src/main/java/com/ivalentin/margolariak/GM.java
  12. 2 2
      app/src/main/java/com/ivalentin/margolariak/GalleryLayout.java
  13. 118 111
      app/src/main/java/com/ivalentin/margolariak/HomeLayout.java
  14. 2 10
      app/src/main/java/com/ivalentin/margolariak/HomeSectionLocation.java
  15. 32 43
      app/src/main/java/com/ivalentin/margolariak/LocationLayout.java
  16. 1 1
      app/src/main/java/com/ivalentin/margolariak/MainActivity.java
  17. 24 32
      app/src/main/java/com/ivalentin/margolariak/MainLayout.java
  18. 5 5
      app/src/main/java/com/ivalentin/margolariak/PhotoLayout.java
  19. 6 8
      app/src/main/java/com/ivalentin/margolariak/PostComment.java
  20. 1 2
      app/src/main/java/com/ivalentin/margolariak/PostLayout.java
  21. 43 13
      app/src/main/java/com/ivalentin/margolariak/ScheduleLayout.java
  22. 2 2
      app/src/main/java/com/ivalentin/margolariak/Sync.java
  23. 1 1
      app/src/main/res/layout/activity_main.xml
  24. 2 1
      app/src/main/res/layout/dialog_schedule.xml
  25. 36 43
      app/src/main/res/layout/fragment_layout_lablanca.xml
  26. 1 1
      app/src/main/res/layout/row_activity_schedule.xml
  27. 1 0
      app/src/main/res/layout/row_comment.xml
  28. 1 1
      app/src/main/res/layout/row_home_activities.xml
  29. 3 2
      app/src/main/res/layout/row_schedule.xml
  30. 1 1
      app/src/main/res/values-en/strings.xml
  31. 1 1
      app/src/main/res/values-eu-rES/strings.xml
  32. 4 0
      app/src/main/res/values/strings.xml
  33. 7 0
      app/src/main/res/xml/backup.xml
  34. 0 0
      gradle.properties

+ 3 - 3
app/build.gradle

@@ -7,7 +7,7 @@ android {
     defaultConfig {
         applicationId "com.ivalentin.margolariak"
         minSdkVersion 12
-        targetSdkVersion 22
+        targetSdkVersion 23
     }
 
     buildTypes {
@@ -19,7 +19,7 @@ android {
 }
 
 dependencies {
-    compile 'com.android.support:support-v4:23.4.0'
-    compile 'com.android.support:appcompat-v7:23.4.0'
+//    compile 'com.android.support:support-v4:23.4.0'
+//    compile 'com.android.support:appcompat-v7:23.4.0'
     compile 'com.google.android.gms:play-services:+'
 }

+ 4 - 7
app/src/main/AndroidManifest.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.ivalentin.margolariak"
-    android:versionCode="10"
-    android:versionName="2.0-alpha03" >
+    android:versionCode="11"
+    android:versionName="2.0-alpha04" >
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
@@ -14,11 +14,7 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     
     <uses-permission android:name="android.permission.VIBRATE"/>
-    
-    <uses-sdk
-        android:minSdkVersion="12"
-        android:targetSdkVersion="22" />
-    
+
     <uses-feature
         android:glEsVersion="0x00020000"
         android:required="true"/>
@@ -30,6 +26,7 @@
         android:theme="@style/AppTheme"
         android:supportsRtl="true"
         android:isGame="false"
+        android:fullBackupContent="@xml/backup"
         android:allowClearUserData="true">
         
         <meta-data

+ 30 - 11
app/src/main/java/com/ivalentin/margolariak/ActivityFutureLayout.java

@@ -4,12 +4,14 @@ import android.annotation.SuppressLint;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.support.v4.app.ActivityCompat;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -56,7 +58,8 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 	private GoogleMap map;
 	private LatLng location;
 	private String markerName = "";
-	private Bundle bund = null;
+	private final Bundle bund = null;
+	private View v;
 
 	@SuppressWarnings("ResultOfMethodCallIgnored")
     @SuppressLint("InflateParams")
@@ -197,6 +200,8 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 
         cursorItinerary.close();
         db.close();
+
+		v = view;
         return view;
     }
 
@@ -314,8 +319,11 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
             dialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
                 @Override
                 public void onCancel(DialogInterface dialog) {
-                    if (map != null)
-                        map.setMyLocationEnabled(false);
+                    if (map != null) {
+						if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+							map.setMyLocationEnabled(false);
+						}
+					}
                     if (mapView != null){
                         mapView.onResume();
                         mapView.onDestroy();
@@ -368,8 +376,11 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 	public void onResume() {
 		if (mapView != null)
 			mapView.onResume();
-		if (map != null)
-			map.setMyLocationEnabled(true);
+		if (map != null) {
+			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+				map.setMyLocationEnabled(true);
+			}
+		}
 		super.onResume();
 	}
 
@@ -382,8 +393,11 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		if (map != null)
-			map.setMyLocationEnabled(false);
+		if (map != null) {
+			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+				map.setMyLocationEnabled(false);
+			}
+		}
 		if (mapView != null){
 			mapView.onResume();
 			mapView.onDestroy();
@@ -400,7 +414,9 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 	public void onPause() {
 		super.onDestroy();
 		if (map != null) {
-			map.setMyLocationEnabled(false);
+			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+				map.setMyLocationEnabled(false);
+			}
 		}
 		if (mapView != null){
 			mapView.onPause();
@@ -417,7 +433,9 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 	public void onLowMemory() {
 		super.onLowMemory();
 		if (mapView != null){
-			mapView.onResume();
+			if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+				mapView.onResume();
+			}
 			mapView.onLowMemory();
 		}
 	}
@@ -433,10 +451,11 @@ public class ActivityFutureLayout extends Fragment implements OnMapReadyCallback
 	@Override
 	public void onMapReady(GoogleMap googleMap) {
 		this.map = googleMap;
-		map.setMyLocationEnabled(true);
 
 		map.getUiSettings().setMyLocationButtonEnabled(false);
-		map.setMyLocationEnabled(true);
+		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+			map.setMyLocationEnabled(true);
+		}
 		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
 		try {
 			MapsInitializer.initialize(this.getActivity());

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

@@ -20,7 +20,6 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import java.io.File;
-import java.util.Locale;
 
 /**
  * Fragment to display activities.
@@ -65,7 +64,7 @@ public class ActivityLayout extends Fragment{
      */
     @SuppressWarnings("ResultOfMethodCallIgnored")
     @SuppressLint("InflateParams") //Throws unknown error when done properly.
-    public void populate(View view){
+    private void populate(View view){
         LinearLayout llListFuture = (LinearLayout) view.findViewById(R.id.ll_activities_future_list);
         LinearLayout llListPast = (LinearLayout) view.findViewById(R.id.ll_activities_past_list);
         LinearLayout entry;

+ 0 - 1
app/src/main/java/com/ivalentin/margolariak/ActivityPastLayout.java

@@ -17,7 +17,6 @@ import android.widget.ImageView;
 import android.widget.TextView;
 
 import java.io.File;
-import java.util.Locale;
 
 /**
  * Fragment to display past activities.

+ 0 - 1
app/src/main/java/com/ivalentin/margolariak/BlogLayout.java

@@ -21,7 +21,6 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 
 import java.io.File;
-import java.util.Locale;
 
 /**
  * Fragment to display the blog entries, paginated.

+ 4 - 10
app/src/main/java/com/ivalentin/margolariak/Distance.java

@@ -7,7 +7,7 @@ package com.ivalentin.margolariak;
  * @author Iñigo Valentin
  *
  */
-public final class Distance {
+final class Distance {
 	
 	/**
 	 * Calculates the distance between two points (given the latitude/longitude of those points). 
@@ -19,22 +19,16 @@ public final class Distance {
 	 * @param lon1 Longitude of the first point
 	 * @param lat2 Latitude of the second point
 	 * @param lon2 Longitude of the second point
-	 * @param unit The result unit. 'M' for statute miles (default), 'K' for kilometers and 'N' for nautical miles.
-	 * 
+	 *
 	 * @return The distance between the points
 	 */
-	public static double calculateDistance(double lat1, double lon1, double lat2, double lon2, char unit) {
+	public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
 		double theta = lon1 - lon2;
 		double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
 		dist = Math.acos(dist);
 		dist = rad2deg(dist);
 		dist = dist * 60 * 1.1515;
-		if (unit == 'K') {
-			dist = dist * 1.609344;
-		}
-		else if (unit == 'N') {
-			dist = dist * 0.8684;
-		}
+		dist = dist * 1.609344;
 		return (dist);
 	}
 	

+ 3 - 11
app/src/main/java/com/ivalentin/margolariak/DownloadImage.java

@@ -23,9 +23,9 @@ import java.net.URLConnection;
  */
 class DownloadImage extends AsyncTask<Void, Void, Void> {
 
-    private String file;
-    private String path;
-    private ImageView iv;
+    private final String file;
+    private final String path;
+    private final ImageView iv;
 
 	/**
 	 * Constructor.
@@ -43,14 +43,6 @@ class DownloadImage extends AsyncTask<Void, Void, Void> {
         this.iv = iv;
     }
 
-    /**
-     * Before starting background thread do nothing.
-     */
-    @Override
-    protected void onPreExecute() {
-        super.onPreExecute();
-    }
-
     /**
      * Downloading file in background thread.
 	 */

+ 0 - 257
app/src/main/java/com/ivalentin/margolariak/Event.java

@@ -1,257 +0,0 @@
-package com.ivalentin.margolariak;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-
-/**
- * An event holds information about an activity of the festival
- * 
- * @author Iñigo Valentin
- * 
- * @see Comparable
- *
- */
-public class Event implements Comparable<Event>{
-	
-	private String name, description, place, host;
-	private double[] coordinates = new double[2];
-	private Date start, end;
-	private boolean gm, schedule;
-	private Integer distance = null;
-	private double[] location = new double[2];
-	private int id;
-	
-	
-	/**
-	 * Constructor.
-	 * 
-	 * @param name Name of the event.
-	 * @param description Description of the event.
-	 * @param gm 1 if it's a Margolari event, 0 otherwise.
-	 * @param schedule 1 if it's an event from the municipal schedule, 0 otherwise.
-	 * @param place Name of the place where the event is hold.
-	 * @param host Name of the people/organization that organizes the event. Can be null.
-	 * @param coordinates Array of doubles [latitude, longitude].
-	 * @param start String whit the date and time of the start of the event, in the format yyyy-MM-dd HH:mm:ss.
-	 * @param end String whit the date and time of the end of the event, in the format yyyy-MM-dd HH:mm:ss. Can be null.
-	 */
-	public Event(int id, String name, String description, int gm, int schedule, String place, String host, double[] coordinates, String start, String end){
-		super();
-		this.id = id;
-		this.name = name;
-		this.description = description;
-		this.place = place;
-		if (gm == 1)
-			this.gm = true;
-		else
-			this.gm = false;
-		if (schedule == 1)
-			this.schedule = true;
-		else
-			this.schedule = false;
-		this.host = host;
-		this.coordinates = coordinates;
-		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
-		try{
-			this.start = format.parse(start);
-		}
-		catch (Exception ex){
-			start = null;
-		}
-		try{
-			this.end = format.parse(end);
-		}
-		catch (Exception ex){
-			end = null;
-		}
-	}
-	
-	/**
-	 * Return the id of the event
-	 * 
-	 * @return the id of the event
-	 */
-	public int getId(){
-		return id;
-	}
-	
-	/**
-	 * Return the name of the event.
-	 * @return The name of the event.
-	 */
-	public String getName() {
-		return name;
-	}
-	
-	/**
-	 * Return the description of the event.
-	 * @return The description of the event.
-	 */
-	public String getDescription() {
-		return description;
-	}
-	
-	/**
-	 * Checks if the event is a Margolari one.
-	 * @return true if it's a Margolari event, false otherwise.
-	 */
-	public boolean isGm(){
-		return gm;
-	}
-	
-	/**
-	 * Checks if the event is an official one.
-	 * @return true if it's an official event, false otherwise.
-	 */
-	public boolean isSchedule(){
-		return schedule;
-	}
-	
-	/**
-	 * Return the place of the event.
-	 * @return The place of the event.
-	 */
-	public String getPlace() {
-		return place;
-	}
-	
-	/**
-	 * Return the host of the event.
-	 * @return The host of the event.
-	 */
-	public String getHost() {
-		return host;
-	}
-	
-	/**
-	 * Return the event coordinates.
-	 * @return The coordinates of the event [latitude, longitude].
-	 */
-	public double[] getCoordinates() {
-		return coordinates;
-	}
-	
-	/**
-	 * Return the event start time.
-	 * @return The event start date and time.
-	 */
-	public Date getStart() {
-		return start;
-	}
-	
-	/**
-	 * Return the event end time.
-	 * @return The event end date and time.
-	 */
-	public Date getEnd() {
-		return end;
-	}
-	
-	/**
-	 * Calculates the event distance to a given point.
-	 * 
-	 * @param loc Array of doubles [latitude, longitude] to calculate the distance of the event from.
-	 * @return The distance, in meters, between the event and the given point.
-	 */
-	public Integer getDistance(double loc[]){
-		location = loc;
-		distance = Math.round((long) (Distance.calculateDistance(location[0], location[1], coordinates[0], coordinates[1], 'K') * 1000));
-		return distance;
-	}
-	
-	/**
-	 * Gets the distance between the event location and a location previously provided using getDistance(double loc[]). 
-	 * 
-	 * @return The distance, in meters, between the event and the location set when calling getDistance(double loc[]). If it wasn't called, it will be null.
-	 */
-	public Integer getDistance(){
-		if (location == null)
-			return null;
-		else
-			return getDistance(location);
-	}
-	
-	/**
-	 * Return the time between the current time and the start of the event.
-	 * @return The time, in minutes, to the event start. A positive value indicates that the event is in the future, and a negative indicates that the event has already started.
-	 */
-	public long getTimeToStart(){
-		Date now = new Date();
-		long dif = (start.getTime() / 60000) - (now.getTime() / 60000);
-		return dif;
-	}
-	
-	/**
-	 * Return the time between the current time and the end of the event.
-	 * @return The time, in minutes, to the event end. A positive value indicates that the event is in the future, and a negative indicates that the event has already started. If the event doesn't have an end date, it will return 0.
-	 */
-	public long getTimeToEnd(){
-		if (end == null)
-			return 0;
-		Date now = new Date();
-		long dif = (start.getTime() / 60000) - (now.getTime() / 60000);
-		return dif;
-	}
-	
-	/**
-	 * Compares the event to another event to establish a relative order. 
-	 * The order is based on the time and the distance to the user.
-	 * 
-	 * @see java.lang.Comparable#compareTo(java.lang.Object)
-	 * 
-	 * @param Other event to compare to this.
-	 * 
-	 * @return Negative integer if this instance is less than another, positive if it's greater, 0 if they are equal.
-	 */
-	@Override
-	public int compareTo(Event another) {
-		float distanceDif, timeDif;
-		float result;
-		
-		
-		//Get distance difference
-		if (getDistance() == null && another.getDistance() == null)
-			distanceDif = 0;
-		else if (getDistance() == null)
-			distanceDif = -1;
-		else if (another.getDistance() == null)
-			distanceDif = 1;
-		else{
-			distanceDif = getDistance() - another.getDistance();
-			if (getDistance() > another.getDistance()){
-				if (getDistance() == 0)
-					distanceDif = 1;
-				else
-					distanceDif = distanceDif / getDistance();
-			}
-			else{
-				if (another.getDistance() == 0)
-					distanceDif = -1;
-				else
-					distanceDif = distanceDif / another.getDistance();
-			}
-		}
-		
-		//Get time to start difference
-		timeDif = Math.abs(getTimeToStart()) - Math.abs(another.getTimeToStart());
-		if (getTimeToStart() > another.getTimeToStart()){
-			if (getTimeToStart() == 0)
-				timeDif = 1;
-			else
-				timeDif = timeDif / getTimeToStart();
-		}
-		else{
-			if (another.getTimeToStart() == 0)
-				timeDif = -1;
-			else
-				timeDif = timeDif / another.getTimeToStart();
-			
-		}
-		
-		result = timeDif + distanceDif;
-		
-		return Math.round(result);
-	}
-}

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

@@ -12,7 +12,7 @@ import java.util.List;
  * @author Inigo Valentin
  *
  */
-public class FetchURL {
+class FetchURL {
  
 	//List of strings that will contain the output, line by line
 	private List<String> output;

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

@@ -14,7 +14,7 @@ import java.util.Locale;
  * @author Iñigo Valentin
  *
  */
-public final class GM {
+final class GM {
 	
 	/**
 	 * Address where the web server is
@@ -40,12 +40,7 @@ public final class GM {
 	 * Name of the preference to store the user code with.
 	 */
 	static final String USER_CODE = "prefcode";
-	
-	/**
-	 * Name of the preference to store the user name with.
-	 */
-	static final String USER_NAME = "prefname";
-	
+
 	/**
 	 * Constant to diferentiate schedules".
 	 */

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

@@ -107,7 +107,7 @@ public class GalleryLayout extends Fragment{
             preview[3] = (ImageView) entry.findViewById(R.id.iv_row_gallery_3);
 
             //Get db rows
-            Cursor cursorImage = db.rawQuery("SELECT id, file, width, height, FROM photo, photo_album WHERE photo = id AND album = " + cursor.getString(0) + " ORDER BY random() LIMIT 4;", null);
+            Cursor cursorImage = db.rawQuery("SELECT id, file, width, height FROM photo, photo_album WHERE photo = id AND album = " + cursor.getString(0) + " ORDER BY random() LIMIT 4;", null);
 
             //Loop
             int i = 0;
@@ -137,7 +137,7 @@ public class GalleryLayout extends Fragment{
             //Set photo counter
 			Cursor cursorCounter = db.rawQuery("SELECT id FROM photo, photo_album WHERE photo = id AND album = " + cursor.getString(0) + ";", null);
             TextView tvPhotoCounter = (TextView) entry.findViewById(R.id.tv_row_gallery_counter);
-            tvPhotoCounter.setText(getResources().getQuantityString(R.plurals.gallery_photo_count, cursorCounter.getColumnCount(), cursorCounter.getColumnCount()));
+            tvPhotoCounter.setText(getResources().getQuantityString(R.plurals.gallery_photo_count, cursorCounter.getCount(), cursorCounter.getCount()));
 
 			//Close cursors
 			cursorCounter.close();

+ 118 - 111
app/src/main/java/com/ivalentin/margolariak/HomeLayout.java

@@ -10,6 +10,7 @@ import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Bitmap;
@@ -23,6 +24,7 @@ import android.net.Uri;
 import android.os.Bundle;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
+import android.support.v4.app.ActivityCompat;
 import android.text.Html;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -36,29 +38,29 @@ import android.widget.Toast;
 /**
  * Section that will be seen when the app is started. 
  * Contains info from almost every other section.
- * 
+ *
  * @author Iñigo Valentin
- * 
+ *
  * @see Fragment
  *
  */
-public class HomeLayout extends Fragment implements LocationListener{
+public class HomeLayout extends Fragment implements LocationListener {
 
 	//The location manager
-	LocationManager locationManager;
+	private LocationManager locationManager;
 
 	private View view;
-	
+
 	/**
 	 * Run when the fragment is inflated.
 	 * Assigns views, gets the date and does the first call to the {//@link populate function}.
-	 * 
+	 *
 	 * @param inflater A LayoutInflater to handle the views
 	 * @param container The parent View
 	 * @param savedInstanceState Bundle with the saved state
-	 * 
+	 *
 	 * @return The fragment view
-	 * 
+	 *
 	 * @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
 	 */
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
@@ -74,8 +76,10 @@ public class HomeLayout extends Fragment implements LocationListener{
 		//Set Location manager
 		//TODO: Only do this if location is required
 		locationManager = (LocationManager) view.getContext().getSystemService(Context.LOCATION_SERVICE);
-		locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION_ACCURACY_TIME, GM.LOCATION_ACCURACY_SPACE, this);
-		onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
+		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) == false) {
+			locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION_ACCURACY_TIME, GM.LOCATION_ACCURACY_SPACE, this);
+			onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
+		}
 
 		//Set the title
 		((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_home));
@@ -87,7 +91,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 		setUpBlog(view);
 
 		//Set up activities sections
-		if (setUpFutureActivities(view) == 0){
+		if (setUpFutureActivities(view) == 0) {
 			setUpPastActivities(view);
 		}
 
@@ -105,7 +109,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 		//Setup the social section
 		setUpSocial(view);
 
-	    //Return the view itself.
+		//Return the view itself.
 		return view;
 	}
 
@@ -115,7 +119,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 * @return The number of entries shown.
 	 */
 	@SuppressLint("InflateParams")
-	private int setUpSchedule(int gm, View view){
+	private int setUpSchedule(int gm, View view) {
 		int count = 0;
 
 		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
@@ -146,8 +150,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 			now = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule_now_content);
 			next = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule_later_content);
 
-		}
-		else{
+		} else {
 			section = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule);
 			listNow = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule_now_list);
 			listNext = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule_later_list);
@@ -164,11 +167,11 @@ public class HomeLayout extends Fragment implements LocationListener{
 
 		//Execute query and loop
 		Cursor cursorNow = db.rawQuery(query, null);
-		if (cursorNow.getCount() == 0){
+		if (cursorNow.getCount() == 0) {
 			now.setVisibility(View.GONE);
 		}
-		while (cursorNow.moveToNext()){
-			count ++;
+		while (cursorNow.moveToNext()) {
+			count++;
 
 			entry = (LinearLayout) factory.inflate(R.layout.row_home_schedule, null);
 
@@ -185,7 +188,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 			tvRowPlace.setText(cursorNow.getString(6));
 
 			//Set icon
-			if (gm == GM.SECTION_LABLANCA_GM_SCHEDULE){
+			if (gm == GM.SECTION_LABLANCA_GM_SCHEDULE) {
 				ImageView pinPoint = (ImageView) entry.findViewById(R.id.iv_row_home_schedule_pinpoint);
 				pinPoint.setImageResource(getResources().getIdentifier("com.ivalentin.gm:drawable/pinpoint_gm", null, null));
 			}
@@ -208,11 +211,11 @@ public class HomeLayout extends Fragment implements LocationListener{
 
 		//Execute query and loop
 		Cursor cursorNext = db.rawQuery(query, null);
-		if (cursorNext.getCount() == 0){
+		if (cursorNext.getCount() == 0) {
 			next.setVisibility(View.GONE);
 		}
-		while (cursorNext.moveToNext()){
-			count ++;
+		while (cursorNext.moveToNext()) {
+			count++;
 
 			entry = (LinearLayout) factory.inflate(R.layout.row_home_schedule, null);
 
@@ -229,7 +232,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 			tvRowPlace.setText(cursorNext.getString(6));
 
 			//Set icon
-			if (gm == GM.SECTION_LABLANCA_GM_SCHEDULE){
+			if (gm == GM.SECTION_LABLANCA_GM_SCHEDULE) {
 				ImageView pinPoint = (ImageView) entry.findViewById(R.id.iv_row_home_schedule_pinpoint);
 				pinPoint.setImageResource(getResources().getIdentifier("com.ivalentin.gm:drawable/pinpoint_gm", null, null));
 			}
@@ -246,20 +249,18 @@ public class HomeLayout extends Fragment implements LocationListener{
 		cursorNext.close();
 
 
-
-		if (count > 0){
+		if (count > 0) {
 			section.setVisibility(View.VISIBLE);
 			if (gm == 1) {
-				section.setOnClickListener(new OnClickListener(){
+				section.setOnClickListener(new OnClickListener() {
 					@Override
 					public void onClick(View v) {
 						((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, false);
 					}
 				});
 
-			}
-			else{
-				section.setOnClickListener(new OnClickListener(){
+			} else {
+				section.setOnClickListener(new OnClickListener() {
 					@Override
 					public void onClick(View v) {
 						((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_SCHEDULE, false);
@@ -389,16 +390,15 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 */
 	private boolean setUpLocation(Location location, View view) {
 		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-		if (preferences.getString(GM.PREF_GM_LOCATION, "").length() > 0){
+		if (preferences.getString(GM.PREF_GM_LOCATION, "").length() > 0) {
 			Double lat = Double.longBitsToDouble(preferences.getLong(GM.PREF_GM_LATITUDE, 0));
 			Double lon = Double.longBitsToDouble(preferences.getLong(GM.PREF_GM_LONGITUDE, 0));
-			Double distance = Distance.calculateDistance(lat, lon, location.getLatitude(), location.getLongitude(), 'K');
+			Double distance = Distance.calculateDistance(lat, lon, location.getLatitude(), location.getLongitude());
 			TextView text = (TextView) view.findViewById(R.id.tv_home_section_location_distance);
 			if (distance <= 2) {
 				distance = 1000 * distance;
 				text.setText(String.format(getString(R.string.home_section_location_text_short), distance.intValue(), (int) (0.012 * distance.intValue())));
-			}
-			else{
+			} else {
 				text.setText(String.format(getString(R.string.home_section_location_text_long), String.format(Locale.US, "%.02f", distance)));
 			}
 
@@ -420,7 +420,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 		//Set onClick listener of section
 		LinearLayout llGallery = (LinearLayout) view.findViewById(R.id.ll_home_section_gallery);
 		//Set click listener
-		llGallery.setOnClickListener(new OnClickListener(){
+		llGallery.setOnClickListener(new OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				((MainActivity) getActivity()).loadSection(GM.SECTION_GALLERY, false);
@@ -438,7 +438,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 		SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
 		Cursor cursor = db.rawQuery("SELECT id, album, file, uploaded FROM photo, photo_album WHERE id = photo ORDER BY uploaded DESC LIMIT 4;", null);
 
-		while (cursor.moveToNext()){
+		while (cursor.moveToNext()) {
 
 			//Set id
 			ivPhoto[counter].setTag(R.string.key_0, cursor.getString(0));
@@ -485,7 +485,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 				}
 			});
 
-			counter ++;
+			counter++;
 		}
 
 		//Close db
@@ -504,7 +504,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 */
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	@SuppressWarnings("ResultOfMethodCallIgnored")
-	private int setUpPastActivities(View view){
+	private int setUpPastActivities(View view) {
 		int counter = 0;
 		String lang = GM.getLang();
 
@@ -517,10 +517,10 @@ public class HomeLayout extends Fragment implements LocationListener{
 		llActivitiesPast.setVisibility(View.VISIBLE);
 
 		//Set click listener
-		llActivitiesPast.setOnClickListener(new OnClickListener(){
+		llActivitiesPast.setOnClickListener(new OnClickListener() {
 			@Override
 			public void onClick(View v) {
-			((MainActivity) getActivity()).loadSection(GM.SECTION_ACTIVITIES, false);
+				((MainActivity) getActivity()).loadSection(GM.SECTION_ACTIVITIES, false);
 			}
 		});
 
@@ -557,8 +557,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 			String text;
 			if (cursor.getString(6).length() < 1) {
 				text = Html.fromHtml(cursor.getString(4)).toString();
-			}
-			else{
+			} else {
 				text = Html.fromHtml(cursor.getString(6)).toString();
 			}
 			if (text.length() > 100) {
@@ -603,20 +602,20 @@ public class HomeLayout extends Fragment implements LocationListener{
 			entry.setOnClickListener(new View.OnClickListener() {
 				@Override
 				public void onClick(View v) {
-				//Toast.makeText(getActivity(), "OPENING POST", Toast.LENGTH_LONG).show();
-				Fragment fragment = new ActivityPastLayout();
-				Bundle bundle = new Bundle();
-				//Pass post id
-				int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_activity_hidden)).getText().toString());
-				bundle.putInt("activity", id);
-				fragment.setArguments(bundle);
-
-				FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
-				FragmentTransaction ft = fm.beginTransaction();
-
-				ft.replace(R.id.activity_main_content_fragment, fragment);
-				ft.addToBackStack("activity_" + id);
-				ft.commit();
+					//Toast.makeText(getActivity(), "OPENING POST", Toast.LENGTH_LONG).show();
+					Fragment fragment = new ActivityPastLayout();
+					Bundle bundle = new Bundle();
+					//Pass post id
+					int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_activity_hidden)).getText().toString());
+					bundle.putInt("activity", id);
+					fragment.setArguments(bundle);
+
+					FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
+					FragmentTransaction ft = fm.beginTransaction();
+
+					ft.replace(R.id.activity_main_content_fragment, fragment);
+					ft.addToBackStack("activity_" + id);
+					ft.commit();
 				}
 			});
 
@@ -642,7 +641,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 */
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	@SuppressWarnings("ResultOfMethodCallIgnored")
-	private int setUpFutureActivities(View view){
+	private int setUpFutureActivities(View view) {
 		int counter = 0;
 		String lang = GM.getLang();
 
@@ -654,7 +653,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 
 		//Get data from the database of the future activities
 		SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
-		Cursor 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 LIMIT 2;", null);
+		Cursor 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 LIMIT 2;", null);
 
 		//If there are future activities...
 		if (cursor.getCount() > 0) {
@@ -664,7 +663,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 			llActivitiesFuture.setVisibility(View.VISIBLE);
 
 			//Set click listener
-			llActivitiesFuture.setOnClickListener(new OnClickListener(){
+			llActivitiesFuture.setOnClickListener(new OnClickListener() {
 				@Override
 				public void onClick(View v) {
 					((MainActivity) getActivity()).loadSection(GM.SECTION_ACTIVITIES, false);
@@ -775,12 +774,12 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 */
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	@SuppressWarnings("ResultOfMethodCallIgnored")
-	private int setUpBlog(View view){
+	private int setUpBlog(View view) {
 		int counter = 0;
 		String lang = GM.getLang();
 
 		LinearLayout llBlog = (LinearLayout) view.findViewById(R.id.ll_home_section_blog);
-		llBlog.setOnClickListener(new OnClickListener(){
+		llBlog.setOnClickListener(new OnClickListener() {
 			@Override
 			public void onClick(View v) {
 				((MainActivity) getActivity()).loadSection(GM.SECTION_BLOG, false);
@@ -801,7 +800,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 		cursor = db.rawQuery("SELECT id, title_" + lang + " AS title, text_" + lang + " AS text, dtime FROM post ORDER BY dtime DESC LIMIT 2;", null);
 
 		//Loop
-		while (cursor.moveToNext()){
+		while (cursor.moveToNext()) {
 
 			//Create a new row
 			entry = (LinearLayout) factory.inflate(R.layout.row_home_blog, null);
@@ -817,7 +816,7 @@ public class HomeLayout extends Fragment implements LocationListener{
 
 			//Set text
 			String text = Html.fromHtml(cursor.getString(2)).toString();
-			if (text.length() > 100){
+			if (text.length() > 100) {
 				text = text.substring(0, 100) + "...";
 			}
 			TextView tvText = (TextView) entry.findViewById(R.id.tv_row_home_blog_text);
@@ -833,20 +832,19 @@ public class HomeLayout extends Fragment implements LocationListener{
 
 			//Get image
 			ImageView iv = (ImageView) entry.findViewById(R.id.iv_row_home_blog_image);
-			Cursor cursorImage = db.rawQuery("SELECT image FROM post_image WHERE post = " + cursor.getString(0) +" ORDER BY idx LIMIT 1;", null);
-			if (cursorImage.getCount() > 0){
+			Cursor cursorImage = db.rawQuery("SELECT image FROM post_image WHERE post = " + cursor.getString(0) + " ORDER BY idx LIMIT 1;", null);
+			if (cursorImage.getCount() > 0) {
 				cursorImage.moveToFirst();
 				String image = cursorImage.getString(0);
 
 				//Check if image exists
 				File f;
 				f = new File(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image);
-				if (f.exists()){
+				if (f.exists()) {
 					//If the image exists, set it.
 					Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image);
 					iv.setImageBitmap(myBitmap);
-				}
-				else {
+				} else {
 					//If not, create directories and download asynchronously
 					File fpath;
 					fpath = new File(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/");
@@ -858,29 +856,29 @@ public class HomeLayout extends Fragment implements LocationListener{
 			cursorImage.close();
 
 			//Set onCLickListener
-			entry.setOnClickListener(new View.OnClickListener(){
+			entry.setOnClickListener(new View.OnClickListener() {
 				@Override
 				public void onClick(View v) {
-				Fragment fragment = new PostLayout();
-				Bundle bundle = new Bundle();
-				//Pass post id
-				int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_blog_hidden)).getText().toString());
-				bundle.putInt("post", id);
-				fragment.setArguments(bundle);
-
-				FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
-				FragmentTransaction ft = fm.beginTransaction();
-
-				ft.replace(R.id.activity_main_content_fragment, fragment);
-				ft.addToBackStack("post_" + id);
-				ft.commit();
+					Fragment fragment = new PostLayout();
+					Bundle bundle = new Bundle();
+					//Pass post id
+					int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_blog_hidden)).getText().toString());
+					bundle.putInt("post", id);
+					fragment.setArguments(bundle);
+
+					FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
+					FragmentTransaction ft = fm.beginTransaction();
+
+					ft.replace(R.id.activity_main_content_fragment, fragment);
+					ft.addToBackStack("post_" + id);
+					ft.commit();
 				}
 			});
 
 			//Add to the list
 			llList.addView(entry);
 
-			counter ++;
+			counter++;
 		}
 
 		//Close database
@@ -894,9 +892,9 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 * Called when the user location changes. 
 	 * Recalculates the list of around events and calls updateLocation() to 
 	 * update the distance in the location section.
-	 * 
+	 *
 	 * @param location The new location
-	 * 
+	 *
 	 * @see android.location.LocationListener#onLocationChanged(android.location.Location)
 	 */
 	@Override
@@ -905,55 +903,58 @@ public class HomeLayout extends Fragment implements LocationListener{
 	}
 
 	/**
-     * Called when the location provider changes it's state. 
-     * Recalculates the list of events in the around section.
-     * 
-     * @param provider The name of the provider
-     * @param status Status code of the provider
-     * @param extras Extras passed 
-     * 
-     * @see android.location.LocationListener#onStatusChanged(java.lang.String, int, android.os.Bundle)
-     */
+	 * Called when the location provider changes it's state.
+	 * Recalculates the list of events in the around section.
+	 *
+	 * @param provider The name of the provider
+	 * @param status Status code of the provider
+	 * @param extras Extras passed
+	 *
+	 * @see android.location.LocationListener#onStatusChanged(java.lang.String, int, android.os.Bundle)
+	 */
 	@Override
 	public void onStatusChanged(String provider, int status, Bundle extras) {
 		//populateAround();
 	}
 
-	
+
 	/**
-     * Called when a location provider is enabled.
-     * Recalculates the list of events.
-     * 
-     * @param provider The name of the provider
-     * 
-     * @see android.location.LocationListener#onProviderEnabled(java.lang.String)
-     */
+	 * Called when a location provider is enabled.
+	 * Recalculates the list of events.
+	 *
+	 * @param provider The name of the provider
+	 *
+	 * @see android.location.LocationListener#onProviderEnabled(java.lang.String)
+	 */
 	@Override
 	public void onProviderEnabled(String provider) {
 		//populateAround();
 	}
 
 	/**
-     * Called when a location provider is disabled. 
-     * Recalculates the list of events.
-     * 
-     * @param provider The name of the provider
-     * 
-     * @see android.location.LocationListener#onProviderDisabled(java.lang.String)
-     */
+	 * Called when a location provider is disabled.
+	 * Recalculates the list of events.
+	 *
+	 * @param provider The name of the provider
+	 *
+	 * @see android.location.LocationListener#onProviderDisabled(java.lang.String)
+	 */
 	@Override
 	public void onProviderDisabled(String provider) {
 		//populateAround();
 	}
-	
+
 	/**
 	 * Called when the fragment is paused. 
 	 * Stops the location manager
 	 * @see android.app.Fragment#onPause()
 	 */
 	@Override
-	public void onPause(){
+	public void onPause() {
 		//TODO: Only do this if location is required
+		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) {
+			return;
+		}
 		locationManager.removeUpdates(this);
 		super.onPause();
 	}
@@ -964,8 +965,11 @@ public class HomeLayout extends Fragment implements LocationListener{
 	 * @see android.app.Fragment#onDestroy()
 	 */
 	@Override
-	public void onDestroy(){
+	public void onDestroy() {
 		//TODO: Only do this if location is required
+		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) {
+			return;
+		}
 		locationManager.removeUpdates(this);
 		super.onDestroy();
 	}
@@ -979,6 +983,9 @@ public class HomeLayout extends Fragment implements LocationListener{
 	@Override
 	public void onResume(){
 		//TODO: Only do this if location is required
+		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) {
+			return;
+		}
 		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
 		super.onResume();
 	}

+ 2 - 10
app/src/main/java/com/ivalentin/margolariak/HomeSectionLocation.java

@@ -25,8 +25,8 @@ class HomeSectionLocation extends AsyncTask<Void, Void, Void> {
 
 	private boolean isLocationReported;
 	private LatLng coord;
-	private View view;
-	private Activity activity;
+	private final View view;
+	private final Activity activity;
 
 	/**
 	 * Constructor.
@@ -41,14 +41,6 @@ class HomeSectionLocation extends AsyncTask<Void, Void, Void> {
 		this.view = v;
 	}
 
-	/**
-	 * Before starting background thread do nothing.
-	 */
-	@Override
-	protected void onPreExecute() {
-		super.onPreExecute();
-	}
-
 	/**
 	 * Downloading file in background thread.
 	 */

+ 32 - 43
app/src/main/java/com/ivalentin/margolariak/LocationLayout.java

@@ -2,9 +2,6 @@
 
 package com.ivalentin.margolariak;
 
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
 import java.util.Locale;
 
 import com.google.android.gms.maps.CameraUpdateFactory;
@@ -18,12 +15,14 @@ import com.google.android.gms.maps.model.MarkerOptions;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
 import android.location.Criteria;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.support.v4.app.ActivityCompat;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -36,61 +35,47 @@ import android.widget.TextView;
  * Section that shows a map with the location of Gasteizko Margolariak. 
  * If no recent report location, it will explain that and will show the 
  * next scheduled activity. 
- * 
+ *
  * @author Iñigo Valentin
- * 
+ *
  * @see Fragment
  * @see OnMapReadyCallback
  *
  */
 public class LocationLayout extends Fragment implements OnMapReadyCallback, LocationListener {
-	
+
 	//The map view
 	private MapView mapView;
 
 	private LocationManager locationManager;
-	
-	//The map
-	private GoogleMap map;
-	
+
 	//Locations for the user and Gasteizko Margolariak
 	private LatLng gmLocation;
-	
+
 	//The main View
 	private View v;
 
 	/**
 	 * Run when the fragment is inflated.
-	 * 
+	 *
 	 * @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)
 	 */
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
-		
+
 		//Get the view
 		v = inflater.inflate(R.layout.fragment_layout_location, container, false);
 
 		//Set up
 		locationManager = (LocationManager) v.getContext().getSystemService(Context.LOCATION_SERVICE);
 
-		
+
 		//Set the title
 		((MainActivity) getActivity()).setSectionTitle(v.getContext().getString(R.string.menu_location));
-		
-		//Get preferences
-		SharedPreferences settings = v.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-		
-		//Get current date and time string formatters
-		Calendar cal;
-		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);
-		Date date = new Date();
-		
 
 		mapView = (MapView) v.findViewById(R.id.mapview);
 		mapView.onCreate(savedInstanceState);
@@ -105,7 +90,7 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 	/**
 	 * Called when the fragment is bought back to the foreground. 
 	 * Ensures that the map is displayed then, and activates the location manager.
-	 * 
+	 *
 	 * @see android.app.Fragment#onResume()
 	 */
 	@Override
@@ -113,7 +98,9 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 		if (mapView != null) {
 			mapView.onResume();
 		}
-		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION_ACCURACY_TIME, GM.LOCATION_ACCURACY_SPACE, this);
+		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)){
+			locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GM.LOCATION_ACCURACY_TIME, GM.LOCATION_ACCURACY_SPACE, this);
+		}
 		super.onResume();
 	}
 
@@ -124,7 +111,9 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 	 */
 	@Override
 	public void onPause(){
-		locationManager.removeUpdates(this);
+		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+			locationManager.removeUpdates(this);
+		}
 		super.onPause();
 	}
 
@@ -137,7 +126,9 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		locationManager.removeUpdates(this);
+		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+			locationManager.removeUpdates(this);
+		}
 		if (mapView != null){
 			mapView.onResume();
 			mapView.onDestroy();
@@ -169,16 +160,14 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 	 */
 	@Override
 	public void onMapReady(GoogleMap googleMap) {
-		this.map = googleMap;
-		map.setMyLocationEnabled(true);
+		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+			googleMap.setMyLocationEnabled(true);
+		}
 		
-		map.getUiSettings().setMyLocationButtonEnabled(false);
-		map.setMyLocationEnabled(true);
+		googleMap.getUiSettings().setMyLocationButtonEnabled(false);
 		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
 		try {
 			MapsInitializer.initialize(this.getActivity());
-			//CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, 14);
-			//map.animateCamera(cameraUpdate);
 		} catch (Exception e) {
 			Log.e("Error initializing maps", e.toString());
 		}
@@ -192,19 +181,20 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 		moGm.title(v.getContext().getString(R.string.app_name));
 		moGm.position(gmLocation);
 		moGm.icon(BitmapDescriptorFactory.fromResource(R.drawable.pinpoint_gm));
-		map.addMarker(moGm);
-		map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon), 14.0f));
+		googleMap.addMarker(moGm);
+		googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon), 14.0f));
 
 		//Start device location requests
-		locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION_ACCURACY_TIME, GM.LOCATION_ACCURACY_SPACE, this);
-		onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
-
+		if (!(ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(v.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
+			locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION_ACCURACY_TIME, GM.LOCATION_ACCURACY_SPACE, this);
+			onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
+		}
 	}
 
 	private void calCulateDistance(Location userLocation){
 		TextView text = (TextView) v.findViewById(R.id.tv_location_distance);
 		try {
-			Double distance = Distance.calculateDistance(userLocation.getLatitude(), userLocation.getLongitude(), gmLocation.latitude, gmLocation.longitude, 'K');
+			Double distance = Distance.calculateDistance(userLocation.getLatitude(), userLocation.getLongitude(), gmLocation.latitude, gmLocation.longitude);
 			if (distance <= 2) {
 				distance = 1000 * distance;
 				text.setText(String.format(getString(R.string.home_section_location_text_short), distance.intValue(), (int) (0.012 * distance.intValue())));
@@ -229,7 +219,6 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 	 */
 	@Override
 	public void onLocationChanged(Location location) {
-		Log.e("CHANGED", Boolean.toString(gmLocation == null));
 		if (gmLocation != null)
 			calCulateDistance(location);
 	}

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

@@ -524,7 +524,7 @@ public class MainActivity extends Activity{
 	/**
 	 * Performs a full sync against the remote database.
 	 */
-	public void sync(){
+	private void sync(){
 		ProgressBar pbSync = (ProgressBar) findViewById(R.id.pb_sync);
 		new Sync(this, pbSync).execute();
 	}

+ 24 - 32
app/src/main/java/com/ivalentin/margolariak/MainLayout.java

@@ -4,12 +4,10 @@ import android.annotation.SuppressLint;
 import android.content.Context;
 import android.os.Handler;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.animation.Interpolator;
 import android.widget.LinearLayout;
-import android.widget.ScrollView;
 import android.widget.Scroller;
 
 /**
@@ -41,12 +39,11 @@ public class MainLayout extends LinearLayout {
 
 	private int contentXOffset;
 	private MenuState currentMenuState = MenuState.HIDDEN;
-	private Scroller menuScroller = new Scroller(this.getContext(), new EaseInInterpolator());
-	private Runnable menuRunnable = new MenuRunnable();
-	private Handler menuHandler = new Handler();
+	private final Scroller menuScroller = new Scroller(this.getContext(), new EaseInInterpolator());
+	private final Runnable menuRunnable = new MenuRunnable();
+	private final Handler menuHandler = new Handler();
 	private int prevX = 0;
 	private boolean isDragging = false;
-	private int lastDiffX = 0;
 
 	/**
 	 * Constructor.
@@ -140,7 +137,7 @@ public class MainLayout extends LinearLayout {
 	 * @see Runnable
 	 *
 	 */
-	protected class MenuRunnable implements Runnable {
+	private class MenuRunnable implements Runnable {
 		@Override
 		public void run() {
 			boolean isScrolling = menuScroller.computeScrollOffset();
@@ -188,7 +185,7 @@ public class MainLayout extends LinearLayout {
 	 * @author Iñigo Valentin
 	 *
 	 */
-	protected class EaseInInterpolator implements Interpolator {
+	private class EaseInInterpolator implements Interpolator {
 		@Override
 		public float getInterpolation(float t) {
 			return (float) Math.pow(t - 1, 5) + 1;
@@ -203,7 +200,7 @@ public class MainLayout extends LinearLayout {
 	 * @param event The MotionEvent triggering it.
 	 * @return True if the menu is fully opened or closed and a touch event is happening
 	 */
-	public boolean onContentTouch(MotionEvent event) {
+	private boolean onContentTouch(MotionEvent event) {
 		if (currentMenuState == MenuState.HIDING || currentMenuState == MenuState.SHOWING)
 			return false;
 		int curX = (int) event.getRawX();
@@ -215,28 +212,24 @@ public class MainLayout extends LinearLayout {
 				return true;
 			
 			case MotionEvent.ACTION_MOVE:
-				//int width = this.getWidth();
-				//if (event.getX() <  (float) width / 4){
-					
-					if (!isDragging) {
-						
-						isDragging = true;
-						menu.setVisibility(View.VISIBLE);
-					}
-					diffX = curX - prevX;
-					if (contentXOffset + diffX <= 0) {
-						diffX = -contentXOffset;
-					}
-					else if (contentXOffset + diffX > mainLayoutWidth - menuRightMargin) {
-						diffX = mainLayoutWidth - menuRightMargin - contentXOffset;
-					}
-					content.offsetLeftAndRight(diffX);
-					contentXOffset += diffX;
-					this.invalidate();
-					
-					prevX = curX;
-					lastDiffX = diffX;
-				//}
+				if (!isDragging) {
+
+					isDragging = true;
+					menu.setVisibility(View.VISIBLE);
+				}
+				diffX = curX - prevX;
+				if (contentXOffset + diffX <= 0) {
+					diffX = -contentXOffset;
+				}
+				else if (contentXOffset + diffX > mainLayoutWidth - menuRightMargin) {
+					diffX = mainLayoutWidth - menuRightMargin - contentXOffset;
+				}
+				content.offsetLeftAndRight(diffX);
+				contentXOffset += diffX;
+				this.invalidate();
+
+				prevX = curX;
+
 				return true;
 			
 			case MotionEvent.ACTION_UP:
@@ -253,7 +246,6 @@ public class MainLayout extends LinearLayout {
 				this.invalidate();
 				isDragging = false;
 				prevX = 0;
-				lastDiffX = 0;
 				return true;
 				
 			default:

+ 5 - 5
app/src/main/java/com/ivalentin/margolariak/PhotoLayout.java

@@ -38,10 +38,10 @@ public class PhotoLayout extends Fragment {
 
 	private String albumName;
 
-	Integer photos[];
-	int position;
+	private Integer photos[];
+	private int position;
 
-	Context context;
+	private Context context;
 
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	@Override
@@ -98,7 +98,7 @@ public class PhotoLayout extends Fragment {
 	 *
 	 * @return The position of the photo in the array.
 	 */
-	public int getPosition(Integer[] list, int id){
+	private int getPosition(Integer[] list, int id){
 		int i;
 		try{
 			i = 0;
@@ -277,7 +277,7 @@ public class PhotoLayout extends Fragment {
 			//Start async task
 			LinearLayout form = (LinearLayout) view.findViewById(R.id.ll_new_comment);
 			LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_comment_list);
-			new PostComment("galeria", user, text, lang, photoId, form, list, commentCount, tvComments, context).execute();
+			new PostComment("galeria", user, text, lang, photoId, form, list, context).execute();
 
 			}
 		});

+ 6 - 8
app/src/main/java/com/ivalentin/margolariak/PostComment.java

@@ -24,11 +24,11 @@ import java.util.Date;
 class PostComment extends AsyncTask<String, String, Integer> {
 
     //Elements passed from fragments
-    private String type, user, text, language, userCode;
-    private LinearLayout list, form;
-    private TextView counter;
-    private int id, currentCounter;
-    private Context context;
+    private final String type, user, text, language;
+    private String userCode;
+    private final LinearLayout list, form;
+    private final int id;
+    private final Context context;
 
     //Elements calculated here
     private Button btSend;
@@ -36,7 +36,7 @@ class PostComment extends AsyncTask<String, String, Integer> {
 
     private int code = 404;
 
-    public PostComment(String type, String user, String text, String language, int id, LinearLayout form, LinearLayout list, int currentCounter, TextView counter, Context context) {
+    public PostComment(String type, String user, String text, String language, int id, LinearLayout form, LinearLayout list, Context context) {
         super();
         this.type = type;
         this.user = user;
@@ -44,9 +44,7 @@ class PostComment extends AsyncTask<String, String, Integer> {
         this.form = form;
         this.list = list;
         this.language = language;
-        this.counter = counter;
         this.id = id;
-        this.currentCounter = currentCounter;
         this.context = context;
 
     }

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

@@ -21,7 +21,6 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 import java.io.File;
-import java.util.Locale;
 
 /**
  * Section that shows a post of the blog, with details and comments.
@@ -157,7 +156,7 @@ public class PostLayout extends Fragment {
                 LinearLayout form = (LinearLayout) view.findViewById(R.id.ll_new_comment);
                 LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_comment_list);
                 String lang = GM.getLang();
-                new PostComment("blog", user, text, lang, id, form, list, commentCount, tvComments, context).execute();
+                new PostComment("blog", user, text, lang, id, form, list, context).execute();
 
             }
         });

+ 43 - 13
app/src/main/java/com/ivalentin/margolariak/ScheduleLayout.java

@@ -22,10 +22,12 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.DialogInterface.OnShowListener;
+import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.support.v4.app.ActivityCompat;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.util.Log;
@@ -51,9 +53,9 @@ import android.widget.TextView;
  */
 public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 
-	Bundle bund;
+	private Bundle bund;
 
-	private String dates[] = new String[20];
+	private final String dates[] = new String[20];
 	private int dateCount = 0;
 	private int selected = 0;
 
@@ -411,8 +413,24 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 					
 				    //Else, show the date
 				    else{
-				    	SimpleDateFormat printFormat = new SimpleDateFormat("dd MMMM", Locale.US);
-				    	tvDate.setText(printFormat.format(day));
+						SimpleDateFormat printFormat;
+						switch (lang){
+							case "en":
+								printFormat = new SimpleDateFormat("MMMM dd", Locale.US);
+								tvDate.setText(printFormat.format(day));
+								break;
+							case "eu":
+								printFormat = new SimpleDateFormat("MMMM dd", new Locale("eu", "ES"));
+								tvDate.setText(printFormat.format(day));
+								break;
+							default:
+								printFormat = new SimpleDateFormat("dd", new Locale("es", "ES"));
+								String str = printFormat.format(day) + " de ";
+								printFormat = new SimpleDateFormat("MMMM", new Locale("es", "ES"));
+								str = str + printFormat.format(day);
+								tvDate.setText(str);
+						}
+
 				    }
 				}
 			}
@@ -459,8 +477,11 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 			dialog.setOnCancelListener(new OnCancelListener(){
 				@Override
 				public void onCancel(DialogInterface dialog) {
-					if (map != null)
-						map.setMyLocationEnabled(false);
+					if (map != null) {
+						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(false);
+						}
+					}
 					if (mapView != null){
     					mapView.onResume();
     					mapView.onDestroy();
@@ -513,8 +534,11 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 	public void onResume() {
 		if (mapView != null)
 			mapView.onResume();
-		if (map != null)
-			map.setMyLocationEnabled(true);
+		if (map != null) {
+			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);
+			}
+		}
 		super.onResume();
 	}
 
@@ -527,8 +551,11 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 	@Override
 	public void onDestroy() {
 		super.onDestroy();
-		if (map != null)
-			map.setMyLocationEnabled(false);
+		if (map != null) {
+			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(false);
+			}
+		}
 		if (mapView != null){
 			mapView.onResume();
 			mapView.onDestroy();
@@ -545,7 +572,9 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 	public void onPause() {
 		super.onDestroy();
 		if (map != null) {
-			map.setMyLocationEnabled(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(false);
+			}
 		}
 		if (mapView != null){
 			mapView.onPause();
@@ -578,10 +607,11 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 	@Override
 	public void onMapReady(GoogleMap googleMap) {
 		this.map = googleMap;
-		map.setMyLocationEnabled(true);
 		
 		map.getUiSettings().setMyLocationButtonEnabled(false);
-		map.setMyLocationEnabled(true);
+		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);
+		}
 		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
 		try {
 			MapsInitializer.initialize(this.getActivity());

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

@@ -24,9 +24,9 @@ import android.widget.TextView;
  * @author Inigo Valentin
  *
  */
-public class Sync extends AsyncTask<Void, Void, Void> {
+class Sync extends AsyncTask<Void, Void, Void> {
 	
-	private Context myContextRef;
+	private final Context myContextRef;
 	private ProgressBar pbSync;
 	private Dialog dialog;
 	private MainActivity activity;

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

@@ -16,7 +16,7 @@
 
         <LinearLayout
 			android:layout_width="match_parent"
-			android:layout_height="fill_parent"
+			android:layout_height="wrap_content"
 			android:divider="@drawable/divider"
 			android:orientation="vertical"
 			android:padding="10dp"

+ 2 - 1
app/src/main/res/layout/dialog_schedule.xml

@@ -80,7 +80,8 @@
                     android:id="@+id/tv_dialog_schedule_date"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:textAppearance="@android:style/TextAppearance.Medium"/>
+                    android:textAppearance="@android:style/TextAppearance.Medium"
+                    android:capitalize="sentences"/>
 
                 <TextView
                     android:id="@+id/tv_dialog_schedule_time"

+ 36 - 43
app/src/main/res/layout/fragment_layout_lablanca.xml

@@ -103,77 +103,70 @@
 
         </LinearLayout>
 
+
         <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingBottom="20dp"
-            android:layout_marginTop="15dp">
+            android:background="@drawable/section"
+            android:layout_marginTop="12dp"
+            android:padding="7dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="@string/lablanca_prices"
+                android:textStyle="bold"/>
 
             <LinearLayout
                 android:orientation="vertical"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:background="@drawable/section"
+                android:background="@drawable/entry"
                 android:padding="7dp">
 
                 <TextView
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:textAppearance="?android:attr/textAppearanceLarge"
-                    android:text="@string/lablanca_prices"
-                    android:id="@+id/textView12"
-                    android:textStyle="bold"/>
+                    android:text="@string/lablanca_prices_days"
+                    android:layout_marginBottom="15dp"/>
 
                 <LinearLayout
                     android:orientation="vertical"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
-                    android:background="@drawable/entry"
-                    android:padding="7dp">
-
-                    <TextView
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:textAppearance="?android:attr/textAppearanceLarge"
-                        android:text="@string/lablanca_prices_days"
-                        android:layout_marginBottom="15dp"/>
-
-                    <LinearLayout
-                        android:orientation="vertical"
-                        android:layout_width="match_parent"
-                        android:layout_height="match_parent"
-                        android:id="@+id/ll_lablanca_prices_days_list">
-                    </LinearLayout>
+                    android:id="@+id/ll_lablanca_prices_days_list">
                 </LinearLayout>
+            </LinearLayout>
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="@drawable/entry"
+                android:padding="7dp"
+                android:layout_marginTop="10dp"
+                android:layout_marginBottom="10dp">
+
+                <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textAppearance="?android:attr/textAppearanceLarge"
+                    android:text="@string/lablanca_prices_pack"
+                    android:layout_marginBottom="15dp"/>
 
                 <LinearLayout
                     android:orientation="vertical"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
-                    android:background="@drawable/entry"
-                    android:padding="7dp"
-                    android:layout_marginTop="10dp"
-                    android:layout_marginBottom="10dp">
-
-                    <TextView
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:textAppearance="?android:attr/textAppearanceLarge"
-                        android:text="@string/lablanca_prices_pack"
-                        android:layout_marginBottom="15dp"/>
-
-                    <LinearLayout
-                        android:orientation="vertical"
-                        android:layout_width="match_parent"
-                        android:layout_height="match_parent"
-                        android:id="@+id/ll_lablanca_prices_packs_list"
-                        />
-                </LinearLayout>
-
+                    android:id="@+id/ll_lablanca_prices_packs_list"
+                    />
             </LinearLayout>
-        </LinearLayout>
 
+        </LinearLayout>
     </LinearLayout>
 
+
 </com.ivalentin.margolariak.CustomScrollView>

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

@@ -69,7 +69,7 @@
         <LinearLayout
             android:orientation="horizontal"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
+            android:layout_height="wrap_content"
             android:layout_marginStart="10dp"
             android:id="@+id/ll_row_activity_itinerary_location"
             android:layout_marginTop="10dp"

+ 1 - 0
app/src/main/res/layout/row_comment.xml

@@ -29,6 +29,7 @@
             android:layout_height="wrap_content"
             android:id="@+id/tv_row_comment_date"
             android:layout_marginLeft="15dp"
+            android:layout_marginStart="15dp"
             android:layout_gravity="bottom"
             android:textAppearance="@android:style/TextAppearance.Small" />
 

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

@@ -65,7 +65,7 @@
             android:layout_height="wrap_content"
             android:textAppearance="?android:attr/textAppearanceSmall"
             android:id="@+id/tv_row_home_activity_price"
-            android:gravity="right" />
+            android:gravity="end" />
     </LinearLayout>
 
 </LinearLayout>

+ 3 - 2
app/src/main/res/layout/row_schedule.xml

@@ -86,12 +86,13 @@
                 android:layout_height="30dp"
                 android:id="@+id/iv_row_schedule_pinpoint"
                 android:src="@drawable/pinpoint"
-                android:layout_marginStart="10dp"/>
+                android:layout_marginStart="10dp"
+                android:foregroundGravity="center_vertical"/>
 
             <LinearLayout
                 android:orientation="vertical"
                 android:layout_width="match_parent"
-                android:layout_height="match_parent"
+                android:layout_height="wrap_content"
                 android:gravity="center_vertical">
 
                 <TextView

+ 1 - 1
app/src/main/res/values-en/strings.xml

@@ -61,7 +61,7 @@
 	<string name="settings_about">About us</string>
 	<string name="settings_transparency">Transparency</string>
 	<string name="settings_license_content">Copyright 2016 Iñigo Valentin&lt;br/>&lt;br/>This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.&lt;br/>&lt;br/>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details at http://www.gnu.org/licenses/.&lt;br/>&lt;br/>The name "Gasteizko Margolariak" and its logotype are property of Gasteizko Margolariak.&lt;br/>&lt;br/>&lt;br/>&lt;div style="background-color:#bbbbbb;padding:6px;border-radius:5px;border-style:solid;border-width:2px;border-color:#333333;text-align:center;">You can get the source code for this project at &lt;a href="https://github.com/Seavenois/GM">Github&lt;/a>&lt;/div></string>
-	<string name="settings_privacy_content">In Gasteizko Margolariak we respect your privacy. We don\'t collect ANY data from our users, including personal information, location, shopping habits, sexual preferences, favourite colour, first love\'s name... ANY.&lt;br/>&lt;br/>In order of making you believe us, we\'ll explain what we DO store:&lt;br/>&lt;br/>&lt;ul>&lt;li>A randomly generated user code, unique to your device. This is neccessary to sync content with aur database, so you can get info about our post, activities... But it\'s done in a way that won\'t allow un to identify you as a person with that number.&lt;/li>&lt;li>When commenting on a photo ar an entry, we store your current IP address. This is incredibly usefull for us to know how many actual people are posting comments, and it also makes imposible for us to identify you as a person.&lt;/li>&lt;/ul></string>
+	<string name="settings_privacy_content">In Gasteizko Margolariak we respect your privacy. We don\'t collect ANY data from our users, including personal information, location, shopping habits, sexual preferences, favourite colour, first love\'s name... ANY.&lt;br/>&lt;br/>In order of making you believe us, we\'ll explain what we DO store:&lt;br/>&lt;br/>&lt;ul>&lt;li>A randomly generated user code, unique to your device. This is necessary to sync content with aur database, so you can get info about our post, activities... But it\'s done in a way that won\'t allow un to identify you as a person with that number.&lt;/li>&lt;li>When commenting on a photo ar an entry, we store your current IP address. This is incredibly useful for us to know how many actual people are posting comments, and it also makes imposible for us to identify you as a person.&lt;/li>&lt;/ul></string>
 	<string name="settings_about_content">La Asociación Cultural Gasteizko Margolariak nace en el año 2013 con la idea de estimular la participación ciudadana y fortalecer la cultura y las tradiciones de Vitoria-Gasteiz.&lt;br/>&lt;br/>En nuestro nombre se refleja un barrio en el que las calles nos recuerdan a grandes pintores: el barrio de San Martín. Estamos representados en los barrios, y creemos que son la esencia de esta ciudad.&lt;br/>&lt;br/>Nos convertimos en Cuadrilla de Blusas y Neskas en 2013, y en ese mismo año, miembros de la Comisión de Blusas y Neskas.&lt;br/>&lt;br/>Desde entonces no hemos hecho más que crecer junto con todos los que han decidido, año tras año, apostar por nosotros.</string>
 	<string name="settings_transparency_content">¿Te preocupa saber dónde va tu dinero? En Gasteizko Margolariak queremos que estés tranquilo.&lt;br/>&lt;br/>Muchas de nuestras actividades son gratuitas. Otras, como las fiestas de La Blanca, tienen una cuota de inscripción. Gasteizko Margolariak no es una empresa, es una Asociación Cultural, y como tal, no tenemos beneficios.&lt;br/>&lt;br/>Queremos ser transparentes, y por eso, empezando en 2016, pondremos a tu disposición nuestras cuentas de manera online, para que sepas que cada euro se reinvierte en tí.</string>
 

+ 1 - 1
app/src/main/res/values-eu-rES/strings.xml

@@ -53,7 +53,7 @@
 	<string name="home_section_social">Jarraitu</string>
 
 	<string name="home_section_location_text_0">Gasteizko Margolariak ondoan dago!</string>
-	<string name="home_section_location_text_short">Zure inguruan %1$s metokoan daude (%2$s minutu oinez)</string>
+	<string name="home_section_location_text_short">Zure inguruan %1$d metokoan daude (%2$d minutu oinez)</string>
 	<string name="home_section_location_text_long">Zure inguruan %1$s kilometrokoan daude!</string>
 
 

+ 4 - 0
app/src/main/res/values/strings.xml

@@ -118,6 +118,10 @@
 	<string name="gallery_upload">Subir fotos</string>
 	<string name="gallery_upload_button">Subir</string>
 	<string name="gallery_upload_text">¿Tienes fotografías? ¡Ayudanos a construir esta galería!</string>
+	<plurals name="gallery_photo_count">
+		<item quantity="one">%1$d foto</item>
+		<item quantity="other">%1$d fotos</item>
+	</plurals>
 	<string name="home_section_activities_future">Proximas actividades</string>
 	<string name="home_section_gmschedule">Programa Margolari</string>
 	<string name="home_section_location_text_short">¡Están a solo %1$d metros de ti! (Unos %2$d minutos andando)</string>

+ 7 - 0
app/src/main/res/xml/backup.xml

@@ -0,0 +1,7 @@
+<full-backup-content>
+    <include domain="database" path="gm.db"/>
+    <include domain="sharedpref" path="gmpreferences.xml"/>
+    <exclude domain="file" />
+    <exclude domain="external" />
+    <exclude domain="root" />
+</full-backup-content>

+ 0 - 0
gradle.properties