commit
236a9d1cb1
@ -0,0 +1,33 @@ |
||||
package net.pokeranalytics.android.ui.activity |
||||
|
||||
import android.content.Context |
||||
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.PokerAnalyticsActivity |
||||
|
||||
class Top10Activity : PokerAnalyticsActivity() { |
||||
|
||||
companion object { |
||||
fun newInstance(context: Context) { |
||||
val intent = Intent(context, Top10Activity::class.java) |
||||
context.startActivity(intent) |
||||
} |
||||
|
||||
/** |
||||
* Create a new instance for result |
||||
*/ |
||||
fun newInstanceForResult(fragment: Fragment, requestCode: Int) { |
||||
val intent = Intent(fragment.requireContext(), Top10Activity::class.java) |
||||
fragment.startActivityForResult(intent, requestCode) |
||||
} |
||||
|
||||
} |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(R.layout.activity_top_10) |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,147 @@ |
||||
package net.pokeranalytics.android.ui.fragment |
||||
|
||||
import android.os.Bundle |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import com.google.android.material.tabs.TabLayout |
||||
import io.realm.RealmResults |
||||
import io.realm.Sort |
||||
import io.realm.kotlin.where |
||||
import kotlinx.android.synthetic.main.fragment_top_10.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
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.view.RowViewType |
||||
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager |
||||
|
||||
|
||||
class Top10Fragment : RealmFragment(), RowRepresentableDataSource, RowRepresentableDelegate { |
||||
|
||||
private enum class Tab { |
||||
CASH_GAMES, |
||||
TOURNAMENTS |
||||
} |
||||
|
||||
companion object { |
||||
fun newInstance(): Top10Fragment { |
||||
val fragment = Top10Fragment() |
||||
val bundle = Bundle() |
||||
fragment.arguments = bundle |
||||
return fragment |
||||
} |
||||
} |
||||
|
||||
private lateinit var dataListAdapter: RowRepresentableAdapter |
||||
private lateinit var realmCashGames: RealmResults<Session> |
||||
private lateinit var realmTournaments: RealmResults<Session> |
||||
|
||||
private var currentTab: Tab = Tab.CASH_GAMES |
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
||||
super.onCreateView(inflater, container, savedInstanceState) |
||||
return inflater.inflate(R.layout.fragment_top_10, container, false) |
||||
} |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
initUI() |
||||
initData() |
||||
} |
||||
|
||||
/** |
||||
* Init data |
||||
*/ |
||||
private fun initData() { |
||||
|
||||
this.realmCashGames = getRealm().where<Session>() |
||||
.equalTo("type", Session.Type.CASH_GAME.ordinal) |
||||
.greaterThanOrEqualTo("result.net", 0.0) |
||||
.sort("result.net", Sort.DESCENDING) |
||||
.limit(10) |
||||
.findAll() |
||||
this.realmCashGames.addChangeListener { _, _ -> |
||||
this.dataListAdapter.notifyDataSetChanged() |
||||
} |
||||
|
||||
this.realmTournaments = getRealm().where<Session>() |
||||
.equalTo("type", Session.Type.TOURNAMENT.ordinal) |
||||
.greaterThanOrEqualTo("result.net", 0.0) |
||||
.sort("result.net", Sort.DESCENDING) |
||||
.limit(10) |
||||
.findAll() |
||||
this.realmTournaments.addChangeListener { _, _ -> |
||||
this.dataListAdapter.notifyDataSetChanged() |
||||
} |
||||
|
||||
dataListAdapter = RowRepresentableAdapter(this, this) |
||||
recyclerView.adapter = dataListAdapter |
||||
} |
||||
|
||||
override fun adapterRows(): List<RowRepresentable>? { |
||||
return when (currentTab) { |
||||
Tab.CASH_GAMES -> realmCashGames |
||||
Tab.TOURNAMENTS -> realmTournaments |
||||
} |
||||
} |
||||
|
||||
override fun rowRepresentableForPosition(position: Int): RowRepresentable? { |
||||
return when (currentTab) { |
||||
Tab.CASH_GAMES -> realmCashGames[position] |
||||
Tab.TOURNAMENTS -> realmTournaments[position] |
||||
} |
||||
} |
||||
|
||||
override fun numberOfRows(): Int { |
||||
return when (currentTab) { |
||||
Tab.CASH_GAMES -> realmCashGames.size |
||||
Tab.TOURNAMENTS -> realmTournaments.size |
||||
} |
||||
} |
||||
|
||||
override fun viewTypeForPosition(position: Int): Int { |
||||
return RowViewType.ROW_TOP_10.ordinal |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
setDisplayHomeAsUpEnabled(true) |
||||
|
||||
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
||||
override fun onTabSelected(tab: TabLayout.Tab) { |
||||
when (tab.position) { |
||||
0 -> { |
||||
currentTab = Tab.CASH_GAMES |
||||
dataListAdapter.notifyDataSetChanged() |
||||
} |
||||
1 -> { |
||||
currentTab = Tab.TOURNAMENTS |
||||
} |
||||
} |
||||
dataListAdapter.notifyDataSetChanged() |
||||
} |
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab) { |
||||
} |
||||
|
||||
override fun onTabReselected(tab: TabLayout.Tab) { |
||||
} |
||||
}) |
||||
|
||||
|
||||
val viewManager = SmoothScrollLinearLayoutManager(requireContext()) |
||||
recyclerView.apply { |
||||
setHasFixedSize(true) |
||||
layoutManager = viewManager |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
<vector android:height="24dp" android:tint="#FFFFFF" |
||||
android:viewportHeight="24.0" android:viewportWidth="24.0" |
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<path android:fillColor="#FF000000" android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z"/> |
||||
</vector> |
||||
@ -0,0 +1,15 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:orientation="vertical"> |
||||
|
||||
<fragment |
||||
android:id="@+id/top10Fragment" |
||||
android:name="net.pokeranalytics.android.ui.fragment.Top10Fragment" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:layout="@layout/fragment_session" /> |
||||
|
||||
</LinearLayout> |
||||
@ -0,0 +1,72 @@ |
||||
<?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:id="@+id/container" |
||||
android:animateLayoutChanges="true" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.activity.HomeActivity"> |
||||
|
||||
<com.google.android.material.appbar.AppBarLayout |
||||
android:id="@+id/appBar" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:theme="@style/PokerAnalyticsTheme.Toolbar.Session" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent"> |
||||
|
||||
<androidx.appcompat.widget.Toolbar |
||||
android:id="@+id/toolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="?attr/actionBarSize" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:title="@string/top_10" /> |
||||
|
||||
<com.google.android.material.tabs.TabLayout |
||||
android:id="@+id/tabs" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:tabMode="fixed"> |
||||
|
||||
<com.google.android.material.tabs.TabItem |
||||
android:id="@+id/filterSessions" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/cash_games" /> |
||||
|
||||
<com.google.android.material.tabs.TabItem |
||||
android:id="@+id/filterTransactions" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/tournaments" /> |
||||
|
||||
</com.google.android.material.tabs.TabLayout> |
||||
|
||||
</com.google.android.material.appbar.AppBarLayout> |
||||
|
||||
<FrameLayout |
||||
android:id="@+id/selectedFilter" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:visibility="gone" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/appBar" /> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recyclerView" |
||||
android:layout_width="0dp" |
||||
android:layout_height="0dp" |
||||
android:clipToPadding="false" |
||||
android:paddingBottom="16dp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/selectedFilter" |
||||
tools:listitem="@layout/row_top_10" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
@ -0,0 +1,129 @@ |
||||
<?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="wrap_content" |
||||
android:background="?selectableItemBackground"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/gameResult" |
||||
style="@style/PokerAnalyticsTheme.TextView.Top10Row.Result" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:gravity="center" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
tools:text="$ 1000" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/sessionDate" |
||||
style="@style/PokerAnalyticsTheme.TextView.Top10Row" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_marginBottom="8dp" |
||||
android:gravity="center" |
||||
app:layout_constraintTop_toBottomOf="@+id/gameResult" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
tools:text="July 22th, 2019" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/sessionGameType" |
||||
style="@style/PokerAnalyticsTheme.TextView.Top10Row" |
||||
android:layout_height="wrap_content" |
||||
android:layout_width="match_parent" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="4dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:gravity="center" |
||||
app:layout_constraintTop_toBottomOf="@+id/sessionDate" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
tools:text="$300 NL Hold'em" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:layout_constraintTop_toBottomOf="@+id/sessionGameType" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
android:gravity="center"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:id="@+id/sessionInfoDurationIcon" |
||||
android:layout_width="20dp" |
||||
android:layout_height="20dp" |
||||
android:layout_marginStart="8dp" |
||||
android:src="@drawable/clock" |
||||
android:tint="@color/kaki_lighter" |
||||
android:visibility="gone" |
||||
tools:visibility="visible" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/sessionInfoDuration" |
||||
style="@style/PokerAnalyticsTheme.TextView.Top10Row" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:ellipsize="end" |
||||
android:maxLines="1" |
||||
android:textColor="@color/kaki_lighter" |
||||
tools:text="4:21" |
||||
tools:visibility="visible" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:id="@+id/sessionInfoLocationIcon" |
||||
android:layout_width="20dp" |
||||
android:layout_height="20dp" |
||||
android:layout_marginStart="8dp" |
||||
android:src="@drawable/pin" |
||||
android:tint="@color/kaki_lighter" |
||||
android:visibility="gone" |
||||
tools:visibility="visible" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/sessionInfoLocation" |
||||
style="@style/PokerAnalyticsTheme.TextView.Top10Row" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:ellipsize="end" |
||||
android:maxLines="1" |
||||
android:textColor="@color/kaki_lighter" |
||||
tools:text="Rennes, France" |
||||
tools:visibility="visible" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:id="@+id/sessionInfoTableSizeIcon" |
||||
android:layout_width="20dp" |
||||
android:layout_height="20dp" |
||||
android:layout_marginStart="8dp" |
||||
android:src="@drawable/info" |
||||
android:tint="@color/kaki_lighter" |
||||
android:visibility="gone" |
||||
tools:visibility="visible" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/sessionInfoTableSize" |
||||
style="@style/PokerAnalyticsTheme.TextView.Top10Row" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:ellipsize="end" |
||||
android:maxLines="1" |
||||
android:textColor="@color/kaki_lighter" |
||||
tools:text="Rennes, France" |
||||
tools:visibility="visible" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
Loading…
Reference in new issue