2020-04-08 14:21:33 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.settings.logins
|
|
|
|
|
2020-07-23 01:21:31 +02:00
|
|
|
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
2020-04-08 14:21:33 +02:00
|
|
|
import org.mozilla.fenix.ext.urlToTrimmedHost
|
|
|
|
|
|
|
|
sealed class SortingStrategy {
|
2020-05-13 00:32:01 +02:00
|
|
|
abstract operator fun invoke(logins: List<SavedLogin>): List<SavedLogin>
|
2020-04-08 14:21:33 +02:00
|
|
|
|
2020-07-23 01:21:31 +02:00
|
|
|
data class Alphabetically(private val publicSuffixList: PublicSuffixList) : SortingStrategy() {
|
2020-05-13 00:32:01 +02:00
|
|
|
override fun invoke(logins: List<SavedLogin>): List<SavedLogin> {
|
2020-07-23 01:21:31 +02:00
|
|
|
return logins.sortedBy { it.origin.urlToTrimmedHost(publicSuffixList) }
|
2020-04-08 14:21:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 01:21:31 +02:00
|
|
|
object LastUsed : SortingStrategy() {
|
2020-05-13 00:32:01 +02:00
|
|
|
override fun invoke(logins: List<SavedLogin>): List<SavedLogin> {
|
2020-04-08 14:21:33 +02:00
|
|
|
return logins.sortedByDescending { it.timeLastUsed }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|