Skip to content

Commit

Permalink
enumerate values for alignment endstate
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Dec 21, 2023
1 parent 7f7bf1b commit 306a7ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
29 changes: 18 additions & 11 deletions app/src/main/java/com/sduduzog/slimlauncher/adapters/HomeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ import com.sduduzog.slimlauncher.R
import com.sduduzog.slimlauncher.models.HomeApp
import com.sduduzog.slimlauncher.utils.OnLaunchAppListener

/**
* Corresponding to the resulting gravity, not the option key
*/
enum class Alignment (val value: Int) {
LEFT(3),
RIGHT(5),
CENTER(1)
}

class HomeAdapter(private val listener: OnLaunchAppListener)
: RecyclerView.Adapter<HomeAdapter.ViewHolder>() {

private var apps: List<HomeApp> = listOf()
private var gravity: Int = 3
private var gravity: Alignment = Alignment.LEFT

constructor(listener: OnLaunchAppListener, alignment: Int) : this(listener) {
setAlignment(alignment)
Expand All @@ -28,7 +36,7 @@ class HomeAdapter(private val listener: OnLaunchAppListener)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = apps.elementAt(position)
holder.mLabelView.text = item.appNickname ?: item.appName
holder.mLabelView.gravity = gravity
holder.mLabelView.gravity = gravity.value
holder.mLabelView.setOnClickListener {
listener.onLaunch(item, it)
}
Expand All @@ -41,19 +49,18 @@ class HomeAdapter(private val listener: OnLaunchAppListener)
notifyDataSetChanged()
}

fun getGravity(): Int = gravity
fun getGravity(): Alignment = gravity

fun setGravity(gravity: Int) {
fun setGravity(gravity: Alignment) {
this.gravity = gravity
}

fun setAlignment(alignment: Int) {
if (alignment == 2) // right
gravity = 5
else if (alignment == 1) // center
gravity = 1
else // left
gravity = 3
private fun setAlignment(alignment: Int) {
gravity = when (alignment) {
2 -> Alignment.RIGHT
1 -> Alignment.CENTER
else -> Alignment.LEFT
}
}

inner class ViewHolder(mView: View) : RecyclerView.ViewHolder(mView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import java.text.SimpleDateFormat
import java.util.*
import javax.inject.Inject


@AndroidEntryPoint
class HomeFragment : BaseFragment(), OnLaunchAppListener {
@Inject
Expand Down

0 comments on commit 306a7ee

Please sign in to comment.