Use the drawer image loader to load images (#364)

This commit is contained in:
davidoskky 2021-10-22 20:04:28 +02:00 committed by GitHub
parent 5472c607cd
commit 58b0574cf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

View File

@ -135,7 +135,7 @@ dependencies {
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
// glide
implementation 'com.github.bumptech.glide:glide:4.1.1'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1'
// Drawer

View File

@ -4,7 +4,7 @@ import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.net.Uri
import android.os.Build
@ -13,6 +13,7 @@ import android.preference.PreferenceManager
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
@ -54,6 +55,7 @@ import com.ashokvarma.bottomnavigation.BottomNavigationBar
import com.ashokvarma.bottomnavigation.BottomNavigationItem
import com.ashokvarma.bottomnavigation.TextBadgeItem
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.ftinc.scoop.Scoop
import com.mikepenz.aboutlibraries.LibsBuilder
import com.mikepenz.materialdrawer.holder.BadgeStyle
@ -457,6 +459,23 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
}
private fun handleDrawer() {
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
Glide.with(this@HomeActivity)
.asBitmap()
.load(uri)
.apply(RequestOptions()
.placeholder(R.mipmap.ic_launcher)
.fallback(R.mipmap.ic_launcher)
.fitCenter())
.into(imageView)
}
override fun cancel(imageView: ImageView) {
Glide.with(this@HomeActivity).clear(imageView)
}
})
val drawerListener = object : DrawerLayout.DrawerListener {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
}
@ -515,7 +534,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
addProfiles(
ProfileDrawerItem().apply {
nameText = settings.getString("url", "").toString()
background = resources.getDrawable(R.drawable.bg)
setBackgroundResource(R.drawable.bg)
iconRes = R.mipmap.ic_launcher
selectionListEnabledForSingleProfile = false
}
@ -646,6 +665,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
val item = PrimaryDrawerItem().apply {
nameText = source.getTitleDecoded()
identifier = source.id.toLong()
iconUrl = source.getIcon(this@HomeActivity)
onDrawerItemClickListener = { _,_,_ ->
allItems = ArrayList()
maybeSourceFilter = source
@ -656,16 +676,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
false
}
}
if (source.getIcon(this@HomeActivity).isNotBlank()) {
thread {
try {
item.iconDrawable = BitmapDrawable(resources, Glide.with(this@HomeActivity).asBitmap().load(source.getIcon(this@HomeActivity)).submit(100, 100).get())
} catch (e: Exception) {
}
}
} else {
item.iconRes = R.mipmap.ic_launcher
}
binding.mainDrawer.itemAdapter.add(item)
}
}