Custom emojis in drawer (#737)
* upgrade MaterialDrawer * improve CustomEmojiHelper so now any parent view can be used for invalidation * cleanup MainActivity a bit * add emojiList to account database and show compatEmojis and custom emojis in drawer * improve perf of drawer profile update * fix account switching * reuse gson, break after profile item was found
This commit is contained in:
parent
b5a8915845
commit
9b422a97fe
9 changed files with 99 additions and 64 deletions
|
|
@ -18,9 +18,13 @@ package com.keylesspalace.tusky.db
|
|||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.Index
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
import android.arch.persistence.room.TypeConverters
|
||||
|
||||
import com.keylesspalace.tusky.entity.Emoji
|
||||
|
||||
@Entity(indices = [Index(value = ["domain", "accountId"],
|
||||
unique = true)])
|
||||
@TypeConverters(Converters::class)
|
||||
data class AccountEntity(@field:PrimaryKey(autoGenerate = true) var id: Long,
|
||||
val domain: String,
|
||||
var accessToken: String,
|
||||
|
|
@ -38,7 +42,8 @@ data class AccountEntity(@field:PrimaryKey(autoGenerate = true) var id: Long,
|
|||
var notificationVibration: Boolean = true,
|
||||
var notificationLight: Boolean = true,
|
||||
var lastNotificationId: String = "0",
|
||||
var activeNotifications: String = "[]") {
|
||||
var activeNotifications: String = "[]",
|
||||
var emojis: List<Emoji> = emptyList()) {
|
||||
|
||||
val identifier: String
|
||||
get() = "$domain:$accountId"
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ class AccountManager(db: AppDatabase) {
|
|||
it.username = account.username
|
||||
it.displayName = account.name
|
||||
it.profilePictureUrl = account.avatar
|
||||
it.emojis = account.emojis ?: emptyList()
|
||||
|
||||
Log.d(TAG, "updateActiveAccount: saving account with id " + it.id)
|
||||
it.id = accountDao.insertOrReplace(it)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import android.support.annotation.NonNull;
|
|||
* DB version & declare DAO
|
||||
*/
|
||||
|
||||
@Database(entities = {TootEntity.class, AccountEntity.class, InstanceEntity.class}, version = 7, exportSchema = false)
|
||||
@Database(entities = {TootEntity.class, AccountEntity.class, InstanceEntity.class}, version = 8, exportSchema = false)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
|
||||
public abstract TootDao tootDao();
|
||||
|
|
@ -87,8 +87,15 @@ public abstract class AppDatabase extends RoomDatabase {
|
|||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS `InstanceEntity` (`instance` TEXT NOT NULL, `emojiList` TEXT, `maximumTootCharacters` INTEGER, PRIMARY KEY(`instance`))");
|
||||
database.execSQL("INSERT OR REPLACE INTO `InstanceEntity` SELECT `instance`,`emojiList`,NULL FROM `EmojiListEntity`;");
|
||||
database.execSQL("INSERT OR REPLACE INTO `InstanceEntity` SELECT `instance`,`emojiList`, NULL FROM `EmojiListEntity`;");
|
||||
database.execSQL("DROP TABLE `EmojiListEntity`;");
|
||||
}
|
||||
};
|
||||
|
||||
public static final Migration MIGRATION_7_8 = new Migration(7, 8) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE `AccountEntity` ADD COLUMN `emojis` TEXT NOT NULL DEFAULT '[]'");
|
||||
}
|
||||
};
|
||||
}
|
||||
36
app/src/main/java/com/keylesspalace/tusky/db/Converters.kt
Normal file
36
app/src/main/java/com/keylesspalace/tusky/db/Converters.kt
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* Copyright 2018 Conny Duck
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky 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 Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.db
|
||||
|
||||
import android.arch.persistence.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.keylesspalace.tusky.entity.Emoji
|
||||
|
||||
class Converters {
|
||||
|
||||
private val gson = Gson()
|
||||
|
||||
@TypeConverter
|
||||
fun jsonToEmojiList(emojiListJson: String?): List<Emoji>? {
|
||||
return gson.fromJson(emojiListJson, object : TypeToken<List<Emoji>>() {}.type)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun emojiListToJson(emojiList: List<Emoji>?): String {
|
||||
return gson.toJson(emojiList)
|
||||
}
|
||||
}
|
||||
|
|
@ -17,10 +17,7 @@ package com.keylesspalace.tusky.db
|
|||
|
||||
import android.arch.persistence.room.Entity
|
||||
import android.arch.persistence.room.PrimaryKey
|
||||
import android.arch.persistence.room.TypeConverter
|
||||
import android.arch.persistence.room.TypeConverters
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.keylesspalace.tusky.entity.Emoji
|
||||
|
||||
@Entity
|
||||
|
|
@ -29,17 +26,3 @@ data class InstanceEntity(
|
|||
@field:PrimaryKey var instance: String,
|
||||
val emojiList: List<Emoji>?,
|
||||
val maximumTootCharacters: Int?)
|
||||
|
||||
|
||||
class Converters {
|
||||
|
||||
@TypeConverter
|
||||
fun jsonToList(emojiListJson: String?): List<Emoji>? {
|
||||
return Gson().fromJson(emojiListJson, object : TypeToken<List<Emoji>>() {}.type)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun listToJson(emojiList: List<Emoji>?): String {
|
||||
return Gson().toJson(emojiList)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue