|
|
|
|
@ -1,6 +1,8 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
|
|
|
|
|
|
import android.app.Activity |
|
|
|
|
import android.content.ClipData |
|
|
|
|
import android.content.ClipboardManager |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Bundle |
|
|
|
|
@ -8,6 +10,7 @@ import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
@ -18,6 +21,8 @@ import kotlinx.coroutines.launch |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
|
import net.pokeranalytics.android.calculus.NewPerformanceListener |
|
|
|
|
import net.pokeranalytics.android.calculus.ReportTask |
|
|
|
|
import net.pokeranalytics.android.calculus.ReportWhistleBlower |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.calculus.calcul.ReportDisplay |
|
|
|
|
import net.pokeranalytics.android.databinding.FragmentReportsBinding |
|
|
|
|
@ -26,6 +31,7 @@ import net.pokeranalytics.android.model.combined |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Deletable |
|
|
|
|
import net.pokeranalytics.android.model.realm.Performance |
|
|
|
|
import net.pokeranalytics.android.model.realm.ReportSetup |
|
|
|
|
import net.pokeranalytics.android.model.realm.Result |
|
|
|
|
import net.pokeranalytics.android.ui.activity.ReportCreationActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.ReportActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.RequestCode |
|
|
|
|
@ -41,7 +47,7 @@ import net.pokeranalytics.android.ui.view.rows.StaticReport |
|
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import java.util.Date |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data class ReportSection(val report: StaticReport, var performances: MutableList<PerformanceRow>) { |
|
|
|
|
@ -182,10 +188,24 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
adapter = dataListAdapter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
binding.addButton.setOnClickListener { |
|
|
|
|
binding.addButton.setOnClickListener { |
|
|
|
|
ReportCreationActivity.newInstanceForResult(this, requireContext()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val sessionCount = getRealm().where(Result::class.java).count() |
|
|
|
|
binding.computeButton.isVisible = adapterRows.isEmpty() && sessionCount > 5 |
|
|
|
|
binding.computeButton.setOnClickListener { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
forceReportWhistleBlowerStart() |
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
e.message?.let { |
|
|
|
|
this.showSnackBar(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.paApplication?.reportWhistleBlower?.addListener(this) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -199,7 +219,7 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
|
|
|
|
|
private fun updateRows() { |
|
|
|
|
this.adapterRows.clear() |
|
|
|
|
if (this.reportSetups.size > 0) { |
|
|
|
|
if (this.reportSetups.isNotEmpty()) { |
|
|
|
|
adapterRows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.custom)) |
|
|
|
|
adapterRows.addAll(this.reportSetups) |
|
|
|
|
} |
|
|
|
|
@ -342,4 +362,32 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun forceReportWhistleBlowerStart() { |
|
|
|
|
|
|
|
|
|
val rwb = ReportWhistleBlower(requireContext()) |
|
|
|
|
val reportTask = ReportTask(rwb, requireContext()) |
|
|
|
|
reportTask.handler = { |
|
|
|
|
|
|
|
|
|
Timber.d("test") |
|
|
|
|
|
|
|
|
|
val paused = paApplication?.reportWhistleBlower?.paused |
|
|
|
|
reportTask.messages.add(">>> main RWB paused = $paused") |
|
|
|
|
|
|
|
|
|
val message = reportTask.messages.joinToString("\n") |
|
|
|
|
CoroutineScope(coroutineContext).launch(Dispatchers.Main) { |
|
|
|
|
Timber.d("test2") |
|
|
|
|
|
|
|
|
|
copyToClipboard(requireContext(), message) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
reportTask.start() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun copyToClipboard(context: Context, text: String) { |
|
|
|
|
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager |
|
|
|
|
val clip = ClipData.newPlainText("label", text) |
|
|
|
|
clipboard.setPrimaryClip(clip) |
|
|
|
|
} |
|
|
|
|
} |