Przeglądaj źródła

Preference keys reworked.

Preference keys and defaults have been predefined in a static class (GM). Data values to store (such as db version, user code,,,) and actual preferences have been separated into two different files. Preferences to sync in background and receive notifications are now actually respected. The data usage entry in settings have been removed.
seavenois 9 lat temu
rodzic
commit
b6acc0fd93

+ 21 - 15
app/src/main/java/com/ivalentin/margolariak/AlarmReceiver.java

@@ -41,12 +41,12 @@ public class AlarmReceiver extends BroadcastReceiver {
     	Log.d("Alarm", "Received");
 		    	
 		//Open the preferences to be available several times later.
-		SharedPreferences settings = context.getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+		SharedPreferences preferences = context.getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
 		
 		FetchURL fu;
 		
 		//Check if the user wants to receive notifications
-		if (settings.getInt(GM.PREF_NOTIFICATION , GM.DEFAULT_PREF_NOTIFICATION) == 1){
+		if (preferences.getBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, GM.PREFERENCES.DEFAULT.NOTIFICATIONS)){
 
 			//Get the file
 			try{
@@ -63,7 +63,8 @@ public class AlarmReceiver extends BroadcastReceiver {
 					String action = notification.substring(notification.indexOf("<action>") + 8, notification.indexOf("</action>"));
 
 					//Is the notification seen already?
-					if(!settings.getBoolean(GM.NOTIFICATION_SEEN_ + id, false)){
+					//TODO: Create a db table for this
+					if(!preferences.getBoolean(GM.NOTIFICATION_SEEN_ + id, false)){
 
 						String lang = GM.getLang();
 						String title = notification.substring(notification.indexOf("<title_" + lang + ">") + 10, notification.indexOf("</title_" + lang + ">"));
@@ -111,7 +112,7 @@ public class AlarmReceiver extends BroadcastReceiver {
 						mNotificationManager.notify(Integer.parseInt(id), mBuilder.build());
 
 						//Mark as notified
-						SharedPreferences.Editor editor = settings.edit();
+						SharedPreferences.Editor editor = preferences.edit();
 						editor.putBoolean(GM.NOTIFICATION_SEEN_ + id, true);
 						editor.apply();
 					}
@@ -133,17 +134,22 @@ public class AlarmReceiver extends BroadcastReceiver {
      * @param context The context of the app
      */
     public void setAlarm(Context context) {
-        AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
-        Intent intent = new Intent(context, AlarmReceiver.class);
-        PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
-        
-        //Set the alarm cycle.
-        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, GM.PERIOD_SYNC, GM.PERIOD_SYNC, alarmIntent);
-        
-        // Enable SampleBootReceiver to automatically restart the alarm when the device is rebooted.
-        ComponentName receiver = new ComponentName(context, BootReceiver.class);
-        PackageManager pm = context.getPackageManager();
-        pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);           
+		//Only do this if the preference is enabled
+		SharedPreferences prefs = context.getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
+		if (prefs.getBoolean(GM.PREFERENCES.KEY.SYNC, GM.PREFERENCES.DEFAULT.SYNC)) {
+
+			AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+			Intent intent = new Intent(context, AlarmReceiver.class);
+			PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
+
+			//Set the alarm cycle.
+			alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, GM.PERIOD_SYNC, GM.PERIOD_SYNC, alarmIntent);
+
+			// Enable SampleBootReceiver to automatically restart the alarm when the device is rebooted.
+			ComponentName receiver = new ComponentName(context, BootReceiver.class);
+			PackageManager pm = context.getPackageManager();
+			pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
+		}
     }
 
 }

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

@@ -142,6 +142,46 @@ final class GM {
 		}
 	}
 
+	static final class DATA {
+
+		static final String DATA = "data";
+
+		static final class KEY {
+
+			static final String USER = "user-id";
+			static final String PREVIOUS_APP_VERSION = "previous_app_version";
+			static final String LABLANCA = "lablanca";
+		}
+
+		static final class DEFAULT {
+
+			static final String USER = "";
+			static final int PREVIOUS_APP_VERSION = 0;
+			static final boolean LABLANCA = false;
+		}
+	}
+
+	static final class PREFERENCES {
+
+		static final String PREFERNCES = "preferences";
+
+		static final class KEY {
+
+			static final String SYNC = "performBackgroundSyncs";
+			static final String NOTIFICATIONS = "recieveNotificacions";
+		}
+
+		static final class DEFAULT {
+
+			static final boolean SYNC = true;
+			static final boolean NOTIFICATIONS = true;
+		}
+	}
+
+	static class URL {
+		static final String GITHUB = "https://github.com/GasteizkoMargolariak/GasteizkoMargolariakApp";
+	}
+
 	static final String CLIENT = "com.ivalentin.margolariak";
 
 	/**
@@ -277,37 +317,37 @@ final class GM {
 	/**
 	 * Name of the preference group for the app.
 	 */
-	static final String PREF = "gmpreferences";
+	//static final String PREF = "gmpreferences";
 	
 	/**
 	 * Name of the preference to store the database version with.
 	 */
-	static final String PREF_DB_VERSION = "prefDbVersion";
+	//static final String PREF_DB_VERSION = "prefDbVersion";
 
 	/**
 	 * Name of the preference to store the previous app version.
 	 */
-	static final String PREF_PREVIOUS_VERSION = "prefAppPreviousVersion";
+	//static final String PREF_PREVIOUS_VERSION = "prefAppPreviousVersion";
 
 	/**
 	 * Name of the preference to store the setting that allows user to upload comments.
 	 */
-	static final String PREF_DB_PHOTOS = "prefDbPhotos";
+	//static final String PREF_DB_PHOTOS = "prefDbPhotos";
 
 	/**
 	 * Name of the preference that indicates if we are on festivals.
 	 */
-	static final String PREF_DB_FESTIVALS = "prefDbFestivals";
+	//static final String PREF_DB_FESTIVALS = "prefDbFestivals";
 
 	/**
 	 * Name of the preference indicating if the user wants to to receive notifications intended for the general public.
 	 */
-	static final String PREF_NOTIFICATION = "prefNotification";
+	//static final String PREF_NOTIFICATION = "prefNotification";
 
 	/**
 	 * Default value of the preference indicating if the user wants to to receive notifications intended for the general public.
 	 */
-	static final int DEFAULT_PREF_NOTIFICATION = 1;
+	//static final int DEFAULT_PREF_NOTIFICATION = 1;
 
 	/**
 	 * Header of a preference to indicate received notifications.

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

@@ -160,8 +160,8 @@ public class HomeLayout extends Fragment implements LocationListener {
 	private int setUpSchedule(int gm, View view) {
 		int count = 0;
 
-		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-		if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 0) {
+		SharedPreferences data = view.getContext().getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
+		if (!data.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
 			return count;
 		}
 
@@ -418,9 +418,9 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 */
 	@SuppressWarnings("ResultOfMethodCallIgnored")
 	private boolean setUpLablanca(View view) {
-		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
 		Boolean set = false;
-		if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1) {
+		if (preferences.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
 			LinearLayout llSection = (LinearLayout) view.findViewById(R.id.ll_home_section_lablanca);
 			TextView tvText = (TextView) view.findViewById(R.id.tv_home_section_lablanca_text);
 			ImageView ivImage = (ImageView) view.findViewById(R.id.iv_home_section_lablanca_image);
@@ -496,7 +496,8 @@ public class HomeLayout extends Fragment implements LocationListener {
 	 * @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);
+		SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
+		//Do this from db
 		if (!preferences.getString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION).equals(GM.DEFAULT_PREF_GM_LOCATION)) {
 			try {
 				Double lat = Double.longBitsToDouble(preferences.getLong(GM.PREF_GM_LATITUDE, 0));

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

@@ -77,7 +77,8 @@ class HomeSectionLocation extends AsyncTask<Void, Void, Void> {
 	protected void onPostExecute(Void v) {
 		if (isLocationReported){
 
-			SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+			//TODO: Do this on a db table
+			SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, 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));

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

@@ -173,7 +173,8 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 		}
 		
 		//Set GM marker
-		SharedPreferences preferences = v.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+		//TODO: Use db
+		SharedPreferences preferences = v.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
 		Double lat = Double.longBitsToDouble(preferences.getLong(GM.PREF_GM_LATITUDE, 0));
 		Double lon = Double.longBitsToDouble(preferences.getLong(GM.PREF_GM_LONGITUDE, 0));
 		gmLocation = new LatLng(lat, lon);
@@ -220,7 +221,7 @@ public class LocationLayout extends Fragment implements OnMapReadyCallback, Loca
 	@Override
 	public void onLocationChanged(Location location) {
 		//TODO: Read again the GM Location.
-		SharedPreferences preferences = v.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+		SharedPreferences preferences = v.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
 		if (!preferences.getString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION).equals(GM.DEFAULT_PREF_GM_LOCATION)) {
 
 			Double lat = Double.longBitsToDouble(preferences.getLong(GM.PREF_GM_LATITUDE, 0));

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

@@ -81,7 +81,8 @@ public class MainActivity extends Activity {
 				result = true;
 			}
 
-			SharedPreferences settings = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+			//TODO: Store in database
+			SharedPreferences settings = getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
 			SharedPreferences.Editor editor = settings.edit();
 			if (result) {
 				editor.putLong(GM.PREF_GM_LATITUDE, Double.doubleToLongBits(Double.parseDouble(lat)));
@@ -183,8 +184,8 @@ public class MainActivity extends Activity {
 
 			case GM.SECTION_LABLANCA:
 				//Get settings
-				SharedPreferences preferences = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-				if (preferences.getInt(GM.PREF_DB_FESTIVALS, 0) == 1) {
+				SharedPreferences sharedData = getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
+				if (sharedData.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
 					fragment = new LablancaLayout();
 				} else {
 					fragment = new LablancaNoFestivalsLayout();
@@ -366,218 +367,210 @@ public class MainActivity extends Activity {
 		});
 
 		//Get preferences
-		SharedPreferences preferences = getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-		SharedPreferences.Editor editor = preferences.edit();
+		SharedPreferences sharedData = getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
+		SharedPreferences.Editor dataEditor = sharedData.edit();
 
-		//TODO: Read preferences. If there is a recent location, show the menu entry
+		//TODO: Read database. If there is a recent location, show the menu entry
 
 		//If the user code is not set, generate one
-		if (preferences.getString(GM.USER_CODE, "").length() == 0) {
+		if (sharedData.getString(GM.DATA.KEY.USER, GM.DATA.DEFAULT.USER).length() == GM.DATA.DEFAULT.USER.length()) {
 			SecureRandom random = new SecureRandom();
 			String newCode = new BigInteger(130, random).toString(32).substring(0, 16);
-			editor.putString(GM.USER_CODE, newCode);
-			editor.apply();
+			dataEditor.putString(GM.USER_CODE, newCode);
+			dataEditor.apply();
 		}
 
 		//Cerate database if it's not already created
 		createDatabase();
 
 		//If the database has just been updated, recreate the database
-		if (preferences.getInt(GM.PREF_PREVIOUS_VERSION, 0) < BuildConfig.VERSION_CODE) {
-			Log.d("UPDATE", "App updated from version " + preferences.getInt(GM.PREF_PREVIOUS_VERSION, 0) + " to " + BuildConfig.VERSION_CODE + ". Forcing a new sync...");
+		if (sharedData.getInt(GM.DATA.KEY.PREVIOUS_APP_VERSION, GM.DATA.DEFAULT.PREVIOUS_APP_VERSION) < BuildConfig.VERSION_CODE) {
+			Log.d("UPDATE", "App updated from version " + sharedData.getInt(GM.DATA.KEY.PREVIOUS_APP_VERSION, GM.DATA.DEFAULT.PREVIOUS_APP_VERSION) + " to " + BuildConfig.VERSION_CODE + ". Forcing a new sync...");
 			deleteDatabase();
-			editor.putInt(GM.PREF_PREVIOUS_VERSION, BuildConfig.VERSION_CODE);
-			editor.putInt(GM.PREF_DB_VERSION, 0);
-			editor.apply();
+			dataEditor.putInt(GM.DATA.KEY.PREVIOUS_APP_VERSION, BuildConfig.VERSION_CODE);
+			dataEditor.apply();
 			createDatabase();
 			initialSync();
 		}
 		else {
+			//Sync db
+			sync();
 
-			//If its the first time
-			if (preferences.getInt(GM.PREF_DB_VERSION, GM.DEFAULT_PREF_DB_VERSION) == GM.DEFAULT_PREF_DB_VERSION) {
-				initialSync();
-			}
-			//If t's not the first time
-			else {
-				//Sync db
-				sync();
+			//Load initial section
+			loadSection(GM.SECTION_HOME);
 
-				//Load initial section
-				loadSection(GM.SECTION_HOME);
+			//If the intent had extras (from notifications), do something
+			if (actionText != null) {
+				TextView tvDialogTitle, tvDialogText;
+				Button btDialogClose, btDialogAction;
+				Drawable dialogIcon;
+				if (actionTitle != null) {
 
-				//If the intent had extras (from notifications), do something
-				if (actionText != null) {
-					TextView tvDialogTitle, tvDialogText;
-					Button btDialogClose, btDialogAction;
-					Drawable dialogIcon;
-					if (actionTitle != null) {
-
-						//Create a dialog
-						final Dialog dialog = new Dialog(this);
-
-						//Set up dialog window
-						dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
-						dialog.setContentView(R.layout.dialog_notification);
-
-						//Set title
-						tvDialogTitle = (TextView) dialog.findViewById(R.id.tv_dialog_notification_title);
-						tvDialogTitle.setText(actionTitle);
-
-						//Set text
-						tvDialogText = (TextView) dialog.findViewById(R.id.tv_dialog_notification_text);
-						tvDialogText.setText(actionText);
-
-						//Set close button
-						btDialogClose = (Button) dialog.findViewById(R.id.bt_dialog_notification_close);
-						btDialogClose.setOnClickListener(new OnClickListener() {
-							@Override
-							public void onClick(View v) {
-								dialog.dismiss();
-							}
-						});
-
-						//Set the icon
-						dialogIcon = getResources().getDrawable(R.drawable.ic_launcher);
-						if (dialogIcon != null) {
-							dialogIcon.setBounds(0, 0, (int) (tvDialogTitle.getTextSize() * 1.4), (int) (tvDialogTitle.getTextSize() * 1.4));
-						}
-						tvDialogTitle.setCompoundDrawables(dialogIcon, null, null, null);
-						tvDialogTitle.setCompoundDrawablePadding(20);
+					//Create a dialog
+					final Dialog dialog = new Dialog(this);
 
-						//Get preferences
-						int festivals = preferences.getInt(GM.PREF_DB_FESTIVALS, 0);
+					//Set up dialog window
+					dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+					dialog.setContentView(R.layout.dialog_notification);
 
-						//Set the action button
-						btDialogAction = (Button) dialog.findViewById(R.id.bt_dialog_notification_action);
-						if (action != null) {
-							switch (action) {
+					//Set title
+					tvDialogTitle = (TextView) dialog.findViewById(R.id.tv_dialog_notification_title);
+					tvDialogTitle.setText(actionTitle);
 
-								case GM.EXTRA_ACTION_LABLANCA:
+					//Set text
+					tvDialogText = (TextView) dialog.findViewById(R.id.tv_dialog_notification_text);
+					tvDialogText.setText(actionText);
 
-									//Set up the action button
-									btDialogAction.setVisibility(View.VISIBLE);
-									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_lablanca));
-									btDialogAction.setOnClickListener(new OnClickListener() {
-										@Override
-										public void onClick(View v) {
-											dialog.dismiss();
-											loadSection(GM.SECTION_LABLANCA);
-										}
-									});
-									break;
-
-								case GM.EXTRA_ACTION_LOCATION:
-
-									if (!preferences.getString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION).equals(GM.DEFAULT_PREF_GM_LOCATION)) {
-										//Set up the action button if location is reported
-										btDialogAction.setVisibility(View.VISIBLE);
-										btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_location));
-										btDialogAction.setOnClickListener(new OnClickListener() {
-											@Override
-											public void onClick(View v) {
-												dialog.dismiss();
-												loadSection(GM.SECTION_LOCATION);
-											}
-										});
+					//Set close button
+					btDialogClose = (Button) dialog.findViewById(R.id.bt_dialog_notification_close);
+					btDialogClose.setOnClickListener(new OnClickListener() {
+						@Override
+						public void onClick(View v) {
+							dialog.dismiss();
+						}
+					});
 
+					//Set the icon
+					dialogIcon = getResources().getDrawable(R.drawable.ic_launcher);
+					if (dialogIcon != null) {
+						dialogIcon.setBounds(0, 0, (int) (tvDialogTitle.getTextSize() * 1.4), (int) (tvDialogTitle.getTextSize() * 1.4));
+					}
+					tvDialogTitle.setCompoundDrawables(dialogIcon, null, null, null);
+					tvDialogTitle.setCompoundDrawablePadding(20);
+
+					//Get preferences
+					boolean festivals = sharedData.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA);
+
+					//Set the action button
+					btDialogAction = (Button) dialog.findViewById(R.id.bt_dialog_notification_action);
+					if (action != null) {
+						switch (action) {
+
+							case GM.EXTRA_ACTION_LABLANCA:
+
+								//Set up the action button
+								btDialogAction.setVisibility(View.VISIBLE);
+								btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_lablanca));
+								btDialogAction.setOnClickListener(new OnClickListener() {
+									@Override
+									public void onClick(View v) {
+										dialog.dismiss();
+										loadSection(GM.SECTION_LABLANCA);
 									}
-									break;
+								});
+								break;
 
-								case GM.EXTRA_ACTION_BLOG:
+							case GM.EXTRA_ACTION_LOCATION:
 
-									//Set up the action button
+								//TODO: Read from database
+								if (!sharedData.getString(GM.PREF_GM_LOCATION, GM.DEFAULT_PREF_GM_LOCATION).equals(GM.DEFAULT_PREF_GM_LOCATION)) {
+									//Set up the action button if location is reported
 									btDialogAction.setVisibility(View.VISIBLE);
-									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_blog));
+									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_location));
 									btDialogAction.setOnClickListener(new OnClickListener() {
 										@Override
 										public void onClick(View v) {
 											dialog.dismiss();
-											loadSection(GM.SECTION_BLOG);
+											loadSection(GM.SECTION_LOCATION);
 										}
 									});
-									break;
 
-								case GM.EXTRA_ACTION_ACTIVITIES:
+								}
+								break;
+
+							case GM.EXTRA_ACTION_BLOG:
+
+								//Set up the action button
+								btDialogAction.setVisibility(View.VISIBLE);
+								btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_blog));
+								btDialogAction.setOnClickListener(new OnClickListener() {
+									@Override
+									public void onClick(View v) {
+										dialog.dismiss();
+										loadSection(GM.SECTION_BLOG);
+									}
+								});
+								break;
+
+							case GM.EXTRA_ACTION_ACTIVITIES:
+
+								//Set up the action button
+								btDialogAction.setVisibility(View.VISIBLE);
+								btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_activities));
+								btDialogAction.setOnClickListener(new OnClickListener() {
+									@Override
+									public void onClick(View v) {
+										dialog.dismiss();
+										loadSection(GM.SECTION_ACTIVITIES);
+									}
+								});
+								break;
+
+							case GM.EXTRA_ACTION_GALLERY:
+
+								//Set up the action button
+								btDialogAction.setVisibility(View.VISIBLE);
+								btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gallery));
+								btDialogAction.setOnClickListener(new OnClickListener() {
+									@Override
+									public void onClick(View v) {
+										dialog.dismiss();
+										loadSection(GM.SECTION_GALLERY);
+									}
+								});
+								break;
 
+							case GM.EXTRA_ACTION_GMSCHEDULE:
+
+								if (festivals) {
 									//Set up the action button
 									btDialogAction.setVisibility(View.VISIBLE);
-									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_activities));
+									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gmschedule));
 									btDialogAction.setOnClickListener(new OnClickListener() {
 										@Override
 										public void onClick(View v) {
 											dialog.dismiss();
-											loadSection(GM.SECTION_ACTIVITIES);
+											loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE);
 										}
 									});
