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:
		| @@ -108,6 +108,7 @@ dependencies { | ||||
|     implementation 'androidx.vectordrawable:vectordrawable:1.2.0-alpha02' | ||||
|     implementation "androidx.browser:browser:1.3.0" | ||||
|     implementation "androidx.cardview:cardview:$android_version" | ||||
|     implementation "androidx.annotation:annotation:1.2.0" | ||||
|     implementation 'androidx.constraintlayout:constraintlayout:2.1.1' | ||||
|     implementation 'org.jsoup:jsoup:1.13.1' | ||||
|  | ||||
| @@ -138,7 +139,7 @@ dependencies { | ||||
|     implementation 'com.github.bumptech.glide:okhttp3-integration:4.1.1' | ||||
|  | ||||
|     // Drawer | ||||
|     implementation 'co.zsmb:materialdrawer-kt:2.0.2' | ||||
|     implementation 'com.mikepenz:materialdrawer:8.4.4' | ||||
|  | ||||
|     // Themes | ||||
|     implementation 'com.52inc:scoops:1.0.0' | ||||
|   | ||||
| @@ -14,11 +14,13 @@ import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import android.view.View | ||||
| import android.widget.Toast | ||||
| import androidx.appcompat.app.ActionBarDrawerToggle | ||||
| import androidx.appcompat.app.AlertDialog | ||||
| import androidx.appcompat.app.AppCompatActivity | ||||
| import androidx.appcompat.widget.SearchView | ||||
| import androidx.core.view.MenuItemCompat | ||||
| import androidx.core.view.doOnNextLayout | ||||
| import androidx.drawerlayout.widget.DrawerLayout | ||||
| import androidx.recyclerview.widget.* | ||||
| import androidx.room.Room | ||||
| 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.persistence.toEntity | ||||
| 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.BottomNavigationItem | ||||
| import com.ashokvarma.bottomnavigation.TextBadgeItem | ||||
| import com.bumptech.glide.Glide | ||||
| import com.ftinc.scoop.Scoop | ||||
| import com.mikepenz.aboutlibraries.LibsBuilder | ||||
| import com.mikepenz.materialdrawer.Drawer | ||||
| import com.mikepenz.materialdrawer.holder.BadgeStyle | ||||
| import com.mikepenz.materialdrawer.holder.ColorHolder | ||||
| import com.mikepenz.materialdrawer.holder.StringHolder | ||||
| import com.mikepenz.materialdrawer.model.DividerDrawerItem | ||||
| import com.mikepenz.materialdrawer.model.PrimaryDrawerItem | ||||
| import com.mikepenz.materialdrawer.model.ProfileDrawerItem | ||||
| 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.Dispatchers | ||||
| import kotlinx.coroutines.launch | ||||
| @@ -116,7 +123,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|     private lateinit var tabNewBadge: TextBadgeItem | ||||
|     private lateinit var tabArchiveBadge: TextBadgeItem | ||||
|     private lateinit var tabStarredBadge: TextBadgeItem | ||||
|     private lateinit var drawer: Drawer | ||||
|     private lateinit var api: SelfossApi | ||||
|     private lateinit var customTabActivityHelper: CustomTabActivityHelper | ||||
|     private lateinit var editor: SharedPreferences.Editor | ||||
| @@ -166,6 +172,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|         handleThemeBinding() | ||||
|  | ||||
|         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( | ||||
|             applicationContext, | ||||
| @@ -446,61 +457,69 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|     } | ||||
|  | ||||
|     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 = | ||||
|                 PreferenceManager.getDefaultSharedPreferences(this) | ||||
|                     .getBoolean("account_header_displaying", false) | ||||
|  | ||||
|         drawer = drawer { | ||||
|             rootViewRes = R.id.drawer_layout | ||||
|             toolbar = binding.toolBar | ||||
|             actionBarDrawerToggleEnabled = true | ||||
|             actionBarDrawerToggleAnimated = true | ||||
|             showOnFirstLaunch = true | ||||
|             onSlide { _, p1 -> | ||||
|                 binding.bottomBar.alpha = (1 - p1) | ||||
|             } | ||||
|             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 | ||||
|         binding.mainDrawer.addStickyFooterItem( | ||||
|             PrimaryDrawerItem().apply { | ||||
|                 nameRes = R.string.drawer_report_bug | ||||
|                 iconRes = R.drawable.ic_bug_report_black_24dp | ||||
|                 isIconTinted = true | ||||
|                 onDrawerItemClickListener = { _, _, _ -> | ||||
|                     val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Config.trackerUrl)) | ||||
|                     startActivity(browserIntent) | ||||
|                     false | ||||
|                 } | ||||
|             } | ||||
|             }) | ||||
|  | ||||
|             footer { | ||||
|                 primaryItem(R.string.drawer_report_bug) { | ||||
|                     icon = R.drawable.ic_bug_report_black_24dp | ||||
|                     iconTintingEnabled = true | ||||
|                     onClick { _ -> | ||||
|                         val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Config.trackerUrl)) | ||||
|                         startActivity(browserIntent) | ||||
|                         false | ||||
|                     } | ||||
|         binding.mainDrawer.addStickyFooterItem( | ||||
|             PrimaryDrawerItem().apply { | ||||
|                 nameRes = R.string.title_activity_settings | ||||
|                 iconRes = R.drawable.ic_settings_black_24dp | ||||
|                 isIconTinted = true | ||||
|                 onDrawerItemClickListener = { _, _, _ -> | ||||
|                     startActivityForResult( | ||||
|                         Intent( | ||||
|                             this@HomeActivity, | ||||
|                             SettingsActivity::class.java | ||||
|                         ), | ||||
|                         MENU_PREFERENCES | ||||
|                     ) | ||||
|                     false | ||||
|                 } | ||||
|             }) | ||||
|  | ||||
|                 primaryItem(R.string.title_activity_settings) { | ||||
|                     icon = R.drawable.ic_settings_black_24dp | ||||
|                     iconTintingEnabled = true | ||||
|                     onClick { _ -> | ||||
|                         startActivityForResult( | ||||
|                             Intent( | ||||
|                                 this@HomeActivity, | ||||
|                                 SettingsActivity::class.java | ||||
|                             ), | ||||
|                             MENU_PREFERENCES | ||||
|                         ) | ||||
|                         false | ||||
|         if (displayAccountHeader) { | ||||
|             AccountHeaderView(this).apply { | ||||
|                 attachToSliderView(binding.mainDrawer) | ||||
|                 addProfiles( | ||||
|                     ProfileDrawerItem().apply { | ||||
|                         nameText = settings.getString("url", "").toString() | ||||
|                         background = resources.getDrawable(R.drawable.bg) | ||||
|                         iconRes = R.mipmap.ic_launcher | ||||
|                         selectionListEnabledForSingleProfile = false | ||||
|                     } | ||||
|                 } | ||||
|                 ) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -511,10 +530,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|             fun handleTags(maybeTags: List<Tag>?) { | ||||
|                 if (maybeTags == null) { | ||||
|                     if (loadedFromCache) { | ||||
|                         drawer.addItem( | ||||
|                         binding.mainDrawer.itemAdapter.add( | ||||
|                             SecondaryDrawerItem() | ||||
|                                 .withName(getString(R.string.drawer_error_loading_tags)) | ||||
|                                 .withSelectable(false) | ||||
|                                 .apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false } | ||||
|                         ) | ||||
|                     } | ||||
|                 } else { | ||||
| @@ -523,39 +541,38 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|                         .sortedBy { it.unread == 0 } | ||||
|                     tagsBadge = filteredTags.map { | ||||
|                         val gd = GradientDrawable() | ||||
|                         val color = try { | ||||
|                         val gdColor = try { | ||||
|                             Color.parseColor(it.color) | ||||
|                         } catch (e: IllegalArgumentException) { | ||||
|                             appColors.colorPrimary | ||||
|                         } | ||||
|  | ||||
|                         gd.setColor(color) | ||||
|                         gd.setColor(gdColor) | ||||
|                         gd.shape = GradientDrawable.RECTANGLE | ||||
|                         gd.setSize(30, 30) | ||||
|                         gd.cornerRadius = 30F | ||||
|                         var drawerItem = | ||||
|                         val drawerItem = | ||||
|                             PrimaryDrawerItem() | ||||
|                                 .withName(it.tag) | ||||
|                                 .withIdentifier(it.tag.longHash()) | ||||
|                                 .withIcon(gd) | ||||
|                                 .withBadgeStyle( | ||||
|                                     BadgeStyle().withTextColor(Color.WHITE) | ||||
|                                         .withColor(appColors.colorAccent) | ||||
|                                 ) | ||||
|                                 .withOnDrawerItemClickListener { _, _, _ -> | ||||
|                                     allItems = ArrayList() | ||||
|                                     maybeTagFilter = it | ||||
|                                     SharedItems.tagFilter = it.tag | ||||
|                                     getElementsAccordingToTab() | ||||
|                                     fetchOnEmptyList() | ||||
|                                     false | ||||
|                                 } | ||||
|                                 .apply { | ||||
|                                     nameText = it.getTitleDecoded() | ||||
|                                     identifier = it.tag.longHash() | ||||
|                                     iconDrawable = gd | ||||
|                                     badgeStyle = BadgeStyle().apply { | ||||
|                                         textColor = ColorHolder.fromColor(Color.WHITE) | ||||
|                                         color = ColorHolder.fromColor(appColors.colorAccent) } | ||||
|                                     onDrawerItemClickListener = { _,_,_ -> | ||||
|                                         allItems = ArrayList() | ||||
|                                         maybeTagFilter = it | ||||
|                                         SharedItems.tagFilter = it.tag | ||||
|                                         getElementsAccordingToTab() | ||||
|                                         fetchOnEmptyList() | ||||
|                                         false | ||||
|                                     } } | ||||
|                         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) | ||||
|                     }.toMap() | ||||
| @@ -565,10 +582,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|             fun handleHiddenTags(maybeTags: List<Tag>?) { | ||||
|                 if (maybeTags == null) { | ||||
|                     if (loadedFromCache) { | ||||
|                         drawer.addItem( | ||||
|                             SecondaryDrawerItem() | ||||
|                                 .withName(getString(R.string.drawer_error_loading_tags)) | ||||
|                                 .withSelectable(false) | ||||
|                         binding.mainDrawer.itemAdapter.add( | ||||
|                             SecondaryDrawerItem().apply { | ||||
|                                 nameRes = R.string.drawer_error_loading_tags | ||||
|                                 isSelectable = false | ||||
|                             } | ||||
|                         ) | ||||
|                     } | ||||
|                 } else { | ||||
| @@ -576,39 +594,37 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|                         maybeTags.filter { hiddenTags.contains(it.tag) } | ||||
|                     tagsBadge = filteredHiddenTags.map { | ||||
|                         val gd = GradientDrawable() | ||||
|                         val color = try { | ||||
|                         val gdColor = try { | ||||
|                             Color.parseColor(it.color) | ||||
|                         } catch (e: IllegalArgumentException) { | ||||
|                             appColors.colorPrimary | ||||
|                         } | ||||
|  | ||||
|                         gd.setColor(color) | ||||
|                         gd.setColor(gdColor) | ||||
|                         gd.shape = GradientDrawable.RECTANGLE | ||||
|                         gd.setSize(30, 30) | ||||
|                         gd.cornerRadius = 30F | ||||
|                         var drawerItem = | ||||
|                             PrimaryDrawerItem() | ||||
|                                 .withName(it.tag) | ||||
|                                 .withIdentifier(it.tag.longHash()) | ||||
|                                 .withIcon(gd) | ||||
|                                 .withBadgeStyle( | ||||
|                                     BadgeStyle().withTextColor(Color.WHITE) | ||||
|                                         .withColor(appColors.colorAccent) | ||||
|                                 ) | ||||
|                                 .withOnDrawerItemClickListener { _, _, _ -> | ||||
|                         val drawerItem = | ||||
|                             PrimaryDrawerItem().apply { | ||||
|                                 nameText = it.getTitleDecoded() | ||||
|                                 identifier = it.tag.longHash() | ||||
|                                 iconDrawable = gd | ||||
|                                 badgeStyle = BadgeStyle().apply { | ||||
|                                     textColor = ColorHolder.fromColor(Color.WHITE) | ||||
|                                     color = ColorHolder.fromColor(appColors.colorAccent) } | ||||
|                                 onDrawerItemClickListener = { _,_,_ -> | ||||
|                                     allItems = ArrayList() | ||||
|                                     maybeTagFilter = it | ||||
|                                     SharedItems.tagFilter = it.tag | ||||
|                                     getElementsAccordingToTab() | ||||
|                                     fetchOnEmptyList() | ||||
|                                     false | ||||
|                                 } | ||||
|                                 } } | ||||
|  | ||||
|                         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) | ||||
|                     }.toMap() | ||||
| @@ -618,51 +634,52 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|             fun handleSources(maybeSources: List<Source>?) { | ||||
|                 if (maybeSources == null) { | ||||
|                     if (loadedFromCache) { | ||||
|                         drawer.addItem( | ||||
|                             SecondaryDrawerItem() | ||||
|                                 .withName(getString(R.string.drawer_error_loading_sources)) | ||||
|                                 .withSelectable(false) | ||||
|                         binding.mainDrawer.itemAdapter.add( | ||||
|                             SecondaryDrawerItem().apply { | ||||
|                                 nameRes = R.string.drawer_error_loading_sources | ||||
|                                 isSelectable = false | ||||
|                             } | ||||
|                         ) | ||||
|                     } | ||||
|                 } else { | ||||
|                     for (tag in maybeSources) { | ||||
|                         val item = PrimaryDrawerItem() | ||||
|                                 .withName(tag.getTitleDecoded()) | ||||
|                                 .withIdentifier(tag.id.toLong()) | ||||
|                                 .withOnDrawerItemClickListener { _, _, _ -> | ||||
|                                     allItems = ArrayList() | ||||
|                                     maybeSourceFilter = tag | ||||
|                                     SharedItems.sourceIDFilter = tag.id.toLong() | ||||
|                                     SharedItems.sourceFilter = tag.title | ||||
|                                     getElementsAccordingToTab() | ||||
|                                     fetchOnEmptyList() | ||||
|                                     false | ||||
|                                 } | ||||
|                         if (tag.getIcon(this@HomeActivity).isNotBlank()) { | ||||
|                     for (source in maybeSources) { | ||||
|                         val item = PrimaryDrawerItem().apply { | ||||
|                             nameText = source.getTitleDecoded() | ||||
|                             identifier = source.id.toLong() | ||||
|                             onDrawerItemClickListener = { _,_,_ -> | ||||
|                                 allItems = ArrayList() | ||||
|                                 maybeSourceFilter = source | ||||
|                                 SharedItems.sourceIDFilter = source.id.toLong() | ||||
|                                 SharedItems.sourceFilter = source.title | ||||
|                                 getElementsAccordingToTab() | ||||
|                                 fetchOnEmptyList() | ||||
|                                 false | ||||
|                             } | ||||
|                         } | ||||
|                         if (source.getIcon(this@HomeActivity).isNotBlank()) { | ||||
|                             thread { | ||||
|                                 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) { | ||||
|                                 } | ||||
|                             } | ||||
|                         } 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) { | ||||
|                 drawer.addItem( | ||||
|                     SecondaryDrawerItem() | ||||
|                         .withName(getString(R.string.drawer_item_filters)) | ||||
|                         .withSelectable(false) | ||||
|                         .withIdentifier(DRAWER_ID_FILTERS) | ||||
|                         .withBadge(getString(R.string.drawer_action_clear)) | ||||
|                         .withOnDrawerItemClickListener { _, _, _ -> | ||||
|                 binding.mainDrawer.itemAdapter.add( | ||||
|                     SecondaryDrawerItem().apply { | ||||
|                         nameRes = R.string.drawer_item_filters | ||||
|                         isSelectable = false | ||||
|                         identifier = DRAWER_ID_FILTERS | ||||
|                         badgeRes = R.string.drawer_action_clear | ||||
|                         onDrawerItemClickListener = { _,_,_ -> | ||||
|                             allItems = ArrayList() | ||||
|                             maybeSourceFilter = null | ||||
|                             SharedItems.sourceFilter = null | ||||
| @@ -673,55 +690,59 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|                             fetchOnEmptyList() | ||||
|                             false | ||||
|                         } | ||||
|                     } | ||||
|                 ) | ||||
|                 if (hiddenTags.isNotEmpty()) { | ||||
|                     drawer.addItem(DividerDrawerItem()) | ||||
|                     drawer.addItem( | ||||
|                         SecondaryDrawerItem() | ||||
|                             .withName(getString(R.string.drawer_item_hidden_tags)) | ||||
|                             .withIdentifier(DRAWER_ID_HIDDEN_TAGS) | ||||
|                             .withSelectable(false) | ||||
|                     binding.mainDrawer.itemAdapter.add( | ||||
|                         DividerDrawerItem(), | ||||
|                         SecondaryDrawerItem().apply { | ||||
|                             nameRes = R.string.drawer_item_hidden_tags | ||||
|                             identifier = DRAWER_ID_HIDDEN_TAGS | ||||
|                             isSelectable = false | ||||
|                         } | ||||
|                     ) | ||||
|                     handleHiddenTags(maybeDrawerData.tags) | ||||
|                 } | ||||
|                 drawer.addItem(DividerDrawerItem()) | ||||
|                 drawer.addItem( | ||||
|                     SecondaryDrawerItem() | ||||
|                         .withName(getString(R.string.drawer_item_tags)) | ||||
|                         .withIdentifier(DRAWER_ID_TAGS) | ||||
|                         .withSelectable(false) | ||||
|                 binding.mainDrawer.itemAdapter.add( | ||||
|                     DividerDrawerItem(), | ||||
|                     SecondaryDrawerItem().apply { | ||||
|                         nameRes = R.string.drawer_item_tags | ||||
|                         identifier = DRAWER_ID_TAGS | ||||
|                         isSelectable = false | ||||
|                     } | ||||
|                 ) | ||||
|                 handleTags(maybeDrawerData.tags) | ||||
|                 drawer.addItem(DividerDrawerItem()) | ||||
|                 drawer.addItem( | ||||
|                     SecondaryDrawerItem() | ||||
|                         .withName(getString(R.string.drawer_item_sources)) | ||||
|                         .withIdentifier(DRAWER_ID_TAGS) | ||||
|                         .withBadge(getString(R.string.drawer_action_edit)) | ||||
|                         .withSelectable(false) | ||||
|                         .withOnDrawerItemClickListener { _, _, _ -> | ||||
|                             startActivity(Intent(this, SourcesActivity::class.java)) | ||||
|                 binding.mainDrawer.itemAdapter.add( | ||||
|                     DividerDrawerItem(), | ||||
|                     SecondaryDrawerItem().apply { | ||||
|                         nameRes = R.string.drawer_item_sources | ||||
|                         identifier = DRAWER_ID_SOURCES | ||||
|                         isSelectable = false | ||||
|                         badgeRes = R.string.drawer_action_edit | ||||
|                         onDrawerItemClickListener = { v,_,_ -> | ||||
|                             startActivity(Intent(v!!.context, SourcesActivity::class.java)) | ||||
|                             false | ||||
|                         } | ||||
|                     } | ||||
|                 ) | ||||
|                 handleSources(maybeDrawerData.sources) | ||||
|                 drawer.addItem(DividerDrawerItem()) | ||||
|                 drawer.addItem( | ||||
|                     PrimaryDrawerItem() | ||||
|                         .withName(R.string.action_about) | ||||
|                         .withSelectable(false) | ||||
|                         .withIcon(R.drawable.ic_info_outline_white_24dp) | ||||
|                         .withIconTintingEnabled(true) | ||||
|                         .withOnDrawerItemClickListener { _, _, _ -> | ||||
|                 binding.mainDrawer.itemAdapter.add( | ||||
|                     DividerDrawerItem(), | ||||
|                     PrimaryDrawerItem().apply { | ||||
|                         nameRes = R.string.action_about | ||||
|                         isSelectable = false | ||||
|                         iconRes = R.drawable.ic_info_outline_white_24dp | ||||
|                         isIconTinted = true | ||||
|                         onDrawerItemClickListener = { _,_,_ -> | ||||
|                             LibsBuilder() | ||||
|                                 .withAboutIconShown(true) | ||||
|                                 .withAboutVersionShown(true) | ||||
|                                 .start(this@HomeActivity) | ||||
|                             false | ||||
|                         } | ||||
|                     } | ||||
|                 ) | ||||
|  | ||||
|  | ||||
|                 if (!loadedFromCache) { | ||||
|                     if (maybeDrawerData.tags != null) { | ||||
|                         thread { | ||||
| @@ -741,17 +762,17 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|                 } | ||||
|             } else { | ||||
|                 if (!loadedFromCache) { | ||||
|                     drawer.addItem( | ||||
|                         PrimaryDrawerItem() | ||||
|                             .withName(getString(R.string.no_tags_loaded)) | ||||
|                             .withIdentifier(DRAWER_ID_TAGS) | ||||
|                             .withSelectable(false) | ||||
|                     ) | ||||
|                     drawer.addItem( | ||||
|                         PrimaryDrawerItem() | ||||
|                             .withName(getString(R.string.no_sources_loaded)) | ||||
|                             .withIdentifier(DRAWER_ID_SOURCES) | ||||
|                             .withSelectable(false) | ||||
|                     binding.mainDrawer.itemAdapter.add( | ||||
|                         PrimaryDrawerItem().apply { | ||||
|                             nameRes = R.string.no_tags_loaded | ||||
|                             identifier = DRAWER_ID_TAGS | ||||
|                             isSelectable = false | ||||
|                         }, | ||||
|                         PrimaryDrawerItem().apply { | ||||
|                             nameRes = R.string.no_sources_loaded | ||||
|                             identifier = DRAWER_ID_SOURCES | ||||
|                             isSelectable = false | ||||
|                         } | ||||
|                     ) | ||||
|                 } | ||||
|             } | ||||
| @@ -802,14 +823,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         drawer.addItem( | ||||
|             PrimaryDrawerItem().withName(getString(R.string.drawer_loading)).withSelectable( | ||||
|                 false | ||||
|             ) | ||||
|         binding.mainDrawer.itemAdapter.add( | ||||
|             PrimaryDrawerItem().apply { | ||||
|                 nameRes = R.string.drawer_loading | ||||
|                 isSelectable = false | ||||
|             } | ||||
|         ) | ||||
|  | ||||
|         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() }) | ||||
|             runOnUiThread { | ||||
|                 handleDrawerData(drawerData, loadedFromCache = true) | ||||
| @@ -1095,9 +1117,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|  | ||||
|     private fun reloadTagsBadges() { | ||||
|         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 { | ||||
| @@ -1127,7 +1149,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|     override fun onActivityResult(req: Int, result: Int, data: Intent?) { | ||||
|         when (req) { | ||||
|             MENU_PREFERENCES -> { | ||||
|                 drawer.closeDrawer() | ||||
|                 //drawer.closeDrawer() | ||||
|                 recreate() | ||||
|             } | ||||
|             else -> super.onActivityResult(req, result, data) | ||||
|   | ||||
| @@ -60,23 +60,18 @@ class MyApp : MultiDexApplication() { | ||||
|  | ||||
|     private fun initDrawerImageLoader() { | ||||
|         DrawerImageLoader.init(object : AbstractDrawerImageLoader() { | ||||
|             override fun set( | ||||
|                 imageView: ImageView?, | ||||
|                 uri: Uri?, | ||||
|                 placeholder: Drawable?, | ||||
|                 tag: String? | ||||
|             ) { | ||||
|             override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { | ||||
|                 Glide.with(imageView?.context) | ||||
|                     .loadMaybeBasicAuth(config, uri.toString()) | ||||
|                     .apply(RequestOptions.fitCenterTransform().placeholder(placeholder)) | ||||
|                     .into(imageView) | ||||
|             } | ||||
|  | ||||
|             override fun cancel(imageView: ImageView?) { | ||||
|             override fun cancel(imageView: 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) | ||||
|             } | ||||
|         }) | ||||
|   | ||||
| @@ -30,7 +30,11 @@ data class Tag( | ||||
|     @SerializedName("tag") val tag: String, | ||||
|     @SerializedName("color") val color: String, | ||||
|     @SerializedName("unread") val unread: Int | ||||
| ) | ||||
| ) { | ||||
|     fun getTitleDecoded(): String { | ||||
|         return Html.fromHtml(tag).toString() | ||||
|     } | ||||
| } | ||||
|  | ||||
| class SuccessResponse(@SerializedName("success") val success: Boolean) { | ||||
|     val isSuccess: Boolean | ||||
|   | ||||
| @@ -59,9 +59,9 @@ class AppColors(a: Activity) { | ||||
|         } | ||||
|  | ||||
|         textColor = if (isDarkTheme) { | ||||
|             R.color.md_white_1000 | ||||
|             R.color.white | ||||
|         } else { | ||||
|             R.color.md_grey_900 | ||||
|             R.color.grey_900 | ||||
|         } | ||||
|  | ||||
|         val wrapper = Context::class.java | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <RelativeLayout | ||||
| <androidx.drawerlayout.widget.DrawerLayout | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:id="@+id/drawerContainer" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     tools:context="apps.amine.bou.readerforselfoss.HomeActivity" | ||||
| @@ -36,51 +37,43 @@ | ||||
|  | ||||
|                 </com.google.android.material.appbar.AppBarLayout> | ||||
|  | ||||
|                 <FrameLayout | ||||
|                     android:id="@+id/drawer_layout" | ||||
|                     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|                     xmlns:tools="http://schemas.android.com/tools" | ||||
|                 <androidx.swiperefreshlayout.widget.SwipeRefreshLayout | ||||
|                     android:id="@+id/swipeRefreshLayout" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="match_parent"> | ||||
|  | ||||
|                     <androidx.swiperefreshlayout.widget.SwipeRefreshLayout | ||||
|                         android:id="@+id/swipeRefreshLayout" | ||||
|                     <LinearLayout | ||||
|                         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_height="match_parent" | ||||
|                             android:orientation="vertical" | ||||
|                             android:background="?android:attr/windowBackground"> | ||||
|                             android:layout_height="wrap_content" | ||||
|                             android:gravity="center_horizontal" | ||||
|                             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 | ||||
|                                 android:id="@+id/emptyText" | ||||
|                                 android:layout_width="match_parent" | ||||
|                                 android:layout_height="wrap_content" | ||||
|                                 android:gravity="fill" | ||||
|                                 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" /> | ||||
|                         <androidx.recyclerview.widget.RecyclerView | ||||
|                             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.recyclerview.widget.RecyclerView | ||||
|                                 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> | ||||
|  | ||||
|                     </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> | ||||
|  | ||||
|                 </FrameLayout> | ||||
|             </LinearLayout> | ||||
|  | ||||
|         </androidx.coordinatorlayout.widget.CoordinatorLayout> | ||||
| @@ -90,4 +83,11 @@ | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="60dp"/> | ||||
|     </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> | ||||
| @@ -4,30 +4,34 @@ | ||||
|         <item name="android:windowBackground">@drawable/background_splash</item> | ||||
|     </style> | ||||
|  | ||||
|     <style name="NoBar" parent="MaterialDrawerTheme.Light"> | ||||
|     <style name="NoBar" parent="Theme.MaterialComponents.Light.NoActionBar"> | ||||
|         <item name="colorPrimary">@color/colorPrimary</item> | ||||
|         <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||||
|         <item name="colorAccent">@color/colorAccent</item> | ||||
|         <item name="colorAccentDark">@color/colorAccentDark</item> | ||||
|         <item name="cardBackgroundColor">@color/white</item> | ||||
|         <item name="android:colorBackground">@color/md_grey_50</item> | ||||
|         <item name="android:textColorPrimary">@color/md_grey_900</item> | ||||
|         <item name="android:textColorSecondary">@color/md_grey_400</item> | ||||
|         <item name="material_drawer_header_selection_text">@color/md_grey_900</item> | ||||
|         <item name="android:colorBackground">@color/grey_50</item> | ||||
|         <item name="colorSurface">@color/grey_50</item> | ||||
|         <item name="android:textColorPrimary">@color/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> | ||||
|     </style> | ||||
|  | ||||
|     <style name="NoBarDark" parent="MaterialDrawerTheme"> | ||||
|     <style name="NoBarDark" parent="Theme.MaterialComponents.DayNight.NoActionBar"> | ||||
|         <item name="colorPrimary">@color/colorPrimary</item> | ||||
|         <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||||
|         <item name="colorAccent">@color/colorAccent</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="bnbBackgroundColor">@color/md_grey_900</item> | ||||
|         <item name="android:textColorPrimary">@color/md_white_1000</item> | ||||
|         <item name="android:textColorSecondary">@color/md_grey_600</item> | ||||
|         <item name="material_drawer_header_selection_text">@color/md_grey_900</item> | ||||
|         <item name="colorSurface">@color/darkBackground</item> | ||||
|         <item name="bnbBackgroundColor">@color/grey_900</item> | ||||
|         <item name="android:textColorPrimary">@color/white</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> | ||||
|     </style> | ||||
|  | ||||
| @@ -35,7 +39,6 @@ | ||||
|     <style name="ToolBarStyle" parent="Theme.AppCompat"> | ||||
|         <item name="android:textColorPrimary">@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="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item> | ||||
|         <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>--> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user