Parcourir la source

La Blanca section implemented

seavenois il y a 10 ans
Parent
commit
a0eccdb402

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

@@ -98,9 +98,8 @@ public class ActivityFutureLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/preview/");
-                if(fpath.mkdirs()) {
-                    new DownloadImage(GM.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i]).execute();
-                }
+                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 ++;

+ 4 - 6
app/src/main/java/com/ivalentin/gm/ActivityLayout.java

@@ -140,9 +140,8 @@ public class ActivityLayout extends Fragment{
                         //If not, create directories and download asynchronously
                         File fpath;
                         fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
-                        if(fpath.mkdirs()) {
-                            new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
-                        }
+                        fpath.mkdirs();
+                        new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
                     }
                 }
                 cursorImage.close();
@@ -233,9 +232,8 @@ public class ActivityLayout extends Fragment{
                     //If not, create directories and download asynchronously
                     File fpath;
                     fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
-                    if (fpath.mkdirs()) {
-                        new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
-                    }
+                    fpath.mkdirs();
+                    new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
                 }
             }
             cursorImage.close();

+ 3 - 4
app/src/main/java/com/ivalentin/gm/ActivityPastLayout.java

@@ -106,10 +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/");
-                if(fpath.mkdirs()) {
-                    new DownloadImage(GM.SERVER + "/img/actividades/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/preview/" + image, images[i]).execute();
-                }
-            }
+                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 ++;
         }

+ 4 - 5
app/src/main/java/com/ivalentin/gm/AlarmReceiver.java

@@ -2,6 +2,7 @@ package com.ivalentin.gm;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
 
@@ -162,11 +163,9 @@ public class AlarmReceiver extends BroadcastReceiver {
 		}
 		if (result){
 			SharedPreferences.Editor editor = settings.edit();
-	    	editor.putString(GM.PREF_GM_LATITUDE, lat);
-	    	editor.putString(GM.PREF_GM_LONGITUDE, lon);
-	    	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.putLong(GM.PREF_GM_LATITUDE, Double.doubleToLongBits(Double.parseDouble(lat)));
+			editor.putLong(GM.PREF_GM_LONGITUDE, Double.doubleToLongBits(Double.parseDouble(lon)));
+			editor.putString(GM.PREF_GM_LOCATION, new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime()));
 	    	editor.apply();
 		}
     }

+ 4 - 6
app/src/main/java/com/ivalentin/gm/AlbumLayout.java

@@ -125,9 +125,8 @@ public class AlbumLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-                if(fpath.mkdirs()) {
-					new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivLeft).execute();
-				}
+                fpath.mkdirs();
+				new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivLeft).execute();
             }
 
 			//Count comments
@@ -191,9 +190,8 @@ public class AlbumLayout extends Fragment {
                     //If not, create directories and download asynchronously
                     File fpath;
                     fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-                    if(fpath.mkdirs()) {
-						new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivRight).execute();
-					}
+                    fpath.mkdirs();
+					new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivRight).execute();
                 }
 
 				//Count comments

+ 15 - 0
app/src/main/java/com/ivalentin/gm/GM.java

