parent
e02b1f6253
commit
2c6c81f4d6
@ -0,0 +1,48 @@ |
|||||||
|
package net.pokeranalytics.android.ui.activity |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.content.Intent |
||||||
|
import android.os.Bundle |
||||||
|
import kotlinx.android.synthetic.main.activity_new_session.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.ui.fragment.NewSessionFragment |
||||||
|
import net.pokeranalytics.android.util.PokerAnalyticsActivity |
||||||
|
|
||||||
|
class NewSessionActivity: PokerAnalyticsActivity() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
fun newInstance(context: Context, isTournament: Boolean) { |
||||||
|
val intent = Intent(context, NewSessionActivity::class.java) |
||||||
|
intent.putExtra("is_tournament", isTournament) |
||||||
|
context.startActivity(intent) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
setContentView(R.layout.activity_new_session) |
||||||
|
|
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
val isTournament = intent.getBooleanExtra("is_tournament", false) |
||||||
|
val fragment = newSessionFragment as NewSessionFragment |
||||||
|
fragment.setData(isTournament) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init data |
||||||
|
*/ |
||||||
|
private fun initData() { |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
package net.pokeranalytics.android.ui.adapter |
||||||
|
|
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import timber.log.Timber |
||||||
|
|
||||||
|
class NewSessionAdapter(private var session: Session) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
const val ROW_SESSION: Int = 100 |
||||||
|
} |
||||||
|
|
||||||
|
//var onClickOnSession: ((position: Int) -> Unit)? = null |
||||||
|
|
||||||
|
inner class RowSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||||
|
fun bind() { |
||||||
|
Timber.d("Bind session") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||||
|
when (viewType) { |
||||||
|
ROW_SESSION -> return RowSessionViewHolder( |
||||||
|
LayoutInflater.from(parent.context).inflate( |
||||||
|
R.layout.row_history_session, |
||||||
|
parent, |
||||||
|
false |
||||||
|
) |
||||||
|
) |
||||||
|
else -> throw IllegalStateException("Need to implement type $viewType in NewSessionAdapter") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||||
|
when (getItemViewType(position)) { |
||||||
|
ROW_SESSION -> (holder as NewSessionAdapter.RowSessionViewHolder).bind() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemCount(): Int { |
||||||
|
return 2 |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemViewType(position: Int): Int { |
||||||
|
return ROW_SESSION |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,56 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment |
||||||
|
|
||||||
|
import android.os.Bundle |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import kotlinx.android.synthetic.main.fragment_new_session.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import net.pokeranalytics.android.ui.adapter.NewSessionAdapter |
||||||
|
import net.pokeranalytics.android.util.PokerAnalyticsFragment |
||||||
|
|
||||||
|
class NewSessionFragment: PokerAnalyticsFragment() { |
||||||
|
|
||||||
|
private lateinit var newSession: Session |
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||||
|
return inflater.inflate(R.layout.fragment_new_session, container, false) |
||||||
|
} |
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||||
|
super.onViewCreated(view, savedInstanceState) |
||||||
|
|
||||||
|
initData() |
||||||
|
initUI() |
||||||
|
} |
||||||
|
|
||||||
|
private fun initData() { |
||||||
|
newSession = Session() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init UI |
||||||
|
*/ |
||||||
|
private fun initUI() { |
||||||
|
|
||||||
|
val viewManager = LinearLayoutManager(requireContext()) |
||||||
|
val newSessionAdapter = NewSessionAdapter(newSession) |
||||||
|
|
||||||
|
recyclerView.apply { |
||||||
|
setHasFixedSize(true) |
||||||
|
layoutManager = viewManager |
||||||
|
adapter = newSessionAdapter |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set fragment data |
||||||
|
*/ |
||||||
|
fun setData(isTournament: Boolean) { |
||||||
|
title.text = if (isTournament) "New tournament" else "New cash game" |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<?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"> |
||||||
|
|
||||||
|
<fragment |
||||||
|
android:id="@+id/newSessionFragment" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:name="net.pokeranalytics.android.ui.fragment.NewSessionFragment" /> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
<?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"> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/title" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:text="New session" |
||||||
|
android:layout_marginTop="8dp" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
android:layout_marginEnd="8dp" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/recyclerView" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintTop_toBottomOf="@+id/title" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
android:layout_marginTop="8dp"/> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue