mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-24 23:41:19 +02:00
refactor some duplicated code
This commit is contained in:
parent
3d80ee1984
commit
614dbab1fd
@ -29,10 +29,31 @@ object AmberUtils {
|
|||||||
var isActivityRunning: Boolean = false
|
var isActivityRunning: Boolean = false
|
||||||
val cachedDecryptedContent = mutableMapOf<HexKey, String>()
|
val cachedDecryptedContent = mutableMapOf<HexKey, String>()
|
||||||
lateinit var account: Account
|
lateinit var account: Account
|
||||||
lateinit var activityResultLauncher: ActivityResultLauncher<Intent>
|
private lateinit var activityResultLauncher: ActivityResultLauncher<Intent>
|
||||||
lateinit var decryptResultLauncher: ActivityResultLauncher<Intent>
|
private lateinit var decryptResultLauncher: ActivityResultLauncher<Intent>
|
||||||
lateinit var blockListResultLauncher: ActivityResultLauncher<Intent>
|
private lateinit var blockListResultLauncher: ActivityResultLauncher<Intent>
|
||||||
lateinit var signEventResultLauncher: ActivityResultLauncher<Intent>
|
private lateinit var signEventResultLauncher: ActivityResultLauncher<Intent>
|
||||||
|
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
|
fun requestRejectedToast() {
|
||||||
|
GlobalScope.launch(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
Amethyst.instance,
|
||||||
|
"Sign request rejected",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
|
fun default() {
|
||||||
|
isActivityRunning = false
|
||||||
|
ServiceManager.shouldPauseService = true
|
||||||
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
isActivityRunning = false
|
||||||
|
ServiceManager.shouldPauseService = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
fun start(activity: MainActivity) {
|
fun start(activity: MainActivity) {
|
||||||
@ -40,13 +61,7 @@ object AmberUtils {
|
|||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) {
|
) {
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
if (it.resultCode != Activity.RESULT_OK) {
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
requestRejectedToast()
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
val json = it.data?.getStringExtra("event") ?: ""
|
val json = it.data?.getStringExtra("event") ?: ""
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
@ -57,21 +72,14 @@ object AmberUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isActivityRunning = false
|
default()
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
activityResultLauncher = activity.registerForActivityResult(
|
activityResultLauncher = activity.registerForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) {
|
) {
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
if (it.resultCode != Activity.RESULT_OK) {
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
requestRejectedToast()
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
val event = it.data?.getStringExtra("signature") ?: ""
|
val event = it.data?.getStringExtra("signature") ?: ""
|
||||||
val id = it.data?.getStringExtra("id") ?: ""
|
val id = it.data?.getStringExtra("id") ?: ""
|
||||||
@ -79,25 +87,14 @@ object AmberUtils {
|
|||||||
content.put(id, event)
|
content.put(id, event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isActivityRunning = false
|
default()
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
decryptResultLauncher = activity.registerForActivityResult(
|
decryptResultLauncher = activity.registerForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) {
|
) {
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
if (it.resultCode != Activity.RESULT_OK) {
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
requestRejectedToast()
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
val event = it.data?.getStringExtra("signature") ?: ""
|
val event = it.data?.getStringExtra("signature") ?: ""
|
||||||
val id = it.data?.getStringExtra("id") ?: ""
|
val id = it.data?.getStringExtra("id") ?: ""
|
||||||
@ -106,25 +103,14 @@ object AmberUtils {
|
|||||||
cachedDecryptedContent[id] = event
|
cachedDecryptedContent[id] = event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isActivityRunning = false
|
default()
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blockListResultLauncher = activity.registerForActivityResult(
|
blockListResultLauncher = activity.registerForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) {
|
) {
|
||||||
if (it.resultCode != Activity.RESULT_OK) {
|
if (it.resultCode != Activity.RESULT_OK) {
|
||||||
GlobalScope.launch(Dispatchers.Main) {
|
requestRejectedToast()
|
||||||
Toast.makeText(
|
|
||||||
Amethyst.instance,
|
|
||||||
"Sign request rejected",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
val decryptedContent = it.data?.getStringExtra("signature") ?: ""
|
val decryptedContent = it.data?.getStringExtra("signature") ?: ""
|
||||||
val id = it.data?.getStringExtra("id") ?: ""
|
val id = it.data?.getStringExtra("id") ?: ""
|
||||||
@ -133,12 +119,7 @@ object AmberUtils {
|
|||||||
account.live.invalidateData()
|
account.live.invalidateData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isActivityRunning = false
|
default()
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
isActivityRunning = false
|
|
||||||
ServiceManager.shouldPauseService = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user