@@ -261,6 +261,21 @@ public final class GM {
 	 */
 	static final int LOCATION_ACCURACY = 20;
 
+	public static final String getLang(){
+		String currLang = Locale.getDefault().getISO3Language();//getDisplayLanguage();
+		switch (currLang){
+			case "spa":
+				currLang = "es";
+				break;
+			case "eus":
+				currLang = "eu";
+				break;
+			default:
+				currLang = "en";
+		}
+		return currLang;
+	}
+
 	/**
 	 * Formats a datetime format strings and returns a human readable date, depending on the language
 	 *

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

@@ -129,9 +129,8 @@ public class GalleryLayout extends Fragment{
                     //If not, create directories and download asynchronously
                     File fpath;
                     fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/miniature/");
-                    if (fpath.mkdirs()) {
-                        new DownloadImage(GM.SERVER + "/img/galeria/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/miniature/" + image, preview[i]).execute();
-                    }
+                    fpath.mkdirs();
+                    new DownloadImage(GM.SERVER + "/img/galeria/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/miniature/" + image, preview[i]).execute();
                 }
                 i ++;
 

+ 161 - 61
app/src/main/java/com/ivalentin/gm/HomeLayout.java

@@ -14,14 +14,18 @@ import com.google.android.gms.maps.model.MarkerOptions;
 
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.app.Fragment;
+import android.location.Criteria;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
+import android.net.Uri;
 import android.os.Bundle;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
@@ -34,6 +38,7 @@ import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
+import android.widget.Toast;
 
 /**
  * Section that will be seen when the app is started. 
@@ -48,20 +53,14 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 
 	//The location manager
 	LocationManager locationManager;
-	Location listener;
-	
-	//The location of the user
-	private double[] coordinates = new double[2];
 
-	//Language
-	private String currLang;
-	
 	//Map stuff for the dialog
 	private MapView mapView;
 	private Bundle bund;
 	private GoogleMap map;
 	private LatLng location;
 	private String markerName = "";
+	private View view;
 	
 	/**
 	 * Run when the fragment is inflated.
@@ -80,28 +79,19 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
 
 		//Load the layout.
-		View view = inflater.inflate(R.layout.fragment_layout_home, null);
+		view = inflater.inflate(R.layout.fragment_layout_home, null);
 
-		//Get language
-		currLang = Locale.getDefault().getDisplayLanguage();
-		if (!currLang.equals("es") && !currLang.equals("eu")){
-			currLang = "en";
-		}
-				
 		//Set Location manager
+		//TODO: Only do this if location is required
 		locationManager = (LocationManager) view.getContext().getSystemService(Context.LOCATION_SERVICE);
-		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 5, this);
+		locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), 1000, 0, this);
+		onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
+		//locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 5, this);
 		
 		//Set the title
 		((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_home));
-	    
-		//Get the location passed from MainActivity so we dont have to wait for it to be aquired.
-		Bundle bundle = this.getArguments();
-		coordinates[0] = bundle.getDouble("lat", 0);
-		coordinates[1] = bundle.getDouble("lon", 0);
 
 		//TODO: These methods are empty yet
-		setUpLocation(view);
 		setUpLablanca(view);
 		setUpGmschedule(view);
 		setUpCityschedule(view);
@@ -118,6 +108,13 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		//Set up the gallery section
 		setUpGallery(view);
 
+		//Asynchronously set up location section
+		new HomeSectionLocation(((MainActivity) getActivity()).getMainView()).execute();
+		setUpLocation(view);
+
+		//Setup the social section
+		setUpSocial(view);
+
 	    //Return the view itself.
 		return view;
 	}
@@ -127,9 +124,92 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 *
 	 * @return The number of entries shown.
 	 */
-	private int setUpSocial(View view) {
-		//TODO: setUpSocial(View view)
-		return 0;
+	private void setUpSocial(View view) {
+		ImageView phone = (ImageView) view.findViewById(R.id.iv_home_section_social_phone);
+		ImageView mail = (ImageView) view.findViewById(R.id.iv_home_section_social_mail);
+		ImageView whatsapp = (ImageView) view.findViewById(R.id.iv_home_section_social_whatsapp);
+		ImageView facebook = (ImageView) view.findViewById(R.id.iv_home_section_social_facebook);
+		ImageView twitter = (ImageView) view.findViewById(R.id.iv_home_section_social_twitter);
+		ImageView googleplus = (ImageView) view.findViewById(R.id.iv_home_section_social_googleplus);
+		ImageView instagram = (ImageView) view.findViewById(R.id.iv_home_section_social_instagram);
+
+		phone.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				String url = v.getContext().getString(R.string.social_phone_link);
+				Intent intent = new Intent(Intent.ACTION_DIAL);
+				intent.setData(Uri.parse(url));
+				startActivity(intent);
+			}
+		});
+
+		mail.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				String url = v.getContext().getString(R.string.social_mail_link);
+				Intent i = new Intent(Intent.ACTION_VIEW);
+				i.setData(Uri.parse(url));
+				startActivity(i);
+			}
+		});
+
+		whatsapp.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+
+				try {
+					Uri mUri = Uri.parse(getString(R.string.social_whatsapp_link));
+					Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
+					mIntent.setPackage(getString(R.string.social_whatsapp_package));
+					mIntent.putExtra(getString(R.string.social_whatsapp_chat), true);
+					startActivity(mIntent);
+				} catch (Exception e) {
+					Toast.makeText(v.getContext(), getString(R.string.social_whatsapp_error), Toast.LENGTH_LONG).show();
+				}
+			}
+		});
+
+		facebook.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				String url = v.getContext().getString(R.string.social_facebook_link);
+				Intent i = new Intent(Intent.ACTION_VIEW);
+				i.setData(Uri.parse(url));
+				startActivity(i);
+			}
+		});
+
+		twitter.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				String url = v.getContext().getString(R.string.social_twitter_link);
+				Intent i = new Intent(Intent.ACTION_VIEW);
+				i.setData(Uri.parse(url));
+				startActivity(i);
+			}
+		});
+
+		googleplus.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				String url = v.getContext().getString(R.string.social_googleplus_link);
+				Intent i = new Intent(Intent.ACTION_VIEW);
+				i.setData(Uri.parse(url));
+				startActivity(i);
+			}
+		});
+
+		instagram.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				String url = v.getContext().getString(R.string.social_instagram_link);
+				Intent i = new Intent(Intent.ACTION_VIEW);
+				i.setData(Uri.parse(url));
+				startActivity(i);
+			}
+		});
+
+		return;
 	}
 
 	/**
@@ -182,6 +262,30 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		return false;
 	}
 
+	/**
+	 * Populates the Location section of the home screen.
+	 *
+	 * @return True if the section has been shown, false otherwise.
+	 */
+	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){
+			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');
+			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{
+				text.setText(String.format(getString(R.string.home_section_location_text_long), String.format("%.02f", distance)));
+			}
+
+		}
+		return false;
+	}
+
 	/**
 	 * Populates the Gallery section of the home screen.
 	 * Loads four photos.
@@ -232,32 +336,31 @@ 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/");
-				if (fpath.mkdirs()) {
-					new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivPhoto[counter]).execute();
-				}
+				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();
 				}
 			});
 
@@ -281,10 +384,11 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	private int setUpPastActivities(View view){
 		int counter = 0;
+		String lang = GM.getLang();
 
 		//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_" + currLang + " AS title, text_" + currLang + " AS text, price, after_" + currLang + " AS after FROM activity WHERE date < date('now') ORDER BY date DESC LIMIT 2;", null);
+		Cursor cursor = db.rawQuery("SELECT id, date, city, title_" + lang + " AS title, text_" + lang + " AS text, price, after_" + lang + " AS after FROM activity WHERE date < date('now') ORDER BY date DESC LIMIT 2;", null);
 
 		//Show section
 		LinearLayout llActivitiesPast = (LinearLayout) view.findViewById(R.id.ll_home_section_activities_past);
@@ -343,7 +447,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 
 			//Set date
 			TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_home_activity_date);
-			tvDate.setText(GM.formatDate(cursor.getString(1) + " 00:00:00", currLang, false));
+			tvDate.setText(GM.formatDate(cursor.getString(1) + " 00:00:00", lang, false));
 
 			//Set hidden id
 			TextView tvId = (TextView) entry.findViewById(R.id.tv_row_home_activity_hidden);
@@ -367,9 +471,8 @@ 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/");
-					if (fpath.mkdirs()) {
-						new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
-					}
+					fpath.mkdirs();
+					new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
 				}
 			}
 			cursorImage.close();
@@ -418,6 +521,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	private int setUpFutureActivities(View view){
 		int counter = 0;
+		String lang = GM.getLang();
 
 		LinearLayout llList = (LinearLayout) view.findViewById(R.id.ll_home_section_activities_future_content);
 		LinearLayout entry;
@@ -427,7 +531,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 
 		//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_" + currLang+ " AS title, text_" + currLang + " 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) {
@@ -476,7 +580,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 
 				//Set date
 				TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_home_activity_date);
-				tvDate.setText(GM.formatDate(cursor.getString(1) + " 00:00:00", currLang, false));
+				tvDate.setText(GM.formatDate(cursor.getString(1) + " 00:00:00", lang, false));
 
 				//Set hidden id
 				TextView tvId = (TextView) entry.findViewById(R.id.tv_row_home_activity_hidden);
@@ -500,9 +604,8 @@ 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/");
-						if (fpath.mkdirs()) {
-							new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
-						}
+						fpath.mkdirs();
+						new DownloadImage(GM.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv).execute();
 					}
 				}
 
@@ -549,8 +652,8 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 */
 	@SuppressLint("InflateParams") //Throws unknown error when done properly.
 	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(){
@@ -571,7 +674,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 		final Cursor cursor;
 
 		//Get data from the database
-		cursor = db.rawQuery("SELECT id, title_" + currLang+ " AS title, text_" + currLang + " AS text, dtime FROM post ORDER BY dtime DESC LIMIT 2;", null);
+		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()){
@@ -598,7 +701,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 
 			//Set date
 			TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_home_blog_date);
