fix kotlin
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
[*.{kt,kts}]
|
||||||
|
indent_size=2
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import com.google.firebase.messaging.RemoteMessage
|
|||||||
|
|
||||||
class BackgroundNotificationHandler(
|
class BackgroundNotificationHandler(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val notifInterface: BackgroundNotificationHandlerInterface
|
private val notifInterface: BackgroundNotificationHandlerInterface,
|
||||||
) {
|
) {
|
||||||
fun handleMessage(remoteMessage: RemoteMessage) {
|
fun handleMessage(remoteMessage: RemoteMessage) {
|
||||||
if (ExpoBackgroundNotificationHandlerModule.isForegrounded) {
|
if (ExpoBackgroundNotificationHandlerModule.isForegrounded) {
|
||||||
|
|||||||
+48
-47
@@ -8,67 +8,68 @@ class ExpoBackgroundNotificationHandlerModule : Module() {
|
|||||||
var isForegrounded = false
|
var isForegrounded = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() =
|
||||||
Name("ExpoBackgroundNotificationHandler")
|
ModuleDefinition {
|
||||||
|
Name("ExpoBackgroundNotificationHandler")
|
||||||
|
|
||||||
OnCreate {
|
OnCreate {
|
||||||
NotificationPrefs(appContext.reactContext).initialize()
|
NotificationPrefs(appContext.reactContext).initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
OnActivityEntersForeground {
|
OnActivityEntersForeground {
|
||||||
isForegrounded = true
|
isForegrounded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
OnActivityEntersBackground {
|
OnActivityEntersBackground {
|
||||||
isForegrounded = false
|
isForegrounded = false
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("getAllPrefsAsync") {
|
AsyncFunction("getAllPrefsAsync") {
|
||||||
return@AsyncFunction NotificationPrefs(appContext.reactContext).getAllPrefs()
|
return@AsyncFunction NotificationPrefs(appContext.reactContext).getAllPrefs()
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("getBoolAsync") { forKey: String ->
|
AsyncFunction("getBoolAsync") { forKey: String ->
|
||||||
return@AsyncFunction NotificationPrefs(appContext.reactContext).getBoolean(forKey)
|
return@AsyncFunction NotificationPrefs(appContext.reactContext).getBoolean(forKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("getStringAsync") { forKey: String ->
|
AsyncFunction("getStringAsync") { forKey: String ->
|
||||||
return@AsyncFunction NotificationPrefs(appContext.reactContext).getString(forKey)
|
return@AsyncFunction NotificationPrefs(appContext.reactContext).getString(forKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("getStringArrayAsync") { forKey: String ->
|
AsyncFunction("getStringArrayAsync") { forKey: String ->
|
||||||
return@AsyncFunction NotificationPrefs(appContext.reactContext).getStringArray(forKey)
|
return@AsyncFunction NotificationPrefs(appContext.reactContext).getStringArray(forKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("setBoolAsync") { forKey: String, value: Boolean ->
|
AsyncFunction("setBoolAsync") { forKey: String, value: Boolean ->
|
||||||
NotificationPrefs(appContext.reactContext).setBoolean(forKey, value)
|
NotificationPrefs(appContext.reactContext).setBoolean(forKey, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("setStringAsync") { forKey: String, value: String ->
|
AsyncFunction("setStringAsync") { forKey: String, value: String ->
|
||||||
NotificationPrefs(appContext.reactContext).setString(forKey, value)
|
NotificationPrefs(appContext.reactContext).setString(forKey, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("setStringArrayAsync") { forKey: String, value: Array<String> ->
|
AsyncFunction("setStringArrayAsync") { forKey: String, value: Array<String> ->
|
||||||
NotificationPrefs(appContext.reactContext).setStringArray(forKey, value)
|
NotificationPrefs(appContext.reactContext).setStringArray(forKey, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("addToStringArrayAsync") { forKey: String, string: String ->
|
AsyncFunction("addToStringArrayAsync") { forKey: String, string: String ->
|
||||||
NotificationPrefs(appContext.reactContext).addToStringArray(forKey, string)
|
NotificationPrefs(appContext.reactContext).addToStringArray(forKey, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("removeFromStringArrayAsync") { forKey: String, string: String ->
|
AsyncFunction("removeFromStringArrayAsync") { forKey: String, string: String ->
|
||||||
NotificationPrefs(appContext.reactContext).removeFromStringArray(forKey, string)
|
NotificationPrefs(appContext.reactContext).removeFromStringArray(forKey, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("addManyToStringArrayAsync") { forKey: String, strings: Array<String> ->
|
AsyncFunction("addManyToStringArrayAsync") { forKey: String, strings: Array<String> ->
|
||||||
NotificationPrefs(appContext.reactContext).addManyToStringArray(forKey, strings)
|
NotificationPrefs(appContext.reactContext).addManyToStringArray(forKey, strings)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("removeManyFromStringArrayAsync") { forKey: String, strings: Array<String> ->
|
AsyncFunction("removeManyFromStringArrayAsync") { forKey: String, strings: Array<String> ->
|
||||||
NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings)
|
NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings)
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncFunction("setBadgeCountAsync") { _: Int ->
|
AsyncFunction("setBadgeCountAsync") { _: Int ->
|
||||||
// This does nothing on Android
|
// This does nothing on Android
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-49
@@ -2,20 +2,24 @@ package expo.modules.backgroundnotificationhandler
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
|
||||||
val DEFAULTS = mapOf<String, Any>(
|
val DEFAULTS =
|
||||||
"playSoundChat" to true,
|
mapOf<String, Any>(
|
||||||
"playSoundFollow" to false,
|
"playSoundChat" to true,
|
||||||
"playSoundLike" to false,
|
"playSoundFollow" to false,
|
||||||
"playSoundMention" to false,
|
"playSoundLike" to false,
|
||||||
"playSoundQuote" to false,
|
"playSoundMention" to false,
|
||||||
"playSoundReply" to false,
|
"playSoundQuote" to false,
|
||||||
"playSoundRepost" to false,
|
"playSoundReply" to false,
|
||||||
"mutedThreads" to mapOf<String, List<String>>()
|
"playSoundRepost" to false,
|
||||||
)
|
"mutedThreads" to mapOf<String, List<String>>(),
|
||||||
|
)
|
||||||
|
|
||||||
class NotificationPrefs (private val context: Context?) {
|
class NotificationPrefs(
|
||||||
private val prefs = context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE)
|
private val context: Context?,
|
||||||
?: throw Error("Context is null")
|
) {
|
||||||
|
private val prefs =
|
||||||
|
context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE)
|
||||||
|
?: throw Error("Context is null")
|
||||||
|
|
||||||
fun initialize() {
|
fun initialize() {
|
||||||
prefs
|
prefs
|
||||||
@@ -41,94 +45,99 @@ class NotificationPrefs (private val context: Context?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllPrefs(): MutableMap<String, *> {
|
fun getAllPrefs(): MutableMap<String, *> = prefs.all
|
||||||
return prefs.all
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getBoolean(key: String): Boolean {
|
fun getBoolean(key: String): Boolean = prefs.getBoolean(key, false)
|
||||||
return prefs.getBoolean(key, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getString(key: String): String? {
|
fun getString(key: String): String? = prefs.getString(key, null)
|
||||||
return prefs.getString(key, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getStringArray(key: String): Array<String>? {
|
fun getStringArray(key: String): Array<String>? = prefs.getStringSet(key, null)?.toTypedArray()
|
||||||
return prefs.getStringSet(key, null)?.toTypedArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setBoolean(key: String, value: Boolean) {
|
fun setBoolean(
|
||||||
|
key: String,
|
||||||
|
value: Boolean,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
putBoolean(key, value)
|
putBoolean(key, value)
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setString(key: String, value: String) {
|
fun setString(
|
||||||
|
key: String,
|
||||||
|
value: String,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
putString(key, value)
|
putString(key, value)
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setStringArray(key: String, value: Array<String>) {
|
fun setStringArray(
|
||||||
|
key: String,
|
||||||
|
value: Array<String>,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
putStringSet(key, value.toSet())
|
putStringSet(key, value.toSet())
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addToStringArray(key: String, string: String) {
|
fun addToStringArray(
|
||||||
|
key: String,
|
||||||
|
string: String,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
||||||
set.add(string)
|
set.add(string)
|
||||||
putStringSet(key, set)
|
putStringSet(key, set)
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeFromStringArray(key: String, string: String) {
|
fun removeFromStringArray(
|
||||||
|
key: String,
|
||||||
|
string: String,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
||||||
set.remove(string)
|
set.remove(string)
|
||||||
putStringSet(key, set)
|
putStringSet(key, set)
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addManyToStringArray(key: String, strings: Array<String>) {
|
fun addManyToStringArray(
|
||||||
|
key: String,
|
||||||
|
strings: Array<String>,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
||||||
set.addAll(strings.toSet())
|
set.addAll(strings.toSet())
|
||||||
putStringSet(key, set)
|
putStringSet(key, set)
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeManyFromStringArray(key: String, strings: Array<String>) {
|
fun removeManyFromStringArray(
|
||||||
|
key: String,
|
||||||
|
strings: Array<String>,
|
||||||
|
) {
|
||||||
prefs
|
prefs
|
||||||
.edit()
|
.edit()
|
||||||
.apply {
|
.apply {
|
||||||
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
|
||||||
set.removeAll(strings.toSet())
|
set.removeAll(strings.toSet())
|
||||||
putStringSet(key, set)
|
putStringSet(key, set)
|
||||||
}
|
}.apply()
|
||||||
.apply()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -5,7 +5,10 @@ import android.graphics.Canvas
|
|||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
import androidx.appcompat.widget.AppCompatImageView
|
import androidx.appcompat.widget.AppCompatImageView
|
||||||
|
|
||||||
class AppCompatImageViewExtended(context: Context, private val parent: GifView): AppCompatImageView(context) {
|
class AppCompatImageViewExtended(
|
||||||
|
context: Context,
|
||||||
|
private val parent: GifView,
|
||||||
|
) : AppCompatImageView(context) {
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
|
|
||||||
@@ -34,4 +37,4 @@ class AppCompatImageViewExtended(context: Context, private val parent: GifView):
|
|||||||
drawable.start()
|
drawable.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-41
@@ -6,49 +6,50 @@ import expo.modules.kotlin.modules.Module
|
|||||||
import expo.modules.kotlin.modules.ModuleDefinition
|
import expo.modules.kotlin.modules.ModuleDefinition
|
||||||
|
|
||||||
class ExpoBlueskyGifViewModule : Module() {
|
class ExpoBlueskyGifViewModule : Module() {
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() =
|
||||||
Name("ExpoBlueskyGifView")
|
ModuleDefinition {
|
||||||
|
Name("ExpoBlueskyGifView")
|
||||||
|
|
||||||
AsyncFunction("prefetchAsync") { sources: List<String> ->
|
AsyncFunction("prefetchAsync") { sources: List<String> ->
|
||||||
val activity = appContext.currentActivity ?: return@AsyncFunction
|
val activity = appContext.currentActivity ?: return@AsyncFunction
|
||||||
val glide = Glide.with(activity)
|
val glide = Glide.with(activity)
|
||||||
|
|
||||||
sources.forEach { source ->
|
sources.forEach { source ->
|
||||||
glide
|
glide
|
||||||
.download(source)
|
.download(source)
|
||||||
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
||||||
.submit()
|
.submit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
View(GifView::class) {
|
||||||
|
Events(
|
||||||
|
"onPlayerStateChange",
|
||||||
|
)
|
||||||
|
|
||||||
|
Prop("source") { view: GifView, source: String ->
|
||||||
|
view.source = source
|
||||||
|
}
|
||||||
|
|
||||||
|
Prop("placeholderSource") { view: GifView, source: String ->
|
||||||
|
view.placeholderSource = source
|
||||||
|
}
|
||||||
|
|
||||||
|
Prop("autoplay") { view: GifView, autoplay: Boolean ->
|
||||||
|
view.autoplay = autoplay
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFunction("playAsync") { view: GifView ->
|
||||||
|
view.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFunction("pauseAsync") { view: GifView ->
|
||||||
|
view.pause()
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncFunction("toggleAsync") { view: GifView ->
|
||||||
|
view.toggle()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
View(GifView::class) {
|
|
||||||
Events(
|
|
||||||
"onPlayerStateChange"
|
|
||||||
)
|
|
||||||
|
|
||||||
Prop("source") { view: GifView, source: String ->
|
|
||||||
view.source = source
|
|
||||||
}
|
|
||||||
|
|
||||||
Prop("placeholderSource") { view: GifView, source: String ->
|
|
||||||
view.placeholderSource = source
|
|
||||||
}
|
|
||||||
|
|
||||||
Prop("autoplay") { view: GifView, autoplay: Boolean ->
|
|
||||||
view.autoplay = autoplay
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncFunction("playAsync") { view: GifView ->
|
|
||||||
view.play()
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncFunction("pauseAsync") { view: GifView ->
|
|
||||||
view.pause()
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncFunction("toggleAsync") { view: GifView ->
|
|
||||||
view.toggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+75
-70
@@ -1,6 +1,5 @@
|
|||||||
package expo.modules.blueskygifview
|
package expo.modules.blueskygifview
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
@@ -15,7 +14,10 @@ import expo.modules.kotlin.exception.Exceptions
|
|||||||
import expo.modules.kotlin.viewevent.EventDispatcher
|
import expo.modules.kotlin.viewevent.EventDispatcher
|
||||||
import expo.modules.kotlin.views.ExpoView
|
import expo.modules.kotlin.views.ExpoView
|
||||||
|
|
||||||
class GifView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
class GifView(
|
||||||
|
context: Context,
|
||||||
|
appContext: AppContext,
|
||||||
|
) : ExpoView(context, appContext) {
|
||||||
// Events
|
// Events
|
||||||
private val onPlayerStateChange by EventDispatcher()
|
private val onPlayerStateChange by EventDispatcher()
|
||||||
|
|
||||||
@@ -44,8 +46,7 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <editor-fold desc="Lifecycle">
|
||||||
//<editor-fold desc="Lifecycle">
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.setBackgroundColor(Color.TRANSPARENT)
|
this.setBackgroundColor(Color.TRANSPARENT)
|
||||||
@@ -70,80 +71,82 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
|
|||||||
super.onDetachedFromWindow()
|
super.onDetachedFromWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
|
|
||||||
//<editor-fold desc="Loading">
|
// <editor-fold desc="Loading">
|
||||||
|
|
||||||
private fun load() {
|
private fun load() {
|
||||||
if (placeholderSource == null || source == null) {
|
if (placeholderSource == null || source == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.webpRequest = glide.load(source)
|
this.webpRequest =
|
||||||
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
glide
|
||||||
.skipMemoryCache(false)
|
.load(source)
|
||||||
.listener(object: RequestListener<Drawable> {
|
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
||||||
override fun onResourceReady(
|
.skipMemoryCache(false)
|
||||||
resource: Drawable?,
|
.listener(
|
||||||
model: Any?,
|
object : RequestListener<Drawable> {
|
||||||
target: Target<Drawable>?,
|
override fun onResourceReady(
|
||||||
dataSource: com.bumptech.glide.load.DataSource?,
|
resource: Drawable?,
|
||||||
isFirstResource: Boolean
|
model: Any?,
|
||||||
): Boolean {
|
target: Target<Drawable>?,
|
||||||
if (placeholderRequest != null) {
|
dataSource: com.bumptech.glide.load.DataSource?,
|
||||||
glide.clear(placeholderRequest)
|
isFirstResource: Boolean,
|
||||||
}
|
): Boolean {
|
||||||
return false
|
if (placeholderRequest != null) {
|
||||||
}
|
glide.clear(placeholderRequest)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLoadFailed(
|
override fun onLoadFailed(
|
||||||
e: GlideException?,
|
e: GlideException?,
|
||||||
model: Any?,
|
model: Any?,
|
||||||
target: Target<Drawable>?,
|
target: Target<Drawable>?,
|
||||||
isFirstResource: Boolean
|
isFirstResource: Boolean,
|
||||||
): Boolean {
|
): Boolean = true
|
||||||
return true
|
},
|
||||||
}
|
).into(this.imageView)
|
||||||
})
|
|
||||||
.into(this.imageView)
|
|
||||||
|
|
||||||
if (this.imageView.drawable == null || this.imageView.drawable !is Animatable) {
|
if (this.imageView.drawable == null || this.imageView.drawable !is Animatable) {
|
||||||
this.placeholderRequest = glide.load(placeholderSource)
|
this.placeholderRequest =
|
||||||
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
glide
|
||||||
// Let's not bloat the memory cache with placeholders
|
.load(placeholderSource)
|
||||||
.skipMemoryCache(true)
|
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
||||||
.listener(object: RequestListener<Drawable> {
|
// Let's not bloat the memory cache with placeholders
|
||||||
override fun onResourceReady(
|
.skipMemoryCache(true)
|
||||||
resource: Drawable?,
|
.listener(
|
||||||
model: Any?,
|
object : RequestListener<Drawable> {
|
||||||
target: Target<Drawable>?,
|
override fun onResourceReady(
|
||||||
dataSource: com.bumptech.glide.load.DataSource?,
|
resource: Drawable?,
|
||||||
isFirstResource: Boolean
|
model: Any?,
|
||||||
): Boolean {
|
target: Target<Drawable>?,
|
||||||
// Incase this request finishes after the webp, let's just not set
|
dataSource: com.bumptech.glide.load.DataSource?,
|
||||||
// the drawable. This shouldn't happen because the request should get cancelled
|
isFirstResource: Boolean,
|
||||||
if (imageView.drawable == null) {
|
): Boolean {
|
||||||
imageView.setImageDrawable(resource)
|
// Incase this request finishes after the webp, let's just not set
|
||||||
}
|
// the drawable. This shouldn't happen because the request should get cancelled
|
||||||
return true
|
if (imageView.drawable == null) {
|
||||||
}
|
imageView.setImageDrawable(resource)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun onLoadFailed(
|
override fun onLoadFailed(
|
||||||
e: GlideException?,
|
e: GlideException?,
|
||||||
model: Any?,
|
model: Any?,
|
||||||
target: Target<Drawable>?,
|
target: Target<Drawable>?,
|
||||||
isFirstResource: Boolean
|
isFirstResource: Boolean,
|
||||||
): Boolean {
|
): Boolean = true
|
||||||
return true
|
},
|
||||||
}
|
).submit()
|
||||||
})
|
|
||||||
.submit()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
|
|
||||||
//<editor-fold desc="Controls">
|
// <editor-fold desc="Controls">
|
||||||
|
|
||||||
fun play() {
|
fun play() {
|
||||||
this.imageView.play()
|
this.imageView.play()
|
||||||
@@ -165,16 +168,18 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
|
|
||||||
//<editor-fold desc="Util">
|
// <editor-fold desc="Util">
|
||||||
|
|
||||||
fun firePlayerStateChange() {
|
fun firePlayerStateChange() {
|
||||||
onPlayerStateChange(mapOf(
|
onPlayerStateChange(
|
||||||
"isPlaying" to this.isPlaying,
|
mapOf(
|
||||||
"isLoaded" to this.isLoaded,
|
"isPlaying" to this.isPlaying,
|
||||||
))
|
"isLoaded" to this.isLoaded,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
// </editor-fold>
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -4,7 +4,8 @@ import expo.modules.kotlin.modules.Module
|
|||||||
import expo.modules.kotlin.modules.ModuleDefinition
|
import expo.modules.kotlin.modules.ModuleDefinition
|
||||||
|
|
||||||
class ExpoBlueskyDevicePrefsModule : Module() {
|
class ExpoBlueskyDevicePrefsModule : Module() {
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() =
|
||||||
Name("ExpoBlueskyDevicePrefs")
|
ModuleDefinition {
|
||||||
}
|
Name("ExpoBlueskyDevicePrefs")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-40
@@ -3,52 +3,55 @@ package expo.modules.blueskyswissarmy.referrer
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.android.installreferrer.api.InstallReferrerClient
|
import com.android.installreferrer.api.InstallReferrerClient
|
||||||
import com.android.installreferrer.api.InstallReferrerStateListener
|
import com.android.installreferrer.api.InstallReferrerStateListener
|
||||||
|
import expo.modules.kotlin.Promise
|
||||||
import expo.modules.kotlin.modules.Module
|
import expo.modules.kotlin.modules.Module
|
||||||
import expo.modules.kotlin.modules.ModuleDefinition
|
import expo.modules.kotlin.modules.ModuleDefinition
|
||||||
import expo.modules.kotlin.Promise
|
|
||||||
|
|
||||||
class ExpoBlueskyReferrerModule : Module() {
|
class ExpoBlueskyReferrerModule : Module() {
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() =
|
||||||
Name("ExpoBlueskyReferrer")
|
ModuleDefinition {
|
||||||
|
Name("ExpoBlueskyReferrer")
|
||||||
|
|
||||||
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
|
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
|
||||||
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
|
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
|
||||||
referrerClient.startConnection(object : InstallReferrerStateListener {
|
referrerClient.startConnection(
|
||||||
override fun onInstallReferrerSetupFinished(responseCode: Int) {
|
object : InstallReferrerStateListener {
|
||||||
if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) {
|
override fun onInstallReferrerSetupFinished(responseCode: Int) {
|
||||||
Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.")
|
if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) {
|
||||||
|
Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.")
|
||||||
|
|
||||||
val response = referrerClient.installReferrer
|
val response = referrerClient.installReferrer
|
||||||
Log.d("ExpoGooglePlayReferrer", "Install referrer: ${response.installReferrer}")
|
Log.d("ExpoGooglePlayReferrer", "Install referrer: ${response.installReferrer}")
|
||||||
|
|
||||||
promise.resolve(
|
promise.resolve(
|
||||||
mapOf(
|
mapOf(
|
||||||
"installReferrer" to response.installReferrer,
|
"installReferrer" to response.installReferrer,
|
||||||
"clickTimestamp" to response.referrerClickTimestampSeconds,
|
"clickTimestamp" to response.referrerClickTimestampSeconds,
|
||||||
"installTimestamp" to response.installBeginTimestampSeconds
|
"installTimestamp" to response.installBeginTimestampSeconds,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Log.d("ExpoGooglePlayReferrer", "Failed to get referrer info. Unknown error.")
|
||||||
|
promise.reject(
|
||||||
|
"ERR_GOOGLE_PLAY_REFERRER_UNKNOWN",
|
||||||
|
"Failed to get referrer info",
|
||||||
|
Exception("Failed to get referrer info"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
referrerClient.endConnection()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInstallReferrerServiceDisconnected() {
|
||||||
|
Log.d("ExpoGooglePlayReferrer", "Failed to get referrer info. Service disconnected.")
|
||||||
|
referrerClient.endConnection()
|
||||||
|
promise.reject(
|
||||||
|
"ERR_GOOGLE_PLAY_REFERRER_DISCONNECTED",
|
||||||
|
"Failed to get referrer info",
|
||||||
|
Exception("Failed to get referrer info"),
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
} else {
|
},
|
||||||
Log.d("ExpoGooglePlayReferrer", "Failed to get referrer info. Unknown error.")
|
)
|
||||||
promise.reject(
|
}
|
||||||
"ERR_GOOGLE_PLAY_REFERRER_UNKNOWN",
|
|
||||||
"Failed to get referrer info",
|
|
||||||
Exception("Failed to get referrer info")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
referrerClient.endConnection()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onInstallReferrerServiceDisconnected() {
|
|
||||||
Log.d("ExpoGooglePlayReferrer", "Failed to get referrer info. Service disconnected.")
|
|
||||||
referrerClient.endConnection()
|
|
||||||
promise.reject(
|
|
||||||
"ERR_GOOGLE_PLAY_REFERRER_DISCONNECTED",
|
|
||||||
"Failed to get referrer info",
|
|
||||||
Exception("Failed to get referrer info")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
+19
-17
@@ -13,16 +13,17 @@ import java.io.FileOutputStream
|
|||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
class ExpoReceiveAndroidIntentsModule : Module() {
|
class ExpoReceiveAndroidIntentsModule : Module() {
|
||||||
override fun definition() = ModuleDefinition {
|
override fun definition() =
|
||||||
Name("ExpoReceiveAndroidIntents")
|
ModuleDefinition {
|
||||||
|
Name("ExpoReceiveAndroidIntents")
|
||||||
|
|
||||||
OnNewIntent {
|
OnNewIntent {
|
||||||
handleIntent(it)
|
handleIntent(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleIntent(intent: Intent?) {
|
private fun handleIntent(intent: Intent?) {
|
||||||
if(appContext.currentActivity == null || intent == null) return
|
if (appContext.currentActivity == null || intent == null) return
|
||||||
|
|
||||||
if (intent.action == Intent.ACTION_SEND) {
|
if (intent.action == Intent.ACTION_SEND) {
|
||||||
if (intent.type == "text/plain") {
|
if (intent.type == "text/plain") {
|
||||||
@@ -40,7 +41,7 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
private fun handleTextIntent(intent: Intent) {
|
private fun handleTextIntent(intent: Intent) {
|
||||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||||
val encoded = URLEncoder.encode(it, "UTF-8")
|
val encoded = URLEncoder.encode(it, "UTF-8")
|
||||||
"bluesky://intent/compose?text=${encoded}".toUri().let { uri ->
|
"bluesky://intent/compose?text=$encoded".toUri().let { uri ->
|
||||||
val newIntent = Intent(Intent.ACTION_VIEW, uri)
|
val newIntent = Intent(Intent.ACTION_VIEW, uri)
|
||||||
appContext.currentActivity?.startActivity(newIntent)
|
appContext.currentActivity?.startActivity(newIntent)
|
||||||
}
|
}
|
||||||
@@ -48,11 +49,12 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleImageIntent(intent: Intent) {
|
private fun handleImageIntent(intent: Intent) {
|
||||||
val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
val uri =
|
||||||
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
} else {
|
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
|
||||||
intent.getParcelableExtra(Intent.EXTRA_STREAM)
|
} else {
|
||||||
}
|
intent.getParcelableExtra(Intent.EXTRA_STREAM)
|
||||||
|
}
|
||||||
if (uri == null) return
|
if (uri == null) return
|
||||||
|
|
||||||
handleImageIntents(listOf(uri))
|
handleImageIntents(listOf(uri))
|
||||||
@@ -76,16 +78,16 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
uris.forEachIndexed { index, uri ->
|
uris.forEachIndexed { index, uri ->
|
||||||
val info = getImageInfo(uri)
|
val info = getImageInfo(uri)
|
||||||
val params = buildUriData(info)
|
val params = buildUriData(info)
|
||||||
allParams = "${allParams}${params}"
|
allParams = "${allParams}$params"
|
||||||
|
|
||||||
if (index < uris.count() - 1) {
|
if (index < uris.count() - 1) {
|
||||||
allParams = "${allParams},"
|
allParams = "$allParams,"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val encoded = URLEncoder.encode(allParams, "UTF-8")
|
val encoded = URLEncoder.encode(allParams, "UTF-8")
|
||||||
|
|
||||||
"bluesky://intent/compose?imageUris=${encoded}".toUri().let {
|
"bluesky://intent/compose?imageUris=$encoded".toUri().let {
|
||||||
val newIntent = Intent(Intent.ACTION_VIEW, it)
|
val newIntent = Intent(Intent.ACTION_VIEW, it)
|
||||||
appContext.currentActivity?.startActivity(newIntent)
|
appContext.currentActivity?.startActivity(newIntent)
|
||||||
}
|
}
|
||||||
@@ -104,7 +106,7 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
return mapOf(
|
return mapOf(
|
||||||
"width" to bitmap.width,
|
"width" to bitmap.width,
|
||||||
"height" to bitmap.height,
|
"height" to bitmap.height,
|
||||||
"path" to file.path.toString()
|
"path" to file.path.toString(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,6 +116,6 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
val path = info.getValue("path")
|
val path = info.getValue("path")
|
||||||
val width = info.getValue("width")
|
val width = info.getValue("width")
|
||||||
val height = info.getValue("height")
|
val height = info.getValue("height")
|
||||||
return "file://${path}|${width}|${height}"
|
return "file://$path|$width|$height"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user