-
Notifications
You must be signed in to change notification settings - Fork 1
Improve score widget #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdrlzy
wants to merge
6
commits into
main
Choose a base branch
from
feature/score-widget-improve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve score widget #106
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3c9e2cd
Improve score widget
mdrlzy 04c4b97
Extract dependency to versions.toml
mdrlzy 1e562ae
Wrap setupIndexAndScoreStorage with Dispatchers.IO
mdrlzy fe5d59c
Fix select another resource
mdrlzy cc74810
Handle file not found in index
mdrlzy b207baf
Padding can be added from both compose and xml
mdrlzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
138 changes: 138 additions & 0 deletions
138
sample/src/main/java/dev/arkbuilders/sample/ScoreActivity.kt
This file contains hidden or 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,138 @@ | ||
| package dev.arkbuilders.sample | ||
|
|
||
| import android.os.Bundle | ||
| import android.widget.Toast | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.ComposeView | ||
| import androidx.compose.ui.unit.DpSize | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.lifecycle.lifecycleScope | ||
| import com.google.android.material.button.MaterialButton | ||
| import dev.arkbuilders.arklib.data.folders.FoldersRepo | ||
| import dev.arkbuilders.arklib.data.index.ResourceIndex | ||
| import dev.arkbuilders.arklib.data.index.ResourceIndexRepo | ||
| import dev.arkbuilders.arklib.user.score.ScoreStorage | ||
| import dev.arkbuilders.arklib.user.score.ScoreStorageRepo | ||
| import dev.arkbuilders.components.filepicker.ArkFilePickerConfig | ||
| import dev.arkbuilders.components.filepicker.ArkFilePickerFragment | ||
| import dev.arkbuilders.components.filepicker.ArkFilePickerMode | ||
| import dev.arkbuilders.components.filepicker.onArkPathPicked | ||
| import dev.arkbuilders.components.scorewidget.HorizontalScoreWidgetComposable | ||
| import dev.arkbuilders.components.scorewidget.ScoreWidgetController | ||
| import dev.arkbuilders.components.scorewidget.VerticalScoreWidgetComposable | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.launch | ||
| import kotlinx.coroutines.withContext | ||
| import java.nio.file.Path | ||
| import kotlin.io.path.name | ||
|
|
||
| class ScoreActivity : AppCompatActivity() { | ||
| private var rootFolder: Path? = null | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_score) | ||
|
|
||
| val btnPickRoot = findViewById<MaterialButton>(R.id.btn_pick_root) | ||
| val btnPickResource = findViewById<MaterialButton>(R.id.btn_pick_resource) | ||
|
|
||
| supportFragmentManager.onArkPathPicked( | ||
| this, | ||
| customRequestKey = PICK_ROOT_KEY | ||
| ) { root -> | ||
| rootFolder = root | ||
| btnPickRoot.text = root.name | ||
| } | ||
|
|
||
| supportFragmentManager.onArkPathPicked( | ||
| this, | ||
| customRequestKey = PICK_RESOURCE_KEY | ||
| ) { resourcePath -> | ||
| rootFolder?.let { | ||
| onResourcePicked(root = it, resourcePath) | ||
| } | ||
| } | ||
|
|
||
| btnPickRoot.setOnClickListener { | ||
| ArkFilePickerFragment | ||
| .newInstance(ArkFilePickerConfig(pathPickedRequestKey = PICK_ROOT_KEY)) | ||
| .show(supportFragmentManager, null) | ||
| } | ||
|
|
||
| btnPickResource.setOnClickListener { | ||
| ArkFilePickerFragment | ||
| .newInstance( | ||
| ArkFilePickerConfig( | ||
| pathPickedRequestKey = PICK_RESOURCE_KEY, | ||
| mode = ArkFilePickerMode.FILE | ||
| ) | ||
| ).show(supportFragmentManager, null) | ||
| } | ||
| } | ||
|
|
||
| private fun onResourcePicked( | ||
| root: Path, | ||
| resourcePath: Path | ||
| ) = lifecycleScope.launch { | ||
| val (index, scoreStorage) = setupIndexAndScoreStorage(root) | ||
| val id = index.allPaths().toList() | ||
| .find { it.second == resourcePath }?.first | ||
|
|
||
| id ?: let { | ||
| Toast.makeText( | ||
| this@ScoreActivity, | ||
| "File does not belong to root", | ||
| Toast.LENGTH_SHORT | ||
| ).show() | ||
| return@launch | ||
| } | ||
|
|
||
| findViewById<MaterialButton>(R.id.btn_pick_resource).text = resourcePath.name | ||
|
|
||
| val scoreWidgetController = ScoreWidgetController( | ||
| lifecycleScope, | ||
| getCurrentId = { id }, | ||
| onScoreChanged = {} | ||
| ) | ||
| scoreWidgetController.init(scoreStorage) | ||
|
|
||
| val horizontal = findViewById<ComposeView>(R.id.score_widget_horizontal) | ||
| val vertical = findViewById<ComposeView>(R.id.score_widget_vertical) | ||
|
|
||
| horizontal.disposeComposition() | ||
| horizontal.setContent { | ||
| HorizontalScoreWidgetComposable( | ||
| size = DpSize(200.dp, 80.dp), | ||
| controller = scoreWidgetController | ||
| ) | ||
| } | ||
|
|
||
| vertical.disposeComposition() | ||
| vertical.setContent { | ||
| VerticalScoreWidgetComposable( | ||
| modifier = Modifier.padding(40.dp), | ||
| size = DpSize(50.dp, 120.dp), | ||
| controller = scoreWidgetController | ||
| ) | ||
| } | ||
|
|
||
| scoreWidgetController.setVisible(true) | ||
| scoreWidgetController.displayScore() | ||
| } | ||
|
|
||
| private suspend fun setupIndexAndScoreStorage( | ||
| root: Path | ||
| ): Pair<ResourceIndex, ScoreStorage> = withContext(Dispatchers.IO) { | ||
| val foldersRepo = FoldersRepo(applicationContext) | ||
| val index = ResourceIndexRepo(foldersRepo).provide(root) | ||
| val scoreStorage = ScoreStorageRepo(lifecycleScope).provide(index) | ||
| return@withContext index to scoreStorage | ||
| } | ||
|
|
||
| companion object { | ||
| private val PICK_ROOT_KEY = "pickRootKey" | ||
| private val PICK_RESOURCE_KEY = "pickResourceKey" | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,45 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <com.google.android.material.button.MaterialButton | ||
| android:id="@+id/btn_pick_root" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="12dp" | ||
| android:text="Pick root" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent" /> | ||
|
|
||
| <com.google.android.material.button.MaterialButton | ||
| android:id="@+id/btn_pick_resource" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="12dp" | ||
| android:text="Pick resource" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toBottomOf="@id/btn_pick_root" /> | ||
|
|
||
| <androidx.compose.ui.platform.ComposeView | ||
| android:id="@+id/score_widget_horizontal" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:padding="70dp" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toBottomOf="@id/btn_pick_resource" /> | ||
|
|
||
| <androidx.compose.ui.platform.ComposeView | ||
| android:id="@+id/score_widget_vertical" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toBottomOf="@id/score_widget_horizontal" /> | ||
|
|
||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> |
This file contains hidden or 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
34 changes: 0 additions & 34 deletions
34
scorewidget/src/main/java/dev/arkbuilders/components/scorewidget/ScoreWidget.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setupIndexAndScoreStorageis asuspendfunction so it should be scheduled in background thread. It's now running inmain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was sure that initialization of
IndexandScoreStorageoccurs onDispatcher.IO, butScoreStoragedoes not change dispatcher :/