-			tvDate.setText(GM.formatDate(cursor.getString(3), currLang, false));
+			tvDate.setText(GM.formatDate(cursor.getString(3), lang, false));
 
 			//Set hidden id
 			TextView tvId = (TextView) entry.findViewById(R.id.tv_row_home_blog_hidden);
@@ -623,9 +726,8 @@ 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/");
-					if (fpath.mkdirs()) {
-						new DownloadImage(GM.SERVER + "/img/blog/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image, iv).execute();
-					}
+					fpath.mkdirs();
+					new DownloadImage(GM.SERVER + "/img/blog/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image, iv).execute();
 				}
 			}
 
@@ -792,11 +894,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 */
 	@Override
 	public void onLocationChanged(Location location) {
-		coordinates[0] = location.getLatitude();
-		coordinates[1] = location.getLongitude();
-		//updateLocation();
-		//populateAround();
-		
+		setUpLocation(location, view);
 	}
 
 	/**
@@ -849,6 +947,7 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 	 */
 	@Override
 	public void onPause(){
+		//TODO: Only do this if location is required
 		locationManager.removeUpdates(this);
 		if (map != null)
 			map.setMyLocationEnabled(false);
@@ -870,7 +969,8 @@ public class HomeLayout extends Fragment implements LocationListener, OnMapReady
 			mapView.onResume();
 		if (map != null)
 			map.setMyLocationEnabled(true);
-		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 5, this);
+		//TODO: Only do this if location is required
+		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
 		super.onResume();
 	}
 	

+ 113 - 0
app/src/main/java/com/ivalentin/gm/HomeSectionLocation.java

@@ -0,0 +1,113 @@
+package com.ivalentin.gm;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.AsyncTask;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+
+import com.google.android.gms.maps.model.LatLng;
+
+import java.io.BufferedInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+/**
+ * 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 HomeSectionLocation extends AsyncTask<Void, Void, Void> {
+
+	private boolean isLocationReported;
+	private LatLng coord;
+	private View view;
+
+	/**
+	 * Constructor.
+	 *
+	 * @param v Application top view.
+	 *
+	 * @see android.widget.ImageView
+	 */
+	public HomeSectionLocation(View v) {
+		super();
+		this.view = v;
+	}
+
+	/**
+	 * Before starting background thread do nothing.
+	 */
+	@Override
+	protected void onPreExecute() {
+		super.onPreExecute();
+	}
+
+	/**
+	 * Downloading file in background thread.
+	 */
+	@Override
+	protected Void doInBackground(Void... v) {
+
+		String o = "";
+
+		try {
+
+			FetchURL fu = new FetchURL();
+			fu.Run(GM.SERVER + "/app/location.php");
+			//All the info
+			o = fu.getOutput().toString();
+
+		} catch (Exception e) {
+			Log.e("Location error: ", e.getMessage());
+		}
+
+		if (o.contains("<reporting>1</reporting>")){
+			isLocationReported = true;
+			String latString = o.substring(o.indexOf("<lat>") + 5, o.indexOf("</lat>"));
+			String lonString = o.substring(o.indexOf("<lon>") + 5, o.indexOf("</lon>"));
+			coord = new LatLng(Double.parseDouble(latString), Double.parseDouble(lonString));
+		}
+
+		return null;
+	}
+
+
+
+	/**
+	 * After completing background task, set the image on the ImageView.
+	 */
+	@Override
+	protected void onPostExecute(Void v) {
+		if (isLocationReported){
+
+			SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+			SharedPreferences.Editor editor = preferences.edit();
+			editor.putLong(GM.PREF_GM_LATITUDE, Double.doubleToLongBits(coord.latitude));
+			editor.putLong(GM.PREF_GM_LONGITUDE, Double.doubleToLongBits(coord.longitude));
+			editor.putString(GM.PREF_GM_LOCATION, new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime()));
+			editor.apply();
+
+			//Show menu entry
+			LinearLayout menuEntry = (LinearLayout) view.findViewById(R.id.ll_menu_location);
+			menuEntry.setVisibility(View.VISIBLE);
+
+			//Set up home view section
+			LinearLayout section = (LinearLayout) view.findViewById(R.id.ll_home_section_location);
+			section.setVisibility(View.VISIBLE);
+
+		}
+	}
+
+}

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

