|
|
|
|
@ -4,7 +4,6 @@ import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import io.realm.Sort |
|
|
|
|
@ -20,6 +19,11 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
import net.pokeranalytics.android.util.getMonthAndYear |
|
|
|
|
import net.pokeranalytics.android.util.isSameDay |
|
|
|
|
import net.pokeranalytics.android.util.isSameMonth |
|
|
|
|
import net.pokeranalytics.android.util.longDate |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
RowRepresentableDelegate { |
|
|
|
|
@ -35,6 +39,7 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
|
|
|
|
|
private lateinit var historyAdapter: RowRepresentableAdapter |
|
|
|
|
private lateinit var realmSessions: RealmResults<Session> |
|
|
|
|
private val sessions: ArrayList<Session> = ArrayList() |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_history, container, false) |
|
|
|
|
@ -54,6 +59,10 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
override fun onResume() { |
|
|
|
|
super.onResume() |
|
|
|
|
historyAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
sessions.clear() |
|
|
|
|
sessions.addAll(getRealm().copyFromRealm(realmSessions)) |
|
|
|
|
createSessionsHeaders() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -61,7 +70,7 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
newSession.setOnClickListener { |
|
|
|
|
newCashGame.setOnClickListener { |
|
|
|
|
SessionActivity.newInstance(requireContext(), false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -69,13 +78,6 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
SessionActivity.newInstance(requireContext(), true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
newHand.setOnClickListener { |
|
|
|
|
Toast.makeText(requireContext(), "Open new hand", Toast.LENGTH_SHORT).show() |
|
|
|
|
} |
|
|
|
|
newTransaction.setOnClickListener { |
|
|
|
|
Toast.makeText(requireContext(), "Open new transaction", Toast.LENGTH_SHORT).show() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -83,9 +85,12 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
*/ |
|
|
|
|
private fun initData() { |
|
|
|
|
realmSessions = getRealm().where<Session>().findAll().sort("timeFrame.startDate", Sort.DESCENDING) |
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
historyAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
createSessionsHeaders() |
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
@ -93,12 +98,42 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create the sessions headers |
|
|
|
|
*/ |
|
|
|
|
private fun createSessionsHeaders() { |
|
|
|
|
|
|
|
|
|
val groupedByDay = false |
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
val currentCalendar = Calendar.getInstance() |
|
|
|
|
|
|
|
|
|
for ((index, session) in sessions.withIndex()) { |
|
|
|
|
currentCalendar.time = session.creationDate |
|
|
|
|
if (groupedByDay) { |
|
|
|
|
if (!calendar.isSameDay(currentCalendar) || index == 0) { |
|
|
|
|
calendar.time = currentCalendar.time |
|
|
|
|
session.displayHeader = true |
|
|
|
|
session.headerValues = arrayListOf(session.creationDate.longDate(), "$ 123") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!calendar.isSameMonth(currentCalendar) || index == 0) { |
|
|
|
|
calendar.time = currentCalendar.time |
|
|
|
|
session.displayHeader = true |
|
|
|
|
session.headerValues = arrayListOf(session.creationDate.getMonthAndYear(), "$ 123") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun rowRepresentableForPosition(position: Int): RowRepresentable { |
|
|
|
|
return this.realmSessions[position] as RowRepresentable |
|
|
|
|
return this.sessions[position] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun numberOfRows(): Int { |
|
|
|
|
return this.realmSessions.size |
|
|
|
|
return this.sessions.size |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun viewTypeForPosition(position: Int): Int { |
|
|
|
|
@ -106,7 +141,7 @@ class HistoryFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun indexForRow(row: RowRepresentable): Int { |
|
|
|
|
return this.realmSessions.indexOf(row) |
|
|
|
|
return this.sessions.indexOf(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|