Skip to content

Commit

Permalink
Codebase cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zhufucdev committed Jun 14, 2023
1 parent 2b42cf2 commit d4f88ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import com.highcapable.yukihookapi.hook.log.loggerI
import com.highcapable.yukihookapi.hook.param.PackageParam
import com.zhufucdev.data.*
import com.zhufucdev.motion_emulator.PREFERENCE_NAME_BRIDGE
import com.zhufucdev.motion_emulator.data.*
import com.zhufucdev.motion_emulator.data.MapProjector
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.zhufucdev.motion_emulator.ui.map
import android.content.Context
import android.location.Address
import android.location.Geocoder
import android.os.Build
import com.amap.api.services.core.PoiItemV2
import com.amap.api.services.poisearch.PoiResultV2
import com.amap.api.services.poisearch.PoiSearchV2
Expand Down Expand Up @@ -74,21 +75,34 @@ class GooglePoiEngine(private val context: Context) : PoiSearchEngine {
override suspend fun search(point: Point) = suspendCoroutine { res ->
if (!Geocoder.isPresent()) res.resumeWith(Result.failure(IllegalStateException("Geocoder not present")))
val coder = Geocoder(context)
val result = coder.getFromLocation(point.latitude, point.longitude, 1)?.get(0)
if (result == null) {
res.resumeWith(Result.success(null))
return@suspendCoroutine
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
coder.getFromLocation(point.latitude, point.longitude, 1) {
res.resumeWith(Result.success(it.getOrNull(0)?.poi()))
}
} else {
@Suppress("DEPRECATION")
val result = coder.getFromLocation(point.latitude, point.longitude, 1)?.get(0)
if (result == null) {
res.resumeWith(Result.success(null))
return@suspendCoroutine
}

res.resumeWith(Result.success(result.poi()))
res.resumeWith(Result.success(result.poi()))
}
}

override suspend fun search(text: String, limit: Int) = suspendCoroutine { res ->
if (!Geocoder.isPresent()) res.resumeWith(Result.failure(IllegalStateException("Geocoder not present")))
val coder = Geocoder(context)
val results = coder.getFromLocationName(text, limit) ?: emptyList()

res.resumeWith(Result.success(results.map { it.poi() }))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
coder.getFromLocationName(text, limit) { addr ->
res.resumeWith(Result.success(addr.map { it.poi() }))
}
} else {
@Suppress("DEPRECATION")
val results = coder.getFromLocationName(text, limit) ?: emptyList()
res.resumeWith(Result.success(results.map { it.poi() }))
}
}

private fun Address.poi() = Poi(
Expand Down
6 changes: 1 addition & 5 deletions update/src/main/java/com/zhufucdev/update/Update.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.zhufucdev.update

import android.annotation.SuppressLint
import android.app.DownloadManager
import android.app.DownloadManager.COLUMN_LOCAL_URI
import android.app.DownloadManager.Query
import android.content.Context
import android.net.Uri
Expand All @@ -12,7 +11,6 @@ import androidx.compose.runtime.*
import androidx.core.content.getSystemService
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.call.body
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
Expand All @@ -22,9 +20,7 @@ import kotlinx.coroutines.*
import kotlinx.serialization.Serializable
import java.io.File
import kotlin.concurrent.thread
import kotlin.coroutines.coroutineContext
import kotlin.coroutines.suspendCoroutine
import kotlin.time.Duration.Companion.seconds

/**
* Something checks and downloads app updates
Expand Down Expand Up @@ -111,7 +107,7 @@ class Updater(
})

return suspendCoroutine { c ->
val progress = mutableStateOf(0F)
val progress = mutableFloatStateOf(0F)
val status = StatusDownloading(progress, manager, taskId)

thread(start = true) {
Expand Down

0 comments on commit d4f88ed

Please sign in to comment.