@@ -1,10 +1,196 @@
 package com.ivalentin.gm;
 
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+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.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
 
 /**
- * Created by seavenois on 09/06/16.
+ * Fragment openen for La Blanca sections while the festivals are not close.
+ *
+ * @see Fragment
+ *
+ * @author Iñigo Valentin
+ *
  */
 public class LablancaLayout extends Fragment {
 
-}
+	/**
+	 * Run when the fragment is inflated.
+	 *
+	 * @param inflater           A LayoutInflater to manage views
+	 * @param container          The container View
+	 * @param savedInstanceState Bundle containing the state
+	 * @return The fragment view
+	 * @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
+	 */
+	@Override
+	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+		//Load the layout
+		View view = inflater.inflate(R.layout.fragment_layout_lablanca, null);
+
+		//Set the title
+		((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca));
+
+		//Get database info from the database
+		String lang = GM.getLang();
+		int year = Calendar.getInstance().get(Calendar.YEAR);
+		SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
+		Cursor cursor = db.rawQuery("SELECT text_" + lang + ", img FROM festival WHERE year = " + year + ";", null);
+		cursor.moveToFirst();
+
+		//Set text
+		WebView headerText = (WebView) view.findViewById(R.id.tv_lablanca_header);
+		headerText.loadDataWithBaseURL(null, cursor.getString(0), "text/html", "utf-8", null);
+
+		//Set image
+		ImageView headerImage = (ImageView) view.findViewById(R.id.iv_lablanca_header);
+		String image = cursor.getString(1);
+		if (image.length() > 0){
+
+			//Check if image exists
+			File f;
+			f = new File(this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/" + image);
+			if (f.exists()) {
+				//If the image exists, set it.
+				Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/" + image);
+				headerImage.setImageBitmap(myBitmap);
+			} else {
+				//If not, create directories and download asynchronously
+				File fpath;
+				fpath = new File(this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/");
+				fpath.mkdirs();
+				new DownloadImage(GM.SERVER + "/img/fiestas/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/" + image, headerImage).execute();
+			}
+		}
+		else{
+			headerImage.setVisibility(View.GONE);
+		}
+
+		//Get prices for single days
+		Cursor cursorDays = db.rawQuery("SELECT date, name_" + lang + ", price FROM festival_day WHERE strftime('%Y', date) = '" + year + "' ORDER BY date;", null);
+		LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_lablanca_prices_days_list);
+		LinearLayout entry;
+		LayoutInflater factory = LayoutInflater.from(getActivity());
+		while (cursorDays.moveToNext()){
+
+			//Create a new row
+			entry = (LinearLayout) factory.inflate(R.layout.row_festival_price_day, 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 title
+			TextView tvName = (TextView) entry.findViewById(R.id.tv_row_festival_price_day_name);
+			tvName.setText(cursorDays.getString(1));
+
+			//Set price
+			TextView tvPrice = (TextView) entry.findViewById(R.id.tv_row_festival_price_day_price);
+			String price = cursorDays.getString(2) + " " + getString(R.string.eur);
+			tvPrice.setText(price);
+
+			//Set date
+			TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_festival_price_day_date);
+			DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
+			Date date;
+			try {
+				date = format.parse(cursorDays.getString(0));
+				Calendar calendar = Calendar.getInstance();
+				calendar.setTime(date);
+				int day = calendar.get(Calendar.DAY_OF_MONTH);
+				int month = calendar.get(Calendar.MONTH);
+				switch (month){
+					case 6:
+						tvDate.setText(String.format(getString(R.string.lablanca_date_july), day));
+						break;
+					case 7:
+						tvDate.setText(String.format(getString(R.string.lablanca_date_august), day));
+						break;
+				}
+			}
+			catch(Exception ex){
+				Log.e("Date format error", ex.toString());
+			}
+
+			list.addView(entry);
+		}
+
+		//Get prices for single days
+		Cursor cursorPacks = db.rawQuery("SELECT name_" + lang + ", description_" + lang + ", price FROM festival_offer WHERE year = " + year + " ORDER BY days;", null);
+		list = (LinearLayout) view.findViewById(R.id.ll_lablanca_prices_packs_list);
+		while (cursorPacks.moveToNext()){
+
+			//Create a new row
+			entry = (LinearLayout) factory.inflate(R.layout.row_festival_price_pack, 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 title
+			TextView tvName = (TextView) entry.findViewById(R.id.tv_row_festival_price_pack_name);
+			tvName.setText(cursorPacks.getString(0));
+
+			//Set text
+			TextView tvText = (TextView) entry.findViewById(R.id.tv_row_festival_price_pack_text);
+			tvText.setText(cursorPacks.getString(1));
+
+			//Set price
+			TextView tvPrice = (TextView) entry.findViewById(R.id.tv_row_festival_price_pack_price);
+			String price = cursorPacks.getString(2) + " " + getString(R.string.eur);
+			tvPrice.setText(price);
+
+			list.addView(entry);
+		}
+
+		cursor.close();
+		cursorDays.close();
+		cursorPacks.close();
+		db.close();
+
+		//Set listeners for the schedule buttons.
+		Button gmSchedule = (Button) view.findViewById(R.id.bt_lablanca_schedule_gm);
+		Button citySchedule = (Button) view.findViewById(R.id.bt_lablanca_schedule_city);
+
+		gmSchedule.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, false);
+			}
+		});
+
+		citySchedule.setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				((MainActivity) getActivity()).loadSection(GM.SECTION_LABLANCA_SCHEDULE, false);
+			}
+		});
+
+		return view;
+	}
+}

+ 39 - 0
app/src/main/java/com/ivalentin/gm/LablancaNoFestivalsLayout.java

