Răsfoiți Sursa

Preference screen reworked.

The preference view is no longer a PreferenceActivity but a RegularActivity, containing the following elements:

* Sync: Toggleable element to enable or disable background sync. Implemented in the view, but doesn't actually change the preference value yet.
* Notifications: Wether or not to receive notificatins. Again, the view is implemented, but it does nothing. It should be dependant of wether the sync option is enabled or not.
* App version: Shows the app version (done). When clicking, a dialog must open showing the changelog (TODO).
* Source code: A link to the Github repository (done).
* Feedback: (TODO) Should open a dialog to send feedback to the developer.

overall, the whole section needs some UI work.
seavenois 9 ani în urmă
părinte
comite
83b342fda0

+ 39 - 79
app/src/main/java/com/ivalentin/margolariak/SettingsActivity.java

@@ -1,114 +1,74 @@
 package com.ivalentin.margolariak;
 
+import android.app.Activity;
 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 android.view.View;
+import android.view.Window;
+import android.widget.CheckBox;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class SettingsActivity extends Activity {
+
+	//Assign menu items
+	private LinearLayout llSync, llNotifications, llVersion, llSource, llFeedback;
+	private CheckBox cbSync, cbNotifications;
+	private TextView tvSync, tvNotifications, tvVersion;
 
-public class SettingsActivity extends PreferenceActivity {
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 
-		// Load the preferences from an XML resource
-		addPreferencesFromResource(R.xml.preferences);
-
-		SharedPreferences sp = getPreferenceScreen().getSharedPreferences();
-
-		//Set up Sync preference
-		CheckBoxPreference prefSync = (CheckBoxPreference) getPreferenceManager().findPreference(GM.KEY_PREFERENCE_SYNC);
-		if (prefSync.isChecked()){
-			prefSync.setSummary(getString(R.string.preferences_sync_sync_on));
-		}
-		else{
-			prefSync.setSummary(getString(R.string.preferences_sync_sync_off));
-		}
-		prefSync.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
-
-			public boolean onPreferenceChange(Preference preference, Object newValue) {
-				CheckBoxPreference prefNotification = (CheckBoxPreference) getPreferenceManager().findPreference(GM.KEY_PREFERENCE_NOTIFICATION);
-				if (newValue.toString().equals("true")) {
-					preference.setSummary(getString(R.string.preferences_sync_sync_on));
-					if (prefNotification.isChecked()){
-						prefNotification.setSummary(getString(R.string.preferences_sync_notifications_on));
-					}
-					else{
-						prefNotification.setSummary(getString(R.string.preferences_sync_notifications_off));
-					}
-					prefNotification.setEnabled(true);
-				} else {
-					prefNotification.setEnabled(false);
-					prefNotification.setSummary(getString(R.string.preferences_sync_notifications_disabled));
-					preference.setSummary(getString(R.string.preferences_sync_sync_off));
-				}
-				return true;
-			}
-		});
-
-		//Set up Notification preference
-		CheckBoxPreference prefNotification = (CheckBoxPreference) getPreferenceManager().findPreference(GM.KEY_PREFERENCE_NOTIFICATION);
-		if (!prefSync.isChecked()){
-			prefNotification.setEnabled(false);
-		}
-		else {
-			prefNotification.setEnabled(true);
-			if(!prefSync.isChecked()){
-				//TODO
-			}
-			if (prefNotification.isChecked()) {
-				prefNotification.setSummary(getString(R.string.preferences_sync_notifications_on));
-			} else {
-				prefNotification.setSummary(getString(R.string.preferences_sync_notifications_off));
-			}
-		}
+		//Remove title bar.
+		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+		super.onCreate(savedInstanceState);
 
-		prefNotification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+		//Set layout.
+		setContentView(R.layout.activity_settings);
 
-			public boolean onPreferenceChange(Preference preference, Object newValue) {
-				if (newValue.toString().equals("true")) {
-					preference.setSummary(getString(R.string.preferences_sync_notifications_on));
-				} else {
-					preference.setSummary(getString(R.string.preferences_sync_notifications_off));
-				}
-				return true;
-			}
-		});
+		//Assign views
+		llSync = (LinearLayout) findViewById(R.id.ll_settings_sync);
+		llNotifications = (LinearLayout) findViewById(R.id.ll_settings_notifications);
+		llVersion = (LinearLayout) findViewById(R.id.ll_settings_version);
+		llSource = (LinearLayout) findViewById(R.id.ll_settings_source);
+		llFeedback = (LinearLayout) findViewById(R.id.ll_settings_feedback);
+		tvSync = (TextView) findViewById(R.id.tv_settings_sync);
+		tvNotifications = (TextView) findViewById(R.id.tv_settings_notifications);
+		tvVersion = (TextView) findViewById(R.id.tv_settings_version);
+		cbSync = (CheckBox) findViewById(R.id.cb_settings_sync);
+		cbNotifications = (CheckBox) findViewById(R.id.cb_settings_notifications);
 
 		//Set up version preference
