Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 22, 2023
1 parent a6134fc commit e8da0b4
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -104,12 +105,13 @@ class GalleryRowHolder(

thumbnail.run {
LinearLayout.LayoutParams(defaultThumbnailSize.toInt(), defaultThumbnailSize.toInt())
setImageDrawable(placeholder)
}
thumbnail.setImageDrawable(placeholder)

val layout = LinearLayout(context).apply {
addView(thumbnail)
}

binding.rowLayout.addView(layout)
}

Expand Down Expand Up @@ -164,6 +166,8 @@ class GalleryRowHolder(
val linearLayout = binding.rowLayout[index] as LinearLayout
val thumbnail = linearLayout[0] as ImageView

setMargins(row, index, thumbnail)

val imageUrl = getImageUrl(file)
val placeholder = getPlaceholder(file, size.first, size.second)

Expand All @@ -188,6 +192,18 @@ class GalleryRowHolder(
}
}

private fun setMargins(row: GalleryRow, index: Int, thumbnail: ImageView) {
val params = thumbnail.layoutParams as ViewGroup.MarginLayoutParams
val zero = context.resources.getInteger(R.integer.zero)
val margin = context.resources.getInteger(R.integer.small_margin)
if (index < (row.files.size - 1)) {
params.setMargins(zero, zero, margin, margin)
} else {
params.setMargins(zero, zero, zero, margin)
}
thumbnail.layoutParams = params
}

private fun getImageUrl(file: OCFile): String {
return baseUri.toString() +
previewLink +
Expand Down

0 comments on commit e8da0b4

Please sign in to comment.