temporal progress

This commit is contained in:
InsanusMokrassar 2022-11-15 19:55:54 +06:00
parent 70baa30127
commit 53a76c7a73
15 changed files with 272 additions and 174 deletions

View File

@ -1,6 +1,9 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.inmo.kmppscriptbuilder.core.models.Config
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer

View File

@ -1,8 +1,10 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.runtime.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.inmo.kmppscriptbuilder.core.models.Developer
import dev.inmo.kmppscriptbuilder.desktop.utils.CommonTextField
class DeveloperState(
id: String = "",

View File

@ -1,12 +1,19 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.inmo.kmppscriptbuilder.core.models.License
import dev.inmo.kmppscriptbuilder.core.models.getLicenses
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
import io.ktor.client.HttpClient
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
private class LicenseState(
internal class LicenseState(
id: String = "",
title: String = "",
url: String? = null
@ -18,19 +25,21 @@ private class LicenseState(
fun toLicense() = License(id, title, url)
}
private fun License.toLicenseState() = LicenseState(id, title, url)
internal fun License.toLicenseState() = LicenseState(id, title, url)
expect object LicensesDrawer : Drawer<LicensesView>
class LicensesView: VerticalView("Licenses") {
private var licensesListState = mutableStateListOf<LicenseState>()
internal var licensesListState = mutableStateListOf<LicenseState>()
var licenses: List<License>
get() = licensesListState.map { it.toLicense() }
set(value) {
licensesListState.clear()
licensesListState.addAll(value.map { it.toLicenseState() })
}
private val availableLicensesState = mutableStateListOf<License>()
private val licensesOffersToShow = mutableStateListOf<License>()
private var licenseSearchFilter by mutableStateOf("")
internal val availableLicensesState = mutableStateListOf<License>()
internal val licensesOffersToShow = mutableStateListOf<License>()
internal var licenseSearchFilter by mutableStateOf("")
init {
CoroutineScope(Dispatchers.Default).launch {
@ -40,49 +49,7 @@ class LicensesView: VerticalView("Licenses") {
}
}
override val content: @Composable ColumnScope.() -> Unit = {
CommonTextField(licenseSearchFilter, "Search filter") { filterText ->
licenseSearchFilter = filterText
licensesOffersToShow.clear()
if (licenseSearchFilter.isNotEmpty()) {
licensesOffersToShow.addAll(
availableLicensesState.filter { filterText.all { symbol -> symbol.lowercaseChar() in it.title } }
)
}
}
Column {
licensesOffersToShow.forEach {
Column(Modifier.padding(16.dp, 8.dp, 8.dp, 8.dp)) {
CommonText(it.title, Modifier.clickable {
licensesListState.add(it.toLicenseState())
licenseSearchFilter = ""
licensesOffersToShow.clear()
})
Divider()
}
}
}
Button({ licensesListState.add(LicenseState()) }, Modifier.padding(8.dp)) {
CommonText("Add empty license")
}
licensesListState.forEach { license ->
Column(Modifier.padding(8.dp)) {
CommonTextField(
license.id,
"License ID"
) { license.id = it }
CommonTextField(
license.title,
"License title"
) { license.title = it }
CommonTextField(
license.url ?: "",
"License URL"
) { license.url = it }
Button({ licensesListState.remove(license) }, Modifier.padding(8.dp)) {
CommonText("Remove")
}
}
}
override val content: @Composable () -> Unit = {
with(LicensesDrawer) { draw() }
}
}

View File

@ -6,7 +6,7 @@ import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
expect class ListViewDrawer<T>() : Drawer<ListView<T>>
abstract class ListView<T>(protected val title: String) : View() {
abstract class ListView<T>(title: String) : VerticalView(title) {
internal val itemsList = mutableStateListOf<T>()
internal open val addItemText: String = "Add"
@ -18,9 +18,9 @@ abstract class ListView<T>(protected val title: String) : View() {
protected val drawer = ListViewDrawer<T>()
override fun build() {
DrawVertically(title) {
with(drawer) { draw() }
override val content: () -> Unit = {
with(drawer) {
draw()
}
}
}

View File

@ -1,24 +1,20 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.VerticalAlignmentLine
import androidx.compose.ui.unit.dp
import dev.inmo.kmppscriptbuilder.core.models.*
import dev.inmo.kmppscriptbuilder.desktop.utils.*
import dev.inmo.kmppscriptbuilder.core.models.GpgSigning
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
expect object MavenInfoDrawer : Drawer<MavenInfoView>
class MavenInfoView : VerticalView("Project information") {
private var projectNameProperty by mutableStateOf("")
private var projectDescriptionProperty by mutableStateOf("")
private var projectUrlProperty by mutableStateOf("")
private var projectVcsUrlProperty by mutableStateOf("")
private var gpgSignProperty by mutableStateOf<GpgSigning>(GpgSigning.Disabled)
private var publishToMavenCentralProperty by mutableStateOf(false)
private val developersView = DevelopersView()
private val repositoriesView = RepositoriesView()
internal var projectNameProperty by mutableStateOf("")
internal var projectDescriptionProperty by mutableStateOf("")
internal var projectUrlProperty by mutableStateOf("")
internal var projectVcsUrlProperty by mutableStateOf("")
internal var gpgSignProperty by mutableStateOf<GpgSigning>(GpgSigning.Disabled)
internal var publishToMavenCentralProperty by mutableStateOf(false)
internal val developersView = DevelopersView()
internal val repositoriesView = RepositoriesView()
var mavenConfig: MavenConfig
get() = MavenConfig(
@ -50,55 +46,7 @@ class MavenInfoView : VerticalView("Project information") {
// developersView.developers = value.developers
}
@Composable
private fun addGpgSigningButton(gpgSigning: GpgSigning) {
if (gpgSignProperty == gpgSigning) {
Button({}, Modifier.padding(8.dp)) {
Text(gpgSigning.name)
}
} else {
OutlinedButton(
{
gpgSignProperty = gpgSigning
},
Modifier.padding(8.dp)
) {
Text(gpgSigning.name)
}
}
}
override val content: @Composable ColumnScope.() -> Unit = {
CommonTextField(
projectNameProperty,
"Public project name"
) { projectNameProperty = it }
CommonTextField(
projectDescriptionProperty,
"Public project description"
) { projectDescriptionProperty = it }
CommonTextField(
projectUrlProperty,
"Public project URL"
) { projectUrlProperty = it }
CommonTextField(
projectVcsUrlProperty,
"Public project VCS URL (with .git)"
) { projectVcsUrlProperty = it }
Row(verticalAlignment = Alignment.CenterVertically) {
Text("Gpg Signing: ")
addGpgSigningButton(GpgSigning.Disabled)
addGpgSigningButton(GpgSigning.Optional)
addGpgSigningButton(GpgSigning.Enabled)
}
SwitchWithLabel(
"Include publication to MavenCentral",
publishToMavenCentralProperty,
placeSwitchAtTheStart = true
) { publishToMavenCentralProperty = it }
developersView.init()
repositoriesView.init()
override val content: @Composable () -> Unit = {
with (MavenInfoDrawer) { draw() }
}
}

View File

@ -1,40 +1,19 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.inmo.kmppscriptbuilder.core.models.*
import dev.inmo.kmppscriptbuilder.desktop.utils.VerticalView
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.inmo.kmppscriptbuilder.core.models.MultiplatformProjectType
import dev.inmo.kmppscriptbuilder.core.models.ProjectType
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
expect object ProjectTypeDrawer : Drawer<ProjectTypeView>
class ProjectTypeView : VerticalView("Project type") {
var projectType by mutableStateOf<ProjectType>(MultiplatformProjectType)
@Composable
private fun addProjectTypeButton(newProjectType: ProjectType) {
if (projectType == newProjectType) {
Button({}, Modifier.padding(8.dp)) {
Text(newProjectType.name)
}
} else {
OutlinedButton(
{
projectType = newProjectType
},
Modifier.padding(8.dp)
) {
Text(newProjectType.name)
}
}
}
override val content: @Composable ColumnScope.() -> Unit = {
Row(verticalAlignment = Alignment.CenterVertically) {
addProjectTypeButton(MultiplatformProjectType)
addProjectTypeButton(JVMProjectType)
addProjectTypeButton(JSProjectType)
}
override val content: @Composable () -> Unit = {
with(ProjectTypeDrawer) { draw() }
}
}

View File

@ -1,8 +1,11 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository
import dev.inmo.kmppscriptbuilder.desktop.utils.CommonTextField
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
class RepositoryState(
name: String = "",
@ -16,6 +19,8 @@ class RepositoryState(
private fun MavenPublishingRepository.toRepositoryState() = RepositoryState(name, url)
expect object RepositoryStateDrawer : Drawer<RepositoryState>
class RepositoriesView : ListView<RepositoryState>("Repositories info") {
var repositories: List<MavenPublishingRepository>
get() = itemsList.map { it.toRepository() }
@ -30,16 +35,10 @@ class RepositoriesView : ListView<RepositoryState>("Repositories info") {
override val removeItemText: String = "Remove repository"
override fun createItem(): RepositoryState = RepositoryState()
@Composable
override fun buildView(item: RepositoryState) {
CommonTextField(
item.name,
"Repository name"
) { item.name = it }
CommonTextField(
item.url,
"Repository url"
) { item.url = it }
with(RepositoryStateDrawer) { with(item) { draw() } }
}
}

View File

@ -0,0 +1,11 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.runtime.Composable
abstract class VerticalView(protected val title: String) : View() {
abstract val content: @Composable () -> Unit
@Composable
override fun build() {
DrawVertically(title, content)
}
}

View File

@ -6,7 +6,7 @@ import androidx.compose.runtime.Composable
expect fun TitleText(text: String)
@Composable
expect fun CommonText(text: String)
expect fun CommonText(text: String, onClick: (() -> Unit)? = null)
@Composable
expect fun CommonTextField(presetText: String, hint: String, onChange: (String) -> Unit)

View File

@ -0,0 +1,59 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Divider
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonText
import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonTextField
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
actual object LicensesDrawer : Drawer<LicensesView> {
override fun LicensesView.draw() {
CommonTextField(licenseSearchFilter, "Search filter") { filterText ->
licenseSearchFilter = filterText
licensesOffersToShow.clear()
if (licenseSearchFilter.isNotEmpty()) {
licensesOffersToShow.addAll(
availableLicensesState.filter { filterText.all { symbol -> symbol.lowercaseChar() in it.title } }
)
}
}
Column {
licensesOffersToShow.forEach {
Column(Modifier.padding(16.dp, 8.dp, 8.dp, 8.dp)) {
CommonText(it.title) {
licensesListState.add(it.toLicenseState())
licenseSearchFilter = ""
licensesOffersToShow.clear()
}
Divider()
}
}
}
Button({ licensesListState.add(LicenseState()) }, Modifier.padding(8.dp)) {
CommonText("Add empty license",)
}
licensesListState.forEach { license ->
Column(Modifier.padding(8.dp)) {
CommonTextField(
license.id,
"License ID"
) { license.id = it }
CommonTextField(
license.title,
"License title"
) { license.title = it }
CommonTextField(
license.url ?: "",
"License URL"
) { license.url = it }
Button({ licensesListState.remove(license) }, Modifier.padding(8.dp)) {
CommonText("Remove",)
}
}
}
}
}

View File

@ -11,13 +11,13 @@ import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
actual class ListViewDrawer<T> : Drawer<ListView<T>> {
override fun ListView<T>.draw() {
Button({ itemsList.add(createItem()) }) {
CommonText(addItemText)
CommonText(addItemText,)
}
itemsList.forEach { item ->
Column(Modifier.padding(8.dp)) {
buildView(item)
Button({ itemsList.remove(item) }, Modifier.padding(8.dp)) {
CommonText(removeItemText)
CommonText(removeItemText,)
}
}
}

View File

@ -0,0 +1,68 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.OutlinedButton
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.inmo.kmppscriptbuilder.core.models.GpgSigning
import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonTextField
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
import dev.inmo.kmppscriptbuilder.core.ui.utils.SwitchWithLabel
actual object MavenInfoDrawer : Drawer<MavenInfoView> {
@Composable
private fun MavenInfoView.addGpgSigningButton(gpgSigning: GpgSigning) {
if (gpgSignProperty == gpgSigning) {
Button({}, Modifier.padding(8.dp)) {
Text(gpgSigning.name)
}
} else {
OutlinedButton(
{
gpgSignProperty = gpgSigning
},
Modifier.padding(8.dp)
) {
Text(gpgSigning.name)
}
}
}
override fun MavenInfoView.draw() {
CommonTextField(
projectNameProperty,
"Public project name"
) { projectNameProperty = it }
CommonTextField(
projectDescriptionProperty,
"Public project description"
) { projectDescriptionProperty = it }
CommonTextField(
projectUrlProperty,
"Public project URL"
) { projectUrlProperty = it }
CommonTextField(
projectVcsUrlProperty,
"Public project VCS URL (with .git)"
) { projectVcsUrlProperty = it }
Row(verticalAlignment = Alignment.CenterVertically) {
Text("Gpg Signing: ")
addGpgSigningButton(GpgSigning.Disabled)
addGpgSigningButton(GpgSigning.Optional)
addGpgSigningButton(GpgSigning.Enabled)
}
SwitchWithLabel(
"Include publication to MavenCentral",
publishToMavenCentralProperty,
placeSwitchAtTheStart = true
) { publishToMavenCentralProperty = it }
developersView.init()
repositoriesView.init()
}
}

View File

@ -0,0 +1,44 @@
package dev.inmo.kmppscriptbuilder.core.ui
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.OutlinedButton
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.inmo.kmppscriptbuilder.core.models.JSProjectType
import dev.inmo.kmppscriptbuilder.core.models.JVMProjectType
import dev.inmo.kmppscriptbuilder.core.models.MultiplatformProjectType
import dev.inmo.kmppscriptbuilder.core.models.ProjectType
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
actual object ProjectTypeDrawer : Drawer<ProjectTypeView> {
@Composable
private fun ProjectTypeView.addProjectTypeButton(newProjectType: ProjectType) {
if (projectType == newProjectType) {
Button({}, Modifier.padding(8.dp)) {
Text(newProjectType.name)
}
} else {
OutlinedButton(
{
projectType = newProjectType
},
Modifier.padding(8.dp)
) {
Text(newProjectType.name)
}
}
}
override fun ProjectTypeView.draw() {
Row(verticalAlignment = Alignment.CenterVertically) {
addProjectTypeButton(MultiplatformProjectType)
addProjectTypeButton(JVMProjectType)
addProjectTypeButton(JSProjectType)
}
}
}

View File

@ -0,0 +1,18 @@
package dev.inmo.kmppscriptbuilder.core.ui
import dev.inmo.kmppscriptbuilder.core.ui.utils.CommonTextField
import dev.inmo.kmppscriptbuilder.core.ui.utils.Drawer
actual object RepositoryStateDrawer : Drawer<RepositoriesView> {
override fun RepositoriesView.draw() {
CommonTextField(
item.name,
"Repository name"
) { item.name = it }
CommonTextField(
item.url,
"Repository url"
) { item.url = it }
}
}

View File

@ -37,7 +37,7 @@ actual fun SwitchWithLabel(
switchCreator()
}
Box(Modifier.fillMaxWidth().align(Alignment.CenterVertically).clickable { }) {
CommonText(label)
CommonText(label,)
}
if (!placeSwitchAtTheStart) {
switchCreator()
@ -53,14 +53,14 @@ actual fun CommonTextField(presetText: String, hint: String, onChange: (String)
Modifier.fillMaxWidth(),
singleLine = true,
label = {
CommonText(hint)
CommonText(hint,)
}
)
}
@Composable
actual fun CommonText(text: String) {
Text(text)
actual fun CommonText(text: String, onClick: (() -> Unit)?) {
Text(text, modifier = Modifier.run { onClick ?.let { clickable(onClick = it) } ?: this })
}
@Composable