fix kotlin

This commit is contained in:
Hailey
2024-07-10 17:41:45 -07:00
parent 921b13dbdc
commit de25c4b676
10 changed files with 297 additions and 270 deletions
+2
View File
@@ -0,0 +1,2 @@
[*.{kt,kts}]
indent_size=2
@@ -5,7 +5,7 @@ import com.google.firebase.messaging.RemoteMessage
class BackgroundNotificationHandler(
private val context: Context,
private val notifInterface: BackgroundNotificationHandlerInterface
private val notifInterface: BackgroundNotificationHandlerInterface,
) {
fun handleMessage(remoteMessage: RemoteMessage) {
if (ExpoBackgroundNotificationHandlerModule.isForegrounded) {
@@ -8,7 +8,8 @@ class ExpoBackgroundNotificationHandlerModule : Module() {
var isForegrounded = false
}
override fun definition() = ModuleDefinition {
override fun definition() =
ModuleDefinition {
Name("ExpoBackgroundNotificationHandler")
OnCreate {
@@ -2,7 +2,8 @@ package expo.modules.backgroundnotificationhandler
import android.content.Context
val DEFAULTS = mapOf<String, Any>(
val DEFAULTS =
mapOf<String, Any>(
"playSoundChat" to true,
"playSoundFollow" to false,
"playSoundLike" to false,
@@ -10,11 +11,14 @@ val DEFAULTS = mapOf<String, Any>(
"playSoundQuote" to false,
"playSoundReply" to false,
"playSoundRepost" to false,
"mutedThreads" to mapOf<String, List<String>>()
"mutedThreads" to mapOf<String, List<String>>(),
)
class NotificationPrefs (private val context: Context?) {
private val prefs = context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE)
class NotificationPrefs(
private val context: Context?,
) {
private val prefs =
context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE)
?: throw Error("Context is null")
fun initialize() {
@@ -41,94 +45,99 @@ class NotificationPrefs (private val context: Context?) {
}
}
}
}
.apply()
}.apply()
}
fun getAllPrefs(): MutableMap<String, *> {
return prefs.all
}
fun getAllPrefs(): MutableMap<String, *> = prefs.all
fun getBoolean(key: String): Boolean {
return prefs.getBoolean(key, false)
}
fun getBoolean(key: String): Boolean = prefs.getBoolean(key, false)
fun getString(key: String): String? {
return prefs.getString(key, null)
}
fun getString(key: String): String? = prefs.getString(key, null)
fun getStringArray(key: String): Array<String>? {
return prefs.getStringSet(key, null)?.toTypedArray()
}
fun getStringArray(key: String): Array<String>? = prefs.getStringSet(key, null)?.toTypedArray()
fun setBoolean(key: String, value: Boolean) {
fun setBoolean(
key: String,
value: Boolean,
) {
prefs
.edit()
.apply {
putBoolean(key, value)
}
.apply()
}.apply()
}
fun setString(key: String, value: String) {
fun setString(
key: String,
value: String,
) {
prefs
.edit()
.apply {
putString(key, value)
}
.apply()
}.apply()
}
fun setStringArray(key: String, value: Array<String>) {
fun setStringArray(
key: String,
value: Array<String>,
) {
prefs
.edit()
.apply {
putStringSet(key, value.toSet())
}
.apply()
}.apply()
}
fun addToStringArray(key: String, string: String) {
fun addToStringArray(
key: String,
string: String,
) {
prefs
.edit()
.apply {
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
set.add(string)
putStringSet(key, set)
}
.apply()
}.apply()
}
fun removeFromStringArray(key: String, string: String) {
fun removeFromStringArray(
key: String,
string: String,
) {
prefs
.edit()
.apply {
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
set.remove(string)
putStringSet(key, set)
}
.apply()
}.apply()
}
fun addManyToStringArray(key: String, strings: Array<String>) {
fun addManyToStringArray(
key: String,
strings: Array<String>,
) {
prefs
.edit()
.apply {
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
set.addAll(strings.toSet())
putStringSet(key, set)
}
.apply()
}.apply()
}
fun removeManyFromStringArray(key: String, strings: Array<String>) {
fun removeManyFromStringArray(
key: String,
strings: Array<String>,
) {
prefs
.edit()
.apply {
val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
set.removeAll(strings.toSet())
putStringSet(key, set)
}
.apply()
}.apply()
}
}
@@ -5,7 +5,10 @@ import android.graphics.Canvas
import android.graphics.drawable.Animatable
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) {
super.onDraw(canvas)
@@ -6,7 +6,8 @@ import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
class ExpoBlueskyGifViewModule : Module() {
override fun definition() = ModuleDefinition {
override fun definition() =
ModuleDefinition {
Name("ExpoBlueskyGifView")
AsyncFunction("prefetchAsync") { sources: List<String> ->
@@ -23,7 +24,7 @@ class ExpoBlueskyGifViewModule : Module() {
View(GifView::class) {
Events(
"onPlayerStateChange"
"onPlayerStateChange",
)
Prop("source") { view: GifView, source: String ->
@@ -1,6 +1,5 @@
package expo.modules.blueskygifview
import android.content.Context
import android.graphics.Color
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.views.ExpoView
class GifView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
class GifView(
context: Context,
appContext: AppContext,
) : ExpoView(context, appContext) {
// Events
private val onPlayerStateChange by EventDispatcher()
@@ -44,7 +46,6 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
}
}
// <editor-fold desc="Lifecycle">
init {
@@ -79,16 +80,19 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
return
}
this.webpRequest = glide.load(source)
this.webpRequest =
glide
.load(source)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.skipMemoryCache(false)
.listener(object: RequestListener<Drawable> {
.listener(
object : RequestListener<Drawable> {
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: com.bumptech.glide.load.DataSource?,
isFirstResource: Boolean
isFirstResource: Boolean,
): Boolean {
if (placeholderRequest != null) {
glide.clear(placeholderRequest)
@@ -100,25 +104,26 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return true
}
})
.into(this.imageView)
isFirstResource: Boolean,
): Boolean = true
},
).into(this.imageView)
if (this.imageView.drawable == null || this.imageView.drawable !is Animatable) {
this.placeholderRequest = glide.load(placeholderSource)
this.placeholderRequest =
glide
.load(placeholderSource)
.diskCacheStrategy(DiskCacheStrategy.DATA)
// Let's not bloat the memory cache with placeholders
.skipMemoryCache(true)
.listener(object: RequestListener<Drawable> {
.listener(
object : RequestListener<Drawable> {
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: com.bumptech.glide.load.DataSource?,
isFirstResource: Boolean
isFirstResource: Boolean,
): Boolean {
// Incase this request finishes after the webp, let's just not set
// the drawable. This shouldn't happen because the request should get cancelled
@@ -132,12 +137,10 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return true
}
})
.submit()
isFirstResource: Boolean,
): Boolean = true
},
).submit()
}
}
@@ -170,10 +173,12 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
// <editor-fold desc="Util">
fun firePlayerStateChange() {
onPlayerStateChange(mapOf(
onPlayerStateChange(
mapOf(
"isPlaying" to this.isPlaying,
"isLoaded" to this.isLoaded,
))
),
)
}
// </editor-fold>
@@ -4,7 +4,8 @@ import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
class ExpoBlueskyDevicePrefsModule : Module() {
override fun definition() = ModuleDefinition {
override fun definition() =
ModuleDefinition {
Name("ExpoBlueskyDevicePrefs")
}
}
@@ -3,17 +3,19 @@ package expo.modules.blueskyswissarmy.referrer
import android.util.Log
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import expo.modules.kotlin.Promise
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.kotlin.Promise
class ExpoBlueskyReferrerModule : Module() {
override fun definition() = ModuleDefinition {
override fun definition() =
ModuleDefinition {
Name("ExpoBlueskyReferrer")
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
referrerClient.startConnection(
object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) {
Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.")
@@ -25,15 +27,15 @@ class ExpoBlueskyReferrerModule : Module() {
mapOf(
"installReferrer" to response.installReferrer,
"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")
Exception("Failed to get referrer info"),
)
}
referrerClient.endConnection()
@@ -45,10 +47,11 @@ class ExpoBlueskyReferrerModule : Module() {
promise.reject(
"ERR_GOOGLE_PLAY_REFERRER_DISCONNECTED",
"Failed to get referrer info",
Exception("Failed to get referrer info")
Exception("Failed to get referrer info"),
)
}
})
},
)
}
}
}
@@ -13,7 +13,8 @@ import java.io.FileOutputStream
import java.net.URLEncoder
class ExpoReceiveAndroidIntentsModule : Module() {
override fun definition() = ModuleDefinition {
override fun definition() =
ModuleDefinition {
Name("ExpoReceiveAndroidIntents")
OnNewIntent {
@@ -40,7 +41,7 @@ class ExpoReceiveAndroidIntentsModule : Module() {
private fun handleTextIntent(intent: Intent) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
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)
appContext.currentActivity?.startActivity(newIntent)
}
@@ -48,7 +49,8 @@ class ExpoReceiveAndroidIntentsModule : Module() {
}
private fun handleImageIntent(intent: Intent) {
val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val uri =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
} else {
intent.getParcelableExtra(Intent.EXTRA_STREAM)
@@ -76,16 +78,16 @@ class ExpoReceiveAndroidIntentsModule : Module() {
uris.forEachIndexed { index, uri ->
val info = getImageInfo(uri)
val params = buildUriData(info)
allParams = "${allParams}${params}"
allParams = "${allParams}$params"
if (index < uris.count() - 1) {
allParams = "${allParams},"
allParams = "$allParams,"
}
}
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)
appContext.currentActivity?.startActivity(newIntent)
}
@@ -104,7 +106,7 @@ class ExpoReceiveAndroidIntentsModule : Module() {
return mapOf(
"width" to bitmap.width,
"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 width = info.getValue("width")
val height = info.getValue("height")
return "file://${path}|${width}|${height}"
return "file://$path|$width|$height"
}
}