Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/twidere/text/util/EmojiSpannableFactory.kt

48 lines
1.6 KiB
Kotlin
Raw Normal View History

2015-12-20 12:54:05 +01:00
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
2016-08-28 06:24:48 +02:00
package org.mariotaku.twidere.text.util
2015-12-20 12:54:05 +01:00
2016-08-28 06:24:48 +02:00
import android.text.Spannable
import android.widget.TextView
2017-05-13 08:19:23 +02:00
import org.mariotaku.twidere.extension.applyTo
2017-02-13 17:44:56 +01:00
import org.mariotaku.twidere.text.SafeSpannableString
2016-08-28 06:24:48 +02:00
import org.mariotaku.twidere.util.ExternalThemeManager
2017-04-16 15:09:56 +02:00
import org.mariotaku.twidere.util.dagger.GeneralComponent
2016-08-28 06:24:48 +02:00
import javax.inject.Inject
2015-12-20 12:54:05 +01:00
/**
* Created by mariotaku on 15/12/20.
*/
2017-02-13 17:44:56 +01:00
class EmojiSpannableFactory(textView: TextView) : Spannable.Factory() {
2015-12-20 12:54:05 +01:00
@Inject
2019-10-24 17:52:11 +02:00
internal lateinit var externalThemeManager: ExternalThemeManager
2015-12-20 12:54:05 +01:00
2016-08-28 06:24:48 +02:00
init {
2017-04-16 15:09:56 +02:00
GeneralComponent.get(textView.context).inject(this)
2015-12-20 12:54:05 +01:00
}
2016-08-28 06:24:48 +02:00
override fun newSpannable(source: CharSequence): Spannable {
2017-02-13 17:44:56 +01:00
val spannable = SafeSpannableString(source)
2017-05-13 08:19:23 +02:00
externalThemeManager.emoji?.applyTo(spannable)
2016-08-28 06:24:48 +02:00
return spannable
2015-12-20 12:54:05 +01:00
}
}