Button bar in navigation drawer
This commit is contained in:
parent
3b42061377
commit
96b7ca264d
5 changed files with 148 additions and 53 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.fsck.k9.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Resources
|
||||
|
@ -7,8 +8,10 @@ import android.graphics.PorterDuff
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
|
@ -44,12 +47,10 @@ import com.mikepenz.materialdrawer.model.interfaces.selectedColorInt
|
|||
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||
import com.mikepenz.materialdrawer.util.addItems
|
||||
import com.mikepenz.materialdrawer.util.addStickyFooterItem
|
||||
import com.mikepenz.materialdrawer.util.getDrawerItem
|
||||
import com.mikepenz.materialdrawer.util.removeAllItems
|
||||
import com.mikepenz.materialdrawer.widget.AccountHeaderView
|
||||
import com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
|
||||
import java.util.ArrayList
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
@ -69,6 +70,12 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
private val messagingController: MessagingController by inject()
|
||||
private val accountImageLoader: AccountImageLoader by inject()
|
||||
|
||||
private val buttonRow: LinearLayout = parent.findViewById(R.id.material_drawer_button_row)
|
||||
private val buttonSettings: ImageView = parent.findViewById(R.id.drawer_button_settings)
|
||||
private val buttonManageFolders: ImageView = parent.findViewById(R.id.drawer_button_manage_folders)
|
||||
private val buttonRefreshAll: ImageView = parent.findViewById(R.id.drawer_button_refresh_all)
|
||||
private val buttonRefreshAccount: ImageView = parent.findViewById(R.id.drawer_button_refresh_account)
|
||||
|
||||
private val drawer: DrawerLayout = parent.findViewById(R.id.drawerLayout)
|
||||
private val sliderView: MaterialDrawerSliderView = parent.findViewById(R.id.material_drawer_slider)
|
||||
private val headerView: AccountHeaderView = AccountHeaderView(parent).apply {
|
||||
|
@ -99,6 +106,7 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
|
||||
initializeImageLoader()
|
||||
configureAccountHeader()
|
||||
configureButtonBar()
|
||||
|
||||
drawer.addDrawerListener(parent.createDrawerListener())
|
||||
sliderView.tintStatusBar = true
|
||||
|
@ -125,8 +133,6 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
}
|
||||
}
|
||||
|
||||
addFooterItems()
|
||||
|
||||
accountsViewModel.displayAccountsLiveData.observeNotNull(parent) { accounts ->
|
||||
setAccounts(accounts)
|
||||
}
|
||||
|
@ -162,6 +168,7 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
openedAccountUuid = account.uuid
|
||||
val eventHandled = !parent.openRealAccount(account)
|
||||
updateUserAccountsAndFolders(account)
|
||||
updateButtonBarVisibility(false)
|
||||
|
||||
eventHandled
|
||||
}
|
||||
|
@ -209,6 +216,36 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
return if (unreadCount > 0) unreadCount.toString() else null
|
||||
}
|
||||
|
||||
private fun updateButtonBarVisibility(showsAccounts: Boolean) {
|
||||
buttonManageFolders.visibility = if (showsAccounts) View.GONE else View.VISIBLE
|
||||
buttonRefreshAccount.visibility = if (showsAccounts) View.GONE else View.VISIBLE
|
||||
buttonRefreshAll.visibility = if (showsAccounts) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun configureButtonBar() {
|
||||
headerView.onAccountHeaderSelectionViewClickListener = { view, profile ->
|
||||
updateButtonBarVisibility(!headerView.selectionListShown)
|
||||
false
|
||||
}
|
||||
updateButtonBarVisibility(headerView.selectionListShown)
|
||||
|
||||
buttonRow.setOnTouchListener { _, _ -> true } // To avoid touch going through
|
||||
buttonSettings.setOnClickListener { SettingsActivity.launch(parent) }
|
||||
buttonManageFolders.setOnClickListener { parent.launchManageFoldersScreen() }
|
||||
buttonRefreshAccount.setOnClickListener { refreshAndShowProgress(headerView.activeProfile?.tag as Account) }
|
||||
buttonRefreshAll.setOnClickListener { refreshAndShowProgress(null) }
|
||||
|
||||
val showContentDescription = View.OnLongClickListener { v ->
|
||||
Toast.makeText(parent, v.contentDescription, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
buttonSettings.setOnLongClickListener(showContentDescription)
|
||||
buttonManageFolders.setOnLongClickListener(showContentDescription)
|
||||
buttonRefreshAccount.setOnLongClickListener(showContentDescription)
|
||||
buttonRefreshAll.setOnLongClickListener(showContentDescription)
|
||||
}
|
||||
|
||||
private fun setAccounts(displayAccounts: List<DisplayAccount>) {
|
||||
val oldSelectedBackgroundColor = selectedBackgroundColor
|
||||
|
||||
|
@ -259,35 +296,6 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
}
|
||||
}
|
||||
|
||||
private fun addFooterItems() {
|
||||
sliderView.addStickyFooterItem(
|
||||
PrimaryDrawerItem().apply {
|
||||
nameRes = R.string.folders_action
|
||||
iconRes = folderIconProvider.iconFolderResId
|
||||
identifier = DRAWER_ID_FOLDERS
|
||||
isSelectable = false
|
||||
}
|
||||
)
|
||||
|
||||
sliderView.addStickyFooterItem(
|
||||
PrimaryDrawerItem().apply {
|
||||
nameRes = R.string.preferences_action
|
||||
iconRes = getResId(R.attr.iconActionSettings)
|
||||
identifier = DRAWER_ID_PREFERENCES
|
||||
isSelectable = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun getResId(resAttribute: Int): Int {
|
||||
val typedValue = TypedValue()
|
||||
val found = parent.theme.resolveAttribute(resAttribute, typedValue, true)
|
||||
if (!found) {
|
||||
throw AssertionError("Couldn't find resource with attribute $resAttribute")
|
||||
}
|
||||
return typedValue.resourceId
|
||||
}
|
||||
|
||||
private fun getFolderDisplayName(folder: Folder): String {
|
||||
return folderNameFormatter.displayName(folder)
|
||||
}
|
||||
|
@ -299,20 +307,26 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
foldersViewModel.loadFolders(account)
|
||||
}
|
||||
|
||||
// Account can be null to refresh all (unified inbox or account list).
|
||||
swipeRefreshLayout.setOnRefreshListener {
|
||||
val accountToRefresh = if (headerView.selectionListShown) null else account
|
||||
messagingController.checkMail(
|
||||
accountToRefresh, true, true,
|
||||
object : SimpleMessagingListener() {
|
||||
override fun checkMailFinished(context: Context?, account: Account?) {
|
||||
swipeRefreshLayout.post {
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
}
|
||||
refreshAndShowProgress(if (headerView.selectionListShown) null else account)
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshAndShowProgress(account: Account?) {
|
||||
// Account can be null to refresh all (unified inbox or account list).
|
||||
if (!swipeRefreshLayout.isRefreshing) {
|
||||
swipeRefreshLayout.isRefreshing = true
|
||||
}
|
||||
messagingController.checkMail(
|
||||
account, true, true,
|
||||
object : SimpleMessagingListener() {
|
||||
override fun checkMailFinished(context: Context?, account: Account?) {
|
||||
swipeRefreshLayout.post {
|
||||
swipeRefreshLayout.isRefreshing = false
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun initializeWithAccountColor(account: Account) {
|
||||
|
@ -329,8 +343,6 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) : K
|
|||
|
||||
private fun handleItemClickListener(drawerItem: IDrawerItem<*>) {
|
||||
when (drawerItem.identifier) {
|
||||
DRAWER_ID_PREFERENCES -> SettingsActivity.launch(parent)
|
||||
DRAWER_ID_FOLDERS -> parent.launchManageFoldersScreen()
|
||||
DRAWER_ID_UNIFIED_INBOX -> parent.openUnifiedInbox()
|
||||
else -> {
|
||||
val folder = drawerItem.tag as Folder
|
||||
|
|
10
app/ui/legacy/src/main/res/drawable/ic_folder_manage.xml
Normal file
10
app/ui/legacy/src/main/res/drawable/ic_folder_manage.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M4 4C2.89 4 2 4.89 2 6V18C2 19.11 2.9 20 4 20H12.08A7 7 0 0 1 12 19A7 7 0 0 1 19 12A7 7 0 0 1 22 12.69V8C22 6.89 21.1 6 20 6H12L10 4H4M18 14C17.87 14 17.76 14.09 17.74 14.21L17.55 15.53C17.25 15.66 16.96 15.82 16.7 16L15.46 15.5C15.35 15.5 15.22 15.5 15.15 15.63L14.15 17.36C14.09 17.47 14.11 17.6 14.21 17.68L15.27 18.5C15.25 18.67 15.24 18.83 15.24 19C15.24 19.17 15.25 19.33 15.27 19.5L14.21 20.32C14.12 20.4 14.09 20.53 14.15 20.64L15.15 22.37C15.21 22.5 15.34 22.5 15.46 22.5L16.7 22C16.96 22.18 17.24 22.35 17.55 22.47L17.74 23.79C17.76 23.91 17.86 24 18 24H20C20.11 24 20.22 23.91 20.24 23.79L20.43 22.47C20.73 22.34 21 22.18 21.27 22L22.5 22.5C22.63 22.5 22.76 22.5 22.83 22.37L23.83 20.64C23.89 20.53 23.86 20.4 23.77 20.32L22.7 19.5C22.72 19.33 22.74 19.17 22.74 19C22.74 18.83 22.73 18.67 22.7 18.5L23.76 17.68C23.85 17.6 23.88 17.47 23.82 17.36L22.82 15.63C22.76 15.5 22.63 15.5 22.5 15.5L21.27 16C21 15.82 20.73 15.65 20.42 15.53L20.23 14.21C20.22 14.09 20.11 14 20 14H18M19 17.5C19.83 17.5 20.5 18.17 20.5 19C20.5 19.83 19.83 20.5 19 20.5C18.16 20.5 17.5 19.83 17.5 19C17.5 18.17 18.17 17.5 19 17.5Z" />
|
||||
</vector>
|
10
app/ui/legacy/src/main/res/drawable/ic_refresh_all.xml
Normal file
10
app/ui/legacy/src/main/res/drawable/ic_refresh_all.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M 15.857724,5.2112257 C 14.378581,4.5245963 13.792531,3.9942489 12,4 7.5800227,4.014181 4.01,7.58 4.01,12 c 0,4.42 3.57,8 7.99,8 3.73,0 7.524253,-2.99534 8.059024,-6.794874 L 17.65,14 C 16.83,16.33 14.61,18 12,18 8.69,18 6,15.31 6,12 6,8.69 8.6900019,6.0035629 12,6 c 1.452738,-0.00156 2.062645,0.5403058 3.076787,1.0329571 l -1.787121,3.6480969 6.559477,-2.4440265 -2.444026,-6.559477 z m 4.452463,0.308222 1.367566,3.6691007 -3.693934,1.4494656 -0.757545,1.913288 6.559477,-2.444026 -2.444026,-6.559477 z" />
|
||||
</vector>
|
|
@ -47,16 +47,78 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/material_drawer_swipe_refresh"
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="start">
|
||||
|
||||
<com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
|
||||
android:id="@+id/material_drawer_slider"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/material_drawer_swipe_refresh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
<com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
|
||||
android:id="@+id/material_drawer_slider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/messageListDividerColor" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/material_drawer_button_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="4dp"
|
||||
android:background="?android:attr/windowBackground">
|
||||
<ImageView
|
||||
android:id="@+id/drawer_button_refresh_account"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="?attr/iconActionRefresh"
|
||||
android:contentDescription="@string/check_mail_action"
|
||||
android:padding="12dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/drawer_button_refresh_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_refresh_all"
|
||||
android:contentDescription="@string/check_all_mail_action"
|
||||
android:padding="12dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/drawer_button_manage_folders"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_folder_manage"
|
||||
android:contentDescription="@string/folders_action"
|
||||
android:padding="12dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/drawer_button_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="?attr/iconActionSettings"
|
||||
android:contentDescription="@string/preferences_action"
|
||||
android:padding="12dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
|
|
|
@ -133,6 +133,7 @@ Please submit bug reports, contribute new features and ask questions at
|
|||
<string name="discard_action">Discard</string>
|
||||
<string name="save_draft_action">Save as draft</string>
|
||||
<string name="check_mail_action">Check mail</string>
|
||||
<string name="check_all_mail_action">Check mail in all accounts</string>
|
||||
<string name="send_messages_action">Send messages</string>
|
||||
<string name="refresh_folders_action">Refresh folder list</string>
|
||||
<string name="filter_folders_action">Find folder</string>
|
||||
|
|
Loading…
Reference in a new issue