-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): spotlight comments username
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 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
54 changes: 54 additions & 0 deletions
54
core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/SpotlightCommentsUsername.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package me.rhunk.snapenhance.core.features.impl.ui | ||
|
||
import android.annotation.SuppressLint | ||
import android.widget.TextView | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent | ||
import me.rhunk.snapenhance.core.features.Feature | ||
import me.rhunk.snapenhance.core.features.FeatureLoadParams | ||
import me.rhunk.snapenhance.core.features.impl.messaging.Messaging | ||
import me.rhunk.snapenhance.core.util.EvictingMap | ||
import me.rhunk.snapenhance.core.util.ktx.getId | ||
|
||
class SpotlightCommentsUsername : Feature("SpotlightCommentsUsername", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { | ||
private val usernameCache = EvictingMap<String, String>(150) | ||
|
||
@SuppressLint("SetTextI18n") | ||
override fun onActivityCreate() { | ||
if (!context.config.global.spotlightCommentsUsername.get()) return | ||
|
||
val messaging = context.feature(Messaging::class) | ||
val commentsCreatorBadgeTimestampId = context.resources.getId("comments_creator_badge_timestamp") | ||
|
||
context.event.subscribe(BindViewEvent::class) { event -> | ||
val commentsCreatorBadgeTimestamp = event.view.findViewById<TextView>(commentsCreatorBadgeTimestampId) ?: return@subscribe | ||
|
||
val posterUserId = event.prevModel.toString().takeIf { it.startsWith("Comment") } | ||
?.substringAfter("posterUserId=")?.substringBefore(",")?.substringBefore(")") ?: return@subscribe | ||
|
||
fun setUsername(username: String) { | ||
usernameCache[posterUserId] = username | ||
commentsCreatorBadgeTimestamp.text = " (${username})" + commentsCreatorBadgeTimestamp.text.toString() | ||
} | ||
|
||
usernameCache[posterUserId]?.let { | ||
setUsername(it) | ||
return@subscribe | ||
} | ||
|
||
context.coroutineScope.launch { | ||
val username = runCatching { | ||
messaging.fetchSnapchatterInfos(listOf(posterUserId)).firstOrNull() | ||
}.onFailure { | ||
context.log.error("Failed to fetch snapchatter info for user $posterUserId", it) | ||
}.getOrNull()?.username ?: return@launch | ||
|
||
withContext(Dispatchers.Main) { | ||
setUsername(username) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
core/src/main/kotlin/me/rhunk/snapenhance/core/wrapper/impl/Snapchatter.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.rhunk.snapenhance.core.wrapper.impl | ||
|
||
import me.rhunk.snapenhance.core.wrapper.AbstractWrapper | ||
|
||
|
||
|
||
class BitmojiInfo(obj: Any?) : AbstractWrapper(obj) { | ||
var avatarId by field<String?>("mAvatarId") | ||
var backgroundId by field<String?>("mBackgroundId") | ||
var sceneId by field<String?>("mSceneId") | ||
var selfieId by field<String?>("mSelfieId") | ||
} | ||
|
||
class Snapchatter(obj: Any?) : AbstractWrapper(obj) { | ||
val bitmojiInfo by field<BitmojiInfo?>("mBitmojiInfo") | ||
var displayName by field<String?>("mDisplayName") | ||
var userId by field("mUserId") { SnapUUID(it) } | ||
var username by field<String>("mUsername") | ||
} |