Fixed null and -1 strings

This commit is contained in:
Bnyro 2022-05-16 20:14:27 +02:00
parent af62aa7df2
commit fef5589534
4 changed files with 10 additions and 24 deletions

View File

@ -65,13 +65,11 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){
val channelImage = v.findViewById<ImageView>(R.id.search_channel_image) val channelImage = v.findViewById<ImageView>(R.id.search_channel_image)
Picasso.get().load(item.uploaderAvatar).fit().centerCrop().into(channelImage) Picasso.get().load(item.uploaderAvatar).fit().centerCrop().into(channelImage)
val title = v.findViewById<TextView>(R.id.search_description) val title = v.findViewById<TextView>(R.id.search_description)
if (item.title!!.length > 60) { title.text = if (item.title!!.length > 60) item.title?.substring(0, 60) + "..." else item.title
title.text = item.title?.substring(0, 60) + "..."
} else {
title.text = item.title
}
val views = v.findViewById<TextView>(R.id.search_views) val views = v.findViewById<TextView>(R.id.search_views)
views.text = item.views.formatShort() +""+item.uploadedDate val viewsString = if (item.views?.toInt() != -1) item.views.formatShort() else ""
val uploadDate = if (item.uploadedDate != null) item.uploadedDate else ""
views.text = if (viewsString != "" && uploadDate != "") viewsString + "" + uploadDate else viewsString + uploadDate
val channelName = v.findViewById<TextView>(R.id.search_channel_name) val channelName = v.findViewById<TextView>(R.id.search_channel_name)
channelName.text = item.uploaderName channelName.text = item.uploaderName
v.setOnClickListener{ v.setOnClickListener{
@ -111,13 +109,13 @@ class CustomViewHolder1(private val v: View): RecyclerView.ViewHolder(v){
val playlistImage = v.findViewById<ImageView>(R.id.search_thumbnail) val playlistImage = v.findViewById<ImageView>(R.id.search_thumbnail)
Picasso.get().load(item.thumbnail).fit().centerCrop().into(playlistImage) Picasso.get().load(item.thumbnail).fit().centerCrop().into(playlistImage)
val playlistNumber = v.findViewById<TextView>(R.id.search_playlist_number) val playlistNumber = v.findViewById<TextView>(R.id.search_playlist_number)
playlistNumber.text = item.videos.toString() if (item.videos?.toInt() != -1) playlistNumber.text = item.videos.toString()
val playlistName = v.findViewById<TextView>(R.id.search_description) val playlistName = v.findViewById<TextView>(R.id.search_description)
playlistName.text = item.name playlistName.text = item.name
val playlistChannelName = v.findViewById<TextView>(R.id.search_name) val playlistChannelName = v.findViewById<TextView>(R.id.search_name)
playlistChannelName.text = item.uploaderName playlistChannelName.text = item.uploaderName
val playlistVideosNumber = v.findViewById<TextView>(R.id.search_playlist_videos) val playlistVideosNumber = v.findViewById<TextView>(R.id.search_playlist_videos)
playlistVideosNumber.text = item.videos.toString()+" videos" if (item.videos?.toInt() != -1) playlistVideosNumber.text = v.context.getString(R.string.videoCount, item.videos.toString())
v.setOnClickListener { v.setOnClickListener {
//playlist clicked //playlist clicked
val activity = v.context as MainActivity val activity = v.context as MainActivity

View File

@ -43,21 +43,17 @@
android:id="@+id/search_playlist_number" android:id="@+id/search_playlist_number"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="10" android:layout_centerInParent="true"
android:textColor="#ECE4E4"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_centerHorizontal="true" android:textColor="#ECE4E4" />
/>
<ImageView <ImageView
android:id="@+id/imageView" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_playlist"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@+id/search_playlist_number" android:layout_below="@+id/search_playlist_number"
/> android:layout_centerInParent="true"
app:srcCompat="@drawable/ic_playlist" />
</RelativeLayout> </RelativeLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
@ -67,7 +63,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_playlist" app:layout_constraintStart_toEndOf="@+id/card_playlist"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -77,7 +72,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_playlist" app:layout_constraintStart_toEndOf="@+id/card_playlist"
app:layout_constraintTop_toBottomOf="@+id/search_description" /> app:layout_constraintTop_toBottomOf="@+id/search_description" />
@ -86,7 +80,6 @@
android:id="@+id/search_playlist_videos" android:id="@+id/search_playlist_videos"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline" app:layout_constraintStart_toStartOf="@+id/guideline"

View File

@ -50,7 +50,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -60,7 +59,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toBottomOf="@+id/channel_description" /> app:layout_constraintTop_toBottomOf="@+id/channel_description" />

View File

@ -53,7 +53,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -63,7 +62,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail" app:layout_constraintStart_toEndOf="@+id/card_search_thumbnail"
app:layout_constraintTop_toBottomOf="@+id/search_description" /> app:layout_constraintTop_toBottomOf="@+id/search_description" />
@ -83,7 +81,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/search_channel_image" app:layout_constraintStart_toEndOf="@+id/search_channel_image"
app:layout_constraintTop_toBottomOf="@+id/search_views" /> app:layout_constraintTop_toBottomOf="@+id/search_views" />