seavenois 10 лет назад
Родитель
Сommit
51d7b54106

+ 17 - 16
app/src/main/java/com/ivalentin/gm/ActivityFutureLayout.java

@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -20,36 +21,40 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 14/06/16.
+ * Fragment to display upcoming activities.
+ * The id of the activity to display is passes in a bundle.
+ * Everything is done on the onCreateView method.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Fragment
+ *
  */
 public class ActivityFutureLayout extends Fragment {
 
-    String currLang;
-
-    Context context;
-
     @SuppressLint("InflateParams") //Throws unknown error when done properly.
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
         //Load the layout
         View view = inflater.inflate(R.layout.fragment_layout_activity_future, null);
-        context = view.getContext();
 
         //Get bundled id
         Bundle bundle = this.getArguments();
         int id = bundle.getInt("activity", -1);
         if (id == -1){
-            //TODO: Error, do something
+            Log.e("Activity error", "No such activity: " + id);
+            this.getActivity().onBackPressed();
         }
 
         //Get data from database
         SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
         final Cursor cursor;
-        currLang = Locale.getDefault().getDisplayLanguage();
+        String currLang = Locale.getDefault().getDisplayLanguage();
         if (!currLang.equals("es") && !currLang.equals("eu")){
             currLang = "en";
         }
+
         cursor = db.rawQuery("SELECT id, title_" + currLang+ " AS title, text_" + currLang + " AS text, date, city, price FROM activity WHERE id = " + id + ";", null);
         cursor.moveToFirst();
 
@@ -72,7 +77,7 @@ public class ActivityFutureLayout extends Fragment {
         ((MainActivity) getActivity()).setSectionTitle(cursor.getString(1));
         wvText.loadDataWithBaseURL(null, cursor.getString(2), "text/html", "utf-8", null);
         tvDate.setText(GM.formatDate(cursor.getString(3) + " 00:00:00", currLang, false));
-        tvPrice.setText(cursor.getString(5) + "€");
+        tvPrice.setText(String.format(getString(R.string.price), cursor.getInt(5)));
         tvCity.setText(cursor.getString(4));
 
         //Get images
@@ -93,8 +98,9 @@ public class ActivityFutureLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/");
-                fpath.mkdirs();
-                new DownloadImage(GM.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i]).execute();
+                if(fpath.mkdirs()) {
+                    new DownloadImage(GM.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i]).execute();
+                }
             }
             images[i].setVisibility(View.VISIBLE);
             i ++;
