Upgrade MaterialDrawer (#359)

* Upgrade material drawer library

* Add footer options to drawer

* Apply styles to drawer

* Added sources and tags to side drawer

* Hide bottom bar when the side drawer is opened

* Display hamburger icon to open the side drawer

* Add information about libraries to the side drawer

* Cleanup

* Implement reloading badges
This commit is contained in:
davidoskky 2021-10-15 20:14:21 +02:00 committed by GitHub
parent fa697f1313
commit 5640b7e56c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 265 additions and 240 deletions

View File

@ -108,6 +108,7 @@ dependencies {
implementation 'androidx.vectordrawable:vectordrawable:1.2.0-alpha02' implementation 'androidx.vectordrawable:vectordrawable:1.2.0-alpha02'
implementation "androidx.browser:browser:1.3.0" implementation "androidx.browser:browser:1.3.0"
implementation "androidx.cardview:cardview:$android_version" implementation "androidx.cardview:cardview:$android_version"
implementation "androidx.annotation:annotation:1.2.0"
implementation 'androidx.constraintlayout:constraintlayout:2.1.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'org.jsoup:jsoup:1.13.1' implementation 'org.jsoup:jsoup:1.13.1'
@ -138,7 +139,7 @@ dependencies {
implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1' implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1'
// Drawer // Drawer
implementation 'co.zsmb:materialdrawer-kt:2.0.2' implementation 'com.mikepenz:materialdrawer:8.4.4'
// Themes // Themes
implementation 'com.52inc:scoops:1.0.0' implementation 'com.52inc:scoops:1.0.0'

View File

@ -14,11 +14,13 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
import androidx.core.view.doOnNextLayout import androidx.core.view.doOnNextLayout
import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.* import androidx.recyclerview.widget.*
import androidx.room.Room import androidx.room.Room
import androidx.work.Constraints import androidx.work.Constraints
@ -48,23 +50,28 @@ import apps.amine.bou.readerforselfoss.utils.longHash
import apps.amine.bou.readerforselfoss.utils.network.isNetworkAccessible import apps.amine.bou.readerforselfoss.utils.network.isNetworkAccessible
import apps.amine.bou.readerforselfoss.utils.persistence.toEntity import apps.amine.bou.readerforselfoss.utils.persistence.toEntity
import apps.amine.bou.readerforselfoss.utils.persistence.toView import apps.amine.bou.readerforselfoss.utils.persistence.toView
import co.zsmb.materialdrawerkt.builders.accountHeader
import co.zsmb.materialdrawerkt.builders.drawer
import co.zsmb.materialdrawerkt.builders.footer
import co.zsmb.materialdrawerkt.draweritems.badgeable.primaryItem
import co.zsmb.materialdrawerkt.draweritems.profile.profile
import com.ashokvarma.bottomnavigation.BottomNavigationBar 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.ftinc.scoop.Scoop import com.ftinc.scoop.Scoop
import com.mikepenz.aboutlibraries.LibsBuilder import com.mikepenz.aboutlibraries.LibsBuilder
import com.mikepenz.materialdrawer.Drawer
import com.mikepenz.materialdrawer.holder.BadgeStyle import com.mikepenz.materialdrawer.holder.BadgeStyle
import com.mikepenz.materialdrawer.holder.ColorHolder
import com.mikepenz.materialdrawer.holder.StringHolder import com.mikepenz.materialdrawer.holder.StringHolder
import com.mikepenz.materialdrawer.model.DividerDrawerItem import com.mikepenz.materialdrawer.model.DividerDrawerItem
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
import com.mikepenz.materialdrawer.model.interfaces.badgeRes
import com.mikepenz.materialdrawer.model.interfaces.badgeText
import com.mikepenz.materialdrawer.model.interfaces.iconDrawable
import com.mikepenz.materialdrawer.model.interfaces.iconRes
import com.mikepenz.materialdrawer.model.interfaces.nameRes
import com.mikepenz.materialdrawer.model.interfaces.nameText
import com.mikepenz.materialdrawer.util.addStickyFooterItem
import com.mikepenz.materialdrawer.util.updateBadge
import com.mikepenz.materialdrawer.widget.AccountHeaderView
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -116,7 +123,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabNewBadge: TextBadgeItem
private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem
private lateinit var tabStarredBadge: TextBadgeItem private lateinit var tabStarredBadge: TextBadgeItem
private lateinit var drawer: Drawer
private lateinit var api: SelfossApi private lateinit var api: SelfossApi
private lateinit var customTabActivityHelper: CustomTabActivityHelper private lateinit var customTabActivityHelper: CustomTabActivityHelper
private lateinit var editor: SharedPreferences.Editor private lateinit var editor: SharedPreferences.Editor
@ -166,6 +172,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
handleThemeBinding() handleThemeBinding()
setSupportActionBar(binding.toolBar) setSupportActionBar(binding.toolBar)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setHomeButtonEnabled(true)
val mDrawerToggle = ActionBarDrawerToggle(this, binding.drawerContainer, binding.toolBar, R.string.material_drawer_open, R.string.material_drawer_close)
binding.drawerContainer.addDrawerListener(mDrawerToggle)
mDrawerToggle.syncState()
db = Room.databaseBuilder( db = Room.databaseBuilder(
applicationContext, applicationContext,
@ -446,61 +457,69 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} }
private fun handleDrawer() { private fun handleDrawer() {
val drawerListener = object : DrawerLayout.DrawerListener {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
}
override fun onDrawerOpened(drawerView: View) {
binding.bottomBar.hide()
}
override fun onDrawerClosed(drawerView: View) {
binding.bottomBar.show()
}
override fun onDrawerStateChanged(newState: Int) {
}
}
binding.drawerContainer.addDrawerListener(drawerListener)
displayAccountHeader = displayAccountHeader =
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("account_header_displaying", false) .getBoolean("account_header_displaying", false)
drawer = drawer { binding.mainDrawer.addStickyFooterItem(
rootViewRes = R.id.drawer_layout PrimaryDrawerItem().apply {
toolbar = binding.toolBar nameRes = R.string.drawer_report_bug
actionBarDrawerToggleEnabled = true iconRes = R.drawable.ic_bug_report_black_24dp
actionBarDrawerToggleAnimated = true isIconTinted = true
showOnFirstLaunch = true onDrawerItemClickListener = { _, _, _ ->
onSlide { _, p1 -> val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Config.trackerUrl))
binding.bottomBar.alpha = (1 - p1) startActivity(browserIntent)
} false
onClosed {
binding.bottomBar.show()
}
onOpened {
binding.bottomBar.hide()
}
if (displayAccountHeader) {
accountHeader {
background = R.drawable.bg
profile(settings.getString("url", "")!!) {
iconDrawable = resources.getDrawable(R.mipmap.ic_launcher)
}
selectionListEnabledForSingleProfile = false
} }
} })
footer { binding.mainDrawer.addStickyFooterItem(
primaryItem(R.string.drawer_report_bug) { PrimaryDrawerItem().apply {
icon = R.drawable.ic_bug_report_black_24dp nameRes = R.string.title_activity_settings
iconTintingEnabled = true iconRes = R.drawable.ic_settings_black_24dp
onClick { _ -> isIconTinted = true
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Config.trackerUrl)) onDrawerItemClickListener = { _, _, _ ->
startActivity(browserIntent) startActivityForResult(
false Intent(
} this@HomeActivity,
SettingsActivity::class.java
),
MENU_PREFERENCES
)
false
} }
})
primaryItem(R.string.title_activity_settings) { if (displayAccountHeader) {
icon = R.drawable.ic_settings_black_24dp AccountHeaderView(this).apply {
iconTintingEnabled = true attachToSliderView(binding.mainDrawer)
onClick { _ -> addProfiles(
startActivityForResult( ProfileDrawerItem().apply {
Intent( nameText = settings.getString("url", "").toString()
this@HomeActivity, background = resources.getDrawable(R.drawable.bg)
SettingsActivity::class.java iconRes = R.mipmap.ic_launcher
), selectionListEnabledForSingleProfile = false
MENU_PREFERENCES
)
false
} }
} )
} }
} }
} }
@ -511,10 +530,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
fun handleTags(maybeTags: List<Tag>?) { fun handleTags(maybeTags: List<Tag>?) {
if (maybeTags == null) { if (maybeTags == null) {
if (loadedFromCache) { if (loadedFromCache) {
drawer.addItem( binding.mainDrawer.itemAdapter.add(
SecondaryDrawerItem() SecondaryDrawerItem()
.withName(getString(R.string.drawer_error_loading_tags)) .apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false }
.withSelectable(false)
) )
} }
} else { } else {
@ -523,39 +541,38 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
.sortedBy { it.unread == 0 } .sortedBy { it.unread == 0 }
tagsBadge = filteredTags.map { tagsBadge = filteredTags.map {
val gd = GradientDrawable() val gd = GradientDrawable()
val color = try { val gdColor = try {
Color.parseColor(it.color) Color.parseColor(it.color)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
appColors.colorPrimary appColors.colorPrimary
} }
gd.setColor(color) gd.setColor(gdColor)
gd.shape = GradientDrawable.RECTANGLE gd.shape = GradientDrawable.RECTANGLE
gd.setSize(30, 30) gd.setSize(30, 30)
gd.cornerRadius = 30F gd.cornerRadius = 30F
var drawerItem = val drawerItem =
PrimaryDrawerItem() PrimaryDrawerItem()
.withName(it.tag) .apply {
.withIdentifier(it.tag.longHash()) nameText = it.getTitleDecoded()
.withIcon(gd) identifier = it.tag.longHash()
.withBadgeStyle( iconDrawable = gd
BadgeStyle().withTextColor(Color.WHITE) badgeStyle = BadgeStyle().apply {
.withColor(appColors.colorAccent) textColor = ColorHolder.fromColor(Color.WHITE)
) color = ColorHolder.fromColor(appColors.colorAccent) }
.withOnDrawerItemClickListener { _, _, _ -> onDrawerItemClickListener = { _,_,_ ->
allItems = ArrayList() allItems = ArrayList()
maybeTagFilter = it maybeTagFilter = it
SharedItems.tagFilter = it.tag SharedItems.tagFilter = it.tag
getElementsAccordingToTab() getElementsAccordingToTab()
fetchOnEmptyList() fetchOnEmptyList()
false false
} } }
if (it.unread > 0) { if (it.unread > 0) {
drawerItem = drawerItem.withBadge("${it.unread}") drawerItem.badgeText = it.unread.toString()
} }
drawer.addItem(
drawerItem binding.mainDrawer.itemAdapter.add(drawerItem)
)
(it.tag.longHash() to it.unread) (it.tag.longHash() to it.unread)
}.toMap() }.toMap()
@ -565,10 +582,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
fun handleHiddenTags(maybeTags: List<Tag>?) { fun handleHiddenTags(maybeTags: List<Tag>?) {
if (maybeTags == null) { if (maybeTags == null) {
if (loadedFromCache) { if (loadedFromCache) {
drawer.addItem( binding.mainDrawer.itemAdapter.add(
SecondaryDrawerItem() SecondaryDrawerItem().apply {
.withName(getString(R.string.drawer_error_loading_tags)) nameRes = R.string.drawer_error_loading_tags
.withSelectable(false) isSelectable = false
}
) )
} }
} else { } else {
@ -576,39 +594,37 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
maybeTags.filter { hiddenTags.contains(it.tag) } maybeTags.filter { hiddenTags.contains(it.tag) }
tagsBadge = filteredHiddenTags.map { tagsBadge = filteredHiddenTags.map {
val gd = GradientDrawable() val gd = GradientDrawable()
val color = try { val gdColor = try {
Color.parseColor(it.color) Color.parseColor(it.color)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
appColors.colorPrimary appColors.colorPrimary
} }
gd.setColor(color) gd.setColor(gdColor)
gd.shape = GradientDrawable.RECTANGLE gd.shape = GradientDrawable.RECTANGLE
gd.setSize(30, 30) gd.setSize(30, 30)
gd.cornerRadius = 30F gd.cornerRadius = 30F
var drawerItem = val drawerItem =
PrimaryDrawerItem() PrimaryDrawerItem().apply {
.withName(it.tag) nameText = it.getTitleDecoded()
.withIdentifier(it.tag.longHash()) identifier = it.tag.longHash()
.withIcon(gd) iconDrawable = gd
.withBadgeStyle( badgeStyle = BadgeStyle().apply {
BadgeStyle().withTextColor(Color.WHITE) textColor = ColorHolder.fromColor(Color.WHITE)
.withColor(appColors.colorAccent) color = ColorHolder.fromColor(appColors.colorAccent) }
) onDrawerItemClickListener = { _,_,_ ->
.withOnDrawerItemClickListener { _, _, _ ->
allItems = ArrayList() allItems = ArrayList()
maybeTagFilter = it maybeTagFilter = it
SharedItems.tagFilter = it.tag SharedItems.tagFilter = it.tag
getElementsAccordingToTab() getElementsAccordingToTab()
fetchOnEmptyList() fetchOnEmptyList()
false false
} } }
if (it.unread > 0) { if (it.unread > 0) {
drawerItem = drawerItem.withBadge("${it.unread}") drawerItem.badgeText = it.unread.toString()
} }
drawer.addItem( binding.mainDrawer.itemAdapter.add(drawerItem)
drawerItem
)
(it.tag.longHash() to it.unread) (it.tag.longHash() to it.unread)
}.toMap() }.toMap()
@ -618,51 +634,52 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
fun handleSources(maybeSources: List<Source>?) { fun handleSources(maybeSources: List<Source>?) {
if (maybeSources == null) { if (maybeSources == null) {
if (loadedFromCache) { if (loadedFromCache) {
drawer.addItem( binding.mainDrawer.itemAdapter.add(
SecondaryDrawerItem() SecondaryDrawerItem().apply {
.withName(getString(R.string.drawer_error_loading_sources)) nameRes = R.string.drawer_error_loading_sources
.withSelectable(false) isSelectable = false
}
) )
} }
} else { } else {
for (tag in maybeSources) { for (source in maybeSources) {
val item = PrimaryDrawerItem() val item = PrimaryDrawerItem().apply {
.withName(tag.getTitleDecoded()) nameText = source.getTitleDecoded()
.withIdentifier(tag.id.toLong()) identifier = source.id.toLong()
.withOnDrawerItemClickListener { _, _, _ -> onDrawerItemClickListener = { _,_,_ ->
allItems = ArrayList() allItems = ArrayList()
maybeSourceFilter = tag maybeSourceFilter = source
SharedItems.sourceIDFilter = tag.id.toLong() SharedItems.sourceIDFilter = source.id.toLong()
SharedItems.sourceFilter = tag.title SharedItems.sourceFilter = source.title
getElementsAccordingToTab() getElementsAccordingToTab()
fetchOnEmptyList() fetchOnEmptyList()
false false
} }
if (tag.getIcon(this@HomeActivity).isNotBlank()) { }
if (source.getIcon(this@HomeActivity).isNotBlank()) {
thread { thread {
try { try {
item.withIcon(BitmapDrawable(resources, Glide.with(this@HomeActivity).asBitmap().load(tag.getIcon(this@HomeActivity)).submit(100, 100).get())) item.iconDrawable = BitmapDrawable(resources, Glide.with(this@HomeActivity).asBitmap().load(source.getIcon(this@HomeActivity)).submit(100, 100).get())
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
} else { } else {
item.withIcon(R.mipmap.ic_launcher) item.iconRes = R.mipmap.ic_launcher
} }
drawer.addItem(item) binding.mainDrawer.itemAdapter.add(item)
} }
} }
} }
drawer.removeAllItems() binding.mainDrawer.itemAdapter.clear()
if (maybeDrawerData != null) { if (maybeDrawerData != null) {
drawer.addItem( binding.mainDrawer.itemAdapter.add(
SecondaryDrawerItem() SecondaryDrawerItem().apply {
.withName(getString(R.string.drawer_item_filters)) nameRes = R.string.drawer_item_filters
.withSelectable(false) isSelectable = false
.withIdentifier(DRAWER_ID_FILTERS) identifier = DRAWER_ID_FILTERS
.withBadge(getString(R.string.drawer_action_clear)) badgeRes = R.string.drawer_action_clear
.withOnDrawerItemClickListener { _, _, _ -> onDrawerItemClickListener = { _,_,_ ->
allItems = ArrayList() allItems = ArrayList()
maybeSourceFilter = null maybeSourceFilter = null
SharedItems.sourceFilter = null SharedItems.sourceFilter = null
@ -673,55 +690,59 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
fetchOnEmptyList() fetchOnEmptyList()
false false
} }
}
) )
if (hiddenTags.isNotEmpty()) { if (hiddenTags.isNotEmpty()) {
drawer.addItem(DividerDrawerItem()) binding.mainDrawer.itemAdapter.add(
drawer.addItem( DividerDrawerItem(),
SecondaryDrawerItem() SecondaryDrawerItem().apply {
.withName(getString(R.string.drawer_item_hidden_tags)) nameRes = R.string.drawer_item_hidden_tags
.withIdentifier(DRAWER_ID_HIDDEN_TAGS) identifier = DRAWER_ID_HIDDEN_TAGS
.withSelectable(false) isSelectable = false
}
) )
handleHiddenTags(maybeDrawerData.tags) handleHiddenTags(maybeDrawerData.tags)
} }
drawer.addItem(DividerDrawerItem()) binding.mainDrawer.itemAdapter.add(
drawer.addItem( DividerDrawerItem(),
SecondaryDrawerItem() SecondaryDrawerItem().apply {
.withName(getString(R.string.drawer_item_tags)) nameRes = R.string.drawer_item_tags
.withIdentifier(DRAWER_ID_TAGS) identifier = DRAWER_ID_TAGS
.withSelectable(false) isSelectable = false
}
) )
handleTags(maybeDrawerData.tags) handleTags(maybeDrawerData.tags)
drawer.addItem(DividerDrawerItem()) binding.mainDrawer.itemAdapter.add(
drawer.addItem( DividerDrawerItem(),
SecondaryDrawerItem() SecondaryDrawerItem().apply {
.withName(getString(R.string.drawer_item_sources)) nameRes = R.string.drawer_item_sources
.withIdentifier(DRAWER_ID_TAGS) identifier = DRAWER_ID_SOURCES
.withBadge(getString(R.string.drawer_action_edit)) isSelectable = false
.withSelectable(false) badgeRes = R.string.drawer_action_edit
.withOnDrawerItemClickListener { _, _, _ -> onDrawerItemClickListener = { v,_,_ ->
startActivity(Intent(this, SourcesActivity::class.java)) startActivity(Intent(v!!.context, SourcesActivity::class.java))
false false
} }
}
) )
handleSources(maybeDrawerData.sources) handleSources(maybeDrawerData.sources)
drawer.addItem(DividerDrawerItem()) binding.mainDrawer.itemAdapter.add(
drawer.addItem( DividerDrawerItem(),
PrimaryDrawerItem() PrimaryDrawerItem().apply {
.withName(R.string.action_about) nameRes = R.string.action_about
.withSelectable(false) isSelectable = false
.withIcon(R.drawable.ic_info_outline_white_24dp) iconRes = R.drawable.ic_info_outline_white_24dp
.withIconTintingEnabled(true) isIconTinted = true
.withOnDrawerItemClickListener { _, _, _ -> onDrawerItemClickListener = { _,_,_ ->
LibsBuilder() LibsBuilder()
.withAboutIconShown(true) .withAboutIconShown(true)
.withAboutVersionShown(true) .withAboutVersionShown(true)
.start(this@HomeActivity) .start(this@HomeActivity)
false false
} }
}
) )
if (!loadedFromCache) { if (!loadedFromCache) {
if (maybeDrawerData.tags != null) { if (maybeDrawerData.tags != null) {
thread { thread {
@ -741,17 +762,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} }
} else { } else {
if (!loadedFromCache) { if (!loadedFromCache) {
drawer.addItem( binding.mainDrawer.itemAdapter.add(
PrimaryDrawerItem() PrimaryDrawerItem().apply {
.withName(getString(R.string.no_tags_loaded)) nameRes = R.string.no_tags_loaded
.withIdentifier(DRAWER_ID_TAGS) identifier = DRAWER_ID_TAGS
.withSelectable(false) isSelectable = false
) },
drawer.addItem( PrimaryDrawerItem().apply {
PrimaryDrawerItem() nameRes = R.string.no_sources_loaded
.withName(getString(R.string.no_sources_loaded)) identifier = DRAWER_ID_SOURCES
.withIdentifier(DRAWER_ID_SOURCES) isSelectable = false
.withSelectable(false) }
) )
} }
} }
@ -802,14 +823,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} }
} }
drawer.addItem( binding.mainDrawer.itemAdapter.add(
PrimaryDrawerItem().withName(getString(R.string.drawer_loading)).withSelectable( PrimaryDrawerItem().apply {
false nameRes = R.string.drawer_loading
) isSelectable = false
}
) )
thread { thread {
var drawerData = DrawerData(db.drawerDataDao().tags().map { it.toView() }, val drawerData = DrawerData(db.drawerDataDao().tags().map { it.toView() },
db.drawerDataDao().sources().map { it.toView() }) db.drawerDataDao().sources().map { it.toView() })
runOnUiThread { runOnUiThread {
handleDrawerData(drawerData, loadedFromCache = true) handleDrawerData(drawerData, loadedFromCache = true)
@ -1095,9 +1117,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private fun reloadTagsBadges() { private fun reloadTagsBadges() {
tagsBadge.forEach { tagsBadge.forEach {
drawer.updateBadge(it.key, StringHolder("${it.value}")) binding.mainDrawer.updateBadge(it.key, StringHolder(it.value.toString()))
} }
drawer.resetDrawerContent() binding.mainDrawer.resetDrawerContent()
} }
private fun calculateNoOfColumns(): Int { private fun calculateNoOfColumns(): Int {
@ -1127,7 +1149,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
override fun onActivityResult(req: Int, result: Int, data: Intent?) { override fun onActivityResult(req: Int, result: Int, data: Intent?) {
when (req) { when (req) {
MENU_PREFERENCES -> { MENU_PREFERENCES -> {
drawer.closeDrawer() //drawer.closeDrawer()
recreate() recreate()
} }
else -> super.onActivityResult(req, result, data) else -> super.onActivityResult(req, result, data)

View File

@ -60,23 +60,18 @@ class MyApp : MultiDexApplication() {
private fun initDrawerImageLoader() { private fun initDrawerImageLoader() {
DrawerImageLoader.init(object : AbstractDrawerImageLoader() { DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
override fun set( override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
imageView: ImageView?,
uri: Uri?,
placeholder: Drawable?,
tag: String?
) {
Glide.with(imageView?.context) Glide.with(imageView?.context)
.loadMaybeBasicAuth(config, uri.toString()) .loadMaybeBasicAuth(config, uri.toString())
.apply(RequestOptions.fitCenterTransform().placeholder(placeholder)) .apply(RequestOptions.fitCenterTransform().placeholder(placeholder))
.into(imageView) .into(imageView)
} }
override fun cancel(imageView: ImageView?) { override fun cancel(imageView: ImageView) {
Glide.with(imageView?.context).clear(imageView) Glide.with(imageView?.context).clear(imageView)
} }
override fun placeholder(ctx: Context?, tag: String?): Drawable { override fun placeholder(ctx: Context, tag: String?): Drawable {
return baseContext.resources.getDrawable(R.mipmap.ic_launcher) return baseContext.resources.getDrawable(R.mipmap.ic_launcher)
} }
}) })

View File

@ -30,7 +30,11 @@ data class Tag(
@SerializedName("tag") val tag: String, @SerializedName("tag") val tag: String,
@SerializedName("color") val color: String, @SerializedName("color") val color: String,
@SerializedName("unread") val unread: Int @SerializedName("unread") val unread: Int
) ) {
fun getTitleDecoded(): String {
return Html.fromHtml(tag).toString()
}
}
class SuccessResponse(@SerializedName("success") val success: Boolean) { class SuccessResponse(@SerializedName("success") val success: Boolean) {
val isSuccess: Boolean val isSuccess: Boolean

View File

@ -59,9 +59,9 @@ class AppColors(a: Activity) {
} }
textColor = if (isDarkTheme) { textColor = if (isDarkTheme) {
R.color.md_white_1000 R.color.white
} else { } else {
R.color.md_grey_900 R.color.grey_900
} }
val wrapper = Context::class.java val wrapper = Context::class.java

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="apps.amine.bou.readerforselfoss.HomeActivity" tools:context="apps.amine.bou.readerforselfoss.HomeActivity"
@ -36,51 +37,43 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<FrameLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/drawer_layout" android:id="@+id/swipeRefreshLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <LinearLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:orientation="vertical"
android:background="?android:attr/windowBackground">
<LinearLayout <TextView
android:id="@+id/emptyText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:gravity="center_horizontal"
android:background="?android:attr/windowBackground"> android:paddingTop="100dp"
android:text="@string/nothing_here"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:background="@android:color/transparent"
android:visibility="gone" />
<TextView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/emptyText" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="fill" android:background="@android:color/transparent"
android:paddingTop="100dp" android:clipToPadding="false"
android:text="@string/nothing_here" android:paddingBottom="60dp"
android:textAlignment="center" android:scrollbars="vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="@android:color/transparent" tools:listitem="@layout/list_item"/>
android:visibility="gone" /> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:clipToPadding="false"
android:paddingBottom="60dp"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/list_item"/>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
</LinearLayout> </LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
@ -90,4 +83,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="60dp"/> android:layout_height="60dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
<com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
android:id="@+id/mainDrawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true" />
</androidx.drawerlayout.widget.DrawerLayout>

View File

@ -4,30 +4,34 @@
<item name="android:windowBackground">@drawable/background_splash</item> <item name="android:windowBackground">@drawable/background_splash</item>
</style> </style>
<style name="NoBar" parent="MaterialDrawerTheme.Light"> <style name="NoBar" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="colorAccentDark">@color/colorAccentDark</item> <item name="colorAccentDark">@color/colorAccentDark</item>
<item name="cardBackgroundColor">@color/white</item> <item name="cardBackgroundColor">@color/white</item>
<item name="android:colorBackground">@color/md_grey_50</item> <item name="android:colorBackground">@color/grey_50</item>
<item name="android:textColorPrimary">@color/md_grey_900</item> <item name="colorSurface">@color/grey_50</item>
<item name="android:textColorSecondary">@color/md_grey_400</item> <item name="android:textColorPrimary">@color/grey_900</item>
<item name="material_drawer_header_selection_text">@color/md_grey_900</item> <item name="android:textColorSecondary">@color/grey_400</item>
<item name="materialDrawerStyle">@style/Widget.MaterialDrawerStyle</item>
<item name="materialDrawerHeaderStyle">@style/Widget.MaterialDrawerHeaderStyle</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style> </style>
<style name="NoBarDark" parent="MaterialDrawerTheme"> <style name="NoBarDark" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="colorAccentDark">@color/colorAccentDark</item> <item name="colorAccentDark">@color/colorAccentDark</item>
<item name="cardBackgroundColor">@color/md_grey_800</item> <item name="cardBackgroundColor">@color/grey_800</item>
<item name="android:colorBackground">@color/darkBackground</item> <item name="android:colorBackground">@color/darkBackground</item>
<item name="bnbBackgroundColor">@color/md_grey_900</item> <item name="colorSurface">@color/darkBackground</item>
<item name="android:textColorPrimary">@color/md_white_1000</item> <item name="bnbBackgroundColor">@color/grey_900</item>
<item name="android:textColorSecondary">@color/md_grey_600</item> <item name="android:textColorPrimary">@color/white</item>
<item name="material_drawer_header_selection_text">@color/md_grey_900</item> <item name="android:textColorSecondary">@color/grey_600</item>
<item name="materialDrawerStyle">@style/Widget.MaterialDrawerStyle</item>
<item name="materialDrawerHeaderStyle">@style/Widget.MaterialDrawerHeaderStyle</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
</style> </style>
@ -35,7 +39,6 @@
<style name="ToolBarStyle" parent="Theme.AppCompat"> <style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@color/white</item> <item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/white</item> <item name="android:textColorSecondary">@color/white</item>
<item name="material_drawer_header_selection_text">@color/md_grey_900</item>
<item name="actionMenuTextColor">@color/white</item> <item name="actionMenuTextColor">@color/white</item>
<!--<item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item> <!--<item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>--> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>-->