-
-
Notifications
You must be signed in to change notification settings - Fork 554
feat: Added coroutine worker for importing watch history #7973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
If someone wants i can add an ongoing notification for subscription and playlist imports however that will not be able to tell how much content to import has been left |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally think that the idea of putting the import work into a dedicated worker goes into the right direction, thanks for proposing.
However, we decided to not add Dagger/Hilt as a dependency, so please refactor your PR to work without it.
Apart from that I left some comments, please have a look at them. Without willing to attack you personally, this code looks a bit AI-generated .
We don't accept contributions that add much additional code that was AI-generated here. So please clarify that this is not the case or rewrite the AI-generated parts as we don't have any permission to license code that was stolen from other projects as GPL3.
| } | ||
|
|
||
|
|
||
| private val notificationChannelId = "DemoNotificationChannelId" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was working on another project called Kotatsu the approach of pausing and resuming the Work manager is where i got this from.
If you want i can write my own logic for pausing and resuming the work manager i am just afraid that my solution might now be better than theirs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is about whether you call it DemoNotificationChannelId, that looks like it's copied from somewhere else without adapting it to our app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the name was actually copied
Sorry about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI code removed, Dagger hilt removed
| private fun createNotificationChannel() { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
|
|
||
| val notificationChannel = NotificationChannel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use NotificationChannelCompat instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will refactor it to use NotificationChannelCompat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change has now been made to use NotificationChannelCompat
| get() = cancel.value | ||
|
|
||
| fun pause() { | ||
| paused.value = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| paused.value = true | |
| paused.emit(true) |
same below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem here is that emit is a suspending function which must be called from another suspending function or a coroutine and i am calling it from a broadcast reciever method OnRecieve which is not a suspending function
| NotificationManagerCompat.IMPORTANCE_DEFAULT | ||
| ).setName("Import Worker") | ||
| .setDescription("Shows a notification when importing") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be translatable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now moved to string.xml
app/src/main/java/com/github/libretube/factory/NotificationFactory.kt
Outdated
Show resolved
Hide resolved
| if (finalState == 0) 0 else ((currentState.toFloat() / finalState) * 100).toInt() | ||
| builder.setContentText("$percent% completed") | ||
| builder.setProgress(finalState, currentState, false) | ||
| builder.clearActions() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a noop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shows the percentage of watch history that has been imported
| ) : BroadcastReceiver() { | ||
| override fun onReceive(context: Context?, intent: Intent?) { | ||
| val id = intent?.getStringExtra(EXTRA_UUID) | ||
| val parsedId: UUID? = try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use UUIDs instead of incrementing integer IDs like everywhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppose a user imports one watch history file and closes the app than again open up the app to import another watch history file than in thjat case there will be no way of knowing what the previous id was thats why i have used UUID
|
@Bnyro do i need to rewrite the other code as well by that i meant the pausing handler since thats not AI generated the only Ai generated one is the notification part that too is in much smaller portion not all of it was Ai generated so please clarify |
|
Only the AI generated code. |
|
okay i will be rewriting it |
1- Previously a coroutine was executed which imported watch history from youtube but there was no way to know the status of the import history i have a added a coroutine worker whose job is to import the watch history with a foreground notification.
2- I have also added dagger hilt in order to inject dependencies. I could have used other approaches but that wouldnt have been a clean solution
3- For now only watch history is being imported through coroutine worker. The reason is that we are inserting watch item one by one but for subscriptions one complete list is inserted which makes it nearly impossible to know the status of those imports however i will still look for a way to achieve that and for playlists too
Bug #7907