@@ -116,11 +122,6 @@ public class ActivityFutureLayout extends Fragment {
                 //Create a new row
                 entry = (LinearLayout) factory.inflate(R.layout.row_activity_schedule, null);
 
-                //Set margins
-                //LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
-                //layoutParams.setMargins(10, 10, 10, 25);
-                //entry.setLayoutParams(layoutParams);
-
                 //Set time
                 TextView tvSchTime = (TextView) entry.findViewById(R.id.tv_row_activity_itinerary_time);
                 tvSchTime.setText(cursor.getString(3).substring(11, 16));

+ 19 - 12
app/src/main/java/com/ivalentin/gm/ActivityLayout.java

@@ -23,13 +23,15 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 09/06/16.
+ * Fragment to display activities.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Fragment
+ *
  */
 public class ActivityLayout extends Fragment{
 
-    //Main View
-    private View view;
-
     /**
      * Run when the fragment is inflated.
      * Assigns views, gets the date and does the first call to the {@link #populate} function.
@@ -47,12 +49,12 @@ public class ActivityLayout extends Fragment{
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
         //Load the layout
-        view = inflater.inflate(R.layout.fragment_layout_activities, null);
+        View view = inflater.inflate(R.layout.fragment_layout_activities, null);
 
         //Set the title
         ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_activities));
 
-        populate();
+        populate(view);
         return view;
     }
 
@@ -60,7 +62,8 @@ public class ActivityLayout extends Fragment{
      * Populates the list of activities.
      * It uses the default layout as parent.
      */
-    public void populate(){
+    @SuppressLint("InflateParams") //Throws unknown error when done properly.
+    public 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;
@@ -101,7 +104,7 @@ public class ActivityLayout extends Fragment{
 
                 //Set price
                 TextView tvPrice = (TextView) entry.findViewById(R.id.tv_row_activity_future_price);
-                tvPrice.setText(cursor.getString(5) + "€");
+                tvPrice.setText(String.format(getString(R.string.price), cursor.getInt(5)));
 
                 //Set text
                 String text = Html.fromHtml(cursor.getString(4)).toString();
@@ -137,10 +140,12 @@ public class ActivityLayout extends Fragment{
                         //If not, create directories and download asynchronously
                         File fpath;
                         fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
-                        fpath.mkdirs();
-                        new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+                        if(fpath.mkdirs()) {
+                            new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+                        }
                     }
                 }
+                cursorImage.close();
 
                 //Set onCLickListener
                 entry.setOnClickListener(new View.OnClickListener() {
@@ -228,10 +233,12 @@ public class ActivityLayout extends Fragment{
                     //If not, create directories and download asynchronously
                     File fpath;
                     fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
-                    fpath.mkdirs();
-                    new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+                    if (fpath.mkdirs()) {
+                        new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+                    }
                 }
             }
+            cursorImage.close();
 
             //Set onCLickListener
             entry.setOnClickListener(new View.OnClickListener() {

+ 18 - 10
app/src/main/java/com/ivalentin/gm/ActivityPastLayout.java

@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -19,36 +20,42 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 14/06/16.
+ * Fragment to display past activities.
+ * The id of the activity to display is passes in a bundle.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Fragment
+ *
  */
 public class ActivityPastLayout extends Fragment {
 
     //Main View
-    private View view;
+    //private View view;
 
-    String currLang;
+    //String currLang;
 
-    Context context;
+    //Context context;
 
     @SuppressLint("InflateParams") //Throws unknown error when done properly.
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
         //Load the layout
-        view = inflater.inflate(R.layout.fragment_layout_activity_past, null);
-        context = view.getContext();
+        View view = inflater.inflate(R.layout.fragment_layout_activity_past, null);
 
         //Get bundled id
         Bundle bundle = this.getArguments();
         int id = bundle.getInt("activity", -1);
         if (id == -1){
-            //TODO: Error, do something
+            Log.e("Activity error", "No such activity: " + id);
+            this.getActivity().onBackPressed();
         }
 
         //Get data from database
         SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
         final Cursor cursor;
-        currLang = Locale.getDefault().getDisplayLanguage();
+        String currLang = Locale.getDefault().getDisplayLanguage();
         if (!currLang.equals("es") && !currLang.equals("eu")){
             currLang = "en";
         }
@@ -99,8 +106,9 @@ public class ActivityPastLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/");
-                fpath.mkdirs();
-                new DownloadImage(GM.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i]).execute();
+                if(fpath.mkdirs()) {
+                    new DownloadImage(GM.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i]).execute();
+                }
             }
             images[i].setVisibility(View.VISIBLE);
             i ++;

+ 13 - 36
app/src/main/java/com/ivalentin/gm/AlarmReceiver.java

@@ -3,7 +3,6 @@ package com.ivalentin.gm;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.List;
 import java.util.Locale;
 
 import android.app.AlarmManager;
@@ -17,9 +16,7 @@ import android.content.pm.PackageManager;
 import android.graphics.BitmapFactory;
 import android.media.RingtoneManager;
 import android.support.v4.app.NotificationCompat;
-//import android.app.Notification;
 import android.support.v4.app.TaskStackBuilder;
-//import android.content.WakefulBroadcastReceiver;
 import android.content.BroadcastReceiver;
 import android.util.Log;
 
@@ -52,15 +49,6 @@ public class AlarmReceiver extends BroadcastReceiver {
     public void onReceive(Context context, Intent intent) {
         
     	Log.d("Alarm", "Received");
-    	
-    	//Synchronize database. //TODO: I don't think i need this here.
-    	//new Sync(context).execute();
-
-		//The received web page, line by line.
-		List<String> output = null;
-		
-		//Boolean that will prevent the process to go on if something goes wrong.
-		boolean success = true;
 		    	
 		//Open the preferences to be available several times later.
 		SharedPreferences settings = context.getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
@@ -69,8 +57,7 @@ public class AlarmReceiver extends BroadcastReceiver {
 		
 		//Check if the user wants to receive notifications
 		if (settings.getInt(GM.PREF_NOTIFICATION , GM.DEFAULT_PREF_NOTIFICATION) == 1){
-			success = true;
-			
+
 			//Get the file
 			try{
 				fu = new FetchURL();
@@ -79,14 +66,14 @@ public class AlarmReceiver extends BroadcastReceiver {
 
 				//Parse info
 				String o = fu.getOutput().toString();
-				while (o.indexOf("<notification>") != -1){
+				while (o.contains("<notification>")){
 					//Get non-language-dependant fields
 					String notification = o.substring(o.indexOf("<notification>") + 14, o.indexOf("</notification>"));
 					String id = notification.substring(notification.indexOf("<id>") + 4, notification.indexOf("</id>"));
 					String action = notification.substring(notification.indexOf("<id>") + 4, notification.indexOf("</id>"));
 
 					//Is the notification seen already?
-					if(settings.getBoolean(GM.NOTIFICATION_SEEN_ + id, false) == false){
+					if(!settings.getBoolean(GM.NOTIFICATION_SEEN_ + id, false)){
 
 						//If not, get language dependant values
 						String currLang = Locale.getDefault().getDisplayLanguage();
@@ -149,14 +136,13 @@ public class AlarmReceiver extends BroadcastReceiver {
 						//Mark as notified
 						SharedPreferences.Editor editor = settings.edit();
 						editor.putBoolean(GM.NOTIFICATION_SEEN_ + id, true);
-						editor.commit();
+						editor.apply();
 					}
 				o = o.substring(o.indexOf("</notification>") + 15);
 				}
 			}
 			catch(Exception ex) {
 				Log.e("Notification error", "Error fetching remote file: " + ex.toString());
-				success = false;
 			}
     	}
 		
@@ -165,23 +151,14 @@ public class AlarmReceiver extends BroadcastReceiver {
 		fu = new FetchURL();
 		fu.Run(GM.SERVER + "/app/location.php");
 		String lat = "", lon = "";
-		output = fu.getOutput();
+		String o = fu.getOutput().toString();
 		Log.d("Alarm", "Fetched location");
-		for(int i = 0; i < output.size(); i++){
-			if (output.get(i).length() >= 25){
-				if (output.get(i).substring(0, 25).equals("<location>none</location>"))
-					result = false;
-			}
-			if (output.get(i).length() >= 6){
-				if (output.get(i).substring(0, 5).equals("<lat>")){
-					lat = output.get(i).substring(5, output.get(i).length()-6);
-					result = true;
-				}
-				if (output.get(i).substring(0, 5).equals("<lon>")){
-					lon = output.get(i).substring(5, output.get(i).length()-6);
-					result = true;
-				}
-			}
+		if (o.contains("<location>none</location>"))
+			result = false;
+		if (o.contains("<lat>") && o.contains("<lon>")){
+			lat = o.substring(o.indexOf("<lat>") + 5, o.indexOf("</lat>"));
+			lon = o.substring(o.indexOf("<lon>") + 5, o.indexOf("</lon>"));
+			result = true;
 		}
 		if (result){
 			SharedPreferences.Editor editor = settings.edit();
@@ -190,7 +167,7 @@ public class AlarmReceiver extends BroadcastReceiver {
 	    	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
 	    	Date date = new Date();
 	    	editor.putString(GM.PREF_GM_LOCATION, dateFormat.format(date));
-	    	editor.commit();
+	    	editor.apply();
 		}
     }
 
@@ -215,7 +192,7 @@ public class AlarmReceiver extends BroadcastReceiver {
 
     /**
      * Cancels the alarm.
-     * @param context
+     * @param context The application context
      */
     public void cancelAlarm(Context context) {
     	

+ 29 - 22
app/src/main/java/com/ivalentin/gm/AlbumLayout.java

@@ -23,37 +23,43 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 14/06/16.
+ * Fragment to display photos of a selected album.
+ * Album id is passed in a bundle.
+ * Album name is also passed, to be displayed on photos with no title.
+ * Everything is done when the view is inflated.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Fragment
+ *
  */
 public class AlbumLayout extends Fragment {
 
     //Main View
-    private View view;
+    //private View view;
 
-    private String currLang;
-	private String albumName;
-
-    private Context context;
+    //private String currLang;
+	//private String albumName;
 
     @SuppressLint("InflateParams") //Throws unknown error when done properly.
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
         //Load the layout
-        view = inflater.inflate(R.layout.fragment_layout_album, null);
-        context = view.getContext();
+        View view = inflater.inflate(R.layout.fragment_layout_album, null);
 
         //Get bundled id
         Bundle bundle = this.getArguments();
         int id = bundle.getInt("album", -1);
         if (id == -1){
-            //TODO: Error, do something
+			Log.e("Album error", "No such album: " + id);
+			this.getActivity().onBackPressed();
         }
 
         //Get data from database
         SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
         final Cursor cursor;
-        currLang = Locale.getDefault().getDisplayLanguage();
+        String currLang = Locale.getDefault().getDisplayLanguage();
         if (!currLang.equals("es") && !currLang.equals("eu")){
             currLang = "en";
         }
@@ -62,14 +68,14 @@ public class AlbumLayout extends Fragment {
 
         //Set album elements
         TextView tvTitle = (TextView) view.findViewById(R.id.tv_album_title);
-        TextView tvDescription = (TextView) view.findViewById(R.id.tv_album_description);
+        WebView tvDescription = (WebView) view.findViewById(R.id.wv_album_description);
         tvTitle.setText(cursor.getString(1));
-		albumName = cursor.getString(1);
+		final String albumName = cursor.getString(1);
         if (cursor.getString(2).length() < 1){
             tvDescription.setVisibility(View.GONE);
         }
         else {
-            tvDescription.setText(cursor.getString(2));
+            tvDescription.loadDataWithBaseURL(null, cursor.getString(2), "text/html", "utf-8", null);
         }
 		cursor.close();
 
@@ -89,7 +95,6 @@ public class AlbumLayout extends Fragment {
 
 			//Set left and right layouts
 			LinearLayout left = (LinearLayout) entry.findViewById(R.id.ll_row_album_left);
-			LinearLayout right = (LinearLayout) entry.findViewById(R.id.ll_row_album_right);
 
             //Set title
             TextView tvTitleLeft = (TextView) entry.findViewById(R.id.tv_row_album_title_left);
@@ -120,14 +125,15 @@ public class AlbumLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-                fpath.mkdirs();
-                new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivLeft).execute();
+                if(fpath.mkdirs()) {
+					new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivLeft).execute();
+				}
             }
 
 			//Count comments
 			Cursor cursorComments = db.rawQuery("SELECT id FROM photo_comment WHERE photo = " + imageCursor.getString(0) + ";", null);
 			TextView tvCommentsLeft = (TextView) entry.findViewById(R.id.tv_row_album_comments_left);
-			tvCommentsLeft.setText(" " + cursorComments.getCount());
+			tvCommentsLeft.setText(cursorComments.getCount());
 			cursorComments.close();
 
 			//Set onClickListener
@@ -155,8 +161,8 @@ public class AlbumLayout extends Fragment {
             //If odd pass, to the right line
             if (imageCursor.moveToNext()){
 
-                LinearLayout llRight = (LinearLayout) entry.findViewById(R.id.ll_row_album_right);
-                llRight.setVisibility(View.VISIBLE);
+                LinearLayout right = (LinearLayout) entry.findViewById(R.id.ll_row_album_right);
+                right.setVisibility(View.VISIBLE);
 
                 //Set title
                 TextView tvTitleRight = (TextView) entry.findViewById(R.id.tv_row_album_title_right);
@@ -185,14 +191,15 @@ public class AlbumLayout extends Fragment {
                     //If not, create directories and download asynchronously
                     File fpath;
                     fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-                    fpath.mkdirs();
-                    new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivRight).execute();
+                    if(fpath.mkdirs()) {
+						new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivRight).execute();
+					}
                 }
 
 				//Count comments
 				cursorComments = db.rawQuery("SELECT id FROM photo_comment WHERE photo = " + imageCursor.getString(0) + ";", null);
 				TextView tvCommentsRight = (TextView) entry.findViewById(R.id.tv_row_album_comments_right);
-				tvCommentsRight.setText(" " + cursorComments.getCount());
+				tvCommentsRight.setText(cursorComments.getCount());
 				cursorComments.close();
 
 				//Set onClickListener

+ 2 - 2
app/src/main/java/com/ivalentin/gm/BlogLayout.java

@@ -32,8 +32,8 @@ public class BlogLayout extends Fragment{
     //Main View
     private View view;
 
-    int offset = 0;
-    int totalPost = 0;
+    private int offset = 0;
+    private int totalPost = 0;
 
     /**
      * Run when the fragment is inflated.

+ 1 - 2
app/src/main/java/com/ivalentin/gm/CustomScrollView.java

@@ -65,8 +65,7 @@ public class CustomScrollView extends ScrollView{
 		int width = this.getWidth();
 		super.onTouchEvent(ev);
 		if (ev.getX() <  (float) width / 10){
-			
-			return false;
+						return false;
 		}
 		else{
 			return true;

+ 30 - 18
app/src/main/java/com/ivalentin/gm/DownloadImage.java

@@ -13,12 +13,28 @@ import java.io.OutputStream;
 import java.net.URL;
 import java.net.URLConnection;
 
-class DownloadImage extends AsyncTask<String, String, String> {
-
-    String file;
-    String path;
-    ImageView iv;
-
+/**
+ * Async task to download images on the fly.
+ * The remote image file, the local path, and the ImageView where the image will be loaded are set on the constructor.
+ *
+ * @author Iñigo Valentin
+ *
+ */
+class DownloadImage extends AsyncTask<Void, Void, Void> {
+
+    private String file;
+    private String path;
+    private ImageView iv;
+
+	/**
+	 * Constructor.
+	 *
+	 * @param file URL of the remote file.
+	 * @param path Path, including file name, where the image will be saved.
+	 * @param iv ImageView that will hold the image.
+	 *
+	 * @see android.widget.ImageView
+	 */
     public DownloadImage(String file, String path, ImageView iv) {
         super();
         this.file = file;
@@ -27,18 +43,18 @@ class DownloadImage extends AsyncTask<String, String, String> {
     }
 
     /**
-     * Before starting background thread
-     * */
+     * Before starting background thread do nothing.
+     */
     @Override
     protected void onPreExecute() {
         super.onPreExecute();
     }
 
     /**
-     * Downloading file in background thread
-     * */
+     * Downloading file in background thread.
+	 */
     @Override
-    protected String doInBackground(String... f_url) {
+    protected Void doInBackground(Void... v) {
         int count;
         try {
 
@@ -51,7 +67,6 @@ class DownloadImage extends AsyncTask<String, String, String> {
             InputStream input = new BufferedInputStream(url.openStream(), 8192);
 
             // Output stream to write file
-
             OutputStream output = new FileOutputStream(path);
             byte data[] = new byte[1024];
 
@@ -81,15 +96,12 @@ class DownloadImage extends AsyncTask<String, String, String> {
 
 
     /**
-     * After completing background task
-     * **/
+     * After completing background task, set the image on the ImageView.
+     */
     @Override
-    protected void onPostExecute(String file_url) {
+    protected void onPostExecute(Void v) {
         Log.d("File downloaded", path);
         Bitmap myBitmap = BitmapFactory.decodeFile(path);
-
-        //ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
-
         iv.setImageBitmap(myBitmap);
     }
 

+ 2 - 0
app/src/main/java/com/ivalentin/gm/FakeLinkTextView.java

@@ -1,3 +1,5 @@
+//TODO: Delete this file
+
 package com.ivalentin.gm;
 
 import android.content.Context;

+ 6 - 297
app/src/main/java/com/ivalentin/gm/GM.java

@@ -180,12 +180,7 @@ public final class GM {
 	 * Default value of the preference indicating if the user is Margolari.
 	 */
 	static final int DEFAULT_PREF_GM = 0;
-	
-	/**
-	 * Name of the preference indicating the user name.
-	 */
-	static final String PREF_USERNAME = "prefUsername";
-	
+
 	/**
 	 * Default value of the preference indicating the user name.
 	 */
@@ -260,287 +255,7 @@ public final class GM {
 	 * Name of the database
 	 */
 	static final String DB_NAME = "gm";
-	
-	/**
-	 * Name of the table "place" in the database.
-	 */
-	static final String DB_PLACE = "place";
-	
-	/**
-	 * Name of the table "people" in the database.
-	 */
-	static final String DB_PEOPLE = "people";
-	
-	/**
-	 * Name of the table "event" in the database.
-	 */
-	static final String DB_EVENT = "event";
-	
-	/**
-	 * Name of the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION = "notification";
-	
-	/**
-	 * Name of the column "id" in the table "place" in the database.
-	 */
-	static final String DB_PLACE_ID = "id";
-	
-	/**
-	 * Index of the column "id" in the table "place" in the database.
-	 */
-	static final int BD_PLACE_ID_INDEX = 0;
-	
-	/**
-	 * Name of the column "name" in the table "place" in the database.
-	 */
-	static final String DB_PLACE_NAME = "name";
-	
-	/**
-	 * Index of the column "name" in the table "place" in the database.
-	 */
-	static final int BD_PLACE_NAME_INDEX = 1;
-	
-	/**
-	 * Name of the column "address" in the table "place" in the database.
-	 */
-	static final String DB_PLACE_ADDRESS = "address";
-	
-	/**
-	 * Index of the column "address" in the table "place" in the database.
-	 */
-	static final int BD_PLACE_ADDRESS_INDEX = 2;
-	
-	/**
-	 * Name of the column "cp" in the table "place" in the database.
-	 */
-	static final String DB_PLACE_CP = "cp";
-	
-	/**
-	 * Index of the column "cp" in the table "place" in the database.
-	 */
-	static final int BD_PLACE_CP_INDEX = 3;
-	
-	/**
-	 * Name of the column "lat" in the table "place" in the database.
-	 */
-	static final String DB_PLACE_LATITUDE = "lat";
-	
-	/**
-	 * Index of the column "lat" in the table "place" in the database.
-	 */
-	static final int BD_PLACE_LATITUDE_INDEX = 4;
-	
-	/**
-	 * Name of the column "lon" in the table "place" in the database.
-	 */
-	static final String DB_PLACE_LONGITUDE = "lon";
-	
-	/**
-	 * Index of the column "lon" in the table "place" in the database.
-	 */
-	static final int BD_PLACE_LONGITUDE_INDEX = 5;
-	
-	/**
-	 * Name of the column "id" in the table "people" in the database.
-	 */
-	static final String DB_PEOPLE_ID = "id";
-	
-	/**
-	 * Index of the column "id" in the table "people" in the database.
-	 */
-	static final int BD_PEOPLE_ID_INDEX = 0;
-	
-	/**
-	 * Name of the column "name" in the table "people" in the database.
-	 */
-	static final String DB_PEOPLE_NAME = "name";
-	
-	/**
-	 * Index of the column "name" in the table "people" in the database.
-	 */
-	static final int BD_PEOPLE_NAME_INDEX = 1;
-	
-	/**
-	 * Name of the column "link" in the table "people" in the database.
-	 */
-	static final String DB_PEOPLE_LINK = "link";
-	
-	/**
-	 * Index of the column "link" in the table "people" in the database.
-	 */
-	static final int BD_PEOPLE_LINK_INDEX = 2;
-	
-	/**
-	 * Name of the column "id" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_ID = "id";
-	
-	/**
-	 * Index of the column "id" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_ID_INDEX = 0;
-	
-	/**
-	 * Name of the column "schedule" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_SCHEDULE = "schedule";
-	
-	/**
-	 * Index of the column "schedule" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_SCHEDULE_INDEX = 1;
-	
-	/**
-	 * Name of the column "gm" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_GM = "gm";
-	
-	/**
-	 * Index of the column "gm" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_GM_INDEX = 2;
-	
-	/**
-	 * Name of the column "name" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_NAME = "name";
-	
-	/**
-	 * Index of the column "name" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_NAME_INDEX = 3;
-	
-	/**
-	 * Name of the column "description" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_DESCRIPTION = "description";
-	
-	/**
-	 * Index of the column "description" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_DESCRIPTION_INDEX = 4;
-	
-	/**
-	 * Name of the column "host" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_HOST = "host";
-	
-	/**
-	 * Index of the column "host" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_HOST_INDEX = 5;
-	
-	/**
-	 * Name of the column "place" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_PLACE = "place";
-	
-	/**
-	 * Index of the column "place" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_PLACE_INDEX = 6;
-	
-	/**
-	 * Name of the column "start" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_START = "start";
-	
-	/**
-	 * Index of the column "start" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_START_INDEX = 7;
-	
-	/**
-	 * Name of the column "end" in the table "event" in the database.
-	 */
-	static final String DB_EVENT_END = "end";
-	
-	/**
-	 * Index of the column "end" in the table "event" in the database.
-	 */
-	static final int BD_EVENT_END_INDEX = 8;
-	
-	/**
-	 * Name of the column "id" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_ID = "id";
-	
-	/**
-	 * Index of the column "id" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_ID_INDEX = 0;
-	
-	/**
-	 * Name of the column "user" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_USER = "user";
-	
-	/**
-	 * Index of the column "user" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_USER_INDEX = 1;
-	
-	/**
-	 * Name of the column "time" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_TIME = "time";
-	
-	/**
-	 * Index of the column "time" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_TIME_INDEX = 2;
-	
-	/**
-	 * Name of the column "duration" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_DURATION = "duration";
-	
-	/**
-	 * Index of the column "id" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_DURATION_INDEX = 3;
-	
-	/**
-	 * Name of the column "type" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_TYPE = "type";
-	
-	/**
-	 * Index of the column "type" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_TYPE_INDEX = 4;
-	
-	/**
-	 * Name of the column "title" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_TITLE = "title";
-	
-	/**
-	 * Index of the column "title" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_TITLE_INDEX = 5;
-	
-	/**
-	 * Name of the column "text" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_TEXT = "text";
-	
-	/**
-	 * Index of the column "text" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_TEXT_INDEX = 6;
-	
-	/**
-	 * Name of the column "gm" in the table "notification" in the database.
-	 */
-	static final String DB_NOTIFICATION_GM = "gm";
-	
-	/**
-	 * Index of the column "text" in the table "notification" in the database.
-	 */
-	static final int BD_NOTIFICATION_GM_INDEX = 7;
-	
+
 	/**
 	 * The desired accuracy of the GPS coordinates, used to provide location updates, in meters.
 	 */
@@ -557,7 +272,7 @@ public final class GM {
 	 *
 	 * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
 	 */
-	public static final String formatDate(String dateString, String lang, boolean includeTime){
+	public static String formatDate(String dateString, String lang, boolean includeTime){
 
 		String output = "";
 
@@ -568,7 +283,7 @@ public final class GM {
 		String monthNameEn[] = {"January", "February", "March", "April", "May", "June", "July", "Augost", "September", "Octuber", "November", "December"};
 		String monthNameEu[] = {"urtarrilaren", "otsailaren", "martxoaren", "apirilaren", "maiatzaren", "ekainaren", "uztailaren", "abuztuaren", "irailaren", "urriaren", "azaroaren", "abenduaren"};
 
-		if (lang != "es" && lang != "eu"){
+		if (!lang.equals("es") && !lang.equals("eu")){
 			lang = "en";
 		}
 		DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
@@ -576,15 +291,9 @@ public final class GM {
 		Date date;
 		try{
 			date = format.parse(dateString);
-			df = new SimpleDateFormat("yyyy");
+			df = new SimpleDateFormat("yyyy", Locale.US);
 			String year = df.format(date);
-			//df = new SimpleDateFormat("uu");
-			//int dayNumber = Integer.parseInt(df.format(date));
-			df = new SimpleDateFormat("dd");
-			String day = df.format(date);
-			//df = new SimpleDateFormat("dd");
-			//int monthNumber = Integer.parseInt(df.format(date));
-			df = new SimpleDateFormat("hh:mm");
+			df = new SimpleDateFormat("hh:mm", Locale.US);
 			String time = df.format(date);
 			String dayName, monthName;
 

+ 33 - 36
app/src/main/java/com/ivalentin/gm/GalleryLayout.java

@@ -22,16 +22,18 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 09/06/16.
+ * Fragment of the gallery section.
+ *
+ * @see Fragment
+ *
+ * @author Iñigo Valentin
+ *
  */
 public class GalleryLayout extends Fragment{
 
-    //Main View
-    private View view;
-
     /**
      * Run when the fragment is inflated.
-     * Assigns views, gets the date and does the first call to the {@link #populate} function.
+     * Assigns views, gets the date and does the first call to the {@link @populate()} function.
      *
      * @param inflater A LayoutInflater to manage views
      * @param container The container View
@@ -46,12 +48,12 @@ public class GalleryLayout extends Fragment{
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
         //Load the layout
-        view = inflater.inflate(R.layout.fragment_layout_gallery, null);
+        View view = inflater.inflate(R.layout.fragment_layout_gallery, null);
 
         //Set the title
         ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_gallery));
 
-        populate();
+        populate(view);
 
         return view;
     }
@@ -60,7 +62,8 @@ public class GalleryLayout extends Fragment{
      * Populates the list of activities around.
      * It uses the default layout as parent.
      */
-    public void populate(){
+    @SuppressLint("InflateParams") //Throws unknown error when done properly.
+    private void populate(View view){
 
         //Assign elements
         LinearLayout llList = (LinearLayout) view.findViewById(R.id.ll_gallery_album_list);
@@ -126,49 +129,43 @@ public class GalleryLayout extends Fragment{
                     //If not, create directories and download asynchronously
                     File fpath;
                     fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/miniature/");
-                    fpath.mkdirs();
-                    new DownloadImage(GM.SERVER + "/img/galeria/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/miniature/" + image, preview[i]).execute();
+                    if (fpath.mkdirs()) {
+                        new DownloadImage(GM.SERVER + "/img/galeria/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/miniature/" + image, preview[i]).execute();
+                    }
                 }
                 i ++;
 
             }
-
+            cursorImage.close();
 
             //Set onCLickListener
             entry.setOnClickListener(new View.OnClickListener(){
                 @Override
                 public void onClick(View v) {
-                    Fragment fragment = new AlbumLayout();
-                    Bundle bundle = new Bundle();
-                    //Pass post id
-                    int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_gallery_hidden)).getText().toString());
-                    bundle.putInt("album", id);
-                    fragment.setArguments(bundle);
-
-                    FragmentManager fm = GalleryLayout.this.getActivity().getFragmentManager();
-                    FragmentTransaction ft = fm.beginTransaction();
-
-                    ft.replace(R.id.activity_main_content_fragment, fragment);
-                    ft.addToBackStack("album_" + id);
-                    ft.commit();
-                    //setSectionTitle(title);
-                }
-            });
+                Fragment fragment = new AlbumLayout();
+                Bundle bundle = new Bundle();
 
-            //Set onClick event
-            /*content = (LinearLayout) entry.findViewById(R.id.ll_row_schedule_content);
-            content.setOnClickListener(new View.OnClickListener(){
-                @Override
-                public void onClick(View v) {
-                    TextView tvName = (TextView) v.findViewById(R.id.tv_row_schedule_id);
-                    int id = Integer.parseInt(tvName.getText().toString());
-                    showDialog(id);
+                //Pass post id
+                int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_gallery_hidden)).getText().toString());
+                bundle.putInt("album", id);
+                fragment.setArguments(bundle);
+
+                FragmentManager fm = GalleryLayout.this.getActivity().getFragmentManager();
+                FragmentTransaction ft = fm.beginTransaction();
+
+                ft.replace(R.id.activity_main_content_fragment, fragment);
+                ft.addToBackStack("album_" + id);
+                ft.commit();
                 }
-            });*/
+            });
 
             //Add to the list
             llList.addView(entry);
         }
 
+        //Close database
+        cursor.close();
+        db.close();
+
     }
 }

+ 98 - 97
app/src/main/java/com/ivalentin/gm/HomeLayout.java

@@ -1,11 +1,6 @@
 package com.ivalentin.gm;
 
 import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
 import java.util.Locale;
 
 import com.google.android.gms.maps.CameraUpdate;
@@ -18,7 +13,6 @@ import com.google.android.gms.maps.model.LatLng;
 import com.google.android.gms.maps.model.MarkerOptions;
 
 import android.annotation.SuppressLint;
-import android.app.Dialog;
 import android.content.Context;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
@@ -37,7 +31,6 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
-import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -59,9 +52,6 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	
 	//The location of the user
 	private double[] coordinates = new double[2];
-	
-	//Layouts for each section
-	private LinearLayout llLocation, llLablanca, llGmschedule, llCityschedule, llAround, llGallery, llSocial;
 
 	//Language
 	private String currLang;
@@ -79,7 +69,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 * 
 	 * @param inflater A LayoutInflater to handle the views
 	 * @param container The parent View
-	 * //@param sanvedInstanceState Bundle with the saved state
+	 * @param savedInstanceState Bundle with the saved state
 	 * 
 	 * @return The fragment view
 	 * 
@@ -109,59 +99,13 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		Bundle bundle = this.getArguments();
 		coordinates[0] = bundle.getDouble("lat", 0);
 		coordinates[1] = bundle.getDouble("lon", 0);
-		
-		//Get current date
-		Calendar cal;
-		Date maxDate;
-		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();
-		
-		//Assign the layouts
-		llLocation = (LinearLayout) view.findViewById(R.id.ll_home_section_location);
-		llLablanca = (LinearLayout) view.findViewById(R.id.ll_home_section_lablanca);
-		llGmschedule = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule);
-		llCityschedule = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule);
-		llAround = (LinearLayout) view.findViewById(R.id.ll_home_section_around);
-
-
-		llGallery = (LinearLayout) view.findViewById(R.id.ll_home_section_gallery);
-		llSocial = (LinearLayout) view.findViewById(R.id.ll_home_section_social);
-
-		//Set onClick events for links
-		//TODO: Dont do it like this, do it in separate functions
-		llLocation.setOnClickListener(new OnClickListener(){
-			@Override
-			public void onClick(View v) {
-				((MainActivity) getActivity()).loadSection(GM.SECTION_LOCATION, false);
-			}
-		});
-		llLablanca.setOnClickListener(new OnClickListener(){
-			@Override
-			public void onClick(View v) {
-				((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA, false);
-			}
-		});
-		llGmschedule.setOnClickListener(new OnClickListener(){
-			@Override
-			public void onClick(View v) {
-				((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, false);
-			}
-		});
-		llCityschedule.setOnClickListener(new OnClickListener(){
-			@Override
-			public void onClick(View v) {
-				((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_SCHEDULE, false);
-			}
-		});
-		llAround.setOnClickListener(new OnClickListener(){
-			@Override
-			public void onClick(View v) {
-				((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_AROUND, false);
-			}
-		});
 
+		//TODO: These methods are empty yet
+		setUpLocation(view);
+		setUpLablanca(view);
+		setUpGmschedule(view);
+		setUpCityschedule(view);
+		setUpAround(view);
 
 		//Set up the blog section
 		setUpBlog(view);
@@ -174,13 +118,70 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		//Set up the gallery section
 		setUpGallery(view);
 
-
-		//TODO: Add listeners for social
-
 	    //Return the view itself.
 		return view;
 	}
 
+	/**
+	 * Populates the Social section of the home screen.
+	 *
+	 * @return The number of entries shown.
+	 */
+	private int setUpSocial(View view) {
+		//TODO: setUpSocial(View view)
+		return 0;
+	}
+
+	/**
+	 * Populates the Around section of the home screen.
+	 *
+	 * @return The number of entries shown.
+	 */
+	private int setUpAround(View view) {
+		//TODO: setUpAround(View view)
+		return 0;
+	}
+
+	/**
+	 * Populates the GM Schedule section of the home screen.
+	 *
+	 * @return The number of entries shown.
+	 */
+	private int setUpGmschedule(View view) {
+		//TODO: setUpGMschedule(View view)
+		return 0;
+	}
+
+	/**
+	 * Populates the City Schedule section of the home screen.
+	 *
+	 * @return The number of entries shown.
+	 */
+	private int setUpCityschedule(View view) {
+		//TODO: setUpCitySchedule(View view)
+		return 0;
+	}
+
+	/**
+	 * Populates the La Blanca section of the home screen.
+	 *
+	 * @return True if the section has been shown, false otherwise.
+	 */
+	private boolean setUpLablanca(View view) {
+		//TODO: setUpLablanca(View view)
+		return false;
+	}
+
+	/**
+	 * Populates the Location section of the home screen.
+	 *
+	 * @return True if the section has been shown, false otherwise.
+	 */
+	private boolean setUpLocation(View view) {
+		//TODO: setUpLocation(View view)
+		return false;
+	}
+
 	/**
 	 * Populates the Gallery section of the home screen.
 	 * Loads four photos.
@@ -208,12 +209,6 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		ivPhoto[2] = (ImageView) view.findViewById(R.id.iv_home_section_gallery_2);
 		ivPhoto[3] = (ImageView) view.findViewById(R.id.iv_home_section_gallery_3);
 
-		TextView tvHidden[] = new TextView[4];
-		tvHidden[0] = (TextView) view.findViewById(R.id.tv_home_section_gallery_hidden_0);
-		tvHidden[1] = (TextView) view.findViewById(R.id.tv_home_section_gallery_hidden_1);
-		tvHidden[2] = (TextView) view.findViewById(R.id.tv_home_section_gallery_hidden_2);
-		tvHidden[3] = (TextView) view.findViewById(R.id.tv_home_section_gallery_hidden_3);
-
 		//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, album, file, uploaded FROM photo, photo_album WHERE id = photo ORDER BY uploaded DESC LIMIT 4;", null);
@@ -237,31 +232,32 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 				//If not, create directories and download asynchronously
 				File fpath;
 				fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-				fpath.mkdirs();
-				new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivPhoto[counter]).execute();
+				if (fpath.mkdirs()) {
+					new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivPhoto[counter]).execute();
+				}
 			}
 
 			//Set listeners for images
 			ivPhoto[counter].setOnClickListener(new View.OnClickListener() {
 				@Override
 				public void onClick(View v) {
-					Fragment fragment = new AlbumLayout();
-					Bundle bundle = new Bundle();
+				Fragment fragment = new AlbumLayout();
+				Bundle bundle = new Bundle();
 
-					int photoId = Integer.parseInt((String) v.getTag(R.string.key_0));
-					int albumId = Integer.parseInt((String) v.getTag(R.string.key_1));
+				int photoId = Integer.parseInt((String) v.getTag(R.string.key_0));
+				int albumId = Integer.parseInt((String) v.getTag(R.string.key_1));
 
-					bundle.putInt("album", albumId);
-					bundle.putInt("photo", photoId);
+				bundle.putInt("album", albumId);
+				bundle.putInt("photo", photoId);
 
-					fragment.setArguments(bundle);
+				fragment.setArguments(bundle);
 
-					FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
-					FragmentTransaction ft = fm.beginTransaction();
+				FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
+				FragmentTransaction ft = fm.beginTransaction();
 
-					ft.replace(R.id.activity_main_content_fragment, fragment);
-					ft.addToBackStack("album_" + albumId);
-					ft.commit();
+				ft.replace(R.id.activity_main_content_fragment, fragment);
+				ft.addToBackStack("album_" + albumId);
+				ft.commit();
 				}
 			});
 
@@ -282,6 +278,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 *
 	 * @return The number of entries shown
 	 */
+	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	private int setUpPastActivities(View view){
 		int counter = 0;
 
@@ -297,7 +294,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		llActivitiesPast.setOnClickListener(new OnClickListener(){
 			@Override
 			public void onClick(View v) {
-				((MainActivity) getActivity()).loadSection(GM.SECTION_ACTIVITIES, false);
+			((MainActivity) getActivity()).loadSection(GM.SECTION_ACTIVITIES, false);
 			}
 		});
 
@@ -370,8 +367,9 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 					//If not, create directories and download asynchronously
 					File fpath;
 					fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
-					fpath.mkdirs();
-					new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+					if (fpath.mkdirs()) {
+						new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+					}
 				}
 			}
 			cursorImage.close();
@@ -417,6 +415,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 *
 	 * @return The number of entries shown
 	 */
+	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	private int setUpFutureActivities(View view){
 		int counter = 0;
 
@@ -465,7 +464,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 
 				//Set price
 				TextView tvPrice = (TextView) entry.findViewById(R.id.tv_row_home_activity_price);
-				tvPrice.setText(cursor.getString(5) + "€");
+				tvPrice.setText(String.format(getString(R.string.price), cursor.getInt(5)));
 
 				//Set text
 				String text = Html.fromHtml(cursor.getString(4)).toString();
@@ -501,8 +500,9 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 						//If not, create directories and download asynchronously
 						File fpath;
 						fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
-						fpath.mkdirs();
-						new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+						if (fpath.mkdirs()) {
+							new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
+						}
 					}
 				}
 
@@ -512,7 +512,6 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 				entry.setOnClickListener(new View.OnClickListener() {
 					@Override
 					public void onClick(View v) {
-						//Toast.makeText(getActivity(), "OPENING POST", Toast.LENGTH_LONG).show();
 						Fragment fragment = new ActivityFutureLayout();
 						Bundle bundle = new Bundle();
 						//Pass post id
@@ -548,6 +547,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 *
 	 * @return The number of entries shown
 	 */
+	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	private int setUpBlog(View view){
 
 		int counter = 0;
@@ -623,8 +623,9 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 					//If not, create directories and download asynchronously
 					File fpath;
 					fpath = new File(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/");
-					fpath.mkdirs();
-					new DownloadImage(GM.SERVER + "/img/blog/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image, iv).execute();
+					if (fpath.mkdirs()) {
+						new DownloadImage(GM.SERVER + "/img/blog/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image, iv).execute();
+					}
 				}
 			}
 
@@ -670,7 +671,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 * 
 	 * @return The total price
 	 */
-	private int calculatePrice(Dialog v){
+	/*private int calculatePrice(Dialog v){
 		
 		//Locate views
 		CheckBox[] cbDayName = new CheckBox[6];
@@ -738,7 +739,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		db.close();
 		//Return the total price
 		return total;
-	}
+	}*/
 
 	/**
 	 * Starts the map in the dialogs.

+ 2 - 0
app/src/main/java/com/ivalentin/gm/LocationLayout.java

@@ -1,3 +1,5 @@
+//TODO: Rework this file
+
 package com.ivalentin.gm;
 
 import java.text.SimpleDateFormat;

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

@@ -36,10 +36,8 @@ import android.widget.TextView;
  *
  */
 public class MainActivity extends Activity implements LocationListener{
-	//public class MainActivity extends AppCompatActivity implements LocationListener{
 
-
-		//Set of GPS coordinates
+	//Set of GPS coordinates
 	private double[] coordinates = new double[2];
 	
 	//The main layout of the app

+ 36 - 14
app/src/main/java/com/ivalentin/gm/PhotoLayout.java

@@ -12,7 +12,6 @@ import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.webkit.WebView;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageView;
@@ -24,15 +23,21 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 16/06/16.
+ * Section that shows a photo of the gallery, with details and comments.
+ * Contains info from almost every other section.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Fragment
+ *
  */
 public class PhotoLayout extends Fragment {
 
 	//Main View
 	private View view;
 
-	String currLang;
-	String albumName;
+	private String currLang;
+	private String albumName;
 
 	Integer photos[];
 	int position;
@@ -49,10 +54,11 @@ public class PhotoLayout extends Fragment {
 
 		//Get bundled id
 		Bundle bundle = this.getArguments();
-		albumName = bundle.getString(albumName, "");
+		albumName = bundle.getString("albumName", "");
 		int id = bundle.getInt("photo", -1);
 		if (id == -1) {
-			//TODO: Error, do something
+			Log.e("Photo error", "No such photo: " + id);
+			this.getActivity().onBackPressed();
 		}
 
 		photos = loadPhotos(id);
@@ -66,7 +72,7 @@ public class PhotoLayout extends Fragment {
 			public void onClick(View v) {
 				if (position > 0){
 					position --;
-					populate(position);
+					populate(photos[position]);
 				}
 			}
 		});
@@ -75,7 +81,7 @@ public class PhotoLayout extends Fragment {
 			public void onClick(View v) {
 				if (position < photos.length - 1){
 					position ++;
-					populate(position);
+					populate(photos[position]);
 				}
 			}
 		});
@@ -121,7 +127,6 @@ public class PhotoLayout extends Fragment {
 		SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
 
 		//Get album id for the photo
-		//Log.e("QUERY", "SELECT album FROM photo_album WHERE photo = " + id + ";");
 		Cursor cAlbum = db.rawQuery("SELECT album FROM photo_album WHERE photo = " + id + ";", null);
 		cAlbum.moveToFirst();
 		int album = cAlbum.getInt(0);
@@ -138,8 +143,6 @@ public class PhotoLayout extends Fragment {
 		cursor.close();
 		db.close();
 
-		//Set listeners for previous, next buttons
-
 		return list;
 	}
 
@@ -147,6 +150,7 @@ public class PhotoLayout extends Fragment {
 		populate(id, view);
 	}
 
+	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	private void populate(int id, View v){
 
 		final int photoId = id;
@@ -205,10 +209,28 @@ public class PhotoLayout extends Fragment {
 			//If not, create directories and download asynchronously
 			File fpath;
 			fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-			fpath.mkdirs();
-			new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, imageView).execute();
+			if (fpath.mkdirs()) {
+				new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, imageView).execute();
+			}
 		}
 
+		//Hide or show comments, as needed
+		Button btNext = (Button) v.findViewById(R.id.bt_photo_next);
+		Button btPrevious = (Button) v.findViewById(R.id.bt_photo_previous);
+		if (position == 0){
+			btPrevious.setVisibility(View.INVISIBLE);
+		}
+		else{
+			btPrevious.setVisibility(View.VISIBLE);
+		}
+		if (position == photos.length - 1){
+			btNext.setVisibility(View.INVISIBLE);
+		}
+		else{
+			btNext.setVisibility(View.VISIBLE);
+		}
+
+
 
 		//Get comments
 		Cursor commentCursor = db.rawQuery("SELECT text, dtime, username FROM photo_comment WHERE photo = " + id + ";", null);
@@ -216,8 +238,8 @@ public class PhotoLayout extends Fragment {
 		final int commentCount = commentCursor.getCount();
 		cursor.moveToFirst();
 		LinearLayout entry;
-		LinearLayout commentList = (LinearLayout) v.findViewById(R.id.ll_comment_list);
 		LayoutInflater factory = LayoutInflater.from(getActivity());
+		llCommentList.removeAllViews();
 		while (commentCursor.moveToNext()) {
 			entry = (LinearLayout) factory.inflate(R.layout.row_comment, null);
 

+ 6 - 19
app/src/main/java/com/ivalentin/gm/PostComment.java

@@ -1,5 +1,6 @@
 package com.ivalentin.gm;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.AsyncTask;
@@ -53,13 +54,11 @@ class PostComment extends AsyncTask<String, String, Integer> {
      * */
     @Override
     protected void onPreExecute() {
-        //Log.e("PRE", "START");
         super.onPreExecute();
         btSend = (Button) form.findViewById(R.id.bt_comment_send);
         pb = (ProgressBar) form.findViewById(R.id.pb_comment);
         btSend.setVisibility(View.GONE);
         pb.setVisibility(View.VISIBLE);
-        //Log.e("PRE", "END");
     }
 
     /**
@@ -67,14 +66,10 @@ class PostComment extends AsyncTask<String, String, Integer> {
      * */
     @Override
     protected Integer doInBackground(String... f_url) {
-        //.e("DIB", "START");
-        int count;
         URL url;
-        String urlString, urlParams;
+        String urlParams;
         try {
 
-            //url = new URL(GM.SERVER + "/" + type + "/comment.php?user=" + user + "&text=" + text);
-            urlString = GM.SERVER + "/" + type + "/comment.php?user=" + URLEncoder.encode(user) + "&text=" + URLEncoder.encode(text);
             urlParams = "user=" + URLEncoder.encode(user) + "&text=" + URLEncoder.encode(text);
             switch (type){
                 case "blog":
@@ -87,7 +82,8 @@ class PostComment extends AsyncTask<String, String, Integer> {
                     urlParams = urlParams + "&activity=" + id;
                     break;
                 default:
-                    //TODO, error, stop
+                    Log.e("Comment error", "Unknown section: " + type);
+                    return -1;
             }
             switch (language){
                 case "es":
@@ -117,13 +113,6 @@ class PostComment extends AsyncTask<String, String, Integer> {
             wr.write(postData);
             conn.connect();
 
-
-            //Log.e("URL", urlString);
-            //url = new URL(urlString);
-            //HttpURLConnection connection = (HttpURLConnection)url.openConnection();
-            //connection.setRequestMethod("GET");
-            //connection.connect();
-
             code = conn.getResponseCode();
             Log.d("Comment status", "" + code);
 
@@ -162,7 +151,8 @@ class PostComment extends AsyncTask<String, String, Integer> {
 
     /**
      * After completing background task
-     * **/
+     */
+    @SuppressLint("InflateParams") //Throws unknown error when done properly.
     @Override
     protected void onPostExecute(Integer a) {
         //Log.e("POS", "START");
@@ -198,8 +188,5 @@ class PostComment extends AsyncTask<String, String, Integer> {
         //Show button again
         btSend.setVisibility(View.VISIBLE);
         pb.setVisibility(View.GONE);
-
-        //ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
-        //Log.e("POS", "END");
     }
 }

+ 14 - 5
app/src/main/java/com/ivalentin/gm/PostLayout.java

@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
 import android.app.Fragment;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -23,7 +24,13 @@ import java.io.File;
 import java.util.Locale;
 
 /**
- * Created by seavenois on 12/06/16.
+ * Section that shows a post of the blog, with details and comments.
+ * Contains info from almost every other section.
+ *
+ * @author Iñigo Valentin
+ *
+ * @see Fragment
+ *
  */
 public class PostLayout extends Fragment {
 
@@ -46,7 +53,8 @@ public class PostLayout extends Fragment {
         Bundle bundle = this.getArguments();
         int id = bundle.getInt("post", -1);
         if (id == -1){
-            //TODO: Error, do something
+            Log.e("Post error", "No such post: " + id);
+            this.getActivity().onBackPressed();
         }
 
         //Get data from database
@@ -103,8 +111,9 @@ public class PostLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/blog/preview/");
-                fpath.mkdirs();
-                new DownloadImage(GM.SERVER + "/img/blog/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/preview/" + image, images[i]).execute();
+                if (fpath.mkdirs()) {
+					new DownloadImage(GM.SERVER + "/img/blog/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/preview/" + image, images[i]).execute();
+				}
             }
             images[i].setVisibility(View.VISIBLE);
             i ++;
@@ -117,7 +126,6 @@ public class PostLayout extends Fragment {
         final int commentCount = commentCursor.getCount();
         cursor.moveToFirst();
         LinearLayout entry;
-        LinearLayout commentList = (LinearLayout) view.findViewById(R.id.ll_comment_list);
         LayoutInflater factory = LayoutInflater.from(getActivity());
         while (commentCursor.moveToNext()) {
             entry = (LinearLayout) factory.inflate(R.layout.row_comment, null);
@@ -164,6 +172,7 @@ public class PostLayout extends Fragment {
             }
         });
 
+        cursor.close();
         db.close();
         return view;
     }

+ 4 - 2
app/src/main/java/com/ivalentin/gm/ScheduleLayout.java

@@ -1,3 +1,5 @@
+//TODO: Rework this file
+
 package com.ivalentin.gm;
 
 import java.text.DateFormat;
@@ -293,9 +295,9 @@ public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
 	    
 	    //Get data from database
 	    if (schedule == GM.SECTION_LABLANCA_GM_SCHEDULE)
-	    	cursor = db.rawQuery("SELECT event.id, event.name, event.description, event.place, place.id, place.name, event.start FROM " + GM.DB_EVENT + ", " + GM.DB_PLACE + " WHERE " + GM.DB_EVENT_GM + " = 1 AND place.id = event.place AND start BETWEEN '" + minDateStr + "' AND '" + maxDateStr + "' AND (lower(event.name) LIKE '%" + filter + "%' OR lower(event.description) LIKE '%" + filter + "%' OR lower(place.name) LIKE '%" + filter + "%') ORDER BY " + GM.DB_EVENT_START + ";", null);
+	    	cursor = db.rawQuery("SELECT event.id, event.name, event.description, event.place, place.id, place.name, event.start FROM event, place WHERE event = 1 AND place.id = event.place AND start BETWEEN '" + minDateStr + "' AND '" + maxDateStr + "' AND (lower(event.name) LIKE '%" + filter + "%' OR lower(event.description) LIKE '%" + filter + "%' OR lower(place.name) LIKE '%" + filter + "%') ORDER BY start;", null);
 	    else
-	    	cursor = db.rawQuery("SELECT event.id, event.name, event.description, event.place, place.id, place.name, event.start FROM " + GM.DB_EVENT + ", " + GM.DB_PLACE + " WHERE " + GM.DB_EVENT_SCHEDULE + " = 1 AND place.id = event.place AND start BETWEEN '" + minDateStr + "' AND '" + maxDateStr + "' AND (lower(event.name) LIKE '%" + filter + "%' OR lower(event.description) LIKE '%" + filter + "%' OR lower(place.name) LIKE '%" + filter + "%') ORDER BY " + GM.DB_EVENT_START + ";", null);
+	    	cursor = db.rawQuery("SELECT event.id, event.name, event.description, event.place, place.id, place.name, event.start FROM event, place WHERE event = 1 AND place.id = event.place AND start BETWEEN '" + minDateStr + "' AND '" + maxDateStr + "' AND (lower(event.name) LIKE '%" + filter + "%' OR lower(event.description) LIKE '%" + filter + "%' OR lower(place.name) LIKE '%" + filter + "%') ORDER BY start;", null);
 		
 	    //Clear the list
 		list.removeAllViews();

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

@@ -25,12 +25,12 @@
             android:text="Large Text"
             android:id="@+id/tv_album_title" />
 
-        <TextView
+        <WebView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:text="Medium Text"
-            android:id="@+id/tv_album_description"
+            android:id="@+id/wv_album_description"
             android:layout_margin="7dp"
             android:background="@drawable/entry"
             android:padding="7dp" />

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

@@ -14,6 +14,9 @@
 	<string name="app_email">gasteizkomargolariak@gmail.com</string>
 
 
+	<!-- Common strings -->
+	<string name="price">Price: %1$d</string>
+
 	<!-- Arrow buttons -->
 
 	<string name="arrow_left">&lt;</string>