notification improvements (#522)
* correctly filter notifications on Api >= 26, other fixes and refactoring * use correct areNotificationsEnabled method in MainActivity * change notification led color
This commit is contained in:
parent
c502e001d7
commit
0b59b8d0ac
7 changed files with 78 additions and 55 deletions
|
|
@ -24,6 +24,8 @@ import com.keylesspalace.tusky.entity.Account
|
|||
* @author ConnyDuck
|
||||
*/
|
||||
|
||||
private const val TAG = "AccountManager"
|
||||
|
||||
class AccountManager {
|
||||
|
||||
@Volatile var activeAccount: AccountEntity? = null
|
||||
|
|
@ -50,7 +52,7 @@ class AccountManager {
|
|||
|
||||
activeAccount?.let{
|
||||
it.isActive = false
|
||||
Log.d("AccountManager", "saving account with id "+it.id)
|
||||
Log.d(TAG, "addAccount: saving account with id "+it.id)
|
||||
|
||||
accountDao.insertOrReplace(it)
|
||||
}
|
||||
|
|
@ -66,13 +68,7 @@ class AccountManager {
|
|||
*/
|
||||
fun saveAccount(account: AccountEntity) {
|
||||
if(account.id != 0L) {
|
||||
Log.d("AccountManager", "saving account with id "+account.id)
|
||||
val index = accounts.indexOf(account)
|
||||
if (index != -1) {
|
||||
accounts.removeAt(index)
|
||||
accounts.add(account)
|
||||
}
|
||||
|
||||
Log.d(TAG, "saveAccount: saving account with id "+account.id)
|
||||
accountDao.insertOrReplace(account)
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +89,7 @@ class AccountManager {
|
|||
if(accounts.size > 0) {
|
||||
accounts[0].isActive = true
|
||||
activeAccount = accounts[0]
|
||||
Log.d(TAG, "logActiveAccountOut: saving account with id "+accounts[0].id)
|
||||
accountDao.insertOrReplace(accounts[0])
|
||||
} else {
|
||||
activeAccount = null
|
||||
|
|
@ -115,10 +112,8 @@ class AccountManager {
|
|||
it.displayName = account.getDisplayName()
|
||||
it.profilePictureUrl = account.avatar
|
||||
|
||||
Log.d("AccountManager", "id before save "+it.id)
|
||||
Log.d(TAG, "updateActiveAccount: saving account with id "+it.id)
|
||||
it.id = accountDao.insertOrReplace(it)
|
||||
Log.d("AccountManager", "id after save "+it.id)
|
||||
|
||||
|
||||
val accountIndex = accounts.indexOf(it)
|
||||
|
||||
|
|
@ -140,6 +135,7 @@ class AccountManager {
|
|||
fun setActiveAccount(accountId: Long) {
|
||||
|
||||
activeAccount?.let{
|
||||
Log.d(TAG, "setActiveAccount: saving account with id "+it.id)
|
||||
it.isActive = false
|
||||
accountDao.insertOrReplace(it)
|
||||
}
|
||||
|
|
@ -172,7 +168,7 @@ class AccountManager {
|
|||
/**
|
||||
* @return true if at least one account has notifications enabled
|
||||
*/
|
||||
fun notificationsEnabled(): Boolean {
|
||||
fun areNotificationsEnabled(): Boolean {
|
||||
return accounts.any { it.notificationsEnabled }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue