parent
f3ec817a31
commit
9d150a9ab8
@ -0,0 +1,52 @@ |
||||
package net.pokeranalytics.android.ui.activity |
||||
|
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import io.realm.Realm |
||||
import io.realm.kotlin.where |
||||
import kotlinx.android.synthetic.main.activity_data_list.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
import net.pokeranalytics.android.ui.fragment.DataListFragment |
||||
import net.pokeranalytics.android.util.PokerAnalyticsActivity |
||||
import net.pokeranalytics.android.util.data.sessionDao |
||||
import java.util.* |
||||
|
||||
class DataListActivity : PokerAnalyticsActivity() { |
||||
|
||||
companion object { |
||||
fun newInstance(context: Context, dataType: Int) { |
||||
val intent = Intent(context, DataListActivity::class.java) |
||||
intent.putExtra("dataType", dataType) |
||||
context.startActivity(intent) |
||||
} |
||||
} |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(R.layout.activity_data_list) |
||||
|
||||
initUI() |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
val dataType = intent.getIntExtra("dataType", 0) |
||||
val fragment = dataListFragment as DataListFragment |
||||
fragment.setData(dataType) |
||||
} |
||||
|
||||
/** |
||||
* Init data |
||||
*/ |
||||
private fun initData() { |
||||
|
||||
|
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
package net.pokeranalytics.android.ui.adapter.components |
||||
|
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
|
||||
interface DataRowDelegate { |
||||
var viewType: RowViewType |
||||
fun data(position: Int) : DynamicRowInterface |
||||
fun size() : Int { return 0 } |
||||
} |
||||
|
||||
interface DataRowCallback { |
||||
fun onRowSelected(position: Int) |
||||
} |
||||
|
||||
class DataListAdapter(var delegate: DataRowDelegate, var callBackDelegate: DataRowCallback? = null) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||
|
||||
override fun getItemViewType(position: Int): Int { |
||||
return delegate.viewType.ordinal |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||
val rowViewType: RowViewType = RowViewType.values()[viewType] |
||||
return rowViewType.viewHolder(parent) |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return delegate.size() |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||
val listener = View.OnClickListener { |
||||
callBackDelegate?.onRowSelected(position) |
||||
} |
||||
(holder as DynamicHolder).bind(this.delegate.data(position), null, listener) |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,68 @@ |
||||
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 io.realm.Realm |
||||
import io.realm.Sort |
||||
import kotlinx.android.synthetic.main.fragment_new_session.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.* |
||||
import net.pokeranalytics.android.ui.adapter.components.* |
||||
import net.pokeranalytics.android.util.PokerAnalyticsFragment |
||||
|
||||
class DataListFragment : PokerAnalyticsFragment(), DataRowDelegate, DataRowCallback { |
||||
|
||||
private lateinit var dataType: DataObjectRowType |
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||
return inflater.inflate(R.layout.fragment_data_list, container, false) |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
|
||||
initData() |
||||
initUI() |
||||
} |
||||
|
||||
override var viewType: RowViewType |
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. |
||||
set(value) {} |
||||
|
||||
override fun data(position: Int): DynamicRowInterface { |
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
||||
} |
||||
|
||||
override fun onRowSelected(position: Int) { |
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. |
||||
} |
||||
|
||||
private fun initData() { |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
val viewManager = LinearLayoutManager(requireContext()) |
||||
val dataListAdapter = DataListAdapter(this, this) |
||||
|
||||
recyclerView.apply { |
||||
setHasFixedSize(true) |
||||
layoutManager = viewManager |
||||
adapter = dataListAdapter |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Set fragment data |
||||
*/ |
||||
fun setData(dataType: Int) { |
||||
this.dataType = DataObjectRowType.values()[dataType] |
||||
} |
||||
} |
||||
@ -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/dataListFragment" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:name="net.pokeranalytics.android.ui.fragment.DataListFragment" /> |
||||
|
||||
</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="Data List" |
||||
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