-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mod 版本信息页展示截图 * 使用RecyclerView展示截图 * 解决截图回收再重载后缩放问题
- Loading branch information
Showing
10 changed files
with
432 additions
and
8 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
106 changes: 106 additions & 0 deletions
106
FCL/src/main/java/com/tungsten/fcl/ui/download/RemoteModScreenshotAdapter.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,106 @@ | ||
package com.tungsten.fcl.ui.download | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.load.DataSource | ||
import com.bumptech.glide.load.engine.DiskCacheStrategy | ||
import com.bumptech.glide.load.engine.GlideException | ||
import com.bumptech.glide.request.RequestListener | ||
import com.bumptech.glide.request.target.Target | ||
import com.tungsten.fcl.R | ||
import com.tungsten.fcl.databinding.ViewModScreenshotBinding | ||
import com.tungsten.fclcore.mod.RemoteMod.Screenshot | ||
import com.tungsten.fclcore.util.StringUtils | ||
import com.tungsten.fcllibrary.component.view.FCLTextView | ||
|
||
|
||
class RemoteModScreenshotAdapter( | ||
val context: Context, | ||
private val screenshotList: List<Screenshot> | ||
) : | ||
RecyclerView.Adapter<RemoteModScreenshotAdapter.ScreenshotViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ScreenshotViewHolder { | ||
return ScreenshotViewHolder( | ||
DataBindingUtil.inflate( | ||
LayoutInflater.from(context), | ||
R.layout.view_mod_screenshot, | ||
parent, | ||
false | ||
) | ||
) | ||
} | ||
|
||
override fun getItemCount(): Int = screenshotList.size | ||
|
||
override fun onBindViewHolder(holder: ScreenshotViewHolder, position: Int) { | ||
holder.setScreenshot(screenshotList[position]) | ||
} | ||
|
||
class ScreenshotViewHolder(val binding: ViewModScreenshotBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun setScreenshot(screenshot: Screenshot) { | ||
binding.retry.setOnClickListener { loadScreenshotImage(screenshot.imageUrl) } | ||
|
||
binding.screenshot.setImageDrawable(null) | ||
loadScreenshotImage(screenshot.imageUrl) | ||
|
||
binding.title.setVisibleIfNotBlank(screenshot.title) | ||
binding.description.setVisibleIfNotBlank(screenshot.description) | ||
} | ||
|
||
private fun loadScreenshotImage(imageUrl: String) { | ||
binding.apply { | ||
setLoading(true) | ||
Glide.with(screenshot) | ||
.load(imageUrl) | ||
.diskCacheStrategy(DiskCacheStrategy.NONE) | ||
.fitCenter() | ||
.addListener(object : RequestListener<Drawable> { | ||
override fun onLoadFailed( | ||
e: GlideException?, | ||
model: Any?, | ||
target: Target<Drawable>, | ||
isFirstResource: Boolean | ||
): Boolean { | ||
setLoading(false) | ||
setFailed() | ||
return false | ||
} | ||
|
||
override fun onResourceReady( | ||
resource: Drawable, | ||
model: Any, | ||
target: Target<Drawable>, | ||
dataSource: DataSource, | ||
isFirstResource: Boolean | ||
): Boolean { | ||
setLoading(false) | ||
return false | ||
} | ||
}) | ||
.into(screenshot) | ||
} | ||
} | ||
|
||
private fun setLoading(loading: Boolean) { | ||
binding.loading.visibility = if (loading) View.VISIBLE else View.GONE | ||
if (loading) binding.retry.visibility = View.GONE | ||
} | ||
|
||
private fun setFailed() { | ||
binding.retry.visibility = View.VISIBLE | ||
} | ||
|
||
private fun FCLTextView.setVisibleIfNotBlank(text: String?) { | ||
visibility = if (StringUtils.isNotBlank(text)) View.VISIBLE else View.GONE | ||
this.text = text | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<com.tungsten.fcllibrary.component.view.FCLLinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<com.tungsten.fcllibrary.component.view.FCLProgressBar | ||
android:id="@+id/loading" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal"/> | ||
|
||
<com.tungsten.fcllibrary.component.view.FCLImageView | ||
android:id="@+id/screenshot" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginTop="10dp" | ||
android:scaleType="fitCenter" | ||
android:adjustViewBounds="true"/> | ||
|
||
<com.tungsten.fcllibrary.component.view.FCLImageView | ||
android:id="@+id/retry" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:scaleType="fitCenter" | ||
android:src="@drawable/ic_baseline_refresh_24" | ||
android:visibility="gone"/> | ||
|
||
<com.tungsten.fcllibrary.component.view.FCLTextView | ||
android:id="@+id/title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:gravity="center_horizontal"/> | ||
|
||
<com.tungsten.fcllibrary.component.view.FCLTextView | ||
android:id="@+id/description" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:textSize="11sp" | ||
android:gravity="center_horizontal"/> | ||
|
||
</com.tungsten.fcllibrary.component.view.FCLLinearLayout> | ||
</layout> |
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
Oops, something went wrong.