Commit 260f76fe authored by Leonardo Aramaki's avatar Leonardo Aramaki

Minor package and visibility refactors

parent 7d31fefb
...@@ -5,10 +5,8 @@ import android.text.Spanned ...@@ -5,10 +5,8 @@ import android.text.Spanned
import android.text.TextUtils import android.text.TextUtils
import android.util.Base64 import android.util.Base64
import android.util.Patterns import android.util.Patterns
import android.widget.EditText
import android.widget.TextView import android.widget.TextView
import chat.rocket.android.emoji.EmojiParser import chat.rocket.android.emoji.EmojiParser
import chat.rocket.android.emoji.EmojiTypefaceSpan
import org.json.JSONObject import org.json.JSONObject
import ru.noties.markwon.Markwon import ru.noties.markwon.Markwon
import java.net.URLDecoder import java.net.URLDecoder
...@@ -21,21 +19,6 @@ fun String.ifEmpty(value: String): String { ...@@ -21,21 +19,6 @@ fun String.ifEmpty(value: String): String {
return this return this
} }
fun CharSequence.ifEmpty(value: String): CharSequence {
if (isEmpty()) {
return value
}
return this
}
fun EditText.erase() {
this.text.clear()
val spans = this.text.getSpans(0, text.length, EmojiTypefaceSpan::class.java)
spans.forEach {
text.removeSpan(it)
}
}
fun String.isEmail(): Boolean = Patterns.EMAIL_ADDRESS.matcher(this).matches() fun String.isEmail(): Boolean = Patterns.EMAIL_ADDRESS.matcher(this).matches()
fun String.encodeToBase64(): String { fun String.encodeToBase64(): String {
...@@ -94,9 +77,3 @@ var TextView.content: CharSequence? ...@@ -94,9 +77,3 @@ var TextView.content: CharSequence?
Markwon.scheduleDrawables(this) Markwon.scheduleDrawables(this)
Markwon.scheduleTableRows(this) Markwon.scheduleTableRows(this)
} }
var TextView.spanned: CharSequence?
get() = text
set(value) {
text = spanned
}
\ No newline at end of file
...@@ -16,13 +16,12 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -16,13 +16,12 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import chat.rocket.android.emoji.internal.EmojiCategory
import chat.rocket.android.emoji.internal.EmojiPagerAdapter
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
class EmojiKeyboardPopup( class EmojiKeyboardPopup(context: Context, view: View) : OverKeyboardPopupWindow(context, view) {
context: Context,
view: View
) : OverKeyboardPopupWindow(context, view) {
private lateinit var viewPager: ViewPager private lateinit var viewPager: ViewPager
private lateinit var tabLayout: TabLayout private lateinit var tabLayout: TabLayout
......
...@@ -7,6 +7,8 @@ import android.view.LayoutInflater ...@@ -7,6 +7,8 @@ import android.view.LayoutInflater
import android.view.Window import android.view.Window
import android.view.WindowManager import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import chat.rocket.android.emoji.internal.EmojiCategory
import chat.rocket.android.emoji.internal.EmojiPagerAdapter
import kotlinx.android.synthetic.main.emoji_picker.* import kotlinx.android.synthetic.main.emoji_picker.*
......
...@@ -3,6 +3,7 @@ package chat.rocket.android.emoji ...@@ -3,6 +3,7 @@ package chat.rocket.android.emoji
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Typeface import android.graphics.Typeface
import chat.rocket.android.emoji.internal.EmojiCategory
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import java.io.BufferedReader import java.io.BufferedReader
...@@ -12,6 +13,7 @@ import java.util.* ...@@ -12,6 +13,7 @@ import java.util.*
import java.util.regex.Pattern import java.util.regex.Pattern
object EmojiRepository { object EmojiRepository {
private val FITZPATRICK_REGEX = "(.*)_(tone[0-9]):".toRegex(RegexOption.IGNORE_CASE) private val FITZPATRICK_REGEX = "(.*)_(tone[0-9]):".toRegex(RegexOption.IGNORE_CASE)
private val shortNameToUnicode = HashMap<String, String>() private val shortNameToUnicode = HashMap<String, String>()
private val SHORTNAME_PATTERN = Pattern.compile(":([-+\\w]+):") private val SHORTNAME_PATTERN = Pattern.compile(":([-+\\w]+):")
...@@ -83,7 +85,7 @@ object EmojiRepository { ...@@ -83,7 +85,7 @@ object EmojiRepository {
* *
* @return All emojis for all categories. * @return All emojis for all categories.
*/ */
fun getAll() = ALL_EMOJIS internal fun getAll() = ALL_EMOJIS
/** /**
* Get all emojis for a given category. * Get all emojis for a given category.
...@@ -92,7 +94,7 @@ object EmojiRepository { ...@@ -92,7 +94,7 @@ object EmojiRepository {
* *
* @return All emoji from specified category * @return All emoji from specified category
*/ */
fun getEmojisByCategory(category: EmojiCategory): List<Emoji> { internal fun getEmojisByCategory(category: EmojiCategory): List<Emoji> {
return ALL_EMOJIS.filter { it.category.toLowerCase() == category.name.toLowerCase() } return ALL_EMOJIS.filter { it.category.toLowerCase() == category.name.toLowerCase() }
} }
...@@ -103,12 +105,12 @@ object EmojiRepository { ...@@ -103,12 +105,12 @@ object EmojiRepository {
* *
* @return Emoji given by shortname or null * @return Emoji given by shortname or null
*/ */
fun getEmojiByShortname(shortname: String) = ALL_EMOJIS.firstOrNull { it.shortname == shortname } internal fun getEmojiByShortname(shortname: String) = ALL_EMOJIS.firstOrNull { it.shortname == shortname }
/** /**
* Add an emoji to the Recents category. * Add an emoji to the Recents category.
*/ */
fun addToRecents(emoji: Emoji) { internal fun addToRecents(emoji: Emoji) {
val emojiShortname = emoji.shortname val emojiShortname = emoji.shortname
val recentsJson = JSONObject(preferences.getString(EmojiKeyboardPopup.PREF_EMOJI_RECENTS, "{}")) val recentsJson = JSONObject(preferences.getString(EmojiKeyboardPopup.PREF_EMOJI_RECENTS, "{}"))
if (recentsJson.has(emojiShortname)) { if (recentsJson.has(emojiShortname)) {
...@@ -125,7 +127,7 @@ object EmojiRepository { ...@@ -125,7 +127,7 @@ object EmojiRepository {
* *
* @return All recent emojis ordered by usage. * @return All recent emojis ordered by usage.
*/ */
fun getRecents(): List<Emoji> { internal fun getRecents(): List<Emoji> {
val list = mutableListOf<Emoji>() val list = mutableListOf<Emoji>()
val recentsJson = JSONObject(preferences.getString(EmojiKeyboardPopup.PREF_EMOJI_RECENTS, "{}")) val recentsJson = JSONObject(preferences.getString(EmojiKeyboardPopup.PREF_EMOJI_RECENTS, "{}"))
for (shortname in recentsJson.keys()) { for (shortname in recentsJson.keys()) {
......
package chat.rocket.android.emoji package chat.rocket.android.emoji
/** /**
* Taken the Fitzpatrick scale as reference adapted to be used with emojione. * Taken the Fitzpatrick scale as reference and adapted to be used with emojione.
* *
* @see <a href="https://en.wikipedia.org/wiki/Fitzpatrick_scale">https://en.wikipedia.org/wiki/Fitzpatrick_scale</a> * @see <a href="https://en.wikipedia.org/wiki/Fitzpatrick_scale">https://en.wikipedia.org/wiki/Fitzpatrick_scale</a>
*/ */
......
package chat.rocket.android.emoji package chat.rocket.android.emoji.internal
import android.text.SpannableString import android.text.SpannableString
import android.text.Spanned import android.text.Spanned
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.emoji.EmojiTypefaceSpan
import chat.rocket.android.emoji.R
enum class EmojiCategory { internal enum class EmojiCategory {
RECENTS { RECENTS {
override fun resourceIcon() = R.drawable.ic_emoji_recents override fun resourceIcon() = R.drawable.ic_emoji_recents
......
package chat.rocket.android.emoji package chat.rocket.android.emoji.internal
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
...@@ -9,6 +9,12 @@ import androidx.recyclerview.widget.DefaultItemAnimator ...@@ -9,6 +9,12 @@ import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.PagerAdapter
import chat.rocket.android.emoji.Emoji
import chat.rocket.android.emoji.EmojiKeyboardListener
import chat.rocket.android.emoji.EmojiParser
import chat.rocket.android.emoji.EmojiRepository
import chat.rocket.android.emoji.Fitzpatrick
import chat.rocket.android.emoji.R
import kotlinx.android.synthetic.main.emoji_category_layout.view.* import kotlinx.android.synthetic.main.emoji_category_layout.view.*
import java.util.* import java.util.*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment