|
|
|
|
@ -8,15 +8,14 @@ import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.filter.Filterable |
|
|
|
|
import net.pokeranalytics.android.model.filter.Query |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.CountableUsage |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Deletable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
|
import net.pokeranalytics.android.ui.interfaces.FilterableType |
|
|
|
|
import net.pokeranalytics.android.ui.view.ImageDecorator |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow |
|
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -24,7 +23,7 @@ import java.util.* |
|
|
|
|
* It contains a list of [FilterCondition] describing the complete query to launch |
|
|
|
|
* The [Filter] is working closely with a [Filterable] interface providing the entity we want the query being launched on |
|
|
|
|
*/ |
|
|
|
|
open class Filter : RealmObject(), RowRepresentable, Identifiable, Deletable, ImageDecorator { |
|
|
|
|
open class Filter : RealmObject(), RowRepresentable, Identifiable, Deletable, CountableUsage, ImageDecorator { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
@ -61,25 +60,20 @@ open class Filter : RealmObject(), RowRepresentable, Identifiable, Deletable, Im |
|
|
|
|
|
|
|
|
|
// the queryWith name |
|
|
|
|
var name: String = "" |
|
|
|
|
get() { |
|
|
|
|
if (field.isEmpty()) { |
|
|
|
|
return this.query.defaultName |
|
|
|
|
} |
|
|
|
|
return field |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// the number of use of the queryWith, |
|
|
|
|
// for MutableRealmInteger, see https://realm.io/docs/java/latest/#counters |
|
|
|
|
val usageCount: MutableRealmInteger = MutableRealmInteger.valueOf(0) |
|
|
|
|
override var useCount: Int = 0 |
|
|
|
|
|
|
|
|
|
var filterConditions: RealmList<FilterCondition> = RealmList() |
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
private var filterableTypeOrdinal: Int? = null |
|
|
|
|
|
|
|
|
|
override val viewType: Int |
|
|
|
|
get() = RowViewType.TITLE_VALUE_ACTION.ordinal |
|
|
|
|
override val imageRes: Int? |
|
|
|
|
get() = R.drawable.ic_outline_settings |
|
|
|
|
override val imageTint: Int? |
|
|
|
|
get() = R.color.green |
|
|
|
|
override val imageClickable: Boolean? |
|
|
|
|
get() = true |
|
|
|
|
|
|
|
|
|
val filterableType: FilterableType |
|
|
|
|
get() { |
|
|
|
|
this.filterableTypeOrdinal?.let { |
|
|
|
|
@ -180,10 +174,10 @@ open class Filter : RealmObject(), RowRepresentable, Identifiable, Deletable, Im |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun isValidForDelete(context: Context, realm: Realm): Boolean { |
|
|
|
|
return id != Preferences.getActiveFilterId(context) |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun getFailedDeleteMessage(status: DeleteValidityStatus): Int { |
|
|
|
|
return R.string.filter_currently_selected |
|
|
|
|
return R.string.relationship_error |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|