Skip to content

Commit

Permalink
Add a switch for enabling and disabling BBCode emoticons
Browse files Browse the repository at this point in the history
This improves the performance for views not needing them
  • Loading branch information
rubengees committed Apr 27, 2018
1 parent 3915ada commit 636b540
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/me/proxer/app/forum/PostAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ class PostAdapter : BaseAdapter<ParsedPost, ViewHolder>() {
}

post.glide = glide
post.enableEmotions = true
post.heightChangedListener = {
post.requestLayout()
layoutManager?.requestSimpleAnimationsInNextLayout()
}

signature.glide = glide
post.enableEmotions = true
signature.heightChangedListener = {
signature.requestLayout()
layoutManager?.requestSimpleAnimationsInNextLayout()
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/me/proxer/app/ui/view/bbcode/BBCodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BBCodeView @JvmOverloads constructor(
var heightChangedListener: (() -> Unit)? = null
var glide: GlideRequests? = null
var userId: String? = null
var enableEmotions = false

init {
orientation = VERTICAL
Expand Down Expand Up @@ -60,7 +61,9 @@ class BBCodeView @JvmOverloads constructor(

tree.glide = glide
tree.userId = userId
tree.enableEmoticons = enableEmotions
tree.makeViews(context).forEach { this.addView(it) }
tree.enableEmoticons = false
tree.userId = null
tree.glide = null
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/kotlin/me/proxer/app/ui/view/bbcode/BBTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BBTree(
companion object {
internal const val GLIDE_ARGUMENT = "glide"
internal const val USER_ID_ARGUMENT = "userId"
internal const val ENABLE_EMOTICONS_ARGUMENT = "enable_emoticons"
}

var glide: GlideRequests? = null
Expand All @@ -42,9 +43,15 @@ class BBTree(
}
}

var enableEmoticons: Boolean = false

fun endsWith(code: String) = prototype.endRegex.matches(code)
fun makeViews(context: Context) = prototype.makeViews(context, children,
args.plus(arrayOf(GLIDE_ARGUMENT to glide, USER_ID_ARGUMENT to userId)))

fun makeViews(context: Context) = prototype.makeViews(context, children, args.plus(arrayOf(
GLIDE_ARGUMENT to glide,
USER_ID_ARGUMENT to userId,
ENABLE_EMOTICONS_ARGUMENT to enableEmoticons
)))

fun optimize() = recursiveOptimize().first()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import me.proxer.app.GlideRequests
import me.proxer.app.ui.view.GifAwareTextView
import me.proxer.app.ui.view.bbcode.BBCodeEmoticons
import me.proxer.app.ui.view.bbcode.BBTree
import me.proxer.app.ui.view.bbcode.BBTree.Companion.ENABLE_EMOTICONS_ARGUMENT
import me.proxer.app.ui.view.bbcode.BBTree.Companion.GLIDE_ARGUMENT
import me.proxer.app.ui.view.bbcode.applyToViews

Expand All @@ -19,13 +20,20 @@ object RootPrototype : BBPrototype {

override fun makeViews(context: Context, children: List<BBTree>, args: Map<String, Any?>): List<View> {
val views = super.makeViews(context, children, args)
val glide = args[GLIDE_ARGUMENT] as GlideRequests?
val enableEmotions = args[ENABLE_EMOTICONS_ARGUMENT] as Boolean?

return when (glide) {
null -> views
else -> applyToViews(views, { view: GifAwareTextView ->
BBCodeEmoticons.replaceWithGifs(view, glide)
})
return when (enableEmotions) {
true -> {
val glide = args[GLIDE_ARGUMENT] as GlideRequests?

when (glide) {
null -> views
else -> applyToViews(views, { view: GifAwareTextView ->
BBCodeEmoticons.replaceWithGifs(view, glide)
})
}
}
else -> views
}
}
}

0 comments on commit 636b540

Please sign in to comment.