@@ -0,0 +1,39 @@
+package com.ivalentin.gm;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+/**
+ * Fragment openen for La Blanca sections while the festivals are not close.
+ *
+ * @see Fragment
+ *
+ * @author Iñigo Valentin
+ *
+ */
+public class LablancaNoFestivalsLayout extends Fragment {
+
+	/**
+	 * Run when the fragment is inflated.
+	 *
+	 * @param inflater           A LayoutInflater to manage views
+	 * @param container          The container View
+	 * @param savedInstanceState Bundle containing the state
+	 * @return The fragment view
+	 * @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
+	 */
+	@Override
+	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+
+		//Load the layout
+		View view = inflater.inflate(R.layout.fragment_layout_lablanca_nofestivals, null);
+
+		//Set the title
+		((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca));
+
+		return view;
+	}
+}

+ 54 - 133
app/src/main/java/com/ivalentin/gm/MainActivity.java

@@ -4,22 +4,17 @@ import java.io.File;
 import java.math.BigInteger;
 import java.security.SecureRandom;
 
+import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
-//import android.content.res.ResourcesCompat;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.database.sqlite.SQLiteDatabase;
 import android.graphics.drawable.Drawable;
-import android.location.Criteria;
-import android.location.Location;
-import android.location.LocationListener;
-import android.location.LocationManager;
 import android.os.Bundle;
-//import android.support.v7.app.AppCompatActivity;
 import android.util.Log;
 import android.view.View;
 import android.view.Window;
@@ -35,22 +30,22 @@ import android.widget.TextView;
  * @author Iñigo Valentin
  *
  */
-public class MainActivity extends Activity implements LocationListener{
+public class MainActivity extends Activity{//} implements LocationListener{
 
-	//Set of GPS coordinates
-	private double[] coordinates = new double[2];
-	
 	//The main layout of the app
 	private MainLayout mLayout;
-	
-	//The location manager to get GPS coordinates
-	private LocationManager locationManager;
-	
-	//GPS coordinates provider
-	private String provider;
-	
-	//Alarm to get location
+
+	//Alarm to get location and notifications.
 	AlarmReceiver alarm;
+
+	/**
+	 * Getter for the activity top view.
+	 *
+	 * @return The activity top view.
+	 */
+	public View getMainView(){
+		return getWindow().getDecorView().getRootView();
+	}
 		
 	/**
 	 * Loads a section in the main screen.
@@ -67,28 +62,23 @@ public class MainActivity extends Activity implements LocationListener{
 		switch (section){
 			case GM.SECTION_HOME:
 				fragment = new HomeLayout();
-				//Pass current GPS coordinates
-				bundle.putDouble("lat", coordinates[0]);
-				bundle.putDouble("lon", coordinates[1]);
-				fragment.setArguments(bundle);
 				title = getString(R.string.menu_home);
 				break;
 
 			case GM.SECTION_LOCATION:
 				fragment = new LocationLayout();
-				//Pass current GPS coordinates
-				bundle.putDouble("lat", coordinates[0]);
-				bundle.putDouble("lon", coordinates[1]);
-				fragment.setArguments(bundle);
 				title = getString(R.string.menu_lablanca_location);
 				break;
 
 			case GM.SECTION_LABLANCA:
-				fragment = new LablancaLayout();
-				//Pass current GPS coordinates
-				bundle.putDouble("lat", coordinates[0]);
-				bundle.putDouble("lon", coordinates[1]);
-				fragment.setArguments(bundle);
+				//Get settings
+				SharedPreferences preferences = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+				if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1){
+					fragment = new LablancaLayout();
+				}
+				else{
+					fragment = new LablancaNoFestivalsLayout();
+				}
 				title = getString(R.string.menu_lablanca);
 				break;
 
@@ -108,10 +98,6 @@ public class MainActivity extends Activity implements LocationListener{
 
 			case GM.SECTION_LABLANCA_AROUND:
 				fragment = new AroundLayout();
-				//Pass current GPS coordinates
-				bundle.putDouble("lat", coordinates[0]);
-				bundle.putDouble("lon", coordinates[1]);
-				fragment.setArguments(bundle);
 				title = getString(R.string.menu_lablanca_around);
 				break;
 
@@ -151,8 +137,7 @@ public class MainActivity extends Activity implements LocationListener{
 		if (fromSliderMenu)
 			mLayout.toggleMenu();
 	}
-	
-	
+
 	/**
 	 * Sets the title of the current section.
 	 * 
@@ -162,71 +147,7 @@ public class MainActivity extends Activity implements LocationListener{
 		TextView tvTitle = (TextView) findViewById(R.id.activity_main_content_title);
 		tvTitle.setText(title);
 	}
-	
-	/** 
-	 * Run when the app resumes. It's extended to request
-	 * location updates when the app is resumed.
-	 * 
-	 * @see android.support.v4.app.FragmentActivity#onResume()
-	 */
-	@Override
-	protected void onResume() {
-		super.onResume();
-		alarm.onReceive(this, this.getIntent());
-		locationManager.requestLocationUpdates(provider, GM.LOCATION_ACCURACY, 1, this);
-	}
-
-	/**
-	 * Run when the app is paused.Extended to remove the location
-	 * listener updates when the Activity is paused.
-	 *  
-	 * @see android.support.v4.app.FragmentActivity#onPause()
-	 */
-	@Override
-	protected void onPause() {
-		super.onPause();
-		locationManager.removeUpdates(this);
-	}
-
-	/**
-	 * Called when the location is updated.
-	 * 
-	 * @param location The updated location.
-	 * 
-	 * @see android.location.LocationListener#onLocationChanged(android.location.Location)
-	 * 
-	 */
-	@Override
-	public void onLocationChanged(Location location) {
-		coordinates[0] = location.getLatitude();
-		coordinates[1] = location.getLongitude();
-	}
 
-	/**
-	 * Extended for nothing. Needed because the class implements LocationListener.
-	 * 
-	 * @see android.location.LocationListener#onStatusChanged(java.lang.String, int, android.os.Bundle)
-	 */
-	@Override
-	public void onStatusChanged(String provider, int status, Bundle extras) {}
-	
-	/**
-	 * Extended for nothing. Needed because the class implements LocationListener.
-	 * 
-	 * @see android.location.LocationListener#onProviderEnabled(java.lang.String)
-	 */
-	@Override
-	public void onProviderEnabled(String provider) {}
-
-	/**
-	 * Extended for nothing. Needed because the class implements LocationListener.
-	 * 
-	 * @see android.location.LocationListener#onProviderDisabled(java.lang.String)
-	 */
-	@Override
-	public void onProviderDisabled(String provider) {}
-	  
-	  
 	/**
 	 * Runs when the activity is created. 
 	 * 
@@ -234,32 +155,14 @@ public class MainActivity extends Activity implements LocationListener{
 	 * 
 	 * @see android.support.v7.app.AppCompatActivity#onCreate(android.os.Bundle)
 	 */
-	//@SuppressLint("TrulyRandom") //I don't care about getting "potentially unsecured numbers" here
+	@SuppressLint("TrulyRandom") //I don't care about getting "potentially unsecured numbers" here
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
-		
-		//Set the location manager.
-	    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
-	   	locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 5, this);
-	    
-	    //Define the criteria how to select the location provider: use default.
-	    Criteria criteria = new Criteria();
-	    provider = locationManager.getBestProvider(criteria, false);
-	    Location location = locationManager.getLastKnownLocation(provider);
 
 	    //Get intent extras
 	    String action = getIntent().getStringExtra(GM.EXTRA_ACTION);
 	    String actionText = getIntent().getStringExtra(GM.EXTRA_TEXT);
 	    String actionTitle = getIntent().getStringExtra(GM.EXTRA_TITLE);
-	    
-	    // Initialize the location fields.
-	    if (location != null){
-	    	//System.out.println("Provider " + provider + " has been selected.");
-	    	onLocationChanged(location);
-	    }
-	    else{
-	    	Log.e("Location", "Location not available");
-	    }
 
 		//Set an alarm for notifications..
 	    alarm = new AlarmReceiver();
@@ -333,21 +236,39 @@ public class MainActivity extends Activity implements LocationListener{
 			@Override
 			public void onClick(View v) { loadSection(GM.SECTION_SETTINGS, true); }
 		});
