mirror of https://github.com/tasks/tasks
Update drawer headers
* Move chevron to end * Animate chevron * 'Add' button replaces 'Create new ...' rowspull/1722/head
parent
ad4af1a2cb
commit
08ff146320
@ -0,0 +1,55 @@
|
|||||||
|
package com.todoroo.astrid.adapter
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.tasks.LocalBroadcastManager
|
||||||
|
import org.tasks.data.CaldavDao
|
||||||
|
import org.tasks.data.GoogleTaskDao
|
||||||
|
import org.tasks.dialogs.NewFilterDialog
|
||||||
|
import org.tasks.filters.NavigationDrawerSubheader
|
||||||
|
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType.*
|
||||||
|
import org.tasks.preferences.MainPreferences
|
||||||
|
import org.tasks.preferences.Preferences
|
||||||
|
import org.tasks.ui.NavigationDrawerFragment
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SubheaderClickHandler @Inject constructor(
|
||||||
|
private val activity: Activity,
|
||||||
|
private val preferences: Preferences,
|
||||||
|
private val googleTaskDao: GoogleTaskDao,
|
||||||
|
private val caldavDao: CaldavDao,
|
||||||
|
private val localBroadcastManager: LocalBroadcastManager,
|
||||||
|
): SubheaderViewHolder.ClickHandler {
|
||||||
|
override fun onClick(subheader: NavigationDrawerSubheader) {
|
||||||
|
(activity as AppCompatActivity).lifecycleScope.launch {
|
||||||
|
val collapsed = !subheader.isCollapsed
|
||||||
|
when (subheader.subheaderType) {
|
||||||
|
PREFERENCE -> preferences.setBoolean(subheader.id.toInt(), collapsed)
|
||||||
|
GOOGLE_TASKS -> googleTaskDao.setCollapsed(subheader.id, collapsed)
|
||||||
|
CALDAV, TASKS, ETESYNC -> caldavDao.setCollapsed(subheader.id, collapsed)
|
||||||
|
}
|
||||||
|
localBroadcastManager.broadcastRefreshList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAdd(subheader: NavigationDrawerSubheader) {
|
||||||
|
when (subheader.addIntentRc) {
|
||||||
|
NavigationDrawerFragment.REQUEST_NEW_FILTER ->
|
||||||
|
NewFilterDialog.newFilterDialog().show(
|
||||||
|
(activity as AppCompatActivity).supportFragmentManager,
|
||||||
|
FRAG_TAG_NEW_FILTER
|
||||||
|
)
|
||||||
|
else -> activity.startActivityForResult(subheader.addIntent, subheader.addIntentRc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showError() =
|
||||||
|
activity.startActivity(Intent(activity, MainPreferences::class.java))
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val FRAG_TAG_NEW_FILTER = "frag_tag_new_filter"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,77 +1,68 @@
|
|||||||
package com.todoroo.astrid.adapter
|
package com.todoroo.astrid.adapter
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import org.tasks.LocalBroadcastManager
|
|
||||||
import org.tasks.R
|
import org.tasks.R
|
||||||
import org.tasks.data.CaldavDao
|
|
||||||
import org.tasks.data.GoogleTaskDao
|
|
||||||
import org.tasks.databinding.FilterAdapterSubheaderBinding
|
import org.tasks.databinding.FilterAdapterSubheaderBinding
|
||||||
import org.tasks.filters.NavigationDrawerSubheader
|
import org.tasks.filters.NavigationDrawerSubheader
|
||||||
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType
|
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType.ETESYNC
|
||||||
import org.tasks.preferences.MainPreferences
|
|
||||||
import org.tasks.preferences.Preferences
|
|
||||||
import org.tasks.themes.DrawableUtil
|
|
||||||
|
|
||||||
internal class SubheaderViewHolder(
|
internal class SubheaderViewHolder(
|
||||||
itemView: View,
|
itemView: View,
|
||||||
private val activity: AppCompatActivity,
|
private val clickHandler: ClickHandler,
|
||||||
private val preferences: Preferences,
|
): RecyclerView.ViewHolder(itemView) {
|
||||||
private val googleTaskDao: GoogleTaskDao,
|
|
||||||
private val caldavDao: CaldavDao,
|
interface ClickHandler {
|
||||||
private val localBroadcastManager: LocalBroadcastManager)
|
fun onClick(subheader: NavigationDrawerSubheader)
|
||||||
: RecyclerView.ViewHolder(itemView) {
|
fun onAdd(subheader: NavigationDrawerSubheader)
|
||||||
|
fun showError()
|
||||||
|
}
|
||||||
|
|
||||||
private val text: TextView
|
private val text: TextView
|
||||||
|
private val chevron: ImageView
|
||||||
|
private val add: ImageView
|
||||||
private val errorIcon: ImageView
|
private val errorIcon: ImageView
|
||||||
|
private var rotation = 0f
|
||||||
|
|
||||||
private lateinit var subheader: NavigationDrawerSubheader
|
private lateinit var subheader: NavigationDrawerSubheader
|
||||||
|
|
||||||
private fun onClick() {
|
|
||||||
activity.lifecycleScope.launch {
|
|
||||||
val collapsed = !subheader.isCollapsed
|
|
||||||
when (subheader.subheaderType) {
|
|
||||||
SubheaderType.PREFERENCE -> preferences.setBoolean(subheader.id.toInt(), collapsed)
|
|
||||||
SubheaderType.GOOGLE_TASKS -> googleTaskDao.setCollapsed(subheader.id, collapsed)
|
|
||||||
SubheaderType.CALDAV, SubheaderType.TASKS, SubheaderType.ETESYNC ->
|
|
||||||
caldavDao.setCollapsed(subheader.id, collapsed)
|
|
||||||
}
|
|
||||||
localBroadcastManager.broadcastRefreshList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(subheader: NavigationDrawerSubheader) {
|
fun bind(subheader: NavigationDrawerSubheader) {
|
||||||
|
add.isVisible = subheader.addIntent != null
|
||||||
this.subheader = subheader
|
this.subheader = subheader
|
||||||
text.text = subheader.listingTitle
|
text.text = subheader.listingTitle
|
||||||
when {
|
when {
|
||||||
subheader.error || subheader.subheaderType == SubheaderType.ETESYNC ->
|
subheader.error || subheader.subheaderType == ETESYNC ->
|
||||||
with(errorIcon) {
|
with(errorIcon) {
|
||||||
setColorFilter(ContextCompat.getColor(activity, R.color.overdue))
|
setColorFilter(ContextCompat.getColor(itemView.context, R.color.overdue))
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
else -> errorIcon.visibility = View.GONE
|
else -> errorIcon.visibility = View.GONE
|
||||||
}
|
}
|
||||||
DrawableUtil.setRightDrawable(
|
rotation = if (subheader.isCollapsed) 180f else 0f
|
||||||
itemView.context,
|
chevron.rotation = rotation
|
||||||
text,
|
}
|
||||||
if (subheader.isCollapsed) R.drawable.ic_keyboard_arrow_down_black_18dp else R.drawable.ic_keyboard_arrow_up_black_18dp)
|
|
||||||
|
private fun rotate() {
|
||||||
|
rotation = if (rotation == 0f) 180f else 0f
|
||||||
|
chevron.animate().rotation(rotation).setDuration(250).start()
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
FilterAdapterSubheaderBinding.bind(itemView).let {
|
FilterAdapterSubheaderBinding.bind(itemView).let {
|
||||||
text = it.text
|
text = it.text
|
||||||
errorIcon = it.iconError
|
errorIcon = it.iconError
|
||||||
it.subheaderRow.setOnClickListener { onClick() }
|
chevron = it.chevron
|
||||||
}
|
add = it.addItem
|
||||||
errorIcon.setOnClickListener {
|
it.subheaderRow.setOnClickListener {
|
||||||
activity.startActivity(Intent(activity, MainPreferences::class.java))
|
rotate()
|
||||||
|
clickHandler.onClick(subheader)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
errorIcon.setOnClickListener { clickHandler.showError() }
|
||||||
|
add.setOnClickListener { clickHandler.onAdd(subheader) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue