parent
5881045de3
commit
4ea758ad38
@ -0,0 +1,55 @@ |
|||||||
|
package net.pokeranalytics.android.ui.activity |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.calculus.Report |
||||||
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||||
|
import net.pokeranalytics.android.ui.fragment.ReportDetailsFragment |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ReportDetailsActivity : PokerAnalyticsActivity() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
// Unparcel fails when setting a custom Parcelable object on Entry so we use a static reference to passe objects |
||||||
|
private var report: Report? = null |
||||||
|
private var reportTitle: String = "" |
||||||
|
|
||||||
|
/** |
||||||
|
* Default constructor |
||||||
|
*/ |
||||||
|
fun newInstance(context: Context, report: Report, reportTitle: String) { |
||||||
|
//parameters = GraphParameters(stat, group, report) |
||||||
|
this.report = report |
||||||
|
this.reportTitle = reportTitle |
||||||
|
val intent = Intent(context, ReportDetailsActivity::class.java) |
||||||
|
context.startActivity(intent) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_report_details) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
report?.let { |
||||||
|
val fragmentTransaction = supportFragmentManager.beginTransaction() |
||||||
|
val reportDetailsFragment = ReportDetailsFragment.newInstance(it, reportTitle) |
||||||
|
fragmentTransaction.add(R.id.reportDetailsContainer, reportDetailsFragment) |
||||||
|
fragmentTransaction.commit() |
||||||
|
|
||||||
|
report = null |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,69 @@ |
|||||||
|
package net.pokeranalytics.android.ui.adapter |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.util.SparseArray |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.fragment.app.FragmentManager |
||||||
|
import androidx.fragment.app.FragmentStatePagerAdapter |
||||||
|
import androidx.viewpager.widget.PagerAdapter |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.calculus.Report |
||||||
|
import net.pokeranalytics.android.ui.fragment.GraphFragment |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
||||||
|
import java.lang.ref.WeakReference |
||||||
|
|
||||||
|
/** |
||||||
|
* Home Adapter |
||||||
|
*/ |
||||||
|
class ReportPagerAdapter(val context: Context, val fragmentManager: FragmentManager, val report: Report) : FragmentStatePagerAdapter(fragmentManager) { |
||||||
|
|
||||||
|
var weakReferences = SparseArray<WeakReference<PokerAnalyticsFragment>>() |
||||||
|
|
||||||
|
override fun getItem(position: Int): PokerAnalyticsFragment { |
||||||
|
return when (position) { |
||||||
|
0 -> GraphFragment.newInstance(report) |
||||||
|
1 -> GraphFragment.newInstance(report) |
||||||
|
2 -> GraphFragment.newInstance(report) |
||||||
|
else -> GraphFragment.newInstance() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun getCount(): Int { |
||||||
|
return 3 |
||||||
|
} |
||||||
|
|
||||||
|
override fun getPageTitle(position: Int): CharSequence? { |
||||||
|
return when(position) { |
||||||
|
0 -> context.getString(R.string.bar) |
||||||
|
1 -> context.getString(R.string.line) |
||||||
|
2 -> context.getString(R.string.table) |
||||||
|
else -> "" |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { |
||||||
|
super.destroyItem(container, position, `object`) |
||||||
|
weakReferences.remove(position) |
||||||
|
} |
||||||
|
|
||||||
|
override fun instantiateItem(container: ViewGroup, position: Int): Any { |
||||||
|
val fragment = super.instantiateItem(container, position) as PokerAnalyticsFragment |
||||||
|
weakReferences.put(position, WeakReference(fragment)) |
||||||
|
return fragment |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemPosition(obj: Any): Int { |
||||||
|
return PagerAdapter.POSITION_UNCHANGED |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return the fragment at the position key |
||||||
|
*/ |
||||||
|
fun getFragment(key: Int): PokerAnalyticsFragment? { |
||||||
|
if (weakReferences.get(key) != null) { |
||||||
|
return weakReferences.get(key).get() |
||||||
|
} |
||||||
|
return null |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,140 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import com.google.android.material.tabs.TabLayout |
||||||
|
import kotlinx.android.synthetic.main.fragment_report_details.* |
||||||
|
import kotlinx.android.synthetic.main.fragment_statistic_details.toolbar |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.calculus.AggregationType |
||||||
|
import net.pokeranalytics.android.calculus.Report |
||||||
|
import net.pokeranalytics.android.calculus.Stat |
||||||
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||||
|
import net.pokeranalytics.android.ui.adapter.ReportPagerAdapter |
||||||
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
||||||
|
|
||||||
|
class ReportDetailsFragment : PokerAnalyticsFragment() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun newInstance(report: Report?, reportTitle: String): ReportDetailsFragment { |
||||||
|
val fragment = ReportDetailsFragment() |
||||||
|
fragment.reportTitle = reportTitle |
||||||
|
report?.let { |
||||||
|
fragment.selectedReport = it |
||||||
|
} |
||||||
|
val bundle = Bundle() |
||||||
|
fragment.arguments = bundle |
||||||
|
return fragment |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private lateinit var parentActivity: PokerAnalyticsActivity |
||||||
|
//private lateinit var computableGroup: ComputableGroup |
||||||
|
//private lateinit var graphFragment: GraphFragment |
||||||
|
private lateinit var selectedReport: Report |
||||||
|
|
||||||
|
private var reports: MutableMap<AggregationType, Report> = hashMapOf() |
||||||
|
private var stat: Stat = Stat.NET_RESULT |
||||||
|
private var displayAggregationChoices: Boolean = true |
||||||
|
private var reportTitle: String = "" |
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
return inflater.inflate(R.layout.fragment_report_details, container, false) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
parentActivity = activity as PokerAnalyticsActivity |
||||||
|
|
||||||
|
// Avoid a bug during setting the title |
||||||
|
toolbar.title = "" |
||||||
|
|
||||||
|
parentActivity.setSupportActionBar(toolbar) |
||||||
|
parentActivity.supportActionBar?.setDisplayHomeAsUpEnabled(true) |
||||||
|
setHasOptionsMenu(true) |
||||||
|
|
||||||
|
toolbar.title = reportTitle |
||||||
|
|
||||||
|
val reportPagerAdapter = ReportPagerAdapter(requireContext(), parentActivity.supportFragmentManager, selectedReport) |
||||||
|
viewPager.adapter = reportPagerAdapter |
||||||
|
viewPager.offscreenPageLimit = 3 |
||||||
|
|
||||||
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
||||||
|
override fun onTabSelected(tab: TabLayout.Tab) { |
||||||
|
viewPager.setCurrentItem(tab.position, false) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab) { |
||||||
|
} |
||||||
|
|
||||||
|
override fun onTabReselected(tab: TabLayout.Tab) { |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
/* |
||||||
|
stat.aggregationTypes.firstOrNull()?.let { aggregationType -> |
||||||
|
reports[aggregationType]?.let { report -> |
||||||
|
graphFragment.setData(report, aggregationType) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
/* |
||||||
|
val aggregationTypes = stat.aggregationTypes |
||||||
|
|
||||||
|
aggregationTypes.forEachIndexed { index, type -> |
||||||
|
val chip = Chip(requireContext()) |
||||||
|
chip.id = index |
||||||
|
chip.text = requireContext().getString(type.resId) |
||||||
|
chip.chipStartPadding = 8f.px |
||||||
|
chip.chipEndPadding = 8f.px |
||||||
|
this.chipGroup.addView(chip) |
||||||
|
} |
||||||
|
|
||||||
|
this.chipGroup.isVisible = displayAggregationChoices |
||||||
|
this.chipGroup.check(0) |
||||||
|
|
||||||
|
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
||||||
|
override fun onCheckedChanged(group: ChipGroup, checkedId: Int) { |
||||||
|
super.onCheckedChanged(group, checkedId) |
||||||
|
val aggregationType = aggregationTypes[checkedId] |
||||||
|
|
||||||
|
reports[aggregationType]?.let { report -> |
||||||
|
graphFragment.setData(report, aggregationType) |
||||||
|
} ?: run { |
||||||
|
launchStatComputation(aggregationType) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
}) |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Set data |
||||||
|
*/ |
||||||
|
fun setData(report: Report) { |
||||||
|
this.selectedReport = report |
||||||
|
|
||||||
|
/* |
||||||
|
stat.aggregationTypes.firstOrNull()?.let { |
||||||
|
reports[it] = report |
||||||
|
} |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:id="@+id/reportDetailsContainer"> |
||||||
|
|
||||||
|
</FrameLayout> |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent"> |
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout |
||||||
|
android:id="@+id/appBar" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:theme="@style/PokerAnalyticsTheme.Toolbar.Session" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar |
||||||
|
android:id="@+id/toolbar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="?attr/actionBarSize" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
tools:title="@string/app_name" /> |
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout |
||||||
|
android:id="@+id/tabs" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content"> |
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem |
||||||
|
android:id="@+id/tabBar" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:text="@string/bar" /> |
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem |
||||||
|
android:id="@+id/tabLine" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:text="@string/line" /> |
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabItem |
||||||
|
android:id="@+id/tabTable" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:text="@string/table" /> |
||||||
|
|
||||||
|
</com.google.android.material.tabs.TabLayout> |
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout> |
||||||
|
|
||||||
|
<net.pokeranalytics.android.ui.view.NoPagingViewPager |
||||||
|
android:id="@+id/viewPager" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toBottomOf="@+id/appBar" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue