add basic settings screen (+ navigation!)
This commit is contained in:
parent
37832f1d8b
commit
70beae84e7
|
@ -47,10 +47,11 @@ dependencies {
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.4.0'
|
implementation 'androidx.fragment:fragment-ktx:1.4.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation "androidx.room:room-runtime:$room_version"
|
|
||||||
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
|
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
|
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
|
||||||
implementation 'androidx.preference:preference-ktx:1.1.1'
|
implementation 'androidx.preference:preference-ktx:1.1.1'
|
||||||
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
|
implementation "androidx.room:room-ktx:$room_version"
|
||||||
implementation 'com.google.android.material:material:1.4.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
|
|
@ -13,19 +13,22 @@ object History {
|
||||||
@Dao
|
@Dao
|
||||||
interface HistoryEntryDao {
|
interface HistoryEntryDao {
|
||||||
@Query("SELECT * FROM HistoryEntry WHERE :uri = uri LIMIT 1")
|
@Query("SELECT * FROM HistoryEntry WHERE :uri = uri LIMIT 1")
|
||||||
fun get(uri: String): HistoryEntry?
|
suspend fun get(uri: String): HistoryEntry?
|
||||||
|
|
||||||
@Query("SELECT * FROM HistoryEntry ORDER BY lastVisit DESC")
|
@Query("SELECT * FROM HistoryEntry ORDER BY lastVisit DESC")
|
||||||
fun getAll(): List<HistoryEntry>
|
suspend fun getAll(): List<HistoryEntry>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM HistoryEntry ORDER BY lastVisit DESC LIMIT 1")
|
||||||
|
suspend fun getLast(): HistoryEntry?
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
fun insert(vararg entries: HistoryEntry)
|
suspend fun insert(vararg entries: HistoryEntry)
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
fun update(vararg entries: HistoryEntry)
|
suspend fun update(vararg entries: HistoryEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun record(uri: String, title: String?) {
|
suspend fun record(uri: String, title: String?) {
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
val dao = Database.INSTANCE.historyEntryDao()
|
val dao = Database.INSTANCE.historyEntryDao()
|
||||||
val entry = dao.get(uri)
|
val entry = dao.get(uri)
|
||||||
|
@ -34,4 +37,6 @@ object History {
|
||||||
else
|
else
|
||||||
dao.update(entry.also { it.title = title; it.lastVisit = now })
|
dao.update(entry.also { it.title = title; it.lastVisit = now })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getLast(): HistoryEntry? = Database.INSTANCE.historyEntryDao().getLast()
|
||||||
}
|
}
|
|
@ -1,11 +1,29 @@
|
||||||
package dev.lowrespalmtree.comet
|
package dev.lowrespalmtree.comet
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.preference.EditTextPreference
|
||||||
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
import androidx.preference.SeekBarPreference
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat() {
|
class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||||
|
findPreference<Preference>("home_set")?.setOnPreferenceClickListener {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val lastEntry = History.getLast()
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
if (lastEntry != null)
|
||||||
|
findPreference<EditTextPreference>("home")?.text = lastEntry.uri
|
||||||
|
else
|
||||||
|
toast(requireContext(), R.string.no_current_url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
7
app/src/main/java/dev/lowrespalmtree/comet/UiUtils.kt
Normal file
7
app/src/main/java/dev/lowrespalmtree/comet/UiUtils.kt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package dev.lowrespalmtree.comet
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
|
fun toast(context: Context, stringId: Int, length: Int = Toast.LENGTH_SHORT) =
|
||||||
|
Toast.makeText(context, stringId, length).show()
|
|
@ -7,11 +7,9 @@
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/pageViewFragment"
|
android:id="@+id/pageViewFragment"
|
||||||
android:name="dev.lowrespalmtree.comet.PageViewFragment"
|
android:name="dev.lowrespalmtree.comet.PageViewFragment"
|
||||||
android:label="PageViewFragment" >
|
android:label="PageViewFragment" />
|
||||||
</fragment>
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/settingsFragment"
|
android:id="@+id/settingsFragment"
|
||||||
android:name="dev.lowrespalmtree.comet.SettingsFragment"
|
android:name="dev.lowrespalmtree.comet.SettingsFragment"
|
||||||
android:label="SettingsFragment">
|
android:label="SettingsFragment" />
|
||||||
</fragment>
|
|
||||||
</navigation>
|
</navigation>
|
|
@ -4,18 +4,29 @@
|
||||||
<string name="url">URL</string>
|
<string name="url">URL</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="history">History</string>
|
<string name="history">History</string>
|
||||||
<!-- Preference Titles -->
|
|
||||||
<string name="messages_header">Messages</string>
|
|
||||||
<string name="sync_header">Sync</string>
|
|
||||||
|
|
||||||
<!-- Messages Preferences -->
|
<!-- Preferences General -->
|
||||||
|
<string name="pref_general_header">General</string>
|
||||||
|
<string name="pref_home_title">Home page</string>
|
||||||
|
<string name="pref_home_set">Set last visited page as home page</string>
|
||||||
|
<string name="no_current_url">No current URL.</string>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Preference Protocol -->
|
||||||
|
<string name="pref_protocol_header">Protocol</string>
|
||||||
|
<string name="pref_connection_timeout_title">Connection timeout (seconds)</string>
|
||||||
|
<string name="pref_read_timeout_title">Read timeout (seconds)</string>
|
||||||
|
|
||||||
|
<!-- Newly added -->
|
||||||
|
|
||||||
<string name="signature_title">Your signature</string>
|
<string name="signature_title">Your signature</string>
|
||||||
<string name="reply_title">Default reply action</string>
|
<string name="reply_title">Default reply action</string>
|
||||||
|
|
||||||
<!-- Sync Preferences -->
|
|
||||||
<string name="sync_title">Sync email periodically</string>
|
<string name="sync_title">Sync email periodically</string>
|
||||||
<string name="attachment_title">Download incoming attachments</string>
|
<string name="attachment_title">Download incoming attachments</string>
|
||||||
<string name="attachment_summary_on">Automatically download attachments for incoming emails
|
<string name="attachment_summary_on">Automatically download attachments for incoming emails
|
||||||
</string>
|
</string>
|
||||||
<string name="attachment_summary_off">Only download attachments when manually requested</string>
|
<string name="attachment_summary_off">Only download attachments when manually requested</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -1,12 +1,17 @@
|
||||||
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/messages_header">
|
<PreferenceCategory app:title="@string/pref_general_header">
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
app:key="signature"
|
app:key="home"
|
||||||
app:title="@string/signature_title"
|
app:title="@string/pref_home_title"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
app:key="home_set"
|
||||||
|
app:title="@string/pref_home_set" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:defaultValue="reply"
|
app:defaultValue="reply"
|
||||||
app:entries="@array/reply_entries"
|
app:entries="@array/reply_entries"
|
||||||
|
@ -17,7 +22,23 @@
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/sync_header">
|
<PreferenceCategory app:title="@string/pref_protocol_header">
|
||||||
|
|
||||||
|
<SeekBarPreference
|
||||||
|
app:key="connection_timeout"
|
||||||
|
app:title="@string/pref_connection_timeout_title"
|
||||||
|
app:seekBarIncrement="1"
|
||||||
|
app:showSeekBarValue="true"
|
||||||
|
android:max="60"
|
||||||
|
android:defaultValue="10" />
|
||||||
|
|
||||||
|
<SeekBarPreference
|
||||||
|
app:key="read_timeout"
|
||||||
|
app:title="@string/pref_read_timeout_title"
|
||||||
|
app:seekBarIncrement="1"
|
||||||
|
app:showSeekBarValue="true"
|
||||||
|
android:max="60"
|
||||||
|
android:defaultValue="10" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
app:key="sync"
|
app:key="sync"
|
||||||
|
|
Reference in a new issue