Cleaning.
This commit is contained in:
parent
24a1c56fe6
commit
d684f323b8
@ -60,30 +60,16 @@ class ItemCardAdapter(private val app: Activity,
|
||||
holder.saveBtn.isLiked = itm.starred
|
||||
holder.title.text = Html.fromHtml(itm.title)
|
||||
|
||||
var sourceAndDate = itm.sourcetitle
|
||||
val d: Long
|
||||
try {
|
||||
d = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(itm.datetime).time
|
||||
sourceAndDate += " " + DateUtils.getRelativeTimeSpanString(
|
||||
d,
|
||||
Date().time,
|
||||
DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
)
|
||||
} catch (e: ParseException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
holder.sourceTitleAndDate.text = sourceAndDate
|
||||
holder.sourceTitleAndDate.text = itm.sourceAndDateText()
|
||||
|
||||
if (itm.getThumbnail(c).isEmpty()) {
|
||||
Glide.clear(holder.itemImage)
|
||||
holder.itemImage.setImageDrawable(null)
|
||||
} else {
|
||||
if (fullHeightCards) {
|
||||
Glide.with(c).load(itm.getThumbnail(c)).asBitmap().fitCenter().into(holder.itemImage)
|
||||
c.bitmapFitCenter(itm.getThumbnail(c), holder.itemImage)
|
||||
} else {
|
||||
Glide.with(c).load(itm.getThumbnail(c)).asBitmap().centerCrop().into(holder.itemImage)
|
||||
c.bitmapCenterCrop(itm.getThumbnail(c), holder.itemImage)
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,14 +84,7 @@ class ItemCardAdapter(private val app: Activity,
|
||||
.build(itm.sourcetitle.toTextDrawableString(), color)
|
||||
holder.sourceImage.setImageDrawable(drawable)
|
||||
} else {
|
||||
|
||||
Glide.with(c).load(itm.getIcon(c)).asBitmap().centerCrop().into(object : BitmapImageViewTarget(holder.sourceImage) {
|
||||
override fun setResource(resource: Bitmap) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(c.resources, resource)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
fHolder.sourceImage.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
||||
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage)
|
||||
}
|
||||
|
||||
holder.saveBtn.isLiked = itm.starred
|
||||
|
@ -36,11 +36,8 @@ import apps.amine.bou.readerforselfoss.R
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||
import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent
|
||||
import apps.amine.bou.readerforselfoss.utils.*
|
||||
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
|
||||
import apps.amine.bou.readerforselfoss.utils.openInBrowser
|
||||
import apps.amine.bou.readerforselfoss.utils.openItemUrl
|
||||
import apps.amine.bou.readerforselfoss.utils.shareLink
|
||||
|
||||
|
||||
class ItemListAdapter(private val app: Activity,
|
||||
@ -66,21 +63,7 @@ class ItemListAdapter(private val app: Activity,
|
||||
holder.saveBtn.isLiked = itm.starred
|
||||
holder.title.text = Html.fromHtml(itm.title)
|
||||
|
||||
var sourceAndDate = itm.sourcetitle
|
||||
val d: Long
|
||||
try {
|
||||
d = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(itm.datetime).time
|
||||
sourceAndDate += " " + DateUtils.getRelativeTimeSpanString(
|
||||
d,
|
||||
Date().time,
|
||||
DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
)
|
||||
} catch (e: ParseException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
holder.sourceTitleAndDate.text = sourceAndDate
|
||||
holder.sourceTitleAndDate.text = itm.sourceAndDateText()
|
||||
|
||||
if (itm.getThumbnail(c).isEmpty()) {
|
||||
val sizeInInt = 46
|
||||
@ -111,18 +94,10 @@ class ItemListAdapter(private val app: Activity,
|
||||
val drawable = builder.build(textDrawable.toString(), color)
|
||||
holder.sourceImage.setImageDrawable(drawable)
|
||||
} else {
|
||||
|
||||
val fHolder = holder
|
||||
Glide.with(c).load(itm.getIcon(c)).asBitmap().centerCrop().into(object : BitmapImageViewTarget(holder.sourceImage) {
|
||||
override fun setResource(resource: Bitmap) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(c.resources, resource)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
fHolder.sourceImage.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
||||
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage)
|
||||
}
|
||||
} else {
|
||||
Glide.with(c).load(itm.getThumbnail(c)).asBitmap().centerCrop().into(holder.sourceImage)
|
||||
c.bitmapCenterCrop(itm.getThumbnail(c), holder.sourceImage)
|
||||
}
|
||||
|
||||
if (bars[position]) holder.actionBar.visibility = View.VISIBLE else holder.actionBar.visibility = View.GONE
|
||||
|
@ -2,9 +2,7 @@ package apps.amine.bou.readerforselfoss.adapters
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.support.constraint.ConstraintLayout
|
||||
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
@ -15,8 +13,6 @@ import android.widget.Toast
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
@ -25,6 +21,7 @@ import apps.amine.bou.readerforselfoss.R
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Sources
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||
import apps.amine.bou.readerforselfoss.utils.circularBitmapDrawable
|
||||
import apps.amine.bou.readerforselfoss.utils.toTextDrawableString
|
||||
|
||||
|
||||
@ -42,7 +39,6 @@ class SourcesListAdapter(private val app: Activity,
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val itm = items[position]
|
||||
|
||||
val fHolder = holder
|
||||
if (itm.getIcon(c).isEmpty()) {
|
||||
val color = generator.getColor(itm.title)
|
||||
|
||||
@ -53,18 +49,7 @@ class SourcesListAdapter(private val app: Activity,
|
||||
.build(itm.title.toTextDrawableString(), color)
|
||||
holder.sourceImage.setImageDrawable(drawable)
|
||||
} else {
|
||||
Glide
|
||||
.with(c)
|
||||
.load(itm.getIcon(c))
|
||||
.asBitmap()
|
||||
.centerCrop()
|
||||
.into(object : BitmapImageViewTarget(holder.sourceImage) {
|
||||
override fun setResource(resource: Bitmap) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(c.resources, resource)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
fHolder.sourceImage.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
||||
c.circularBitmapDrawable(itm.getIcon(c), holder.sourceImage)
|
||||
}
|
||||
|
||||
holder.sourceTitle.text = itm.title
|
||||
|
@ -0,0 +1,24 @@
|
||||
package apps.amine.bou.readerforselfoss.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory
|
||||
import android.widget.ImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget
|
||||
|
||||
|
||||
fun Context.bitmapCenterCrop(url: String, iv: ImageView) =
|
||||
Glide.with(this).load(url).asBitmap().centerCrop().into(iv)
|
||||
|
||||
fun Context.bitmapFitCenter(url: String, iv: ImageView) =
|
||||
Glide.with(this).load(url).asBitmap().fitCenter().into(iv)
|
||||
|
||||
fun Context.circularBitmapDrawable(url: String, iv: ImageView) =
|
||||
Glide.with(this).load(url).asBitmap().centerCrop().into(object : BitmapImageViewTarget(iv) {
|
||||
override fun setResource(resource: Bitmap) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(resources, resource)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
iv.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
@ -1,5 +1,11 @@
|
||||
package apps.amine.bou.readerforselfoss.utils
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
fun String.toTextDrawableString(): String {
|
||||
val textDrawable = StringBuilder()
|
||||
@ -8,3 +14,19 @@ fun String.toTextDrawableString(): String {
|
||||
}
|
||||
return textDrawable.toString()
|
||||
}
|
||||
|
||||
fun Item.sourceAndDateText(): String {
|
||||
var formattedDate: String = try {
|
||||
" " + DateUtils.getRelativeTimeSpanString(
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this.datetime).time,
|
||||
Date().time,
|
||||
DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
)
|
||||
} catch (e: ParseException) {
|
||||
e.printStackTrace()
|
||||
""
|
||||
}
|
||||
|
||||
return this.sourcetitle + formattedDate
|
||||
}
|
Loading…
Reference in New Issue
Block a user