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'
// Drawer
compile('com.mikepenz:materialdrawer:5.9.5@aar') {
transitive = true
}
implementation 'co.zsmb:materialdrawer-kt:1.2.1'
compile 'com.anupcowkur:reservoir:3.1.0'
// 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.drawer.CustomUrlPrimaryDrawerItem
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.ReservoirGetCallback
import com.anupcowkur.reservoir.ReservoirPutCallback
@ -61,20 +66,14 @@ import com.google.gson.reflect.TypeToken
import com.heinrichreimersoftware.androidissuereporter.IssueReporterLauncher
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.LibsBuilder
import com.mikepenz.materialdrawer.AccountHeader
import com.mikepenz.materialdrawer.AccountHeaderBuilder
import com.mikepenz.materialdrawer.Drawer
import com.mikepenz.materialdrawer.DrawerBuilder
import com.mikepenz.materialdrawer.holder.BadgeStyle
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 retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.lang.Exception
class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
@ -114,7 +113,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private lateinit var tabNewBadge: TextBadgeItem
private lateinit var tabArchiveBadge: TextBadgeItem
private lateinit var tabStarredBadge: TextBadgeItem
private lateinit var toolbar: Toolbar
private lateinit var toolBar: Toolbar
private lateinit var drawer: Drawer
private lateinit var api: SelfossApi
private lateinit var customTabActivityHelper: CustomTabActivityHelper
@ -146,8 +145,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
setContentView(R.layout.activity_home)
toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
toolBar = findViewById(R.id.toolbar)
setSupportActionBar(toolBar)
if (savedInstanceState == null) {
val promptView: DefaultLayoutPromptView = findViewById(R.id.prompt_view)
@ -333,55 +332,37 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
displayAccountHeader =
PreferenceManager.getDefaultSharedPreferences(this)
.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 =
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) {
drawer = drawer {
rootViewRes = R.id.drawer_layout
toolbar = toolBar
actionBarDrawerToggleEnabled = true
actionBarDrawerToggleAnimated = true
showOnFirstLaunch = true
onSlide { _, p1 ->
bottomBar.alpha = (1 - p1)
}
override fun onDrawerClosed(v: View?) {
onClosed {
bottomBar.show()
}
override fun onDrawerOpened(v: View?) {
onOpened {
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)
drawerBuilder.withAccountHeader(headerResult)
drawer = drawerBuilder.build()
drawer.addStickyFooterItem(
PrimaryDrawerItem()
.withName(R.string.drawer_report_bug)
.withIcon(R.drawable.ic_bug_report)
.withIconTintingEnabled(true)
.withOnDrawerItemClickListener { _, _, _ ->
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)
@ -390,17 +371,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
.putExtraInfo("Unique ID", settings.getString("unique_id", ""))
.putExtraInfo("From github", BuildConfig.GITHUB_VERSION)
.homeAsUpEnabled(true)
.launch(this)
.launch(this@HomeActivity)
false
}
)
}
drawer.addStickyFooterItem(
PrimaryDrawerItem()
.withName(R.string.title_activity_settings)
.withIcon(R.drawable.ic_settings)
.withIconTintingEnabled(true)
.withOnDrawerItemClickListener { _, _, _ ->
primaryItem(R.string.title_activity_settings) {
icon = R.drawable.ic_settings
iconTintingEnabled = true
onClick { _ ->
startActivityForResult(
Intent(
this@HomeActivity,
@ -410,7 +389,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
)
false
}
)
}
}
}
}
@ -419,6 +400,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
fun handleTags(maybeTags: List<Tag>?) {
if (maybeTags == null) {
if (loadedFromCache)
drawer.addItem(
SecondaryDrawerItem()
.withName(getString(R.string.drawer_error_loading_tags))