forked from NextAlone/Nagram
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'NextAlone:dev' into dev
- Loading branch information
Showing
4 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 74 additions & 4 deletions
78
TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/PeerColorHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,85 @@ | ||
package xyz.nextalone.nagram.helper | ||
|
||
import com.google.gson.Gson | ||
import org.telegram.tgnet.TLRPC | ||
import xyz.nextalone.nagram.NaConfig | ||
|
||
|
||
data class LocalQuoteColorData ( | ||
var colorId: Int?, | ||
var emojiId: Long?, | ||
var profileColorId: Int?, | ||
var profileEmojiId: Long? | ||
) | ||
|
||
|
||
object PeerColorHelper { | ||
var loaded: Boolean = false | ||
var data: LocalQuoteColorData? = null | ||
|
||
@JvmStatic | ||
fun getColorId(user: TLRPC.User): Int? { | ||
if (!NaConfig.useLocalQuoteColor.Bool()) return null | ||
init() | ||
if (user.self && data != null) { | ||
return data!!.colorId | ||
} | ||
return null | ||
} | ||
|
||
@JvmStatic | ||
fun getEmojiId(user: TLRPC.User?): Long? { | ||
if (!NaConfig.useLocalQuoteColor.Bool()) return null | ||
init() | ||
if (user != null && user.self && data != null) { | ||
return data!!.emojiId | ||
} | ||
return null | ||
} | ||
|
||
@JvmStatic | ||
fun getProfileColorId(user: TLRPC.User): Int? { | ||
if (!NaConfig.useLocalQuoteColor.Bool()) return null | ||
init() | ||
if (user.self && data != null) { | ||
return data!!.profileColorId | ||
} | ||
return null | ||
} | ||
|
||
@JvmStatic | ||
fun getProfileEmojiId(user: TLRPC.User?): Long? { | ||
if (!NaConfig.useLocalQuoteColor.Bool()) return null | ||
init() | ||
if (user != null && user.self && data != null) { | ||
return data!!.profileEmojiId | ||
} | ||
return null | ||
} | ||
|
||
@JvmStatic | ||
fun init(force: Boolean = false) { | ||
if (loaded && !force) return | ||
loaded = true | ||
try { | ||
val gson = Gson() | ||
data = gson.fromJson(NaConfig.useLocalQuoteColorData.String(), LocalQuoteColorData::class.java) | ||
} catch (_: Exception) {} | ||
} | ||
|
||
@JvmStatic | ||
fun replaceColor(old: Int?): Int? { | ||
if (NaConfig.useLocalQuoteColor.Bool()) { | ||
return NaConfig.useLocalQuoteColorColor.Int() | ||
fun apply(colorId: Int, emojiId: Long, profileColorId: Int, profileEmojiId: Long) { | ||
if (!NaConfig.useLocalQuoteColor.Bool()) return | ||
var localData = data | ||
if (localData == null) { | ||
localData = LocalQuoteColorData(colorId, emojiId, profileColorId, profileEmojiId) | ||
} else { | ||
localData.colorId = colorId | ||
localData.emojiId = emojiId | ||
localData.profileColorId = profileColorId | ||
localData.profileEmojiId = profileEmojiId | ||
} | ||
return old | ||
NaConfig.useLocalQuoteColorData.setConfigString(Gson().toJson(localData)) | ||
init(true) | ||
} | ||
} |