parent
c2f79015bc
commit
b1064100a6
@ -0,0 +1,107 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.graphics.drawable.GradientDrawable |
||||||
|
import android.util.AttributeSet |
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.widget.FrameLayout |
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
import androidx.core.content.res.ResourcesCompat |
||||||
|
import com.bumptech.glide.Glide |
||||||
|
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade |
||||||
|
import com.bumptech.glide.request.RequestOptions |
||||||
|
import kotlinx.android.synthetic.main.view_player_image.view.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.Player |
||||||
|
import net.pokeranalytics.android.ui.extensions.px |
||||||
|
import net.pokeranalytics.android.util.NULL_TEXT |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Display a row session |
||||||
|
*/ |
||||||
|
class PlayerImageView : FrameLayout { |
||||||
|
|
||||||
|
private lateinit var playerImageView: ConstraintLayout |
||||||
|
|
||||||
|
private var onImageClickListener: OnClickListener? = null |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructors |
||||||
|
*/ |
||||||
|
constructor(context: Context) : super(context) { |
||||||
|
init() |
||||||
|
} |
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { |
||||||
|
init() |
||||||
|
} |
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
||||||
|
init() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Init |
||||||
|
*/ |
||||||
|
private fun init() { |
||||||
|
val layoutInflater = LayoutInflater.from(context) |
||||||
|
playerImageView = layoutInflater.inflate(R.layout.view_player_image, this, false) as ConstraintLayout |
||||||
|
val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) |
||||||
|
addView(playerImageView, layoutParams) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set the session data to the view |
||||||
|
*/ |
||||||
|
fun setPlayer(player: Player) { |
||||||
|
|
||||||
|
// Initial |
||||||
|
val playerInitial = if (player.name.isNotEmpty()) { |
||||||
|
val playerData = player.name.split(" ") |
||||||
|
if (playerData.size > 1) { |
||||||
|
playerData[0].first().toString() + playerData[1].first().toString() |
||||||
|
} else if (player.name.length > 1) { |
||||||
|
player.name.substring(0, 2) |
||||||
|
} else { |
||||||
|
player.name.substring(0, player.name.length) |
||||||
|
} |
||||||
|
} else { |
||||||
|
NULL_TEXT |
||||||
|
} |
||||||
|
playerImageView.playerInitial.text = playerInitial |
||||||
|
|
||||||
|
// Picture |
||||||
|
if (player.picture != null && player.picture?.isNotEmpty() == true) { |
||||||
|
playerImageView.playerStroke.background = null |
||||||
|
|
||||||
|
Glide.with(this) |
||||||
|
.load(player.picture) |
||||||
|
.apply(RequestOptions().circleCrop()) |
||||||
|
.transition(withCrossFade()) |
||||||
|
.into(playerImageView.playerImage) |
||||||
|
|
||||||
|
} else { |
||||||
|
playerImageView.playerStroke.background = ResourcesCompat.getDrawable(resources, R.drawable.circle_stroke_kaki, null) |
||||||
|
} |
||||||
|
|
||||||
|
// Stroke |
||||||
|
player.color?.let { |
||||||
|
val drawable = playerImageView.playerStroke.background as GradientDrawable? |
||||||
|
drawable?.setStroke(4.px, it) |
||||||
|
} |
||||||
|
|
||||||
|
// Click listener |
||||||
|
playerImageView.playerImageSelection.setOnClickListener { |
||||||
|
onImageClickListener?.onClick(it) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set image click listener |
||||||
|
*/ |
||||||
|
fun setOnImageClickListener(onImageClickListener: OnClickListener) { |
||||||
|
this.onImageClickListener = onImageClickListener |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
<?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="@android:color/transparent"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/playerInitial" |
||||||
|
style="@style/PokerAnalyticsTheme.TextView.Player" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintDimensionRatio="1:1" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
tools:text="AH" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView |
||||||
|
android:id="@+id/playerImage" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintDimensionRatio="1:1" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView |
||||||
|
android:id="@+id/playerStroke" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintDimensionRatio="1:1" |
||||||
|
android:background="@drawable/circle_stroke_kaki" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
<View |
||||||
|
android:id="@+id/playerImageSelection" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="0dp" |
||||||
|
app:layout_constraintWidth_percent="0.7" |
||||||
|
app:layout_constraintHeight_percent="0.7" |
||||||
|
android:background="?selectableItemBackgroundBorderless" |
||||||
|
android:elevation="16dp" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue