Fix crashing on Artists or Albums or Songs list

This commit is contained in:
Hemanth S 2020-05-21 05:09:47 +05:30
parent 7db515bb16
commit 021e98d044
3 changed files with 21 additions and 14 deletions

View file

@ -2,6 +2,7 @@ package code.name.monkey.retromusic.adapter.album
import android.app.ActivityOptions
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.MenuItem
@ -47,13 +48,12 @@ open class AlbumAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
println("onCreateViewHolder $itemLayoutRes")
itemLayoutRes = if (itemLayoutRes >= -1) {
itemLayoutRes
} else {
R.layout.item_grid
val view =
try {
LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
} catch (e: Resources.NotFoundException) {
LayoutInflater.from(activity).inflate(R.layout.item_grid, parent, false)
}
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
return createViewHolder(view, viewType)
}

View file

@ -2,6 +2,7 @@ package code.name.monkey.retromusic.adapter.artist
import android.app.ActivityOptions
import android.content.res.ColorStateList
import android.content.res.Resources
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
@ -47,12 +48,12 @@ class ArtistAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
itemLayoutRes = if (itemLayoutRes >= -1) {
itemLayoutRes
} else {
R.layout.item_grid_circle
val view =
try {
LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
} catch (e: Resources.NotFoundException) {
LayoutInflater.from(activity).inflate(R.layout.item_grid_circle, parent, false)
}
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
return createViewHolder(view)
}

View file

@ -2,6 +2,7 @@ package code.name.monkey.retromusic.adapter.song
import android.app.ActivityOptions
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.MenuItem
@ -63,7 +64,12 @@ open class SongAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
val view =
try {
LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)
} catch (e: Resources.NotFoundException) {
LayoutInflater.from(activity).inflate(R.layout.item_list, parent, false)
}
return createViewHolder(view)
}