-									break;
-
-								case GM.EXTRA_ACTION_GALLERY:
+								}
+								break;
 
+							case GM.EXTRA_ACTION_CITYSCHEDULE:
+								if (festivals) {
 									//Set up the action button
 									btDialogAction.setVisibility(View.VISIBLE);
-									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gallery));
+									btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_cityschedule));
 									btDialogAction.setOnClickListener(new OnClickListener() {
 										@Override
 										public void onClick(View v) {
 											dialog.dismiss();
-											loadSection(GM.SECTION_GALLERY);
+											loadSection(GM.SECTION_LABLANCA_SCHEDULE);
 										}
 									});
-									break;
-
-								case GM.EXTRA_ACTION_GMSCHEDULE:
-
-									if (festivals == 1) {
-										//Set up the action button
-										btDialogAction.setVisibility(View.VISIBLE);
-										btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_gmschedule));
-										btDialogAction.setOnClickListener(new OnClickListener() {
-											@Override
-											public void onClick(View v) {
-												dialog.dismiss();
-												loadSection(GM.SECTION_LABLANCA_GM_SCHEDULE);
-											}
-										});
-									}
-									break;
-
-								case GM.EXTRA_ACTION_CITYSCHEDULE:
-									if (festivals == 1) {
-										//Set up the action button
-										btDialogAction.setVisibility(View.VISIBLE);
-										btDialogAction.setText(this.getApplicationContext().getString(R.string.notification_action_cityschedule));
-										btDialogAction.setOnClickListener(new OnClickListener() {
-											@Override
-											public void onClick(View v) {
-												dialog.dismiss();
-												loadSection(GM.SECTION_LABLANCA_SCHEDULE);
-											}
-										});
-									}
-									break;
-
-								//If the notification is just text
-								default:
-									//Hide action button
-									btDialogAction.setVisibility(View.GONE);
-							}
-						} else {
-							btDialogAction.setVisibility(View.GONE);
-						}
+								}
+								break;
 