-		menuLablancaItem[0].setOnClickListener(new OnClickListener() {
-			@Override
-			public void onClick(View v) { loadSection(GM.SECTION_LABLANCA_SCHEDULE, true); }
-		});
-		menuLablancaItem[1].setOnClickListener(new OnClickListener() {
-			@Override
-			public void onClick(View v) { loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, true); }
-		});
-		menuLablancaItem[2].setOnClickListener(new OnClickListener() {
-			@Override
-			public void onClick(View v) { loadSection(GM.SECTION_LABLANCA_AROUND, true); }
-		});
 
-		//If the user code is not set, generate one
+
 		SharedPreferences preferences = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+		if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1) {
+
+			menuLablancaItem[0].setOnClickListener(new OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					loadSection(GM.SECTION_LABLANCA_SCHEDULE, true);
+				}
+			});
+
+			menuLablancaItem[1].setOnClickListener(new OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE, true);
+				}
+			});
+
+			menuLablancaItem[2].setOnClickListener(new OnClickListener() {
+				@Override
+				public void onClick(View v) {
+					loadSection(GM.SECTION_LABLANCA_AROUND, true);
+				}
+			});
+
+			//Show the entries
+			for (int i = 0; i < 3; i ++){
+				menuLablancaItem[i].setVisibility(View.VISIBLE);
+			}
+		}
+
+		//If the user code is not set, generate one
 		if (preferences.getString(GM.USER_CODE, "").length() == 0){
 			SecureRandom random = new SecureRandom();
 			String newCode = new BigInteger(130, random).toString(32).substring(0, 8);

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

@@ -209,9 +209,8 @@ public class PhotoLayout extends Fragment {
 			//If not, create directories and download asynchronously
 			File fpath;
 			fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
-			if (fpath.mkdirs()) {
-				new DownloadImage(GM.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, imageView).execute();
-			}
+			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

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

@@ -92,11 +92,8 @@ public class PostLayout extends Fragment {
 
         //Get images
         Cursor imageCursor = db.rawQuery("SELECT image, idx FROM post_image WHERE post = " + id + " ORDER BY idx LIMIT 5;", null);
-        //imageCursor.moveToFirst();
-        //Log.e("IMGCOUNT", "" + cursor.getCount());
         int i = 0;
         while (imageCursor.moveToNext()) {
-            //Log.e("IMG", "" + i);
             String image = imageCursor.getString(0);
 
             //Check if image exists
@@ -111,9 +108,8 @@ public class PostLayout extends Fragment {
                 //If not, create directories and download asynchronously
                 File fpath;
                 fpath = new File(this.getActivity().getFilesDir().toString() + "/img/blog/preview/");
-                if (fpath.mkdirs()) {
-					new DownloadImage(GM.SERVER + "/img/blog/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/preview/" + image, images[i]).execute();
-				}
+                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 ++;

+ 59 - 35
app/src/main/res/layout/fragment_layout_home.xml

@@ -34,7 +34,39 @@
 				android:background="@drawable/entry"
 				android:padding="7dp">
 
-            </LinearLayout>
+				<TextView
+					android:layout_width="wrap_content"
+					android:layout_height="wrap_content"
+					android:textAppearance="?android:attr/textAppearanceMedium"
+					android:text="@string/home_section_location_text_0"
+					android:id="@+id/textView9"/>
+
+				<LinearLayout
+					android:orientation="horizontal"
+					android:layout_width="match_parent"
+					android:layout_height="match_parent"
+					android:gravity="center_horizontal"
+					android:layout_marginTop="10dp"
+					android:layout_marginBottom="10dp">
+
+					<ImageView
+						android:layout_width="wrap_content"
+						android:layout_height="wrap_content"
+						android:id="@+id/imageView12"
+						android:src="@drawable/pinpoint_gm"
+						android:layout_margin="7dp"
+						android:layout_gravity="center_vertical"/>
+
+					<TextView
+						android:layout_width="wrap_content"
+						android:layout_height="wrap_content"
+						android:textAppearance="?android:attr/textAppearanceMedium"
+						android:text="Medium Text"
+						android:id="@+id/tv_home_section_location_distance"
+						android:layout_gravity="center_vertical"
+						android:layout_margin="7dp"/>
+				</LinearLayout>
+			</LinearLayout>
 
 		</LinearLayout>
 
@@ -398,47 +430,43 @@
 					android:gravity="center_horizontal" >
 
 					<ImageView
-						android:id="@+id/imageView4"
+						android:id="@+id/iv_home_section_social_phone"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
-						android:contentDescription="@string/social_web"
-						android:maxWidth="60dp"
-						android:src="@drawable/social_web" />
+						android:contentDescription="@string/social_mail"
+						android:maxWidth="50dp"
+						android:src="@drawable/social_mail"/>
 
 					<ImageView
-						android:id="@+id/imageView5"
+						android:id="@+id/iv_home_section_social_mail"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_web"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_mail" />
 
 					<ImageView
-						android:id="@+id/imageView6"
+						android:id="@+id/iv_home_section_social_whatsapp"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_web"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_whatsapp" />
 
 					<ImageView
-						android:id="@+id/imageView7"
+						android:id="@+id/iv_home_section_social_facebook"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_facebook"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_facebook" />
 				</LinearLayout>
 
@@ -448,47 +476,43 @@
 					android:gravity="center_horizontal" >
 
 					<ImageView
-						android:id="@+id/imageView8"
+						android:id="@+id/iv_home_section_social_twitter"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_twitter"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_twitter" />
 
 					<ImageView
-						android:id="@+id/imageView9"
+						android:id="@+id/iv_home_section_social_googleplus"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_googleplus"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_googleplus" />
 
 					<ImageView
-						android:id="@+id/imageView10"
+						android:id="@+id/iv_home_section_social_youtube"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_youtube"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_youtube" />
 
 					<ImageView
-						android:id="@+id/imageView11"
+						android:id="@+id/iv_home_section_social_instagram"
 						android:layout_width="wrap_content"
 						android:layout_height="wrap_content"
-						android:layout_margin="16dp"
-						android:layout_weight=".25"
+						android:layout_margin="10dp"
 						android:adjustViewBounds="true"
 						android:contentDescription="@string/social_instagram"
-						android:maxWidth="60dp"
+						android:maxWidth="50dp"
 						android:src="@drawable/social_instagram" />
 				</LinearLayout>
 			</LinearLayout>

+ 176 - 0
app/src/main/res/layout/fragment_layout_lablanca.xml

@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.ivalentin.gm.CustomScrollView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:background="@color/background_app"
+    android:padding="7dp">
+
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:paddingBottom="5dp">
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/section"
+            android:padding="7dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="@string/lablanca_title"
+                android:id="@+id/textView10"/>
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="@drawable/entry"
+                android:padding="7dp">
+
+                <ImageView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:id="@+id/iv_lablanca_header"
+                    android:layout_weight=".4"
+                    android:layout_margin="3dp"
+                    android:background="@color/album_border"
+                    android:padding="1dp"/>
+
+                <WebtView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:textAppearance="?android:attr/textAppearanceMedium"
+                    android:id="@+id/wv_lablanca_header"
+                    android:padding="7dp"
+                    android:layout_marginBottom="7dp"
+                    android:layout_weight=".6"/>
+            </LinearLayout>
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/section"
+            android:padding="7dp"
+            android:layout_marginTop="15dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="@string/lablanca_schedule"
+                />
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="@drawable/entry"
+                android:padding="7dp">
+
+                <Button
+                    android:layout_width="fill_parent"
+                    android:layout_height="fill_parent"
+                    android:text="@string/lablanca_schedule_city"
+                    android:id="@+id/bt_lablanca_schedule_city"
+                    android:background="@drawable/button_selector"
+                    android:textColor="@color/input_button_color"
+                    android:textStyle="bold"
+                    android:layout_margin="6dp"
+                    android:layout_weight=".5"/>
+
+                <Button
+                    android:layout_width="fill_parent"
+                    android:layout_height="fill_parent"
+                    android:text="@string/lablanca_schedule_gm"
+                    android:id="@+id/bt_lablanca_schedule_gm"
+                    android:background="@drawable/button_selector"
+                    android:textColor="@color/input_button_color"
+                    android:textStyle="bold"
+                    android:layout_margin="6dp"
+                    android:layout_weight=".5"/>
+            </LinearLayout>
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:paddingBottom="20dp"
+            android:layout_marginTop="15dp">
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:background="@drawable/section"
+                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"/>
+
+                <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>
+                </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:id="@+id/ll_lablanca_prices_packs_list"
+                        />
+                </LinearLayout>
+
+            </LinearLayout>
+        </LinearLayout>
+
+    </LinearLayout>
+
+</com.ivalentin.gm.CustomScrollView>

+ 42 - 0
app/src/main/res/layout/fragment_layout_lablanca_nofestivals.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.ivalentin.gm.CustomScrollView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:id="@+id/scrollView3"
+    android:background="@color/background_app"
+    android:padding="7dp">
+
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:paddingBottom="20dp">
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/section"
+            android:padding="7dp">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="@string/lablanca_title"
+                android:id="@+id/textView10"/>
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:textAppearance="?android:attr/textAppearanceMedium"
+                android:text="@string/lablanca_nofestivals"
+                android:id="@+id/textView11"
+                android:background="@drawable/entry"
+                android:padding="7dp"/>
+        </LinearLayout>
+
+    </LinearLayout>
+
+</com.ivalentin.gm.CustomScrollView>

+ 53 - 0
app/src/main/res/layout/row_festival_price_day.xml

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content">
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="match_parent"
+        android:layout_marginLeft="25dp"
+        android:layout_marginRight="25dp">
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="@android:style/TextAppearance.Small"
+                android:text="Small Text"
+                android:id="@+id/tv_row_festival_price_day_date"/>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="@android:style/TextAppearance.Medium"
+                android:text="Medium Text"
+                android:id="@+id/tv_row_festival_price_day_name"/>
+
+        </LinearLayout>
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textAppearance="@android:style/TextAppearance.Medium"
+            android:text="Medium Text"
+            android:id="@+id/tv_row_festival_price_day_price"
+            android:textAlignment="textEnd"
+            android:layout_gravity="bottom"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="fill_parent"
+        android:layout_height="1dp"
+        android:background="@color/background_separator"
+        android:layout_margin="10dp">
+    </LinearLayout>
+
+</LinearLayout>

+ 58 - 0
app/src/main/res/layout/row_festival_price_pack.xml

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content">
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="match_parent"
+        android:layout_marginLeft="25dp"
+        android:layout_marginRight="25dp">
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_weight=".3">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="@android:style/TextAppearance.Medium"
+                android:text="Medium Text"
+                android:id="@+id/tv_row_festival_price_pack_name"/>
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:textAppearance="@android:style/TextAppearance.Small"
+                android:text="Small Text"
+                android:id="@+id/tv_row_festival_price_pack_text"
+                android:layout_marginLeft="10dp"/>
+
+        </LinearLayout>
+
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textAppearance="@android:style/TextAppearance.Medium"
+            android:text="Medium Text"
+            android:id="@+id/tv_row_festival_price_pack_price"
+            android:textAlignment="textEnd"
+            android:layout_gravity="bottom"
+            android:gravity="right"
+            android:minWidth="70dp"
+            android:layout_weight=".7"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="fill_parent"
+        android:layout_height="1dp"
+        android:background="@color/background_separator"
+        android:layout_margin="10dp">
+    </LinearLayout>
+
+</LinearLayout>

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

@@ -56,6 +56,8 @@
 	<string name="today">Today</string>
 	<string name="tomorrow">Tomorrow</string>
 
+	<string name="distance_m">meters</string>
+	<string name="distance_k">kilometers</string>
 
 	<!-- "Titles" for days -->
 
@@ -85,7 +87,8 @@
 	<string name="around_no_gps">GPS turned off</string>
 	<string name="around_no_gps_text">Turn on GPS to be able to see events around you.</string>
 	<string name="around_no_gps_button">Open settings</string>
-	<string name="around_distance">%1$s %2$s away from you (About %3$s minutes walking)</string>
+	<string name="around_distance_short">%1$s meters away from you (About %2$s minutes walking)</string>
+	<string name="around_distance_long">%1$s kilometers away from you </string>
 
 
 	<!-- Home section strings -->
@@ -102,7 +105,8 @@
 	<string name="home_section_social">Follow us</string>
 
 	<string name="home_section_location_text_0">Gasteizko Margolariak is around!</string>
-	<string name="home_section_location_text_1">They are just %1$s away from you! (About %2$d minutes walking)</string>
+	<string name="home_section_location_text_short">They are just %1$d meters away from you!\n(About %2$d minutes walking)</string>
+	<string name="home_section_location_text_long">They are just %1$s kilometers away from you!</string>
 
 	<string name="home_section_join">Join Gasteizko Margolariak</string>
 	<string name="home_section_schedule_see">See all</string>
@@ -198,6 +202,18 @@
 		<item quantity="other">%1$d photos</item>
 	</plurals>
 
+	<!--La Blanca section strings-->
+	<string name="lablanca_title">La Blanca</string>
+	<string name="lablanca_nofestivals">Las Fiestas de La Blanca. Esos días, del 4 al 9 de agosto, en los que Vitoria-Gasteiz se transforma. Se llena de color y alegría, y en cada esquina puedes encontrar actividades y espectáculos. Todos las estamos esperando.\n\nPor desgracia, aún hay que esperar más.\n\nNosotros ya estamos trabajando en ello. Tan pronto como vayamos sabiendo más, aquí iremos publicando nuestro programa y otra información sobre las fiestas.</string>
+	<string name="lablanca_prices">Prices</string>
+	<string name="lablanca_prices_days">Single days</string>
+	<string name="lablanca_prices_pack">Packs</string>
+	<string name="lablanca_schedule">Schedule</string>
+	<string name="lablanca_schedule_city">Cty schedule</string>
+	<string name="lablanca_schedule_gm">Margolariak schedule</string>
+	<string name="lablanca_date_july">July %1$s</string>
+	<string name="lablanca_date_august">August %1$s</string>
+
 	<!-- Comments section and form strings -->
 	<string name="comment_your_comment">Your comment</string>
 	<plurals name="comment_comments">
@@ -220,7 +236,7 @@
 
 	<!-- Social networks strings -->
 
-	<string name="social_web">Web</string>
+	<string name="social_phone">Phone</string>
 	<string name="social_facebook">Facebook</string>
 	<string name="social_mail">e-mail</string>
 	<string name="social_whatsapp">Whatsapp</string>
@@ -228,6 +244,7 @@
 	<string name="social_googleplus">Google+</string>
 	<string name="social_youtube">Youtube</string>
 	<string name="social_instagram">Instagram</string>
+	<string name="social_phone_link">tel:+34637140371</string>
 	<string name="social_web_link">http://margolariak.com/</string>
 	<string name="social_mail_link">mailto:gasteizkomargolariak@gmail.com</string>
 	<string name="social_whatsapp_link">smsto:+34637140371</string>

+ 1 - 1
build.gradle

@@ -4,7 +4,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.1.0'
+        classpath 'com.android.tools.build:gradle:2.1.2'
     }
 }