|
|
|
@ -3,9 +3,7 @@ package net.pokeranalytics.android.ui.fragment |
|
|
|
import android.app.Activity |
|
|
|
import android.app.Activity |
|
|
|
import android.content.Intent |
|
|
|
import android.content.Intent |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.* |
|
|
|
import android.view.View |
|
|
|
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import kotlinx.android.synthetic.main.fragment_report_creation.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_report_creation.* |
|
|
|
@ -14,11 +12,14 @@ import net.pokeranalytics.android.calculus.Calculator |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.FiltersActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.ReportCreationActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.ReportCreationActivity |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.interfaces.FilterActivityRequestCode |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.interfaces.FilterableType |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
@ -29,6 +30,7 @@ class ReportCreationFragment : RealmFragment(), RowRepresentableDataSource, RowR |
|
|
|
|
|
|
|
|
|
|
|
private var assistant = Assistant() |
|
|
|
private var assistant = Assistant() |
|
|
|
private var currentRows: List<RowRepresentable> = listOf() |
|
|
|
private var currentRows: List<RowRepresentable> = listOf() |
|
|
|
|
|
|
|
private var reportCreationMenu: Menu? = null |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
@ -37,6 +39,42 @@ class ReportCreationFragment : RealmFragment(), RowRepresentableDataSource, RowR |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
|
|
|
this.initUI() |
|
|
|
|
|
|
|
this.updateUIWithCurrentStep() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
if (requestCode == FilterActivityRequestCode.CREATE_FILTER.ordinal && resultCode == Activity.RESULT_OK) { |
|
|
|
|
|
|
|
this.updateUIWithCurrentStep() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { |
|
|
|
|
|
|
|
super.onCreateOptionsMenu(menu, inflater) |
|
|
|
|
|
|
|
menu?.clear() |
|
|
|
|
|
|
|
inflater?.inflate(R.menu.toolbar_report_creation, menu) |
|
|
|
|
|
|
|
menu?.findItem(R.id.add)?.isVisible = false |
|
|
|
|
|
|
|
reportCreationMenu = menu |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
|
|
|
|
|
|
|
when (item?.itemId) { |
|
|
|
|
|
|
|
R.id.add -> { |
|
|
|
|
|
|
|
if (this.assistant.step == Assistant.Step.FILTER) { |
|
|
|
|
|
|
|
FiltersActivity.newInstanceForResult(this, currentFilterable = FilterableType.SESSION, hideMostUsedFilters = true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Init UI |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
|
|
|
|
|
|
|
|
this.optionsAdapter = RowRepresentableAdapter(this, this) |
|
|
|
this.optionsAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
|
|
@ -47,8 +85,6 @@ class ReportCreationFragment : RealmFragment(), RowRepresentableDataSource, RowR |
|
|
|
adapter = optionsAdapter |
|
|
|
adapter = optionsAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.updateUIWithCurrentStep() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.next.setOnClickListener { |
|
|
|
this.next.setOnClickListener { |
|
|
|
if (assistant.nextEnabled) { |
|
|
|
if (assistant.nextEnabled) { |
|
|
|
this.assistant.nextStep() |
|
|
|
this.assistant.nextStep() |
|
|
|
@ -68,23 +104,17 @@ class ReportCreationFragment : RealmFragment(), RowRepresentableDataSource, RowR |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun finishActivityWithOptions(options: Calculator.Options) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReportCreationActivity.options = options // temp object |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val intent = Intent() |
|
|
|
|
|
|
|
activity?.setResult(Activity.RESULT_OK, intent) |
|
|
|
|
|
|
|
activity?.finish() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Update UI when changing the current step |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun updateUIWithCurrentStep() { |
|
|
|
private fun updateUIWithCurrentStep() { |
|
|
|
|
|
|
|
|
|
|
|
this.next.visibility = if (this.assistant.nextButtonShouldAppear) View.VISIBLE else View.GONE |
|
|
|
this.next.visibility = if (this.assistant.nextButtonShouldAppear) View.VISIBLE else View.GONE |
|
|
|
this.next.text = requireContext().getString(this.assistant.nextButtonTitleResId) |
|
|
|
this.next.text = requireContext().getString(this.assistant.nextButtonTitleResId) |
|
|
|
this.next.isEnabled = this.assistant.nextEnabled |
|
|
|
this.next.isEnabled = this.assistant.nextEnabled |
|
|
|
|
|
|
|
this.reportCreationMenu?.findItem(R.id.add)?.isVisible = this.assistant.addButtonShouldAppear |
|
|
|
|
|
|
|
|
|
|
|
val rows = mutableListOf<RowRepresentable>() |
|
|
|
val rows = mutableListOf<RowRepresentable>() |
|
|
|
|
|
|
|
|
|
|
|
@ -99,6 +129,17 @@ class ReportCreationFragment : RealmFragment(), RowRepresentableDataSource, RowR |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Finish activity |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun finishActivityWithOptions(options: Calculator.Options) { |
|
|
|
|
|
|
|
ReportCreationActivity.options = options // temp object |
|
|
|
|
|
|
|
val intent = Intent() |
|
|
|
|
|
|
|
activity?.setResult(Activity.RESULT_OK, intent) |
|
|
|
|
|
|
|
activity?.finish() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RowRepresentableDataSource |
|
|
|
// RowRepresentableDataSource |
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
@ -261,6 +302,7 @@ class Assistant { |
|
|
|
} |
|
|
|
} |
|
|
|
Step.COMPARATOR -> Criteria.all |
|
|
|
Step.COMPARATOR -> Criteria.all |
|
|
|
Step.FILTER -> { |
|
|
|
Step.FILTER -> { |
|
|
|
|
|
|
|
val data = ArrayList<RowRepresentable>() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
val filters = Filter.sortedByUsage(realm) |
|
|
|
val filters = Filter.sortedByUsage(realm) |
|
|
|
realm.close() |
|
|
|
realm.close() |
|
|
|
@ -296,4 +338,12 @@ class Assistant { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val addButtonShouldAppear: Boolean |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
return when (this.step) { |
|
|
|
|
|
|
|
Step.FILTER -> true |
|
|
|
|
|
|
|
else -> false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |