Skip to content
Snippets Groups Projects
Verified Commit 761a9b1d authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Add support for migrating old Quasseldroid settings

parent cfe5a1d4
No related branches found
No related tags found
No related merge requests found
Pipeline #
Showing
with 187 additions and 32 deletions
...@@ -72,7 +72,7 @@ android { ...@@ -72,7 +72,7 @@ android {
minSdkVersion(16) minSdkVersion(16)
targetSdkVersion(27) targetSdkVersion(27)
applicationId = "de.kuschku.quasseldroid" applicationId = "com.iskrembilen.quasseldroid"
versionCode = cmd("git", "rev-list", "--count", "HEAD")?.toIntOrNull() ?: 1 versionCode = cmd("git", "rev-list", "--count", "HEAD")?.toIntOrNull() ?: 1
versionName = cmd("git", "describe", "--always", "--tags", "HEAD") ?: "1.0.0" versionName = cmd("git", "describe", "--always", "--tags", "HEAD") ?: "1.0.0"
......
...@@ -27,13 +27,18 @@ import dagger.android.AndroidInjector ...@@ -27,13 +27,18 @@ import dagger.android.AndroidInjector
import dagger.android.support.DaggerApplication import dagger.android.support.DaggerApplication
import de.kuschku.malheur.CrashHandler import de.kuschku.malheur.CrashHandler
import de.kuschku.quasseldroid.dagger.DaggerAppComponent import de.kuschku.quasseldroid.dagger.DaggerAppComponent
import de.kuschku.quasseldroid.persistence.AccountDatabase
import de.kuschku.quasseldroid.persistence.LegacyAccountDatabase
import de.kuschku.quasseldroid.settings.AppearanceSettings
import de.kuschku.quasseldroid.settings.SettingsMigration
import de.kuschku.quasseldroid.settings.SettingsMigrationManager
import de.kuschku.quasseldroid.util.backport.AndroidThreeTenBackport import de.kuschku.quasseldroid.util.backport.AndroidThreeTenBackport
import de.kuschku.quasseldroid.util.compatibility.AndroidCompatibilityUtils import de.kuschku.quasseldroid.util.compatibility.AndroidCompatibilityUtils
import de.kuschku.quasseldroid.util.compatibility.AndroidLoggingHandler import de.kuschku.quasseldroid.util.compatibility.AndroidLoggingHandler
import de.kuschku.quasseldroid.util.compatibility.AndroidStreamChannelFactory import de.kuschku.quasseldroid.util.compatibility.AndroidStreamChannelFactory
class Quasseldroid : DaggerApplication() { class Quasseldroid : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out Quasseldroid> = override fun applicationInjector(): AndroidInjector<Quasseldroid> =
DaggerAppComponent.builder().create(this) DaggerAppComponent.builder().create(this)
override fun onCreate() { override fun onCreate() {
...@@ -58,6 +63,94 @@ class Quasseldroid : DaggerApplication() { ...@@ -58,6 +63,94 @@ class Quasseldroid : DaggerApplication() {
AndroidThreeTenBackport.init(this) AndroidThreeTenBackport.init(this)
applicationInjector().inject(this)
// Migrate preferences
SettingsMigrationManager(listOf(
SettingsMigration.migrationOf(0, 1) { prefs, edit ->
// Migrating database
val database = LegacyAccountDatabase.Creator.init(this)
val accounts = database.accounts().all()
database.close()
val accountDatabase = AccountDatabase.Creator.init(this)
accountDatabase.accounts().create(*accounts.map {
AccountDatabase.Account(
id = it.id,
host = it.host,
port = it.port,
user = it.user,
pass = it.pass,
name = it.name,
lastUsed = 0
)
}.toTypedArray())
accountDatabase.close()
Thread(Runnable {
deleteDatabase("data")
}).start()
// Migrating actual settings
if (prefs.contains("selectedtheme")) {
prefs.getString("selectedtheme", "").let { theme ->
when (theme) {
"light" -> AppearanceSettings.Theme.MATERIAL_LIGHT
"dark" -> AppearanceSettings.Theme.MATERIAL_DARK
else -> null
}?.let {
edit.putString(getString(R.string.preference_theme_key), it.name)
}
}
edit.remove("selectedtheme")
}
if (prefs.contains("timestamp")) {
prefs.getString("timestamp", "").let { timestamp ->
edit.putBoolean(getString(R.string.preference_show_seconds_key),
timestamp.contains("ss"))
edit.putBoolean(getString(R.string.preference_show_seconds_key),
timestamp.contains("hh") || timestamp.contains("a"))
}
edit.remove("timestamp")
}
if (prefs.contains("fontsizeChannelList")) {
prefs.getString("fontsizeChannelList", "").toIntOrNull()?.let { fontSize ->
edit.putInt(getString(R.string.preference_textsize_key), fontSize)
}
edit.remove("fontsizeChannelList")
}
if (prefs.contains("allowcoloredtext")) {
prefs.getBoolean("allowcoloredtext", false).let {
edit.putBoolean(getString(R.string.preference_colorize_mirc_key), it)
}
edit.remove("allowcoloredtext")
}
if (prefs.contains("monospace")) {
prefs.getBoolean("monospace", false).let {
edit.putBoolean(getString(R.string.preference_monospace_key), it)
}
edit.remove("monospace")
}
if (prefs.contains("detailed_actions")) {
prefs.getBoolean("detailed_actions", false).let {
edit.putBoolean(getString(R.string.preference_hostmask_actions_key), it)
}
edit.remove("detailed_actions")
}
if (prefs.contains("showlag")) {
prefs.getBoolean("showlag", false).let {
edit.putBoolean(getString(R.string.preference_show_lag_key), it)
}
edit.remove("showlag")
}
}
)).migrate(PreferenceManager.getDefaultSharedPreferences(this))
// Initialize preferences unless already set // Initialize preferences unless already set
PreferenceManager.setDefaultValues(this, R.xml.preferences, false) PreferenceManager.setDefaultValues(this, R.xml.preferences, false)
......
...@@ -29,6 +29,7 @@ import android.content.Intent ...@@ -29,6 +29,7 @@ import android.content.Intent
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build import android.os.Build
import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationCompat
import android.support.v4.app.NotificationManagerCompat import android.support.v4.app.NotificationManagerCompat
...@@ -148,12 +149,8 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C ...@@ -148,12 +149,8 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C
.apply { .apply {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
var defaults = 0 var defaults = 0
if (notificationSettings.notificationSoundEnabled) { if (!notificationSettings.sound.isNullOrEmpty()) {
if (notificationSettings.notificationSound != null) { setSound(Uri.parse(notificationSettings.sound))
setSound(notificationSettings.notificationSound)
} else {
defaults = defaults or NotificationCompat.DEFAULT_SOUND
}
} }
if (notificationSettings.vibrate) { if (notificationSettings.vibrate) {
defaults = defaults or NotificationCompat.DEFAULT_VIBRATE defaults = defaults or NotificationCompat.DEFAULT_VIBRATE
......
...@@ -28,7 +28,6 @@ data class MessageSettings( ...@@ -28,7 +28,6 @@ data class MessageSettings(
val showSeconds: Boolean = false, val showSeconds: Boolean = false,
val use24hClock: Boolean = true, val use24hClock: Boolean = true,
val showHostmaskActions: Boolean = false, val showHostmaskActions: Boolean = false,
val showHostmaskPlain: Boolean = false,
val nicksOnNewLine: Boolean = false, val nicksOnNewLine: Boolean = false,
val timeAtEnd: Boolean = false, val timeAtEnd: Boolean = false,
val showRealNames: Boolean = false, val showRealNames: Boolean = false,
......
...@@ -19,14 +19,11 @@ ...@@ -19,14 +19,11 @@
package de.kuschku.quasseldroid.settings package de.kuschku.quasseldroid.settings
import android.net.Uri
data class NotificationSettings( data class NotificationSettings(
val query: Level = Level.ALL, val query: Level = Level.ALL,
val channel: Level = Level.HIGHLIGHT, val channel: Level = Level.HIGHLIGHT,
val other: Level = Level.NONE, val other: Level = Level.NONE,
val notificationSoundEnabled: Boolean = false, val sound: String? = null,
val notificationSound: Uri? = null,
val vibrate: Boolean = true val vibrate: Boolean = true
) { ) {
enum class Level { enum class Level {
......
...@@ -85,10 +85,6 @@ object Settings { ...@@ -85,10 +85,6 @@ object Settings {
context.getString(R.string.preference_hostmask_actions_key), context.getString(R.string.preference_hostmask_actions_key),
MessageSettings.DEFAULT.showHostmaskActions MessageSettings.DEFAULT.showHostmaskActions
), ),
showHostmaskPlain = getBoolean(
context.getString(R.string.preference_hostmask_plain_key),
MessageSettings.DEFAULT.showHostmaskPlain
),
nicksOnNewLine = getBoolean( nicksOnNewLine = getBoolean(
context.getString(R.string.preference_nicks_on_new_line_key), context.getString(R.string.preference_nicks_on_new_line_key),
MessageSettings.DEFAULT.nicksOnNewLine MessageSettings.DEFAULT.nicksOnNewLine
......
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2018 Janne Koschinski
* Copyright (c) 2018 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.settings
import android.content.SharedPreferences
interface SettingsMigration {
val from: Int
val to: Int
fun migrate(preferences: SharedPreferences, editor: SharedPreferences.Editor)
companion object {
fun migrationOf(from: Int, to: Int,
migrationFunction: (SharedPreferences, SharedPreferences.Editor) -> Unit): SettingsMigration {
return object : SettingsMigration {
override val from = from
override val to = to
override fun migrate(preferences: SharedPreferences, editor: SharedPreferences.Editor) =
migrationFunction(preferences, editor)
}
}
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2018 Janne Koschinski
* Copyright (c) 2018 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.quasseldroid.settings
import android.content.SharedPreferences
class SettingsMigrationManager(
migrations: List<SettingsMigration>
) {
private val migrationMap = migrations.associateBy(SettingsMigration::from)
private val currentVersion = migrations.map(SettingsMigration::to).max()
fun migrate(preferences: SharedPreferences) {
var version = preferences.getInt(SETTINGS_VERSION, 0)
while (version != currentVersion) {
val migration = migrationMap[version]
?: throw IllegalArgumentException("Migration not available")
val editor = preferences.edit()
migration.migrate(preferences, editor)
version = migration.to
editor.putInt(SETTINGS_VERSION, version)
editor.commit()
}
}
companion object {
private const val SETTINGS_VERSION = "settings_version"
}
}
...@@ -205,7 +205,7 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -205,7 +205,7 @@ class QuasselMessageRenderer @Inject constructor(
message.content.sender, message.content.sender,
self, self,
highlight, highlight,
messageSettings.showHostmaskPlain && messageSettings.nicksOnNewLine false
)) ))
} }
val content = contentFormatter.formatContent(message.content.content, highlight) val content = contentFormatter.formatContent(message.content.content, highlight)
......
...@@ -80,9 +80,6 @@ ...@@ -80,9 +80,6 @@
<string name="preference_hostmask_actions_title">Hostmaske in Aktionen</string> <string name="preference_hostmask_actions_title">Hostmaske in Aktionen</string>
<string name="preference_hostmask_actions_summary">Zeigt Ident und Host in Betreten/Verlassen-Nachrichten</string> <string name="preference_hostmask_actions_summary">Zeigt Ident und Host in Betreten/Verlassen-Nachrichten</string>
<string name="preference_hostmask_plain_title">Hostmaske in normalen Nachrichten</string>
<string name="preference_hostmask_plain_summary">Zeigt Ident und Host in normalen Nachrichten</string>
<string name="preference_nicks_on_new_line_title">Separate Spitznamen</string> <string name="preference_nicks_on_new_line_title">Separate Spitznamen</string>
<string name="preference_nicks_on_new_line_summary">Zeigt Spitznamen in einer eigenen Zeile an</string> <string name="preference_nicks_on_new_line_summary">Zeigt Spitznamen in einer eigenen Zeile an</string>
......
...@@ -159,10 +159,6 @@ ...@@ -159,10 +159,6 @@
<string name="preference_hostmask_actions_title">Show Hostmask in actions</string> <string name="preference_hostmask_actions_title">Show Hostmask in actions</string>
<string name="preference_hostmask_actions_summary">Display the full nick!ident@host in join/part/quit messages</string> <string name="preference_hostmask_actions_summary">Display the full nick!ident@host in join/part/quit messages</string>
<string name="preference_hostmask_plain_key" translatable="false">hostmask_plain</string>
<string name="preference_hostmask_plain_title">Show Hostmask in normal messages</string>
<string name="preference_hostmask_plain_summary">Display the full nick!ident@host in normal messages</string>
<string name="preference_nicks_on_new_line_key" translatable="false">nicks_on_new_line</string> <string name="preference_nicks_on_new_line_key" translatable="false">nicks_on_new_line</string>
<string name="preference_nicks_on_new_line_title">Separate Nicknames</string> <string name="preference_nicks_on_new_line_title">Separate Nicknames</string>
<string name="preference_nicks_on_new_line_summary">Shows nicknames on a separate line</string> <string name="preference_nicks_on_new_line_summary">Shows nicknames on a separate line</string>
......
...@@ -146,13 +146,6 @@ ...@@ -146,13 +146,6 @@
android:summary="@string/preference_hostmask_actions_summary" android:summary="@string/preference_hostmask_actions_summary"
android:title="@string/preference_hostmask_actions_title" /> android:title="@string/preference_hostmask_actions_title" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/preference_nicks_on_new_line_key"
android:key="@string/preference_hostmask_plain_key"
android:summary="@string/preference_hostmask_plain_summary"
android:title="@string/preference_hostmask_plain_title" />
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/preference_time_at_end_key" android:key="@string/preference_time_at_end_key"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment