|
|
|
|
@ -6,10 +6,12 @@ import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_new_session.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableAdapter |
|
|
|
|
@ -22,10 +24,10 @@ import net.pokeranalytics.android.ui.fragment.components.DateTimePickerManager |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
class NewSessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate { |
|
|
|
|
class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, BottomSheetDelegate { |
|
|
|
|
|
|
|
|
|
private lateinit var currentSession: Session |
|
|
|
|
private lateinit var sessionAdapterRow : RowRepresentableAdapter |
|
|
|
|
private lateinit var sessionAdapter : RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_new_session, container, false) |
|
|
|
|
@ -33,15 +35,24 @@ class NewSessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, B |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
initData() |
|
|
|
|
initUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(row: RowRepresentable) { |
|
|
|
|
val data = currentSession.getBottomSheetData(row) |
|
|
|
|
when (row) { |
|
|
|
|
SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(), row, this, currentSession.timeFrame?.startDate) |
|
|
|
|
SessionRow.END_DATE -> DateTimePickerManager.create(requireContext(), row, this, currentSession.timeFrame?.endDate) |
|
|
|
|
SessionRow.START_DATE -> DateTimePickerManager.create( |
|
|
|
|
requireContext(), |
|
|
|
|
row, |
|
|
|
|
this, |
|
|
|
|
currentSession.timeFrame?.startDate |
|
|
|
|
) |
|
|
|
|
SessionRow.END_DATE -> DateTimePickerManager.create( |
|
|
|
|
requireContext(), |
|
|
|
|
row, |
|
|
|
|
this, |
|
|
|
|
currentSession.timeFrame?.endDate |
|
|
|
|
) |
|
|
|
|
else -> BottomSheetFragment.create(fragmentManager, row, this, data) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -59,47 +70,13 @@ class NewSessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, B |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun clickOnClear(row: RowRepresentable) { |
|
|
|
|
when(row) { |
|
|
|
|
SessionRow.GAME -> currentSession.game = null |
|
|
|
|
SessionRow.BANKROLL -> currentSession.bankroll = null |
|
|
|
|
SessionRow.LOCATION -> currentSession.location = null |
|
|
|
|
SessionRow.BLINDS -> { |
|
|
|
|
currentSession.cgSmallBlind = null |
|
|
|
|
currentSession.cgBigBlind = null |
|
|
|
|
} |
|
|
|
|
SessionRow.COMMENT -> currentSession.comment = "" |
|
|
|
|
SessionRow.START_DATE -> currentSession.timeFrame?.setDate(Date(), null) |
|
|
|
|
SessionRow.END_DATE -> currentSession.timeFrame?.setDate(Date(), null) |
|
|
|
|
} |
|
|
|
|
sessionAdapterRow.notifyItemChanged(SessionRow.values().indexOf(row)) |
|
|
|
|
currentSession.updateValue(null, row) |
|
|
|
|
sessionAdapter.refreshRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun setValue(value: Any, row: RowRepresentable) { |
|
|
|
|
when(row) { |
|
|
|
|
SessionRow.GAME -> if (value is Game) currentSession.game = value |
|
|
|
|
SessionRow.BANKROLL -> if (value is Bankroll) currentSession.bankroll = value |
|
|
|
|
SessionRow.LOCATION -> if (value is Location) currentSession.location = value |
|
|
|
|
SessionRow.COMMENT -> if (value is String) currentSession.comment = value |
|
|
|
|
SessionRow.BLINDS -> if (value is ArrayList<*>) { |
|
|
|
|
currentSession.cgSmallBlind = (value[0] as String? ?: "0").toDouble() |
|
|
|
|
currentSession.cgBigBlind = (value[1] as String? ?: "0").toDouble() |
|
|
|
|
} |
|
|
|
|
SessionRow.START_DATE -> if (value is Date) { |
|
|
|
|
val timeFrame = currentSession.timeFrame ?: TimeFrame() |
|
|
|
|
timeFrame.setDate(value, null) |
|
|
|
|
currentSession.timeFrame = timeFrame |
|
|
|
|
} |
|
|
|
|
SessionRow.END_DATE -> if (value is Date) { |
|
|
|
|
val timeFrame = currentSession.timeFrame ?: TimeFrame() |
|
|
|
|
timeFrame.setDate(timeFrame.startDate, value) |
|
|
|
|
currentSession.timeFrame = timeFrame |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sessionAdapterRow.notifyItemChanged(SessionRow.values().indexOf(row)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
|
currentSession = Session() |
|
|
|
|
currentSession.updateValue(value, row) |
|
|
|
|
sessionAdapter.refreshRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -112,12 +89,12 @@ class NewSessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, B |
|
|
|
|
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) |
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
sessionAdapterRow = RowRepresentableAdapter(currentSession, this) |
|
|
|
|
sessionAdapter = RowRepresentableAdapter(currentSession, this) |
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
adapter = sessionAdapterRow |
|
|
|
|
adapter = sessionAdapter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -125,8 +102,22 @@ class NewSessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, B |
|
|
|
|
/** |
|
|
|
|
* Set fragment data |
|
|
|
|
*/ |
|
|
|
|
fun setData(isTournament: Boolean) { |
|
|
|
|
fun setData(isTournament: Boolean, sessionId: String) { |
|
|
|
|
toolbar.title = if (isTournament) "Tournament" else "Cash game" |
|
|
|
|
|
|
|
|
|
val realm = getRealm() |
|
|
|
|
val sessionRealm = realm.where<Session>().equalTo("id", sessionId).findFirst() |
|
|
|
|
if (sessionRealm != null) { |
|
|
|
|
currentSession = sessionRealm |
|
|
|
|
} else { |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
currentSession = realm.createObject(Session::class.java, UUID.randomUUID().toString()) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sessionAdapter = RowRepresentableAdapter(currentSession, this) |
|
|
|
|
recyclerView.adapter = sessionAdapter |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |