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)
@ -333,55 +332,37 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
displayAccountHeader = displayAccountHeader =
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean("account_header_displaying", false) .getBoolean("account_header_displaying", false)
val headerResult: AccountHeader? = if (displayAccountHeader) {
AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.drawable.bg)
.addProfiles(
ProfileDrawerItem()
.withName(
settings.getString("url", "")
)
.withIcon(resources.getDrawable(R.mipmap.ic_launcher))
)
.withSelectionListEnabledForSingleProfile(false)
.build()
} else null
val drawerBuilder = drawer = drawer {
DrawerBuilder() rootViewRes = R.id.drawer_layout
.withActivity(this) toolbar = toolBar
.withRootView(R.id.drawer_layout) actionBarDrawerToggleEnabled = true
.withToolbar(toolbar) actionBarDrawerToggleAnimated = true
.withActionBarDrawerToggle(true) showOnFirstLaunch = true
.withActionBarDrawerToggleAnimated(true) onSlide { _, p1 ->
.withShowDrawerOnFirstLaunch(true)
.withOnDrawerListener(object: Drawer.OnDrawerListener {
override fun onDrawerSlide(v: View?, p1: Float) {
bottomBar.alpha = (1 - p1) bottomBar.alpha = (1 - p1)
} }
onClosed {
override fun onDrawerClosed(v: View?) {
bottomBar.show() bottomBar.show()
} }
onOpened {
override fun onDrawerOpened(v: View?) {
bottomBar.hide() bottomBar.hide()
} }
}) if (displayAccountHeader)
accountHeader {
background = R.drawable.bg
profile(settings.getString("url", "")) {
iconDrawable = resources.getDrawable(R.mipmap.ic_launcher)
}
selectionListEnabledForSingleProfile = false
}
if (displayAccountHeader && headerResult != null) footer {
drawerBuilder.withAccountHeader(headerResult) primaryItem(R.string.drawer_report_bug) {
icon = R.drawable.ic_bug_report
drawer = drawerBuilder.build() iconTintingEnabled = true
onClick { _ ->
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)) IssueReporterLauncher.forTarget(getString(R.string.report_github_user), getString(R.string.report_github_repo))
.theme(R.style.Theme_App_Light) .theme(R.style.Theme_App_Light)
.guestToken(BuildConfig.GITHUB_TOKEN) .guestToken(BuildConfig.GITHUB_TOKEN)
@ -390,17 +371,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
.putExtraInfo("Unique ID", settings.getString("unique_id", "")) .putExtraInfo("Unique ID", settings.getString("unique_id", ""))
.putExtraInfo("From github", BuildConfig.GITHUB_VERSION) .putExtraInfo("From github", BuildConfig.GITHUB_VERSION)
.homeAsUpEnabled(true) .homeAsUpEnabled(true)
.launch(this) .launch(this@HomeActivity)
false false
} }
) }
drawer.addStickyFooterItem( primaryItem(R.string.title_activity_settings) {
PrimaryDrawerItem() icon = R.drawable.ic_settings
.withName(R.string.title_activity_settings) iconTintingEnabled = true
.withIcon(R.drawable.ic_settings) onClick { _ ->
.withIconTintingEnabled(true)
.withOnDrawerItemClickListener { _, _, _ ->
startActivityForResult( startActivityForResult(
Intent( Intent(
this@HomeActivity, this@HomeActivity,
@ -410,7 +389,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
) )
false false
} }
) }
}
}
} }
@ -419,6 +400,7 @@ 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))