-						//Set dialog parameters
-						WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
-						lp.copyFrom(dialog.getWindow().getAttributes());
-						lp.width = WindowManager.LayoutParams.MATCH_PARENT;
-						lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
-						lp.gravity = Gravity.CENTER;
-						lp.dimAmount = 0.4f;
-						dialog.getWindow().setAttributes(lp);
-
-						//Show dialog
-						dialog.show();
+							//If the notification is just text
+							default:
+								//Hide action button
+								btDialogAction.setVisibility(View.GONE);
+						}
+					} else {
+						btDialogAction.setVisibility(View.GONE);
 					}
+
+					//Set dialog parameters
+					WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+					lp.copyFrom(dialog.getWindow().getAttributes());
+					lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+					lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+					lp.gravity = Gravity.CENTER;
+					lp.dimAmount = 0.4f;
+					dialog.getWindow().setAttributes(lp);
+
+					//Show dialog
+					dialog.show();
 				}
 			}
 		}
@@ -632,7 +625,7 @@ public class MainActivity extends Activity {
 	private void deleteDatabase() {
 		SQLiteDatabase db;
 		try {
-			deleteDatabase(GM.DB_NAME);
+			getApplicationContext().deleteDatabase(GM.DB_NAME);
 		} catch (Exception ex) {
 			Log.e("Error deleting database", ex.toString());
 		}

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

@@ -61,8 +61,8 @@ class PostComment extends AsyncTask<String, String, Integer> {
         pb.setVisibility(View.VISIBLE);
 
         //Get user code
-        SharedPreferences preferences = context.getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-        userCode = preferences.getString(GM.USER_CODE, "");
+        SharedPreferences sharedData = context.getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
+        userCode = sharedData.getString(GM.DATA.KEY.USER, GM.DATA.DEFAULT.USER);
     }
 
     /**

+ 23 - 27
app/src/main/java/com/ivalentin/margolariak/SettingsActivity.java

@@ -1,12 +1,12 @@
 package com.ivalentin.margolariak;
 
+import android.content.Intent;
 import android.content.SharedPreferences;
+import android.net.Uri;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
 
 public class SettingsActivity extends PreferenceActivity {
 	@Override
@@ -77,42 +77,38 @@ public class SettingsActivity extends PreferenceActivity {
 			}
 		});
 
-
-		//Set up data preference
-		long bgData = sp.getLong(GM.STORAGE_TRAFFIC_BG_RECEIVED, 0) + sp.getLong(GM.STORAGE_TRAFFIC_BG_SENT, 0);
-		long fgData = sp.getLong(GM.STORAGE_TRAFFIC_FG_RECEIVED, 0) + sp.getLong(GM.STORAGE_TRAFFIC_FG_SENT, 0);
-		String value;
-		if (bgData < 1500){
-			value = bgData + getString(R.string.Kb);
-		}
-		else if(bgData < 5 * 1024){
-			NumberFormat formatter = new DecimalFormat("#0.00");
-			value = (formatter.format(((float) bgData) / 1024.0)) + getString(R.string.Mb);
-		}
-		else{
-			value = String.valueOf((int) (((float) bgData) / 1024.0)) + getString(R.string.Mb);
-		}
-		Preference prefData = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_DATA);
-		prefData.setSummary(value);
-
-
-
 		//Set up version preference
 		Preference prefVersion = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
 		prefVersion.setSummary(com.ivalentin.margolariak.BuildConfig.VERSION_NAME);
-		prefNotification.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+		prefVersion.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
 			@Override
 			public boolean onPreferenceClick(Preference preference) {
-				//TODO
+				//TODO: Show changelog
 				return false;
 			}
 		});
 
 		//Set up source preference
-		//TODO
+		Preference prefSource = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
+		prefSource.setSummary(com.ivalentin.margolariak.BuildConfig.VERSION_NAME);
+		prefSource.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+			@Override
+			public boolean onPreferenceClick(Preference preference) {
+				Intent i = new Intent(Intent.ACTION_VIEW);
+				i.setData(Uri.parse(GM.URL.GITHUB));
+				startActivity(i);
+				return false;
+			}
+		});
 
 		//Set up feedback preference
-		//TODO
-
+		Preference prefFeedback = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
+		prefFeedback.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+			@Override
+			public boolean onPreferenceClick(Preference preference) {
+				//TODO: Show dialog
+				return false;
+			}
+		});
 	}
 }

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

@@ -59,8 +59,8 @@ public class SettingsLayout extends Fragment{
 
 
 		//Set initial state of the notification  settings
-		SharedPreferences settings = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
-		if (settings.getInt(GM.PREF_NOTIFICATION, GM.DEFAULT_PREF_NOTIFICATION) == 1){
+		SharedPreferences settings = view.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
+		if (settings.getBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, GM.PREFERENCES.DEFAULT.NOTIFICATIONS)){
 			cbNotification.setChecked(true);
 			tvNotification.setText(view.getContext().getString(R.string.settings_notification_on));
 		}
@@ -76,17 +76,17 @@ public class SettingsLayout extends Fragment{
 				if (cbNotification.isChecked()){
 					cbNotification.setChecked(false);
 					tvNotification.setText(view.getContext().getString(R.string.settings_notification_off));
-					SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+					SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
 					SharedPreferences.Editor editor = preferences.edit();
-					editor.putInt(GM.PREF_NOTIFICATION, 0);
+					editor.putBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, false);
 					editor.apply();
 				}
 				else{
 					cbNotification.setChecked(true);
 					tvNotification.setText(view.getContext().getString(R.string.settings_notification_on));
-					SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+					SharedPreferences preferences = view.getContext().getSharedPreferences(GM.PREFERENCES.PREFERNCES, Context.MODE_PRIVATE);
 					SharedPreferences.Editor editor = preferences.edit();
-					editor.putInt(GM.PREF_NOTIFICATION, 1);
+					editor.putBoolean(GM.PREFERENCES.KEY.NOTIFICATIONS, true);
 					editor.apply();
 				}
 			}

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

@@ -585,10 +585,10 @@ class Sync extends AsyncTask<Void, Void, Void> {
 	protected Void doInBackground(Void... params) {
 
 		//Get preferences
-		SharedPreferences preferences = myContextRef.getSharedPreferences(GM.PREF, Context.MODE_PRIVATE);
+		SharedPreferences preferences = myContextRef.getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
 
 		//Get useful data for the uri
-		String userCode = preferences.getString(GM.USER_CODE, "");
+		String userCode = preferences.getString(GM.DATA.KEY.USER, GM.DATA.DEFAULT.USER);
 
 		//Get database. Stop if it's locked
 		SQLiteDatabase db = myContextRef.openOrCreateDatabase(GM.DB_NAME, Activity.MODE_PRIVATE, null);
@@ -667,6 +667,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 				default:
 					Log.e("SYNC", "The server returned an unexpected code (" + httpCode + ") for the url \"" + uri + "\"");
 			}
+
 			urlConnection.disconnect();
 			return null;
 

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

@@ -167,7 +167,7 @@
 	<string name="settings_notification_on">Recibir notificaciones</string>
 	<string name="home_section_location_text_calculating">Calculando distancia…</string>
 	<string name="pop_menu_about">About us</string>
-	<string name="pop_menu_settings">Settings</string>
+	<string name="pop_menu_settings">Ajustes</string>
 	<string name="pop_menu_sponsors">-</string>
 	<string name="preferences_info">Informazioa</string>
 	<string name="preferences_info_feedback_summary">Send anonymous feedback to the developer</string>

+ 0 - 4
app/src/main/res/xml/preferences.xml

@@ -12,10 +12,6 @@
             android:title="@string/preferences_sync_notifications"
             android:summary="@string/preferences_sync_notifications_on"
             android:defaultValue="true" />
-        <Preference
-            android:key="preference_key_data"
-            android:title="@string/preferences_sync_usage"
-            android:summary="0 kb" />
 
     </PreferenceCategory>