-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5477b3f
commit 2fd2a5f
Showing
49 changed files
with
818 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
app/src/main/java/dev/brahmkshatriya/echo/ui/adapter/CategoryAdapter.kt
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
app/src/main/java/dev/brahmkshatriya/echo/ui/adapter/CategoryViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dev.brahmkshatriya.echo.ui.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.core.view.updateLayoutParams | ||
import com.google.android.material.R | ||
import com.google.android.material.color.MaterialColors | ||
import dev.brahmkshatriya.echo.common.models.Shelf | ||
import dev.brahmkshatriya.echo.databinding.ItemShelfCategoryBinding | ||
|
||
class CategoryViewHolder( | ||
val listener: ShelfAdapter.Listener, | ||
val clientId: String, | ||
val binding: ItemShelfCategoryBinding | ||
) : ShelfListItemViewHolder(binding.root) { | ||
|
||
companion object { | ||
fun create( | ||
parent: ViewGroup, | ||
listener: ShelfAdapter.Listener, | ||
clientId: String | ||
): CategoryViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return CategoryViewHolder( | ||
listener, | ||
clientId, | ||
ItemShelfCategoryBinding.inflate(inflater, parent, false) | ||
) | ||
} | ||
} | ||
|
||
override fun bind(item:Any) { | ||
if (item !is Shelf.Category) return | ||
val root = binding.root | ||
root.setCardBackgroundColor(MaterialColors.getColor(root, R.attr.colorSurfaceVariant)) | ||
root.updateLayoutParams { width = ViewGroup.LayoutParams.WRAP_CONTENT } | ||
binding.title.text = item.title | ||
binding.subtitle.text = item.subtitle | ||
binding.subtitle.isVisible = item.subtitle.isNullOrBlank().not() | ||
|
||
root.setOnClickListener { | ||
listener.onClick(clientId, item, root) | ||
} | ||
root.setOnLongClickListener { | ||
listener.onLongClick(clientId, item, root) | ||
} | ||
} | ||
|
||
override val transitionView = binding.root | ||
} |
86 changes: 86 additions & 0 deletions
86
app/src/main/java/dev/brahmkshatriya/echo/ui/adapter/GridViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.brahmkshatriya.echo.ui.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import dev.brahmkshatriya.echo.common.models.EchoMediaItem | ||
import dev.brahmkshatriya.echo.common.models.EchoMediaItem.Companion.toMediaItem | ||
import dev.brahmkshatriya.echo.common.models.Shelf | ||
import dev.brahmkshatriya.echo.common.models.Track | ||
import dev.brahmkshatriya.echo.databinding.ItemShelfMediaGridBinding | ||
import dev.brahmkshatriya.echo.databinding.NewItemMediaTitleBinding | ||
import dev.brahmkshatriya.echo.ui.adapter.MediaItemViewHolder.Companion.bind | ||
import dev.brahmkshatriya.echo.ui.adapter.MediaItemViewHolder.Companion.icon | ||
import dev.brahmkshatriya.echo.ui.adapter.MediaItemViewHolder.Companion.placeHolder | ||
import dev.brahmkshatriya.echo.utils.loadInto | ||
|
||
class GridViewHolder( | ||
val listener: ShelfAdapter.Listener, | ||
val clientId: String, | ||
val binding: ItemShelfMediaGridBinding | ||
) : ShelfListItemViewHolder(binding.root) { | ||
|
||
@SuppressLint("SetTextI18n") | ||
override fun bind(item:Any) { | ||
val media = when (item) { | ||
is EchoMediaItem -> { | ||
binding.iconContainer.isVisible = true | ||
binding.icon.setImageResource(item.icon()) | ||
binding.icon.isVisible = true | ||
binding.count.isVisible = false | ||
binding.root.setOnClickListener { | ||
listener.onClick(clientId, item, it) | ||
} | ||
binding.root.setOnLongClickListener { | ||
listener.onLongClick(clientId, item, it) | ||
} | ||
item | ||
} | ||
|
||
is Track -> { | ||
val pos = bindingAdapterPosition | ||
val shelf = shelf as Shelf.Lists.Tracks | ||
val isNumbered = shelf.isNumbered | ||
val tracks = shelf.list | ||
val media = item.toMediaItem() | ||
binding.iconContainer.isVisible = isNumbered | ||
binding.icon.isVisible = false | ||
binding.count.isVisible = isNumbered | ||
binding.count.text = (pos + 1).toString() | ||
binding.root.setOnClickListener { | ||
if (isNumbered) | ||
listener.onClick(clientId, null, tracks, pos, it) | ||
else listener.onClick(clientId, media, it) | ||
} | ||
binding.root.setOnLongClickListener { | ||
if (isNumbered) listener.onLongClick(clientId, null, tracks, pos, it) | ||
else listener.onLongClick(clientId, media, it) | ||
} | ||
media | ||
} | ||
|
||
else -> return | ||
} | ||
val titleBinding = NewItemMediaTitleBinding.bind(binding.root) | ||
titleBinding.bind(media) | ||
media.cover.loadInto(binding.imageView, media.placeHolder()) | ||
} | ||
|
||
override val transitionView = binding.root | ||
|
||
companion object { | ||
fun create( | ||
parent: ViewGroup, | ||
listener: ShelfAdapter.Listener, | ||
clientId: String | ||
): GridViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
return GridViewHolder( | ||
listener, | ||
clientId, | ||
ItemShelfMediaGridBinding.inflate(inflater, parent, false) | ||
) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/dev/brahmkshatriya/echo/ui/adapter/LifeCycleListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dev.brahmkshatriya.echo.ui.adapter | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.CallSuper | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.LifecycleRegistry | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
abstract class LifeCycleListAdapter<T : Any, Holder : LifeCycleListAdapter.Holder<T>>( | ||
diffCallback: DiffUtil.ItemCallback<T> | ||
) : ListAdapter<T, Holder>(diffCallback) { | ||
|
||
abstract fun createHolder(parent: ViewGroup, viewType: Int): Holder | ||
|
||
@CallSuper | ||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): Holder { | ||
val holder = createHolder(parent, viewType) | ||
holder.lifecycleRegistry = LifecycleRegistry(holder) | ||
return holder | ||
} | ||
|
||
@CallSuper | ||
override fun onBindViewHolder(holder: Holder, position: Int) { | ||
destroyLifeCycle(holder) | ||
holder.lifecycleRegistry = LifecycleRegistry(holder) | ||
holder.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START) | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
private fun destroyLifeCycle(holder: Holder) { | ||
if (holder.lifecycleRegistry.currentState.isAtLeast(Lifecycle.State.STARTED)) | ||
holder.lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY) | ||
} | ||
|
||
@CallSuper | ||
override fun onViewRecycled(holder: Holder) { | ||
destroyLifeCycle(holder) | ||
} | ||
|
||
abstract class Holder<T>(itemView: View) : RecyclerView.ViewHolder(itemView), LifecycleOwner { | ||
abstract fun bind(item: T) | ||
lateinit var lifecycleRegistry: LifecycleRegistry | ||
override val lifecycle get() = lifecycleRegistry | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.