Open item when sync result notification is single item case
This commit is contained in:
parent
88f6915931
commit
ffeb955a82
@ -225,6 +225,13 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||
savedInstanceState.clear();
|
||||
}
|
||||
});
|
||||
|
||||
if (getIntent().hasExtra(ITEM_ID) && getIntent().hasExtra(IMAGE_URL)) {
|
||||
Intent intent = new Intent(this, ItemActivity.class);
|
||||
intent.putExtras(getIntent());
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ import android.graphics.BitmapFactory
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.readrops.app.R
|
||||
import com.readrops.readropsdb.Database
|
||||
import com.readrops.readropsdb.entities.Item
|
||||
import com.readrops.readropsdb.entities.account.Account
|
||||
import com.readrops.readropslibrary.services.SyncResult
|
||||
|
||||
@ -18,6 +19,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
|
||||
var title: String? = null
|
||||
var contentText: String? = null
|
||||
var largeIcon: Bitmap? = null
|
||||
var item: Item? = null
|
||||
|
||||
if (newItemsInMultipleAccounts()) {
|
||||
var itemsNb = 0
|
||||
@ -42,6 +44,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
|
||||
} else if (feedsIdsForNewItems.size == 1) { // new items from only one feed from one account
|
||||
val feed = database.feedDao().getFeedById(feedsIdsForNewItems.first())
|
||||
title = feed?.name
|
||||
item = syncResult.items.first()
|
||||
|
||||
feed?.iconUrl?.let {
|
||||
val target = GlideApp.with(context)
|
||||
@ -54,7 +57,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
|
||||
}
|
||||
|
||||
contentText = if (syncResult.items.size == 1)
|
||||
syncResult.items.first().title
|
||||
item.title
|
||||
else context.getString(R.string.new_items, syncResult.items.size.toString())
|
||||
}
|
||||
}
|
||||
@ -63,7 +66,8 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
|
||||
|
||||
return SyncResultNotifContent(title,
|
||||
contentText,
|
||||
largeIcon)
|
||||
largeIcon,
|
||||
item)
|
||||
}
|
||||
|
||||
private fun newItemsInMultipleAccounts(): Boolean {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.readrops.app.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.readrops.readropsdb.entities.Item
|
||||
|
||||
data class SyncResultNotifContent(val title: String?,
|
||||
val content: String?,
|
||||
val largeIcon: Bitmap?)
|
||||
val largeIcon: Bitmap?,
|
||||
val item: Item?)
|
@ -67,6 +67,11 @@ class SyncWorker(context: Context, parameters: WorkerParameters) : Worker(contex
|
||||
if (notifContent.title != null && notifContent.content != null) {
|
||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||
|
||||
notifContent.item?.let {
|
||||
intent.putExtra(ReadropsKeys.ITEM_ID, it.id)
|
||||
intent.putExtra(ReadropsKeys.IMAGE_URL, it.imageLink)
|
||||
}
|
||||
|
||||
val notificationBuilder = NotificationCompat.Builder(applicationContext, ReadropsApp.SYNC_CHANNEL_ID)
|
||||
.setContentTitle(notifContent.title)
|
||||
.setContentText(notifContent.content)
|
||||
@ -74,11 +79,12 @@ class SyncWorker(context: Context, parameters: WorkerParameters) : Worker(contex
|
||||
.setContentIntent(PendingIntent.getActivity(applicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.setAutoCancel(true)
|
||||
|
||||
if (notifContent.largeIcon != null)
|
||||
notificationBuilder.setLargeIcon(notifContent.largeIcon)
|
||||
notifContent.largeIcon?.let {
|
||||
notificationBuilder.setLargeIcon(it)
|
||||
}
|
||||
|
||||
notificationManager.notify(SYNC_RESULT_NOTIFICATION_ID,
|
||||
notificationBuilder.build())
|
||||
notificationBuilder.build())
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user