Skip to content

Commit

Permalink
💄 Improve UI experience
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Feb 2, 2020
1 parent 9688248 commit e5de2da
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SongRecyclerViewAdapter(
private val values: MutableList<MusicInfo> = ArrayList()
private var filteredItemList: MutableList<MusicInfo> = values
var currentDifficulty: TW5Difficulty = TW5Difficulty.Master
var listView: RecyclerView? = null

init {
onClickListener = View.OnClickListener { v ->
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)

}
}
}
Expand All @@ -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()
Expand Down Expand Up @@ -208,11 +231,13 @@ class SongRecyclerViewAdapter(
fun sortBy(sortType: SortType) {
this.sortType = sortType
filteredItemList.sortByDescending {
sortType.condition(it,currentDifficulty) as Comparable<Any>
sortType.condition(it, currentDifficulty) as Comparable<Any>
}
notifyDataSetChanged()
scrollToIndex()
}

var userFilter: SongFilter = SongFilter()
var sortType: SortType = SortType.Alphabetical
var currentMusicIDIndex : Int = 0
}
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/shape_gradient_disabled.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/gray"
android:gradientRadius="30dp"
android:startColor="@color/dkgray"
android:type="radial" />
<corners android:radius="@dimen/btn_corner_radius" />
<stroke
android:color="@android:color/black"
android:width="0dp" />
</shape>

14 changes: 14 additions & 0 deletions app/src/main/res/drawable/shape_gradient_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/gray"
android:gradientRadius="30dp"
android:startColor="@color/white"
android:type="radial" />
<corners android:radius="@dimen/btn_corner_radius" />
<stroke
android:color="@android:color/black"
android:width="0dp" />
</shape>

14 changes: 14 additions & 0 deletions app/src/main/res/drawable/shape_gradient_selected.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/green"
android:gradientRadius="30dp"
android:startColor="@color/white"
android:type="radial" />
<corners android:radius="@dimen/btn_corner_radius" />
<stroke
android:color="@android:color/white"
android:width="1dp" />
</shape>

9 changes: 9 additions & 0 deletions app/src/main/res/layout/song_list_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="green">#53DE6A</color>
<color name="blue">#536ADE</color>
<color name="yellow">#FACC43</color>
<color name="gray">#BBBBBB</color>
<color name="white">#FFFFFF</color>
<color name="dkgray">#888888</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<dimen name="app_bar_height">200dp</dimen>
<dimen name="item_width">200dp</dimen>
<dimen name="text_margin">16dp</dimen>
<dimen name="btn_corner_radius">8dp</dimen>
</resources>

0 comments on commit e5de2da

Please sign in to comment.