parent
62c24590f0
commit
15db3c4d3a
@ -0,0 +1,48 @@ |
||||
package net.pokeranalytics.android.ui.activity |
||||
|
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import androidx.fragment.app.Fragment |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.ui.activity.components.BaseActivity |
||||
import net.pokeranalytics.android.ui.activity.components.RequestCode |
||||
import net.pokeranalytics.android.ui.fragment.HandHistoryFragment |
||||
|
||||
class HandHistoryActivity : BaseActivity() { |
||||
|
||||
enum class IntentKey(val keyName: String) { |
||||
IDENTIFIER("identifier") |
||||
} |
||||
|
||||
companion object { |
||||
|
||||
fun newInstance(fragment: Fragment, id: String?) { |
||||
val intent = Intent(fragment.requireContext(), DataListActivity::class.java) |
||||
id?.let { intent.putExtra(IntentKey.IDENTIFIER.keyName, it) } |
||||
fragment.startActivityForResult(intent, RequestCode.NEW_HAND_HISTORY.value) |
||||
} |
||||
|
||||
} |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(R.layout.activity_hand_history) |
||||
|
||||
initUI() |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
val fragmentTransaction = supportFragmentManager.beginTransaction() |
||||
|
||||
val handHistoryId = intent.getStringExtra(IntentKey.IDENTIFIER.keyName) |
||||
val fragment = HandHistoryFragment.newInstance(handHistoryId) |
||||
fragmentTransaction.add(R.id.container, fragment) |
||||
fragmentTransaction.commit() |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,112 @@ |
||||
package net.pokeranalytics.android.ui.fragment |
||||
|
||||
import android.os.Bundle |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.lifecycle.ViewModelProviders |
||||
import androidx.recyclerview.widget.LinearLayoutManager |
||||
import kotlinx.android.synthetic.main.fragment_settings.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
||||
import net.pokeranalytics.android.model.handhistory.HHBuilder |
||||
import net.pokeranalytics.android.model.handhistory.HandSetup |
||||
import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
||||
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
||||
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||
import net.pokeranalytics.android.ui.viewmodel.HandHistoryViewModel |
||||
import net.pokeranalytics.android.util.extensions.findById |
||||
|
||||
class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepresentableDelegate { |
||||
|
||||
private lateinit var model: HandHistoryViewModel |
||||
|
||||
private lateinit var handHistoryAdapter: RowRepresentableAdapter |
||||
|
||||
private var rows: List<RowRepresentable> = listOf() |
||||
|
||||
companion object { |
||||
|
||||
fun newInstance(id: String? = null): HandHistoryFragment { |
||||
val fragment = HandHistoryFragment() |
||||
val bundle = Bundle() |
||||
bundle.putSerializable(BundleKey.PRIMARY_KEY.value, id) |
||||
fragment.arguments = bundle |
||||
return fragment |
||||
} |
||||
|
||||
} |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
|
||||
model = activity?.run { |
||||
ViewModelProviders.of(this)[HandHistoryViewModel::class.java] |
||||
} ?: throw Exception("Invalid Activity") |
||||
|
||||
} |
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||
return inflater.inflate(R.layout.fragment_hand_history, container, false) |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
initData() |
||||
initUI() |
||||
} |
||||
|
||||
private fun initData() { |
||||
|
||||
val handHistoryId = this.arguments?.getString(BundleKey.PRIMARY_KEY.value) |
||||
val builder = handHistoryId?.let { |
||||
val handHistory = getRealm().findById<HandHistory>(it) ?: throw PAIllegalStateException("HandHistory not found") |
||||
HHBuilder(handHistory) |
||||
} ?: run { |
||||
HHBuilder(HandSetup()) |
||||
} |
||||
this.model.setBuilder(builder) |
||||
|
||||
} |
||||
|
||||
private fun initUI() { |
||||
|
||||
setToolbarTitle(getString(R.string.hand_history)) |
||||
|
||||
setDisplayHomeAsUpEnabled(true) |
||||
|
||||
val viewManager = LinearLayoutManager(requireContext()) |
||||
handHistoryAdapter = RowRepresentableAdapter(this, this) |
||||
|
||||
recyclerView.apply { |
||||
setHasFixedSize(true) |
||||
layoutManager = viewManager |
||||
adapter = handHistoryAdapter |
||||
} |
||||
|
||||
this.rows = this.model.builder.value?.rowRepresentables() ?: listOf() |
||||
|
||||
} |
||||
|
||||
// RowRepresentableDataSource |
||||
|
||||
override fun adapterRows(): List<RowRepresentable>? { |
||||
return this.rows |
||||
} |
||||
|
||||
override fun rowRepresentableForPosition(position: Int): RowRepresentable? { |
||||
return this.rows[position] |
||||
} |
||||
|
||||
override fun numberOfRows(): Int { |
||||
return this.rows.size |
||||
} |
||||
|
||||
override fun viewTypeForPosition(position: Int): Int { |
||||
return this.rows[position].viewType |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
package net.pokeranalytics.android.ui.view.handhistory |
||||
|
||||
import net.pokeranalytics.android.model.handhistory.Street |
||||
import net.pokeranalytics.android.model.realm.handhistory.Card |
||||
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||
|
||||
class StreetHeader(var street: Street, var cards: List<Card>, var potSize: Double) : RowRepresentable { |
||||
|
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
package net.pokeranalytics.android.ui.viewmodel |
||||
|
||||
import androidx.lifecycle.MutableLiveData |
||||
import androidx.lifecycle.ViewModel |
||||
import net.pokeranalytics.android.model.handhistory.HHBuilder |
||||
|
||||
class HandHistoryViewModel : ViewModel() { |
||||
|
||||
var builder = MutableLiveData<HHBuilder>() |
||||
|
||||
fun setBuilder(builder: HHBuilder) { |
||||
this.builder.value = builder |
||||
} |
||||
|
||||
fun test() { |
||||
// this.builder. |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,7 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:id="@+id/container" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
</FrameLayout> |
||||
@ -0,0 +1,27 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<androidx.core.widget.NestedScrollView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:fillViewport="true" |
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"> |
||||
|
||||
<FrameLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recyclerView" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clipToPadding="false" /> |
||||
|
||||
</FrameLayout> |
||||
|
||||
</androidx.core.widget.NestedScrollView> |
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
||||
@ -0,0 +1,6 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:orientation="vertical" android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,6 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:orientation="vertical" android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
</LinearLayout> |
||||
Loading…
Reference in new issue