Fix account icon not displayed in sync result notification one account multiple feeds case

This commit is contained in:
Shinokuni 2020-02-23 13:40:58 +01:00
parent ad6a682fd6
commit 4ef8388c16
3 changed files with 91 additions and 3 deletions

View File

@ -2,7 +2,7 @@ package com.readrops.app.utils
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import androidx.core.content.ContextCompat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.readrops.app.R
import com.readrops.readropsdb.Database
@ -40,7 +40,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
title = account.accountName
contentText = context.getString(R.string.new_items, syncResult.items.size.toString())
largeIcon = BitmapFactory.decodeResource(context.resources, account.accountType.iconRes)
largeIcon = Utils.getBitmapFromDrawable(ContextCompat.getDrawable(context, account.accountType.iconRes))
} else if (feedsIdsForNewItems.size == 1) { // new items from only one feed from one account
val feed = database.feedDao().getFeedById(feedsIdsForNewItems.first())
title = feed?.name
@ -52,7 +52,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
.load(it)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.submit()
largeIcon = target.get()
}

View File

@ -0,0 +1,76 @@
package com.readrops.app.utils
import com.readrops.readropsdb.entities.Item
import com.readrops.readropsdb.entities.account.Account
import com.readrops.readropsdb.entities.account.AccountType
import com.readrops.readropslibrary.services.SyncResult
class SyncResultDebugData {
companion object {
fun oneAccountOneFeedOneItem(): Map<Account, SyncResult> {
val account1 = Account().apply {
id = 1
accountType = AccountType.FRESHRSS
}
val item = Item().apply {
id = 1
title = "oneAccountOneFeedOneItem"
feedId = 90
}
return mutableMapOf<Account, SyncResult>().apply {
put(account1, SyncResult().apply { items = mutableListOf(item) })
}
}
fun oneAccountMultipleFeeds(): Map<Account, SyncResult> {
val account1 = Account().apply {
accountName = "Test account"
id = 1
accountType = AccountType.FRESHRSS
}
val item1 = Item().apply {
id = 1
title = "oneAccountMultipleFeeds"
feedId = 1
}
val item2 = Item().apply {
id = 2
title = "oneAccountMultipleFeeds"
feedId = 2
}
return mutableMapOf<Account, SyncResult>().apply {
put(account1, SyncResult().apply { items = mutableListOf(item1, item2) })
}
}
fun multipleAccounts(): Map<Account, SyncResult> {
val account1 = Account().apply {
id = 1
accountType = AccountType.FRESHRSS
}
val account2 = Account().apply {
id = 2
accountType = AccountType.LOCAL
}
val item = Item().apply {
id = 1
title = "multipleAccountsCase"
feedId = 90
}
return mutableMapOf<Account, SyncResult>().apply {
put(account1, SyncResult().apply { items = mutableListOf(item) })
put(account2, SyncResult().apply { items = mutableListOf(item) })
}
}
}
}

View File

@ -2,6 +2,7 @@ package com.readrops.app.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
@ -105,4 +106,15 @@ public final class Utils {
public static String cleanText(String text) {
return Jsoup.parse(text).text().trim();
}
public static Bitmap getBitmapFromDrawable(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
}