Improve Player management

feature/players
Aurelien Hubert 7 years ago
parent 047a08c2a0
commit f1423257b1
  1. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt
  2. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/PlayerDataFragment.kt
  3. 18
      app/src/main/java/net/pokeranalytics/android/ui/view/PlayerImageView.kt
  4. 31
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  5. 81
      app/src/main/res/layout/row_player.xml

@ -3,13 +3,16 @@ package net.pokeranalytics.android.model.realm
import android.content.Context
import io.realm.Realm
import io.realm.RealmObject
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.interfaces.Deletable
import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus
import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.PlayerRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT
@ -33,6 +36,8 @@ open class Player : RealmObject(), NameManageable, Deletable, StaticRowRepresent
// The name of the player
override var name: String = ""
@Ignore
override val viewType: Int = RowViewType.ROW_PLAYER.ordinal
// New fields
var summary: String = ""
@ -41,11 +46,13 @@ open class Player : RealmObject(), NameManageable, Deletable, StaticRowRepresent
override fun isValidForDelete(realm: Realm): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
//TODO
return true
}
override fun getFailedDeleteMessage(status: DeleteValidityStatus): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
//TODO
return R.string.relationship_error
}
override fun adapterRows(): List<RowRepresentable>? {
@ -81,7 +88,7 @@ open class Player : RealmObject(), NameManageable, Deletable, StaticRowRepresent
/**
* Return if the player has a picture
*/
fun hasPicture() : Boolean {
fun hasPicture(): Boolean {
return picture != null && picture?.isNotEmpty() == true
}

@ -17,6 +17,7 @@ import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.PlayerRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import net.pokeranalytics.android.util.NULL_TEXT
import timber.log.Timber
import java.io.File
/**
@ -34,6 +35,7 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
shouldOpenKeyboard = false
return inflater.inflate(R.layout.fragment_player, container, false)
}
@ -89,6 +91,7 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
}
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
Timber.d("onRowSelected")
when (row) {
PlayerRow.PLAYER_IMAGE -> {
openPictureDialog()
@ -113,6 +116,10 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
*/
private fun initUI() {
mediaActivity = parentActivity as MediaActivity?
if (!deleteButtonShouldAppear) {
onRowSelected(0, SimpleRow.NAME)
}
}
/**
@ -124,7 +131,9 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
val placesArray = ArrayList<CharSequence>()
placesArray.add(getString(R.string.take_a_picture))
placesArray.add(getString(R.string.library))
placesArray.add(getString(R.string.select_a_color))
// TODO
//placesArray.add(getString(R.string.select_a_color))
if (player.hasPicture()) {
placesArray.add(getString(R.string.remove_picture))
@ -135,8 +144,6 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou
0 -> mediaActivity?.openImageCaptureIntent(false)
1 -> mediaActivity?.openImageGalleryIntent(false)
2 -> {
}
3 -> {
player.updateValue(null, PlayerRow.PLAYER_IMAGE)
rowRepresentableAdapter.refreshRow(PlayerRow.PLAYER_IMAGE)
}

@ -3,6 +3,7 @@ package net.pokeranalytics.android.ui.view
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
import android.util.TypedValue
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.constraintlayout.widget.ConstraintLayout
@ -22,6 +23,19 @@ import net.pokeranalytics.android.util.NULL_TEXT
*/
class PlayerImageView : FrameLayout {
enum class Size {
NORMAL,
SMALL;
fun getFontSize(): Float {
return when (this) {
NORMAL -> 32f
SMALL -> 16f
}
}
}
private lateinit var playerImageView: ConstraintLayout
private var onImageClickListener: OnClickListener? = null
@ -54,7 +68,7 @@ class PlayerImageView : FrameLayout {
/**
* Set the session data to the view
*/
fun setPlayer(player: Player) {
fun setPlayer(player: Player, size: Size = Size.NORMAL) {
// Initial
val playerInitial = if (player.name.isNotEmpty()) {
@ -70,6 +84,7 @@ class PlayerImageView : FrameLayout {
NULL_TEXT
}
playerImageView.playerInitial.text = playerInitial
playerImageView.playerInitial.setTextSize(TypedValue.COMPLEX_UNIT_SP, size.getFontSize())
// Picture
if (player.hasPicture()) {
@ -83,6 +98,7 @@ class PlayerImageView : FrameLayout {
} else {
playerImageView.playerStroke.background = ResourcesCompat.getDrawable(resources, R.drawable.circle_stroke_kaki, null)
playerImageView.playerImage.setImageDrawable(null)
}
// Stroke

@ -79,6 +79,7 @@ enum class RowViewType(private var layoutRes: Int) {
// Custom row
ROW_SESSION(R.layout.row_feed_session),
ROW_TRANSACTION(R.layout.row_transaction),
ROW_PLAYER(R.layout.row_player),
ROW_PLAYER_IMAGE(R.layout.row_player_image),
ROW_BUTTON(R.layout.row_button),
ROW_FOLLOW_US(R.layout.row_follow_us),
@ -113,6 +114,8 @@ enum class RowViewType(private var layoutRes: Int) {
// Row Transaction
ROW_TRANSACTION -> RowTransactionViewHolder(layout)
ROW_PLAYER -> RowPlayerViewHolder(layout)
ROW_PLAYER_IMAGE -> RowPlayerImageViewHolder(layout)
// Row Button
@ -518,12 +521,38 @@ enum class RowViewType(private var layoutRes: Int) {
}
}
/**
* Display a player image view
*/
inner class RowPlayerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {
if (row is Player) {
itemView.findViewById<PlayerImageView?>(R.id.playerImage)?.let { playerImageView ->
playerImageView.setPlayer(row, PlayerImageView.Size.SMALL)
}
itemView.findViewById<AppCompatTextView?>(R.id.playerName)?.let { textView ->
textView.text = row.name
}
itemView.findViewById<AppCompatTextView?>(R.id.playerSummary)?.let { textView ->
textView.text = row.summary
textView.isVisible = row.summary.isNotEmpty()
}
val listener = View.OnClickListener {
adapter.delegate?.onRowSelected(position, row)
}
itemView.setOnClickListener(listener)
}
}
}
/**
* Display a player image view
*/
inner class RowPlayerImageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {
itemView.findViewById<PlayerImageView>(R.id.playerImageView)?.let { playerImageView ->
itemView.findViewById<PlayerImageView?>(R.id.playerImageView)?.let { playerImageView ->
val listener = View.OnClickListener {
adapter.delegate?.onRowSelected(position, PlayerRow.PLAYER_IMAGE)
}

@ -0,0 +1,81 @@
<?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="@color/gray_dark"
android:foreground="?selectableItemBackground">
<net.pokeranalytics.android.ui.view.PlayerImageView
android:id="@+id/playerImage"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
app:layout_constraintStart_toStartOf="@id/guidelineStart"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:minHeight="48dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/nextArrow"
app:layout_constraintStart_toEndOf="@+id/playerImage"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/playerName"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
tools:text="John Smith" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/playerSummary"
style="@style/PokerAnalyticsTheme.TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:maxLines="3"
android:textColor="@color/kaki_lighter"
android:visibility="visible"
tools:text="Summary" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/nextArrow"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_arrow_right"
android:tint="@color/gray_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/guidelineEnd"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="16dp" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="8dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save