|
|
|
@ -7,61 +7,48 @@ import android.view.inputmethod.InputMethodManager |
|
|
|
import android.widget.EditText |
|
|
|
import android.widget.EditText |
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
import kotlinx.android.synthetic.main.fragment_progress_report.* |
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.Report |
|
|
|
import net.pokeranalytics.android.calculus.Report |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.model.CustomFieldCriteria |
|
|
|
import net.pokeranalytics.android.model.CustomFieldCriteria |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.realm.ReportSetup |
|
|
|
import net.pokeranalytics.android.model.realm.ReportSetup |
|
|
|
import net.pokeranalytics.android.ui.fragment.data.DataManagerFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.data.DataManagerFragment |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.viewmodel.ReportViewModel |
|
|
|
import net.pokeranalytics.android.util.extensions.findById |
|
|
|
import net.pokeranalytics.android.util.extensions.findById |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract class AbstractReportFragment : DataManagerFragment() { |
|
|
|
abstract class AbstractReportFragment : DataManagerFragment() { |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var _selectedReport: Report |
|
|
|
protected val viewModel: ReportViewModel by lazy { |
|
|
|
|
|
|
|
ViewModelProviders.of(requireActivity()).get(ReportViewModel::class.java) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val selectedReport: Report |
|
|
|
val selectedReport: Report |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
return this._selectedReport |
|
|
|
return this.viewModel.report!! |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun setReport(report: Report) { |
|
|
|
val stat: Stat |
|
|
|
this._selectedReport = report |
|
|
|
get() { |
|
|
|
this.primaryKey = report.options.reportSetupId |
|
|
|
return this.viewModel.stat!! |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected var reportTitle: String? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.primaryKey = this.selectedReport.options.reportSetupId |
|
|
|
this.liveDataType = LiveData.REPORT_SETUP |
|
|
|
this.liveDataType = LiveData.REPORT_SETUP |
|
|
|
this.deleteButtonShouldAppear = (this.primaryKey != null) |
|
|
|
this.deleteButtonShouldAppear = (this.primaryKey != null) |
|
|
|
} |
|
|
|
this.saveButtonShouldAppear = this.selectedReport.options.userGenerated |
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
|
|
|
|
super.onStart() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we don't want to use this._selectedReport before onActivityCreated could initialize the variable if necessary |
|
|
|
|
|
|
|
this.saveButtonShouldAppear = this._selectedReport.options.userGenerated |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
|
|
|
|
super.onActivityCreated(savedInstanceState) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!this::_selectedReport.isInitialized) { |
|
|
|
|
|
|
|
this._selectedReport = Report(Calculator.Options()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
setToolbarTitle(reportTitle) |
|
|
|
setToolbarTitle(this.viewModel.title) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun saveData() { |
|
|
|
override fun saveData() { |
|
|
|
@ -114,12 +101,13 @@ abstract class AbstractReportFragment : DataManagerFragment() { |
|
|
|
|
|
|
|
|
|
|
|
private fun saveReport(name: String) { |
|
|
|
private fun saveReport(name: String) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.viewModel.title = name |
|
|
|
|
|
|
|
val rs = this.item as ReportSetup |
|
|
|
getRealm().executeTransaction { realm -> |
|
|
|
getRealm().executeTransaction { realm -> |
|
|
|
|
|
|
|
|
|
|
|
val rs = this.item as ReportSetup |
|
|
|
|
|
|
|
val firstSave = (this.primaryKey == null) |
|
|
|
val firstSave = (this.primaryKey == null) |
|
|
|
if (firstSave) { |
|
|
|
if (firstSave) { |
|
|
|
val options = this._selectedReport.options |
|
|
|
val options = this.selectedReport.options |
|
|
|
rs.name = name |
|
|
|
rs.name = name |
|
|
|
rs.display = options.display.ordinal |
|
|
|
rs.display = options.display.ordinal |
|
|
|
options.stats.forEach { |
|
|
|
options.stats.forEach { |
|
|
|
@ -141,12 +129,11 @@ abstract class AbstractReportFragment : DataManagerFragment() { |
|
|
|
realm.insertOrUpdate(rs) |
|
|
|
realm.insertOrUpdate(rs) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.primaryKey = rs.id |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.deleteButtonShouldAppear = true |
|
|
|
|
|
|
|
toolbar.title = name |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.primaryKey = rs.id |
|
|
|
|
|
|
|
this.deleteButtonShouldAppear = true |
|
|
|
|
|
|
|
setToolbarTitle(this.viewModel.title) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |