Fixed #98. Using kotlin implementation for the drawer. Using the new style code.

This commit is contained in:
Amine 2017-11-11 07:58:29 +01:00
parent 84dfa9a8a5
commit f0563efc62
2 changed files with 148 additions and 168 deletions

View File

@ -159,9 +159,7 @@ dependencies {
compile 'com.klinkerapps:drag-dismiss-activity:1.5.0' compile 'com.klinkerapps:drag-dismiss-activity:1.5.0'
// Drawer // Drawer
compile('com.mikepenz:materialdrawer:5.9.5@aar') { implementation 'co.zsmb:materialdrawer-kt:1.2.1'
transitive = true
}
compile 'com.anupcowkur:reservoir:3.1.0' compile 'com.anupcowkur:reservoir:3.1.0'
// Themes // Themes

View File

@ -41,6 +41,11 @@ import apps.amine.bou.readerforselfoss.utils.checkApkVersion
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
import apps.amine.bou.readerforselfoss.utils.drawer.CustomUrlPrimaryDrawerItem import apps.amine.bou.readerforselfoss.utils.drawer.CustomUrlPrimaryDrawerItem
import apps.amine.bou.readerforselfoss.utils.longHash import apps.amine.bou.readerforselfoss.utils.longHash
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.anupcowkur.reservoir.Reservoir import com.anupcowkur.reservoir.Reservoir
import com.anupcowkur.reservoir.ReservoirGetCallback import com.anupcowkur.reservoir.ReservoirGetCallback
import com.anupcowkur.reservoir.ReservoirPutCallback import com.anupcowkur.reservoir.ReservoirPutCallback
@ -61,20 +66,14 @@ import com.google.gson.reflect.TypeToken
import com.heinrichreimersoftware.androidissuereporter.IssueReporterLauncher import com.heinrichreimersoftware.androidissuereporter.IssueReporterLauncher
import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.LibsBuilder import com.mikepenz.aboutlibraries.LibsBuilder
import com.mikepenz.materialdrawer.AccountHeader
import com.mikepenz.materialdrawer.AccountHeaderBuilder
import com.mikepenz.materialdrawer.Drawer import com.mikepenz.materialdrawer.Drawer
import com.mikepenz.materialdrawer.DrawerBuilder
import com.mikepenz.materialdrawer.holder.BadgeStyle import com.mikepenz.materialdrawer.holder.BadgeStyle
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 retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
import java.lang.Exception
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
@ -114,7 +113,7 @@ 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 toolbar: Toolbar private lateinit var toolBar: Toolbar
private lateinit var drawer: Drawer 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
@ -146,8 +145,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
setContentView(R.layout.activity_home) setContentView(R.layout.activity_home)
toolbar = findViewById(R.id.toolbar) toolBar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar) setSupportActionBar(toolBar)
if (savedInstanceState == null) { if (savedInstanceState == null) {
val promptView: DefaultLayoutPromptView = findViewById(R.id.prompt_view) val promptView: DefaultLayoutPromptView = findViewById(R.id.prompt_view)
@ -331,86 +330,68 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private fun handleDrawer() { private fun handleDrawer() {
displayAccountHeader = displayAccountHeader =
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("account_header_displaying", false) .getBoolean("account_header_displaying", false)
val headerResult: AccountHeader? = if (displayAccountHeader) {
AccountHeaderBuilder() drawer = drawer {
.withActivity(this) rootViewRes = R.id.drawer_layout
.withHeaderBackground(R.drawable.bg) toolbar = toolBar
.addProfiles( actionBarDrawerToggleEnabled = true
ProfileDrawerItem() actionBarDrawerToggleAnimated = true
.withName( showOnFirstLaunch = true
settings.getString("url", "") onSlide { _, p1 ->
bottomBar.alpha = (1 - p1)
}
onClosed {
bottomBar.show()
}
onOpened {
bottomBar.hide()
}
if (displayAccountHeader)
accountHeader {
background = R.drawable.bg
profile(settings.getString("url", "")) {
iconDrawable = resources.getDrawable(R.mipmap.ic_launcher)
}
selectionListEnabledForSingleProfile = false
}
footer {
primaryItem(R.string.drawer_report_bug) {
icon = R.drawable.ic_bug_report
iconTintingEnabled = true
onClick { _ ->
IssueReporterLauncher.forTarget(getString(R.string.report_github_user), getString(R.string.report_github_repo))
.theme(R.style.Theme_App_Light)
.guestToken(BuildConfig.GITHUB_TOKEN)
.guestEmailRequired(true)
.minDescriptionLength(20)
.putExtraInfo("Unique ID", settings.getString("unique_id", ""))
.putExtraInfo("From github", BuildConfig.GITHUB_VERSION)
.homeAsUpEnabled(true)
.launch(this@HomeActivity)
false
}
}
primaryItem(R.string.title_activity_settings) {
icon = R.drawable.ic_settings
iconTintingEnabled = true
onClick { _ ->
startActivityForResult(
Intent(
this@HomeActivity,
SettingsActivity::class.java
),
MENU_PREFERENCES
) )
.withIcon(resources.getDrawable(R.mipmap.ic_launcher)) false
)
.withSelectionListEnabledForSingleProfile(false)
.build()
} else null
val drawerBuilder =
DrawerBuilder()
.withActivity(this)
.withRootView(R.id.drawer_layout)
.withToolbar(toolbar)
.withActionBarDrawerToggle(true)
.withActionBarDrawerToggleAnimated(true)
.withShowDrawerOnFirstLaunch(true)
.withOnDrawerListener(object: Drawer.OnDrawerListener {
override fun onDrawerSlide(v: View?, p1: Float) {
bottomBar.alpha = (1 - p1)
} }
override fun onDrawerClosed(v: View?) {
bottomBar.show()
}
override fun onDrawerOpened(v: View?) {
bottomBar.hide()
}
})
if (displayAccountHeader && headerResult != null)
drawerBuilder.withAccountHeader(headerResult)
drawer = drawerBuilder.build()
drawer.addStickyFooterItem(
PrimaryDrawerItem()
.withName(R.string.drawer_report_bug)
.withIcon(R.drawable.ic_bug_report)
.withIconTintingEnabled(true)
.withOnDrawerItemClickListener { _, _, _ ->
IssueReporterLauncher.forTarget(getString(R.string.report_github_user), getString(R.string.report_github_repo))
.theme(R.style.Theme_App_Light)
.guestToken(BuildConfig.GITHUB_TOKEN)
.guestEmailRequired(true)
.minDescriptionLength(20)
.putExtraInfo("Unique ID", settings.getString("unique_id", ""))
.putExtraInfo("From github", BuildConfig.GITHUB_VERSION)
.homeAsUpEnabled(true)
.launch(this)
false
} }
) }
}
drawer.addStickyFooterItem(
PrimaryDrawerItem()
.withName(R.string.title_activity_settings)
.withIcon(R.drawable.ic_settings)
.withIconTintingEnabled(true)
.withOnDrawerItemClickListener { _, _, _ ->
startActivityForResult(
Intent(
this@HomeActivity,
SettingsActivity::class.java
),
MENU_PREFERENCES
)
false
}
)
} }
@ -419,10 +400,11 @@ 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( drawer.addItem(
SecondaryDrawerItem() SecondaryDrawerItem()
.withName(getString(R.string.drawer_error_loading_tags)) .withName(getString(R.string.drawer_error_loading_tags))
.withSelectable(false)) .withSelectable(false))
} }
else { else {
for (tag in maybeTags) { for (tag in maybeTags) {
@ -432,20 +414,20 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
gd.setSize(30, 30) gd.setSize(30, 30)
gd.cornerRadius = 30F gd.cornerRadius = 30F
drawer.addItem( drawer.addItem(
PrimaryDrawerItem() PrimaryDrawerItem()
.withName(tag.tag) .withName(tag.tag)
.withIdentifier(tag.tag.longHash()) .withIdentifier(tag.tag.longHash())
.withIcon(gd) .withIcon(gd)
.withBadge("${tag.unread}") .withBadge("${tag.unread}")
.withBadgeStyle( .withBadgeStyle(
BadgeStyle().withTextColor(Color.WHITE) BadgeStyle().withTextColor(Color.WHITE)
.withColor(appColors.accent) .withColor(appColors.accent)
) )
.withOnDrawerItemClickListener { _, _, _ -> .withOnDrawerItemClickListener { _, _, _ ->
maybeTagFilter = tag maybeTagFilter = tag
getElementsAccordingToTab() getElementsAccordingToTab()
false false
} }
) )
} }
} }
@ -456,22 +438,22 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
if (maybeSources == null) { if (maybeSources == null) {
if (loadedFromCache) if (loadedFromCache)
drawer.addItem( drawer.addItem(
SecondaryDrawerItem() SecondaryDrawerItem()
.withName(getString(R.string.drawer_error_loading_sources)) .withName(getString(R.string.drawer_error_loading_sources))
.withSelectable(false)) .withSelectable(false))
} }
else else
for (tag in maybeSources) for (tag in maybeSources)
drawer.addItem( drawer.addItem(
CustomUrlPrimaryDrawerItem() CustomUrlPrimaryDrawerItem()
.withName(tag.title) .withName(tag.title)
.withIdentifier(tag.id.toLong()) .withIdentifier(tag.id.toLong())
.withIcon(tag.getIcon(this@HomeActivity)) .withIcon(tag.getIcon(this@HomeActivity))
.withOnDrawerItemClickListener { _, _, _ -> .withOnDrawerItemClickListener { _, _, _ ->
maybeSourceFilter = tag maybeSourceFilter = tag
getElementsAccordingToTab() getElementsAccordingToTab()
false false
} }
) )
} }
@ -479,58 +461,58 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
drawer.removeAllItems() drawer.removeAllItems()
if (maybeDrawerData != null) { if (maybeDrawerData != null) {
drawer.addItem( drawer.addItem(
SecondaryDrawerItem() SecondaryDrawerItem()
.withName(getString(R.string.drawer_item_filters)) .withName(getString(R.string.drawer_item_filters))
.withSelectable(false) .withSelectable(false)
.withIdentifier(DRAWER_ID_FILTERS) .withIdentifier(DRAWER_ID_FILTERS)
.withBadge(getString(R.string.drawer_action_clear)) .withBadge(getString(R.string.drawer_action_clear))
.withOnDrawerItemClickListener { _, _, _ -> .withOnDrawerItemClickListener { _, _, _ ->
maybeSourceFilter = null maybeSourceFilter = null
maybeTagFilter = null maybeTagFilter = null
getElementsAccordingToTab() getElementsAccordingToTab()
false false
} }
) )
drawer.addItem(DividerDrawerItem()) drawer.addItem(DividerDrawerItem())
drawer.addItem( drawer.addItem(
SecondaryDrawerItem() SecondaryDrawerItem()
.withName(getString(R.string.drawer_item_tags)) .withName(getString(R.string.drawer_item_tags))
.withIdentifier(DRAWER_ID_TAGS) .withIdentifier(DRAWER_ID_TAGS)
.withSelectable(false)) .withSelectable(false))
handleTags(maybeDrawerData.tags) handleTags(maybeDrawerData.tags)
drawer.addItem(DividerDrawerItem()) drawer.addItem(DividerDrawerItem())
drawer.addItem( drawer.addItem(
SecondaryDrawerItem() SecondaryDrawerItem()
.withName(getString(R.string.drawer_item_sources)) .withName(getString(R.string.drawer_item_sources))
.withIdentifier(DRAWER_ID_TAGS) .withIdentifier(DRAWER_ID_TAGS)
.withBadge(getString(R.string.drawer_action_edit)) .withBadge(getString(R.string.drawer_action_edit))
.withSelectable(false) .withSelectable(false)
.withOnDrawerItemClickListener { _, _, _ -> .withOnDrawerItemClickListener { _, _, _ ->
startActivity(Intent(this, SourcesActivity::class.java)) startActivity(Intent(this, SourcesActivity::class.java))
false false
} }
) )
handleSources(maybeDrawerData.sources) handleSources(maybeDrawerData.sources)
drawer.addItem(DividerDrawerItem()) drawer.addItem(DividerDrawerItem())
drawer.addItem( drawer.addItem(
PrimaryDrawerItem() PrimaryDrawerItem()
.withName(R.string.action_about) .withName(R.string.action_about)
.withSelectable(false) .withSelectable(false)
.withIcon(R.drawable.ic_info_outline) .withIcon(R.drawable.ic_info_outline)
.withIconTintingEnabled(true) .withIconTintingEnabled(true)
.withOnDrawerItemClickListener { _, _, _ -> .withOnDrawerItemClickListener { _, _, _ ->
LibsBuilder() LibsBuilder()
.withActivityStyle( .withActivityStyle(
if (appColors.isDarkTheme) if (appColors.isDarkTheme)
Libs.ActivityStyle.LIGHT_DARK_TOOLBAR Libs.ActivityStyle.LIGHT_DARK_TOOLBAR
else else
Libs.ActivityStyle.DARK Libs.ActivityStyle.DARK
) )
.withAboutIconShown(true) .withAboutIconShown(true)
.withAboutVersionShown(true) .withAboutVersionShown(true)
.start(this@HomeActivity) .start(this@HomeActivity)
false false
}) })
if (!loadedFromCache) if (!loadedFromCache)
@ -544,15 +526,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} else { } else {
if (!loadedFromCache) { if (!loadedFromCache) {
drawer.addItem( drawer.addItem(
PrimaryDrawerItem() PrimaryDrawerItem()
.withName(getString(R.string.no_tags_loaded)) .withName(getString(R.string.no_tags_loaded))
.withIdentifier(DRAWER_ID_TAGS) .withIdentifier(DRAWER_ID_TAGS)
.withSelectable(false)) .withSelectable(false))
drawer.addItem( drawer.addItem(
PrimaryDrawerItem() PrimaryDrawerItem()
.withName(getString(R.string.no_sources_loaded)) .withName(getString(R.string.no_sources_loaded))
.withIdentifier(DRAWER_ID_SOURCES) .withIdentifier(DRAWER_ID_SOURCES)
.withSelectable(false)) .withSelectable(false))
} }
} }