Use the drawer image loader to load images (#364)
This commit is contained in:
parent
5472c607cd
commit
58b0574cf9
@ -135,7 +135,7 @@ dependencies {
|
|||||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||||
|
|
||||||
// glide
|
// 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'
|
implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1'
|
||||||
|
|
||||||
// Drawer
|
// Drawer
|
||||||
|
@ -4,7 +4,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@ -13,6 +13,7 @@ import android.preference.PreferenceManager
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
@ -54,6 +55,7 @@ import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
|||||||
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
||||||
import com.ashokvarma.bottomnavigation.TextBadgeItem
|
import com.ashokvarma.bottomnavigation.TextBadgeItem
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.ftinc.scoop.Scoop
|
import com.ftinc.scoop.Scoop
|
||||||
import com.mikepenz.aboutlibraries.LibsBuilder
|
import com.mikepenz.aboutlibraries.LibsBuilder
|
||||||
import com.mikepenz.materialdrawer.holder.BadgeStyle
|
import com.mikepenz.materialdrawer.holder.BadgeStyle
|
||||||
@ -457,6 +459,23 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleDrawer() {
|
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 {
|
val drawerListener = object : DrawerLayout.DrawerListener {
|
||||||
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
|
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
|
||||||
}
|
}
|
||||||
@ -515,7 +534,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
addProfiles(
|
addProfiles(
|
||||||
ProfileDrawerItem().apply {
|
ProfileDrawerItem().apply {
|
||||||
nameText = settings.getString("url", "").toString()
|
nameText = settings.getString("url", "").toString()
|
||||||
background = resources.getDrawable(R.drawable.bg)
|
setBackgroundResource(R.drawable.bg)
|
||||||
iconRes = R.mipmap.ic_launcher
|
iconRes = R.mipmap.ic_launcher
|
||||||
selectionListEnabledForSingleProfile = false
|
selectionListEnabledForSingleProfile = false
|
||||||
}
|
}
|
||||||
@ -646,6 +665,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
val item = PrimaryDrawerItem().apply {
|
val item = PrimaryDrawerItem().apply {
|
||||||
nameText = source.getTitleDecoded()
|
nameText = source.getTitleDecoded()
|
||||||
identifier = source.id.toLong()
|
identifier = source.id.toLong()
|
||||||
|
iconUrl = source.getIcon(this@HomeActivity)
|
||||||
onDrawerItemClickListener = { _,_,_ ->
|
onDrawerItemClickListener = { _,_,_ ->
|
||||||
allItems = ArrayList()
|
allItems = ArrayList()
|
||||||
maybeSourceFilter = source
|
maybeSourceFilter = source
|
||||||
@ -656,16 +676,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
false
|
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)
|
binding.mainDrawer.itemAdapter.add(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user