Browse Source

added customization preference

yattoz 5 years ago
parent
commit
912857c9cd

+ 12 - 0
app/src/main/java/fr/forum_thalie/tsumugi/ParametersActivity.kt View File

1
 package fr.forum_thalie.tsumugi
1
 package fr.forum_thalie.tsumugi
2
 
2
 
3
 import android.os.Bundle
3
 import android.os.Bundle
4
+import android.view.MenuItem
4
 import fr.forum_thalie.tsumugi.preferences.*
5
 import fr.forum_thalie.tsumugi.preferences.*
5
 
6
 
6
 
7
 
38
             .replace(R.id.parameters_host_container, fragmentToLoad)
39
             .replace(R.id.parameters_host_container, fragmentToLoad)
39
             .commit()
40
             .commit()
40
     }
41
     }
42
+
43
+    // Make the Up button function as back instead of always bringing us to the main activity
44
+    override fun onOptionsItemSelected(item: MenuItem): Boolean {
45
+        return when (item.itemId) {
46
+            android.R.id.home -> {
47
+                onBackPressed()
48
+                true
49
+            }
50
+            else -> super.onOptionsItemSelected(item)
51
+        }
52
+    }
41
 }
53
 }

+ 20 - 3
app/src/main/java/fr/forum_thalie/tsumugi/preferences/CustomizeFragment.kt View File

1
 package fr.forum_thalie.tsumugi.preferences
1
 package fr.forum_thalie.tsumugi.preferences
2
 
2
 
3
-import android.content.Intent
4
-import android.net.Uri
5
 import android.os.Bundle
3
 import android.os.Bundle
6
-import android.util.Log
7
 import androidx.appcompat.app.AlertDialog
4
 import androidx.appcompat.app.AlertDialog
8
 import androidx.preference.*
5
 import androidx.preference.*
9
 import fr.forum_thalie.tsumugi.R
6
 import fr.forum_thalie.tsumugi.R
40
             true
37
             true
41
         }
38
         }
42
 
39
 
40
+
41
+        val fetchPeriod = preferenceScreen.findPreference<ListPreference>("fetchPeriod")
42
+        fetchPeriod?.summaryProvider = ListPreference.SimpleSummaryProvider.getInstance()
43
+        fetchPeriod?.setOnPreferenceChangeListener { _, newValue ->
44
+            val builder1 = AlertDialog.Builder(context!!)
45
+            if (Integer.parseInt(newValue as String) == 0)
46
+                builder1.setMessage(R.string.restart_the_app)
47
+            else
48
+                builder1.setMessage(R.string.restart_the_app)
49
+            builder1.setCancelable(true)
50
+
51
+            builder1.setPositiveButton("Close" ) { dialog, _ ->
52
+                dialog.cancel()
53
+            }
54
+
55
+            val alert11 = builder1.create()
56
+            alert11.show()
57
+            true
58
+        }
59
+
43
     }
60
     }
44
 }
61
 }

+ 31 - 0
app/src/main/res/values-fr/arrays.xml View File

1
+<?xml version="1.0" encoding="utf-8"?>
2
+<resources>
3
+
4
+    <string-array name="snoozeValues">
5
+        <item name="0">@string/disable</item>
6
+        <item name="1">1</item>
7
+        <item name="2">2</item>
8
+        <item name="5">5</item>
9
+        <item name="10">10</item>
10
+        <item name="15">15</item>
11
+        <item name="20">20</item>
12
+        <item name="25">25</item>
13
+        <item name="30">30</item>
14
+    </string-array>
15
+
16
+    <string-array name="fetchPeriodString">
17
+        <item name="5">Toutes les 5 secondes (mise à jour rapide)</item>
18
+        <item name="10">Toutes les 10 secondes</item>
19
+        <item name="15">Toutes les 15 secondes</item>
20
+        <item name="20">Toutes les 20 secondes</item>
21
+        <item name="30">Toutes les 30 secondes (moins d\'utilisation de batterie)</item>
22
+    </string-array>
23
+    <string-array name="fetchPeriodValues">
24
+        <item name="5">5</item>
25
+        <item name="10">10</item>
26
+        <item name="15">15</item>
27
+        <item name="20">20</item>
28
+        <item name="30">30</item>
29
+    </string-array>
30
+
31
+</resources>

+ 1 - 0
app/src/main/res/values-fr/strings.xml View File

50
     <string name="sleepClosesApp">Minuterie avant fermeture de l\'application</string>
50
     <string name="sleepClosesApp">Minuterie avant fermeture de l\'application</string>
51
     <string name="setSleepDuration">Choisir une durée (en minutes)</string>
51
     <string name="setSleepDuration">Choisir une durée (en minutes)</string>
52
     <string name="willCloseIn">Extinction dans %1$d minutes</string>
52
     <string name="willCloseIn">Extinction dans %1$d minutes</string>
53
+    <string name="fetchPeriod">Choisir la fréquence de mise à jour quand la radio est stoppée</string>
53
 
54
 
54
 </resources>
55
 </resources>

+ 15 - 0
app/src/main/res/values/arrays.xml View File

13
         <item name="30">30</item>
13
         <item name="30">30</item>
14
     </string-array>
14
     </string-array>
15
 
15
 
16
+    <string-array name="fetchPeriodString">
17
+        <item name="5">Every 5 seconds (faster update)</item>
18
+        <item name="10">Every 10 seconds</item>
19
+        <item name="15">Every 15 seconds</item>
20
+        <item name="20">Every 20 seconds</item>
21
+        <item name="30">Every 30 seconds (less battery-intensive)</item>
22
+    </string-array>
23
+    <string-array name="fetchPeriodValues">
24
+        <item name="5">5</item>
25
+        <item name="10">10</item>
26
+        <item name="15">15</item>
27
+        <item name="20">20</item>
28
+        <item name="30">30</item>
29
+    </string-array>
30
+
16
 </resources>
31
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml View File

70
     <string name="sleepClosesApp">Sleep - close app after some time</string>
70
     <string name="sleepClosesApp">Sleep - close app after some time</string>
71
     <string name="setSleepDuration">Set duration (minutes)</string>
71
     <string name="setSleepDuration">Set duration (minutes)</string>
72
     <string name="willCloseIn">Will close in %1$d minutes</string>
72
     <string name="willCloseIn">Will close in %1$d minutes</string>
73
+    <string name="fetchPeriod">Set update period when stopped</string>
73
 
74
 
74
 </resources>
75
 </resources>

+ 10 - 0
app/src/main/res/xml/customize_preferences.xml View File

29
         app:defaultValue="false"
29
         app:defaultValue="false"
30
         />
30
         />
31
 
31
 
32
+    <ListPreference
33
+        app:key="fetchPeriod"
34
+        app:iconSpaceReserved="false"
35
+        android:title="@string/fetchPeriod"
36
+        app:singleLineTitle="false"
37
+        android:entries="@array/fetchPeriodString"
38
+        android:entryValues="@array/fetchPeriodValues"
39
+        android:defaultValue="10"
40
+        />
41
+
32
 </PreferenceScreen>
42
 </PreferenceScreen>