|
|
|
|
@ -6,6 +6,7 @@ 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.DataList |
|
|
|
|
@ -25,7 +26,7 @@ import java.util.* |
|
|
|
|
class SessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomSheetDelegate { |
|
|
|
|
|
|
|
|
|
private lateinit var currentSession: Session |
|
|
|
|
private lateinit var sessionAdapter : DynamicListAdapter |
|
|
|
|
private lateinit var sessionAdapter: DynamicListAdapter |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_new_session, container, false) |
|
|
|
|
@ -33,15 +34,24 @@ class SessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomShee |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
initData() |
|
|
|
|
initUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(row: DynamicRowInterface) { |
|
|
|
|
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) |
|
|
|
|
when (row) { |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -51,7 +61,7 @@ class SessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomShee |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun clickOnAdd(row: DynamicRowInterface) { |
|
|
|
|
when(row) { |
|
|
|
|
when (row) { |
|
|
|
|
SessionRow.GAME -> EditableDataActivity.newInstance(requireContext(), DataList.GAME.ordinal) |
|
|
|
|
SessionRow.BANKROLL -> EditableDataActivity.newInstance(requireContext(), DataList.BANKROLL.ordinal) |
|
|
|
|
SessionRow.LOCATION -> EditableDataActivity.newInstance(requireContext(), DataList.LOCATION.ordinal) |
|
|
|
|
@ -68,13 +78,6 @@ class SessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomShee |
|
|
|
|
sessionAdapter.refreshRow(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
|
val realm = getRealm() |
|
|
|
|
realm.beginTransaction() |
|
|
|
|
currentSession = realm.createObject(Session::class.java, UUID.randomUUID().toString()) |
|
|
|
|
realm.commitTransaction() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init UI |
|
|
|
|
*/ |
|
|
|
|
@ -85,12 +88,10 @@ class SessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomShee |
|
|
|
|
activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) |
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
sessionAdapter = DynamicListAdapter(currentSession, this) |
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
adapter = sessionAdapter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -98,8 +99,22 @@ class SessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomShee |
|
|
|
|
/** |
|
|
|
|
* 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 = DynamicListAdapter(currentSession, this) |
|
|
|
|
recyclerView.adapter = sessionAdapter |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |