diff --git a/app/build.gradle b/app/build.gradle index 8baf614f..ac299e58 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:3.15.7' + implementation 'com.simplemobiletools:commons:3.15.8' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt index 58fff631..ae93e6f0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt @@ -12,7 +12,6 @@ import com.simplemobiletools.clock.adapters.ViewPagerAdapter import com.simplemobiletools.clock.extensions.config import com.simplemobiletools.clock.helpers.TABS_COUNT import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN import com.simplemobiletools.commons.helpers.LICENSE_STETHO import com.simplemobiletools.commons.models.FAQItem import kotlinx.android.synthetic.main.activity_main.* @@ -148,6 +147,6 @@ class MainActivity : SimpleActivity() { FAQItem(R.string.faq_4_title_commons, R.string.faq_4_text_commons) ) - startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_STETHO, BuildConfig.VERSION_NAME, faqItems) + startAboutActivity(R.string.app_name, LICENSE_STETHO, BuildConfig.VERSION_NAME, faqItems) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt index 496606c2..a47a732c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt @@ -54,7 +54,7 @@ class StopwatchFragment : Fragment() { val lap = Lap(currentLap++, lapTicks * UPDATE_INTERVAL, totalTicks * UPDATE_INTERVAL) laps.add(0, lap) lapTicks = 0 - (stopwatch_list.adapter as StopwatchAdapter).updateItems(laps) + updateLaps() } val stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) { @@ -62,6 +62,7 @@ class StopwatchFragment : Fragment() { changeSorting(it) } } + Lap.sorting = sorting stopwatch_list.adapter = stopwatchAdapter } @@ -140,7 +141,19 @@ class StopwatchFragment : Fragment() { } private fun changeSorting(clickedValue: Int) { + sorting = if (sorting and clickedValue != 0) { + sorting.flipBit(SORT_DESCENDING) + } else { + clickedValue or SORT_DESCENDING + } + Lap.sorting = sorting + updateLaps() + } + + private fun updateLaps() { + laps.sort() + (view.stopwatch_list.adapter as StopwatchAdapter).updateItems(laps) } private val updateRunnable = object : Runnable { diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/models/Lap.kt b/app/src/main/kotlin/com/simplemobiletools/clock/models/Lap.kt index e6a4cf53..2dfc57ec 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/models/Lap.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/models/Lap.kt @@ -1,3 +1,37 @@ package com.simplemobiletools.clock.models -data class Lap(val id: Int, var lapTime: Long, var totalTime: Long) +import com.simplemobiletools.clock.helpers.SORT_BY_LAP +import com.simplemobiletools.clock.helpers.SORT_BY_LAP_TIME +import com.simplemobiletools.commons.helpers.SORT_DESCENDING + +data class Lap(val id: Int, var lapTime: Long, var totalTime: Long) : Comparable { + companion object { + var sorting = 0 + } + + override fun compareTo(other: Lap): Int { + var result = when { + sorting and SORT_BY_LAP != 0 -> when { + id == other.id -> 0 + id > other.id -> 1 + else -> -1 + } + sorting and SORT_BY_LAP_TIME != 0 -> when { + lapTime == other.lapTime -> 0 + lapTime > other.lapTime -> 1 + else -> -1 + } + else -> when { + totalTime == other.totalTime -> 0 + totalTime > other.totalTime -> 1 + else -> -1 + } + } + + if (sorting and SORT_DESCENDING != 0) { + result *= -1 + } + + return result + } +}