mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-04 15:19:48 +00:00
WIP Subscription notifs
This commit is contained in:
parent
b3a3e459a4
commit
34ba44ffa4
2 changed files with 40 additions and 3 deletions
|
@ -459,6 +459,10 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
||||||
Logger.i(TAG, "View Received: " + targetData);
|
Logger.i(TAG, "View Received: " + targetData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"VIDEO" -> {
|
||||||
|
val url = intent.getStringExtra("VIDEO");
|
||||||
|
navigate(_fragVideoDetail, url);
|
||||||
|
}
|
||||||
"TAB" -> {
|
"TAB" -> {
|
||||||
when(intent.getStringExtra("TAB")){
|
when(intent.getStringExtra("TAB")){
|
||||||
"Sources" -> {
|
"Sources" -> {
|
||||||
|
@ -925,5 +929,12 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
||||||
sourcesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
sourcesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
return sourcesIntent;
|
return sourcesIntent;
|
||||||
}
|
}
|
||||||
|
fun getVideoIntent(context: Context, videoUrl: String) : Intent {
|
||||||
|
val sourcesIntent = Intent(context, MainActivity::class.java);
|
||||||
|
sourcesIntent.action = "VIDEO";
|
||||||
|
sourcesIntent.putExtra("VIDEO", videoUrl);
|
||||||
|
sourcesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
return sourcesIntent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,12 +4,14 @@ import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.media.MediaSession2Service.MediaNotification
|
||||||
import androidx.concurrent.futures.CallbackToFutureAdapter
|
import androidx.concurrent.futures.CallbackToFutureAdapter
|
||||||
import androidx.concurrent.futures.ResolvableFuture
|
import androidx.concurrent.futures.ResolvableFuture
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.work.CoroutineWorker
|
import androidx.work.CoroutineWorker
|
||||||
import androidx.work.ListenableWorker
|
import androidx.work.ListenableWorker
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||||
import com.futo.platformplayer.getNowDiffSeconds
|
import com.futo.platformplayer.getNowDiffSeconds
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
@ -83,6 +85,8 @@ class BackgroundWorker(private val appContext: Context, workerParams: WorkerPara
|
||||||
|
|
||||||
val newSubChanges = hashSetOf<Subscription>();
|
val newSubChanges = hashSetOf<Subscription>();
|
||||||
val newItems = mutableListOf<IPlatformContent>();
|
val newItems = mutableListOf<IPlatformContent>();
|
||||||
|
|
||||||
|
val contentNotifs = mutableListOf<Pair<Subscription, IPlatformContent>>();
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
StateSubscriptions.instance.getSubscriptionsFeedWithExceptions(true, false,this, { progress, total ->
|
StateSubscriptions.instance.getSubscriptionsFeedWithExceptions(true, false,this, { progress, total ->
|
||||||
Logger.i("BackgroundWorker", "SUBSCRIPTION PROGRESS: ${progress}/${total}");
|
Logger.i("BackgroundWorker", "SUBSCRIPTION PROGRESS: ${progress}/${total}");
|
||||||
|
@ -97,8 +101,11 @@ class BackgroundWorker(private val appContext: Context, workerParams: WorkerPara
|
||||||
}
|
}
|
||||||
}, { sub, content ->
|
}, { sub, content ->
|
||||||
synchronized(newSubChanges) {
|
synchronized(newSubChanges) {
|
||||||
if(!newSubChanges.contains(sub))
|
if(!newSubChanges.contains(sub)) {
|
||||||
newSubChanges.add(sub);
|
newSubChanges.add(sub);
|
||||||
|
if(sub.doNotifications)
|
||||||
|
contentNotifs.add(Pair(sub, content));
|
||||||
|
}
|
||||||
newItems.add(content);
|
newItems.add(content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -106,12 +113,31 @@ class BackgroundWorker(private val appContext: Context, workerParams: WorkerPara
|
||||||
|
|
||||||
manager.cancel(12);
|
manager.cancel(12);
|
||||||
|
|
||||||
if(newItems.size > 0)
|
if(newItems.size > 0) {
|
||||||
|
try {
|
||||||
|
val items = contentNotifs.take(5).toList()
|
||||||
|
for(i in items.indices) {
|
||||||
|
val contentNotif = items.get(i);
|
||||||
|
manager.notify(13 + i, NotificationCompat.Builder(appContext, notificationChannel.id)
|
||||||
|
.setSmallIcon(com.futo.platformplayer.R.drawable.foreground)
|
||||||
|
.setContentTitle("New video by [${contentNotif.first.channel.name}]")
|
||||||
|
.setContentText("${contentNotif.second.name}")
|
||||||
|
.setSilent(true)
|
||||||
|
.setContentIntent(PendingIntent.getActivity(this.appContext, 0, MainActivity.getVideoIntent(this.appContext, contentNotif.second.url),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE))
|
||||||
|
.setChannelId(notificationChannel.id).build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
Logger.e("BackgroundWorker", "Failed to create notif", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
manager.notify(13, NotificationCompat.Builder(appContext, notificationChannel.id)
|
manager.notify(13, NotificationCompat.Builder(appContext, notificationChannel.id)
|
||||||
.setSmallIcon(com.futo.platformplayer.R.drawable.foreground)
|
.setSmallIcon(com.futo.platformplayer.R.drawable.foreground)
|
||||||
.setContentTitle("Grayjay")
|
.setContentTitle("Grayjay")
|
||||||
.setContentText("${newItems.size} new content from ${newSubChanges.size} creators")
|
.setContentText("${newItems.size} new content from ${newSubChanges.size} creators")
|
||||||
.setSilent(true)
|
.setSilent(true)
|
||||||
.setChannelId(notificationChannel.id).build());
|
.setChannelId(notificationChannel.id).build());*/
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue