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();
|
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.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.readrops.app.R
|
import com.readrops.app.R
|
||||||
import com.readrops.readropsdb.Database
|
import com.readrops.readropsdb.Database
|
||||||
|
import com.readrops.readropsdb.entities.Item
|
||||||
import com.readrops.readropsdb.entities.account.Account
|
import com.readrops.readropsdb.entities.account.Account
|
||||||
import com.readrops.readropslibrary.services.SyncResult
|
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 title: String? = null
|
||||||
var contentText: String? = null
|
var contentText: String? = null
|
||||||
var largeIcon: Bitmap? = null
|
var largeIcon: Bitmap? = null
|
||||||
|
var item: Item? = null
|
||||||
|
|
||||||
if (newItemsInMultipleAccounts()) {
|
if (newItemsInMultipleAccounts()) {
|
||||||
var itemsNb = 0
|
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
|
} else if (feedsIdsForNewItems.size == 1) { // new items from only one feed from one account
|
||||||
val feed = database.feedDao().getFeedById(feedsIdsForNewItems.first())
|
val feed = database.feedDao().getFeedById(feedsIdsForNewItems.first())
|
||||||
title = feed?.name
|
title = feed?.name
|
||||||
|
item = syncResult.items.first()
|
||||||
|
|
||||||
feed?.iconUrl?.let {
|
feed?.iconUrl?.let {
|
||||||
val target = GlideApp.with(context)
|
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)
|
contentText = if (syncResult.items.size == 1)
|
||||||
syncResult.items.first().title
|
item.title
|
||||||
else context.getString(R.string.new_items, syncResult.items.size.toString())
|
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,
|
return SyncResultNotifContent(title,
|
||||||
contentText,
|
contentText,
|
||||||
largeIcon)
|
largeIcon,
|
||||||
|
item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newItemsInMultipleAccounts(): Boolean {
|
private fun newItemsInMultipleAccounts(): Boolean {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.readrops.app.utils
|
package com.readrops.app.utils
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import com.readrops.readropsdb.entities.Item
|
||||||
|
|
||||||
data class SyncResultNotifContent(val title: String?,
|
data class SyncResultNotifContent(val title: String?,
|
||||||
val content: 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) {
|
if (notifContent.title != null && notifContent.content != null) {
|
||||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
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)
|
val notificationBuilder = NotificationCompat.Builder(applicationContext, ReadropsApp.SYNC_CHANNEL_ID)
|
||||||
.setContentTitle(notifContent.title)
|
.setContentTitle(notifContent.title)
|
||||||
.setContentText(notifContent.content)
|
.setContentText(notifContent.content)
|
||||||
@ -74,8 +79,9 @@ class SyncWorker(context: Context, parameters: WorkerParameters) : Worker(contex
|
|||||||
.setContentIntent(PendingIntent.getActivity(applicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
.setContentIntent(PendingIntent.getActivity(applicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
|
|
||||||
if (notifContent.largeIcon != null)
|
notifContent.largeIcon?.let {
|
||||||
notificationBuilder.setLargeIcon(notifContent.largeIcon)
|
notificationBuilder.setLargeIcon(it)
|
||||||
|
}
|
||||||
|
|
||||||
notificationManager.notify(SYNC_RESULT_NOTIFICATION_ID,
|
notificationManager.notify(SYNC_RESULT_NOTIFICATION_ID,
|
||||||
notificationBuilder.build())
|
notificationBuilder.build())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user