-		Preference prefVersion = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
-		prefVersion.setSummary(com.ivalentin.margolariak.BuildConfig.VERSION_NAME);
-		prefVersion.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+		tvVersion.setText(com.ivalentin.margolariak.BuildConfig.VERSION_NAME);
+		llVersion.setOnClickListener(new View.OnClickListener() {
 			@Override
-			public boolean onPreferenceClick(Preference preference) {
+			public void onClick(View v) {
 				//TODO: Show changelog
-				return false;
 			}
 		});
 
 		//Set up source preference
-		Preference prefSource = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
-		prefSource.setSummary(com.ivalentin.margolariak.BuildConfig.VERSION_NAME);
-		prefSource.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+		llSource.setOnClickListener(new View.OnClickListener() {
 			@Override
-			public boolean onPreferenceClick(Preference preference) {
+			public void onClick(View v) {
 				Intent i = new Intent(Intent.ACTION_VIEW);
 				i.setData(Uri.parse(GM.URL.GITHUB));
 				startActivity(i);
-				return false;
 			}
 		});
 
 		//Set up feedback preference
-		Preference prefFeedback = getPreferenceManager().findPreference(GM.KEY_PREFERENCE_VERSION);
-		prefFeedback.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+		llFeedback.setOnClickListener(new View.OnClickListener() {
 			@Override
-			public boolean onPreferenceClick(Preference preference) {
-				//TODO: Show dialog
-				return false;
+			public void onClick(View v) {
+				//TODO: Show dialog to enter text
 			}
 		});
+
+		//TODO: Set up sync and notifications
 	}
 }

+ 328 - 0
app/src/main/res/layout/activity_settings.xml

@@ -0,0 +1,328 @@
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical">
+
+    <LinearLayout
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/background_menu"
+        android:gravity="center_vertical"
+        android:orientation="horizontal"
+        android:padding="2dp">
+
+        <!-- Button to open slider menu -->
+
+        <ImageView
+            android:contentDescription="@string/app_name"
+            android:layout_width="40dp"
+            android:layout_height="40dp"
+            android:id="@+id/iv_logo"
+            android:src="@drawable/ic_launcher"
+            android:adjustViewBounds="true"
+            android:layout_weight=".2"
+            android:maxHeight="45dp"
+            android:maxWidth="45dp"
+            android:padding="1dp"/>
+
+        <!-- Layout with the app title and current section -->
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_weight=".8"
+            android:gravity="center"
+            android:orientation="vertical" >
+
+            <!-- App name. Remains unchanged -->
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:text="@string/app_name"
+                android:textSize="18sp"
+                android:textStyle="bold"
+                android:textColor="@color/menu_entry"/>
+
+            <!-- Section title -->
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:text="@string/menu_settings"
+                android:textSize="20sp"
+                android:textColor="@color/menu_entry"/>
+
+        </LinearLayout>
+
+        <ImageButton
+            android:layout_width="40dp"
+            android:layout_height="match_parent"
+            android:src="@android:drawable/ic_menu_revert"
+            android:contentDescription="@string/tutorial_menu"
+            android:onClick="finish();"
+            android:layout_weight=".2"
+            android:id="@+id/bt_menu"
+            app:srcCompat="@android:drawable/ic_menu_revert"
+            android:background="#00000000"/>
+
+        <ProgressBar
+            android:id="@+id/pb_sync"
+            android:layout_width="40dp"
+            android:layout_height="40dp"
+            android:layout_weight=".2"
+            android:visibility="gone"
+            android:maxHeight="40dp"
+            android:maxWidth="40dp"/>
+
+    </LinearLayout>
+
+    <!-- The part where the fragments will be loaded -->
+
+    <ScrollView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/background_app">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            tools:ignore="ScrollViewSize"
+            android:background="@color/background_app"
+            android:orientation="vertical">
+
+            <TextView
+                android:text="@string/preferences_sync"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textStyle="bold"
+                android:textColor="@color/background_menu"
+                android:layout_marginEnd="10dp"
+                android:layout_marginLeft="10dp"
+                android:layout_marginRight="10dp"
+                android:layout_marginStart="10dp"
+                android:layout_marginTop="20dp"
+                android:textSize="20sp"
+                android:layout_marginBottom="10dp"/>
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_settings_sync"
+                android:paddingBottom="15dp"
+                android:paddingLeft="20dp"
+                android:paddingStart="20dp"
+                android:paddingTop="15dp"
+                android:layout_marginBottom="15dp">
+
+                <LinearLayout
+                    android:orientation="vertical"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_weight=".15">
+
+                    <TextView
+                        android:text="@string/preferences_sync_sync"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:textSize="18sp"
+                        android:textColor="@android:color/black"
+                        />
+
+                    <TextView
+                        android:text="@string/preferences_sync_sync_on"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:id="@+id/tv_settings_sync"
+                        android:textSize="16sp"
+                        android:textColor="@android:color/black"
+                        android:layout_marginTop="10dp"
+                        android:layout_marginStart="10dp"
+                        android:layout_marginLeft="10dp"/>
+                </LinearLayout>
+
+                <CheckBox
+                    android:layout_height="50dp"
+                    android:id="@+id/cb_settings_sync"
+                    android:padding="15dp"
+                    android:layout_width="match_parent"
+                    android:layout_weight=".85"
+                    android:gravity="center_vertical|center_horizontal"
+                    android:layout_gravity="center_vertical|center_horizontal"
+                    android:textAlignment="center"/>
+
+            </LinearLayout>
+
+            <LinearLayout
+                android:orientation="horizontal"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_settings_notifications"
+                android:paddingBottom="15dp"
+                android:paddingLeft="20dp"
+                android:paddingStart="20dp"
+                android:paddingTop="15dp"
+                android:layout_marginBottom="15dp">
+
+                <LinearLayout
+                    android:orientation="vertical"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout_weight=".15">
+
+                    <TextView
+                        android:text="@string/preferences_sync_notifications"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:textSize="18sp"
+                        android:textColor="@android:color/black"
+                        />
+
+                    <TextView
+                        android:text="@string/preferences_sync_notifications_on"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        android:id="@+id/tv_settings_notifications"
+                        android:textSize="16sp"
+                        android:textColor="@android:color/black"
+                        android:layout_marginTop="10dp"
+                        android:layout_marginStart="10dp"
+                        android:layout_marginLeft="10dp"/>
+                </LinearLayout>
+
+                <CheckBox
+                    android:layout_height="50dp"
+                    android:id="@+id/cb_settings_notifications"
+                    android:padding="15dp"
+                    android:layout_width="match_parent"
+                    android:layout_weight=".85"
+                    android:gravity="center_vertical|center_horizontal"
+                    android:layout_gravity="center_vertical|center_horizontal"
+                    android:textAlignment="center"/>
+
+            </LinearLayout>
+
+            <TextView
+                android:text="@string/preferences_info"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textStyle="bold"
+                android:textColor="@color/background_menu"
+                android:layout_marginEnd="10dp"
+                android:layout_marginLeft="10dp"
+                android:layout_marginRight="10dp"
+                android:layout_marginStart="10dp"
+                android:layout_marginTop="20dp"
+                android:textSize="20sp"
+                android:layout_marginBottom="10dp"/>
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_settings_version"
+                android:paddingBottom="15dp"
+                android:paddingLeft="20dp"
+                android:paddingStart="20dp"
+                android:paddingTop="15dp"
+                android:layout_marginBottom="15dp">
+
+                <TextView
+                    android:text="@string/preferences_info_version"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="18sp"
+                    android:textColor="@android:color/black"
+                    android:layout_weight=".15"/>
+
+                <TextView
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:id="@+id/tv_settings_version"
+                    android:textSize="16sp"
+                    android:textColor="@android:color/black"
+                    android:layout_marginTop="10dp"
+                    android:layout_marginStart="10dp"
+                    android:layout_marginLeft="10dp"
+                    android:layout_weight=".15"/>
+
+            </LinearLayout>
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_settings_source"
+                android:paddingBottom="15dp"
+                android:paddingLeft="20dp"
+                android:paddingStart="20dp"
+                android:paddingTop="15dp"
+                android:layout_marginBottom="15dp">
+
+                <TextView
+                    android:text="@string/preferences_info_source"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="18sp"
+                    android:textColor="@android:color/black"
+                    android:layout_weight=".15"/>
+
+                <TextView
+                    android:text="@string/preferences_info_source_summary"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="16sp"
+                    android:textColor="@android:color/black"
+                    android:layout_marginTop="10dp"
+                    android:layout_marginStart="10dp"
+                    android:layout_marginLeft="10dp"
+                    android:layout_weight=".15"/>
+
+            </LinearLayout>
+
+            <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:id="@+id/ll_settings_feedback"
+                android:paddingBottom="15dp"
+                android:paddingLeft="20dp"
+                android:paddingStart="20dp"
+                android:paddingTop="15dp"
+                android:layout_marginBottom="15dp">
+
+                <TextView
+                    android:text="@string/preferences_info_feedback"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="18sp"
+                    android:textColor="@android:color/black"
+                    android:layout_weight=".15"/>
+
+                <TextView
+                    android:text="@string/preferences_info_feedback_summary"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:textSize="16sp"
+                    android:textColor="@android:color/black"
+                    android:layout_marginTop="10dp"
+                    android:layout_marginStart="10dp"
+                    android:layout_marginLeft="10dp"
+                    android:layout_weight=".15"/>
+
+            </LinearLayout>
+
+        </LinearLayout>
+
+
+    </ScrollView>
+
+</LinearLayout>
+