Skip to content

Commit

Permalink
兼容知乎 api
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Dec 3, 2024
1 parent 3f0361c commit f1ca964
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class Story(
val title: String,
val hint: String,
val type: Int,
val images: List<String>,
val images: List<String>?,
@Json(name = "image_hue") val imageHue: String,
val url: String,
@Json(name = "ga_prefix") val gaPrefix: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.takwolf.android.demo.refreshandloadmore.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -28,9 +29,14 @@ class StoryListAdapter : ListAdapter<Story, StoryListAdapter.ViewHolder>(StoryDi
fun bind(story: Story) {
binding.tvTitle.text = story.title
binding.tvHint.text = story.hint
binding.imgPhoto.load(story.images[0]) {
placeholder(R.color.image_placeholder)
error(R.color.image_placeholder)
story.images?.also { images ->
binding.imgPhoto.isVisible = true
binding.imgPhoto.load(images[0]) {
placeholder(R.color.image_placeholder)
error(R.color.image_placeholder)
}
} ?: run {
binding.imgPhoto.isVisible = false
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/item_story.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginHorizontal="16dp"
app:contentPadding="8dp"
app:cardCornerRadius="2dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:layout_margin="4dp"
android:orientation="vertical">

<TextView
Expand Down Expand Up @@ -50,6 +50,7 @@
android:id="@+id/img_photo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_margin="4dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
tools:src="@color/image_placeholder"
Expand Down

0 comments on commit f1ca964

Please sign in to comment.