funkyg / funkytunes

A streaming music player for Android, using torrents.
GNU General Public License v3.0
122 stars 24 forks source link

Remove flickering of the notification #13

Closed gjedeer closed 7 years ago

gjedeer commented 7 years ago

Currently the notification progress bar is "flickering" which doesn't look great. I mean the effect that every time bandwidth is reported, the progress bar is set to 0. There's probably a better way than removing the progress bar altogether but I couldn't figure it out.

funkyg commented 7 years ago

I see what you mean. But there is a better solution: reuse the same notification builder, and just update the content text when the notification is updated.

Something like this:

private val notificationBuilder by lazy {
    val contentIntent = PendingIntent.getActivity(service, RequestCode,
            Intent(service, PlayingQueueActivity::class.java), PendingIntent.FLAG_CANCEL_CURRENT)
    NotificationCompat.Builder(service)
            .setContentTitle(service.getString(R.string.notification_loading_title))
            .setContentIntent(contentIntent)
            .setSmallIcon(R.drawable.ic_notification)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setProgress(0, 0, true)
}

private fun updateLoadingNotification() {
    notificationBuilder
            .setContentText(torrentManager.getDownloadSpeed())
    service.startForeground(NotificationId, notificationBuilder.build())
    handler.postDelayed(UpdateLoadingNotificationRunnable, 1000)
}
gjedeer commented 7 years ago

Didn't work. I also tried usng notify() instead of startForeground() with no luck:

        notificationBuilder.setContentText(torrentManager.getDownloadSpeed())
        notificationManager.notify(NotificationId, notificationBuilder.build())
//        service.startForeground(NotificationId, notificationBuilder.build())
        handler.postDelayed(UpdateLoadingNotificationRunnable, 1000)
funkyg commented 7 years ago

Did you put the notificationbuilder as a class member? That definitely worked when i tried it.

gjedeer commented 7 years ago

yeah -> https://github.com/gjedeer/funkytunes/commit/50c672c3f9fbd350cdb0d083b5181684e8c195a8

funkyg commented 7 years ago

hmmm that is weird.but i dont really like to remove the progressbar, cause its harder to see that its actually doing something

not sure what to do :/

gjedeer commented 7 years ago

I will just close this PR