|
|
|
|
@ -5,35 +5,33 @@ import android.content.Intent |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.FiltersFragment |
|
|
|
|
import net.pokeranalytics.android.ui.interfaces.FilterActivityRequestCode |
|
|
|
|
import net.pokeranalytics.android.ui.interfaces.FilterableType |
|
|
|
|
|
|
|
|
|
class FiltersActivity : PokerAnalyticsActivity() { |
|
|
|
|
|
|
|
|
|
enum class IntentKey(val keyName: String) { |
|
|
|
|
FILTER_ID("FILTER_ID"); |
|
|
|
|
FILTER_ID("FILTER_ID"), |
|
|
|
|
FILTERABLE_TYPE("FILTERABLE_TYPE"), |
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private lateinit var fragment: FiltersFragment |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
/** |
|
|
|
|
* Default constructor |
|
|
|
|
*/ |
|
|
|
|
fun newInstance(context: Context, filterId: String? = null) { |
|
|
|
|
context.startActivity(getIntent(context, filterId)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a new instance for result |
|
|
|
|
*/ |
|
|
|
|
fun newInstanceForResult(fragment: Fragment, filterId: String? = null) { |
|
|
|
|
fragment.startActivityForResult(getIntent(fragment.requireContext(), filterId), FilterActivityRequestCode.SELECT_FILTER.ordinal) |
|
|
|
|
fun newInstanceForResult(fragment: Fragment, filterId: String? = null, currentFilterable: FilterableType) { |
|
|
|
|
fragment.startActivityForResult(getIntent(fragment.requireContext(), filterId, currentFilterable), FilterActivityRequestCode.SELECT_FILTER.ordinal) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun getIntent(context:Context, filterId:String?) : Intent { |
|
|
|
|
private fun getIntent(context:Context, filterId:String?, currentFilterable: FilterableType) : Intent { |
|
|
|
|
val intent = Intent(context, FiltersActivity::class.java) |
|
|
|
|
intent.putExtra(IntentKey.FILTERABLE_TYPE.keyName, currentFilterable.ordinal) |
|
|
|
|
filterId?.let { |
|
|
|
|
intent.putExtra(IntentKey.FILTER_ID.keyName, it) |
|
|
|
|
} |
|
|
|
|
@ -59,11 +57,13 @@ class FiltersActivity : PokerAnalyticsActivity() { |
|
|
|
|
val fragmentManager = supportFragmentManager |
|
|
|
|
val fragmentTransaction = fragmentManager.beginTransaction() |
|
|
|
|
val filterId = intent.getStringExtra(IntentKey.FILTER_ID.keyName) |
|
|
|
|
val ordinal = intent.getIntExtra(IntentKey.FILTERABLE_TYPE.keyName, 0) |
|
|
|
|
val filterableType = FilterableType.values()[ordinal] |
|
|
|
|
|
|
|
|
|
fragment = FiltersFragment() |
|
|
|
|
fragmentTransaction.add(R.id.container, fragment) |
|
|
|
|
fragmentTransaction.commit() |
|
|
|
|
fragment.setData(filterId) |
|
|
|
|
fragment.setData(filterId, filterableType) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|