-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactors to picker dialog
Enhance the UX
- Loading branch information
1 parent
560658f
commit 751563b
Showing
17 changed files
with
166 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 0 additions & 85 deletions
85
app/src/main/java/com/osfans/trime/ui/components/CoroutineChoiceDialog.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/osfans/trime/ui/main/settings/ColorPickerDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.osfans.trime.ui.main.settings | ||
|
||
import android.app.AlertDialog | ||
import android.content.Context | ||
import androidx.lifecycle.LifecycleCoroutineScope | ||
import com.osfans.trime.R | ||
import com.osfans.trime.data.theme.ColorManager | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
object ColorPickerDialog { | ||
suspend fun build( | ||
scope: LifecycleCoroutineScope, | ||
context: Context, | ||
): AlertDialog { | ||
val all = withContext(Dispatchers.Default) { ColorManager.presetColorSchemes } | ||
val allIds = all.keys | ||
val allNames = all.values.mapNotNull { it["name"] } | ||
val currentId = ColorManager.selectedColor | ||
val currentIndex = all.keys.indexOfFirst { it == currentId } | ||
return AlertDialog.Builder(context).apply { | ||
setTitle(R.string.looks__selected_color_title) | ||
if (all.isEmpty()) { | ||
setMessage(R.string.no_color_to_select) | ||
} else { | ||
setSingleChoiceItems( | ||
allNames.toTypedArray(), | ||
currentIndex, | ||
) { dialog, which -> | ||
scope.launch { | ||
if (which != currentIndex) { | ||
ColorManager.setColorScheme(allIds.elementAt(which)) | ||
} | ||
dialog.dismiss() | ||
} | ||
} | ||
} | ||
setNegativeButton(android.R.string.cancel, null) | ||
}.create() | ||
} | ||
} |
Oops, something went wrong.