diff --git a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongRecyclerViewAdapter.kt b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongRecyclerViewAdapter.kt index 454f431..46e9bac 100644 --- a/app/src/main/java/com/kyhsgeekcode/dereinfo/SongRecyclerViewAdapter.kt +++ b/app/src/main/java/com/kyhsgeekcode/dereinfo/SongRecyclerViewAdapter.kt @@ -31,6 +31,7 @@ class SongRecyclerViewAdapter( private val values: MutableList = ArrayList() private var filteredItemList: MutableList = values var currentDifficulty: TW5Difficulty = TW5Difficulty.Master + var listView: RecyclerView? = null init { onClickListener = View.OnClickListener { v -> @@ -60,6 +61,7 @@ class SongRecyclerViewAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val view = LayoutInflater.from(parent.context) .inflate(R.layout.song_list_content, parent, false) + listView = parent as RecyclerView return ViewHolder(view) } @@ -78,28 +80,41 @@ class SongRecyclerViewAdapter( } val statistic = DereDatabaseHelper.theInstance.musicInfoIDToStatistic[item.id] val currentStatistic = statistic?.get(currentDifficulty) - Log.d(TAG,"statistic:${currentStatistic.toString()}") + Log.d(TAG, "statistic:${currentStatistic.toString()}") with(holder) { if (currentStatistic != null) { tvLevel.text = """lv.${currentStatistic[StatisticIndex.Level]?.toInt() ?: "??"}""" - tvConditionValue.text = currentStatistic[sortType.getStatisticIndex()]?.formatCleanPercent(2) + tvConditionValue.text = + currentStatistic[sortType.getStatisticIndex()]?.formatCleanPercent(2) } else { tvLevel.text = "-" tvConditionValue.text = "-" } for (button in layoutDifficulties.children) { if (button is Button) { + val btnDifficulty = TW5Difficulty.fromString(button.text.toString()) button.isEnabled = - statistic?.containsKey(TW5Difficulty.fromString(button.text.toString())) == true - button.setOnClickListener{ - if(twoPaneInTablet) { + statistic?.containsKey(btnDifficulty) == true + button.setOnClickListener { + currentMusicIDIndex = item.id + if (twoPaneInTablet) { //display } else { - currentDifficulty = TW5Difficulty.fromString(button.text.toString()) + currentDifficulty = btnDifficulty } sortBy(sortType) notifyDataSetChanged() + scrollToIndex() } + if (button.isEnabled) { + if (currentDifficulty == btnDifficulty) { + button.setBackgroundResource(R.drawable.shape_gradient_selected) + } else { + button.setBackgroundResource(R.drawable.shape_gradient_round) + } + } else + button.setBackgroundResource(R.drawable.shape_gradient_disabled) + } } } @@ -109,6 +124,14 @@ class SongRecyclerViewAdapter( override fun getItemCount() = filteredItemList.size + fun scrollToIndex() { + val realIndex = filteredItemList.indexOfFirst { + it.id == currentMusicIDIndex + } + if (realIndex in 0..filteredItemList.size) + listView?.scrollToPosition(realIndex) + } + fun clear() { values.clear() filteredItemList.clear() @@ -208,11 +231,13 @@ class SongRecyclerViewAdapter( fun sortBy(sortType: SortType) { this.sortType = sortType filteredItemList.sortByDescending { - sortType.condition(it,currentDifficulty) as Comparable + sortType.condition(it, currentDifficulty) as Comparable } notifyDataSetChanged() + scrollToIndex() } var userFilter: SongFilter = SongFilter() var sortType: SortType = SortType.Alphabetical + var currentMusicIDIndex : Int = 0 } diff --git a/app/src/main/res/drawable/shape_gradient_disabled.xml b/app/src/main/res/drawable/shape_gradient_disabled.xml new file mode 100644 index 0000000..897c8f4 --- /dev/null +++ b/app/src/main/res/drawable/shape_gradient_disabled.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/drawable/shape_gradient_round.xml b/app/src/main/res/drawable/shape_gradient_round.xml new file mode 100644 index 0000000..15a7bd0 --- /dev/null +++ b/app/src/main/res/drawable/shape_gradient_round.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/drawable/shape_gradient_selected.xml b/app/src/main/res/drawable/shape_gradient_selected.xml new file mode 100644 index 0000000..6f147c5 --- /dev/null +++ b/app/src/main/res/drawable/shape_gradient_selected.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/layout/song_list_content.xml b/app/src/main/res/layout/song_list_content.xml index 1f711a9..22c7baf 100644 --- a/app/src/main/res/layout/song_list_content.xml +++ b/app/src/main/res/layout/song_list_content.xml @@ -62,6 +62,7 @@ android:id="@+id/buttonDebut" android:layout_width="0dp" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Debut" app:layout_constraintEnd_toStartOf="@id/buttonRegular" app:layout_constraintStart_toStartOf="parent" @@ -71,6 +72,7 @@ android:id="@+id/buttonRegular" android:layout_width="0dp" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Regular" app:layout_constraintEnd_toStartOf="@id/buttonPro" app:layout_constraintStart_toEndOf="@id/buttonDebut" @@ -80,6 +82,7 @@ android:id="@+id/buttonPro" android:layout_width="0dp" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Pro" app:layout_constraintEnd_toStartOf="@id/buttonMaster" app:layout_constraintStart_toEndOf="@id/buttonRegular" @@ -89,6 +92,7 @@ android:id="@+id/buttonMaster" android:layout_width="0dp" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Master" app:layout_constraintEnd_toStartOf="@id/buttonMasterPlus" app:layout_constraintStart_toEndOf="@id/buttonPro" @@ -98,6 +102,7 @@ android:id="@+id/buttonMasterPlus" android:layout_width="0dp" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Master+" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/buttonMaster" @@ -107,6 +112,7 @@ android:id="@+id/buttonLight" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Light" app:layout_constraintEnd_toStartOf="@id/buttonTrick" app:layout_constraintStart_toStartOf="parent" @@ -116,6 +122,7 @@ android:id="@+id/buttonTrick" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Trick" app:layout_constraintEnd_toStartOf="@id/buttonPiano" app:layout_constraintStart_toEndOf="@id/buttonLight" @@ -125,6 +132,7 @@ android:id="@+id/buttonPiano" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Piano" app:layout_constraintEnd_toStartOf="@id/buttonForte" app:layout_constraintStart_toEndOf="@id/buttonTrick" @@ -134,6 +142,7 @@ android:id="@+id/buttonForte" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:background="@drawable/shape_gradient_round" android:text="Forte" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/buttonPiano" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6b3f6ab..f952552 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,10 @@ #008577 #00574B #D81B60 + #53DE6A + #536ADE + #FACC43 + #BBBBBB + #FFFFFF + #888888 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 4030240..f9702f5 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -8,4 +8,5 @@ 200dp 200dp 16dp + 8dp