Added default icon for accounts

This commit is contained in:
dankito 2020-10-10 03:08:55 +02:00
parent c8049ea107
commit 8706778906
2 changed files with 26 additions and 13 deletions

View File

@ -3,13 +3,13 @@ package net.dankito.banking.ui.android.views
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.GravityCompat import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout import androidx.drawerlayout.widget.DrawerLayout
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
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.SecondaryDrawerItem import com.mikepenz.materialdrawer.model.SecondaryDrawerItem
@ -24,9 +24,9 @@ import net.dankito.banking.ui.android.R
import net.dankito.banking.ui.android.dialogs.settings.BankSettingsDialog import net.dankito.banking.ui.android.dialogs.settings.BankSettingsDialog
import net.dankito.banking.ui.android.dialogs.settings.SettingsDialog import net.dankito.banking.ui.android.dialogs.settings.SettingsDialog
import net.dankito.banking.ui.android.extensions.toDrawable import net.dankito.banking.ui.android.extensions.toDrawable
import net.dankito.banking.ui.android.extensions.withIcon
import net.dankito.banking.ui.model.TypedBankData import net.dankito.banking.ui.model.TypedBankData
import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.utils.android.extensions.getColorFromResource
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -90,8 +90,7 @@ open class DrawerView(
.withIdentifier(AllAccountsId) .withIdentifier(AllAccountsId)
.withLevel(BankLevel) .withLevel(BankLevel)
.withSelected(true) .withSelected(true)
// TODO: set default account icon (here and below if bank.iconUrl isn't set .withIcon(getVectorDrawable(R.drawable.ic_accounts, R.color.primaryTextColor_Dark))
.withIcon(activity, GoogleMaterial.Icon.gmd_account_balance, R.color.primaryTextColor_Dark)
.withOnDrawerItemClickListener { _, _, _ -> itemClicked { presenter.selectedAllAccounts() } } .withOnDrawerItemClickListener { _, _, _ -> itemClicked { presenter.selectedAllAccounts() } }
, ,
@ -110,8 +109,7 @@ open class DrawerView(
PrimaryDrawerItem() PrimaryDrawerItem()
.withName(R.string.settings) .withName(R.string.settings)
.withIcon(getVectorDrawable(R.drawable.ic_baseline_settings_24)) .withIcon(getVectorDrawable(R.drawable.ic_baseline_settings_24, R.color.primaryTextColor_Dark))
.withIconColor(ContextCompat.getColorStateList(activity, R.color.primaryTextColor_Dark)!!)
.withSelectable(false) .withSelectable(false)
.withOnDrawerItemClickListener { _, _, _ -> itemClicked { SettingsDialog().show(activity) } } .withOnDrawerItemClickListener { _, _, _ -> itemClicked { SettingsDialog().show(activity) } }
@ -151,16 +149,14 @@ open class DrawerView(
val accountItem = AccountDrawerItem() val accountItem = AccountDrawerItem()
.withName(bank.displayName) .withName(bank.displayName)
.withLevel(BankLevel) .withLevel(BankLevel)
.withSecondaryIcon(getVectorDrawable(R.drawable.ic_baseline_settings_24)) .withSecondaryIcon(getVectorDrawable(R.drawable.ic_baseline_settings_24, R.color.primaryTextColor_Dark))
.withSecondaryIconColor(activity, R.color.primaryTextColor_Dark)
.withOnSecondaryIconClickedListener { closeDrawerAndEditAccount(bank) } .withOnSecondaryIconClickedListener { closeDrawerAndEditAccount(bank) }
.withIcon(bank.iconData?.toDrawable(activity.resources)) .withIcon(bank.iconData?.toDrawable(activity.resources))
.withSelected(presenter.isSingleSelectedBank(bank)) .withSelected(presenter.isSingleSelectedBank(bank))
.withOnDrawerItemClickListener { _, _, _ -> itemClicked { presenter.selectedBank(bank) } } .withOnDrawerItemClickListener { _, _, _ -> itemClicked { presenter.selectedBank(bank) } }
if (bank.iconData == null) { if (bank.iconData == null) {
// TODO: use better default icon accountItem.withIcon(getVectorDrawable(R.drawable.ic_accounts, R.color.primaryTextColor_Dark))
accountItem.withIcon(activity, GoogleMaterial.Icon.gmd_account_balance, R.color.primaryTextColor_Dark)
} }
@ -209,8 +205,14 @@ open class DrawerView(
} }
private fun getVectorDrawable(@DrawableRes drawableResId: Int): Drawable? { private fun getVectorDrawable(@DrawableRes drawableResId: Int, @ColorRes tintColorResId: Int? = null): Drawable? {
return AppCompatResources.getDrawable(activity, drawableResId) val drawable = AppCompatResources.getDrawable(activity, drawableResId)
if (tintColorResId != null && drawable != null) {
DrawableCompat.setTint(drawable, activity.getColorFromResource(tintColorResId))
}
return drawable
} }
} }

View File

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12dp"
android:height="11dp"
android:viewportWidth="12"
android:viewportHeight="11">
<path
android:pathData="M3.5,2.75C3.2239,2.75 3,2.9739 3,3.25v4.5c0,0.2761 0.2239,0.5 0.5,0.5h5C8.7761,8.25 9,8.0261 9,7.75L9,3.25C9,2.9739 8.7761,2.75 8.5,2.75ZM3.95,5.75c-0.1105,0 -0.2,0.0895 -0.2,0.2v0.1c0,0.1105 0.0895,0.2 0.2,0.2h4.1c0.1104,0 0.2,-0.0895 0.2,-0.2v-0.1c0,-0.1105 -0.0896,-0.2 -0.2,-0.2zM6.75,3.95c0,-0.1105 0.0895,-0.2 0.2,-0.2h1.1c0.1104,0 0.2,0.0895 0.2,0.2v0.2c0,0.1105 -0.0896,0.2 -0.2,0.2h-1.1c-0.1105,0 -0.2,-0.0895 -0.2,-0.2zM3.95,6.75c-0.1105,0 -0.2,0.0895 -0.2,0.2v0.1c0,0.1105 0.0895,0.2 0.2,0.2h4.1c0.1104,0 0.2,-0.0895 0.2,-0.2v-0.1c0,-0.1105 -0.0896,-0.2 -0.2,-0.2z"
android:strokeWidth="0.5"
android:fillColor="#989792"
android:fillType="evenOdd"/>
</vector>