forked from recloudstream/cloudstream
		
	fixed hls download notification
This commit is contained in:
		
							parent
							
								
									384e31343f
								
							
						
					
					
						commit
						251da7d157
					
				
					 1 changed files with 54 additions and 23 deletions
				
			
		|  | @ -228,6 +228,9 @@ object VideoDownloadManager { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * @param hlsProgress will together with hlsTotal display another notification if used, to lessen the confusion about estimated size. | ||||||
|  |      * */ | ||||||
|     private suspend fun createNotification( |     private suspend fun createNotification( | ||||||
|         context: Context, |         context: Context, | ||||||
|         source: String?, |         source: String?, | ||||||
|  | @ -236,7 +239,9 @@ object VideoDownloadManager { | ||||||
|         state: DownloadType, |         state: DownloadType, | ||||||
|         progress: Long, |         progress: Long, | ||||||
|         total: Long, |         total: Long, | ||||||
|         notificationCallback: (Int, Notification) -> Unit |         notificationCallback: (Int, Notification) -> Unit, | ||||||
|  |         hlsProgress: Long? = null, | ||||||
|  |         hlsTotal: Long? = null, | ||||||
| 
 | 
 | ||||||
|         ): Notification? { |         ): Notification? { | ||||||
|         try { |         try { | ||||||
|  | @ -270,7 +275,8 @@ object VideoDownloadManager { | ||||||
|                     data = source.toUri() |                     data = source.toUri() | ||||||
|                     flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK |                     flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||||||
|                 } |                 } | ||||||
|                 val pendingIntent: PendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |                 val pendingIntent: PendingIntent = | ||||||
|  |                     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||||
|                         PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE) |                         PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE) | ||||||
|                     } else { |                     } else { | ||||||
|                         PendingIntent.getActivity(context, 0, intent, 0) |                         PendingIntent.getActivity(context, 0, intent, 0) | ||||||
|  | @ -301,12 +307,26 @@ object VideoDownloadManager { | ||||||
|                         builder.setLargeIcon(poster) |                         builder.setLargeIcon(poster) | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 val progressPercentage = progress * 100 / total |                 val progressPercentage: Long | ||||||
|                 val progressMbString = "%.1f".format(progress / 1000000f) |                 val progressMbString: String | ||||||
|                 val totalMbString = "%.1f".format(total / 1000000f) |                 val totalMbString: String | ||||||
|  |                 val suffix: String | ||||||
|  | 
 | ||||||
|  |                 if (hlsProgress != null && hlsTotal != null) { | ||||||
|  |                     progressPercentage = hlsProgress.toLong() * 100 / hlsTotal | ||||||
|  |                     progressMbString = hlsProgress.toString() | ||||||
|  |                     totalMbString = hlsTotal.toString() | ||||||
|  |                     suffix = " - %.1f MB".format(progress / 1000000f) | ||||||
|  |                 } else { | ||||||
|  |                     progressPercentage = progress * 100 / total | ||||||
|  |                     progressMbString = "%.1f MB".format(progress / 1000000f) | ||||||
|  |                     totalMbString = "%.1f MB".format(total / 1000000f) | ||||||
|  |                     suffix = "" | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 val bigText = |                 val bigText = | ||||||
|                     if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) { |                     if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) { | ||||||
|                         (if (linkName == null) "" else "$linkName\n") + "$rowTwo\n$progressPercentage % ($progressMbString MB/$totalMbString MB)" |                         (if (linkName == null) "" else "$linkName\n") + "$rowTwo\n$progressPercentage % ($progressMbString/$totalMbString)$suffix" | ||||||
|                     } else if (state == DownloadType.IsFailed) { |                     } else if (state == DownloadType.IsFailed) { | ||||||
|                         downloadFormat.format(context.getString(R.string.download_failed), rowTwo) |                         downloadFormat.format(context.getString(R.string.download_failed), rowTwo) | ||||||
|                     } else if (state == DownloadType.IsDone) { |                     } else if (state == DownloadType.IsDone) { | ||||||
|  | @ -319,7 +339,8 @@ object VideoDownloadManager { | ||||||
|                 bodyStyle.bigText(bigText) |                 bodyStyle.bigText(bigText) | ||||||
|                 builder.setStyle(bodyStyle) |                 builder.setStyle(bodyStyle) | ||||||
|             } else { |             } else { | ||||||
|                 val txt = if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) { |                 val txt = | ||||||
|  |                     if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) { | ||||||
|                         rowTwo |                         rowTwo | ||||||
|                     } else if (state == DownloadType.IsFailed) { |                     } else if (state == DownloadType.IsFailed) { | ||||||
|                         downloadFormat.format(context.getString(R.string.download_failed), rowTwo) |                         downloadFormat.format(context.getString(R.string.download_failed), rowTwo) | ||||||
|  | @ -541,6 +562,8 @@ object VideoDownloadManager { | ||||||
|         val type: DownloadType, |         val type: DownloadType, | ||||||
|         val bytesDownloaded: Long, |         val bytesDownloaded: Long, | ||||||
|         val bytesTotal: Long, |         val bytesTotal: Long, | ||||||
|  |         val hlsProgress: Long? = null, | ||||||
|  |         val hlsTotal: Long? = null, | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     data class StreamData( |     data class StreamData( | ||||||
|  | @ -664,7 +687,9 @@ object VideoDownloadManager { | ||||||
| 
 | 
 | ||||||
|         val displayName = getDisplayName(name, extension) |         val displayName = getDisplayName(name, extension) | ||||||
|         val relativePath = |         val relativePath = | ||||||
|             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && basePath.first.isDownloadDir()) getRelativePath(folder) else folder |             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && basePath.first.isDownloadDir()) getRelativePath( | ||||||
|  |                 folder | ||||||
|  |             ) else folder | ||||||
| 
 | 
 | ||||||
|         fun deleteFile(): Int { |         fun deleteFile(): Int { | ||||||
|             return delete(context, name, relativePath, extension, parentId, basePath.first) |             return delete(context, name, relativePath, extension, parentId, basePath.first) | ||||||
|  | @ -1087,7 +1112,9 @@ object VideoDownloadManager { | ||||||
|         val basePath = context.getBasePath() |         val basePath = context.getBasePath() | ||||||
| 
 | 
 | ||||||
|         val relativePath = |         val relativePath = | ||||||
|             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && basePath.first.isDownloadDir()) getRelativePath(folder) else folder |             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && basePath.first.isDownloadDir()) getRelativePath( | ||||||
|  |                 folder | ||||||
|  |             ) else folder | ||||||
| 
 | 
 | ||||||
|         val stream = setupStream(context, name, relativePath, extension, realIndex > 0) |         val stream = setupStream(context, name, relativePath, extension, realIndex > 0) | ||||||
|         if (stream.errorCode != SUCCESS_STREAM) return stream.errorCode |         if (stream.errorCode != SUCCESS_STREAM) return stream.errorCode | ||||||
|  | @ -1170,6 +1197,8 @@ object VideoDownloadManager { | ||||||
|                     type, |                     type, | ||||||
|                     bytesDownloaded, |                     bytesDownloaded, | ||||||
|                     (bytesDownloaded * (totalTs / tsProgress.toFloat())).toLong(), |                     (bytesDownloaded * (totalTs / tsProgress.toFloat())).toLong(), | ||||||
|  |                     tsProgress, | ||||||
|  |                     totalTs | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|         } |         } | ||||||
|  | @ -1325,7 +1354,9 @@ object VideoDownloadManager { | ||||||
|                         meta.type, |                         meta.type, | ||||||
|                         meta.bytesDownloaded, |                         meta.bytesDownloaded, | ||||||
|                         meta.bytesTotal, |                         meta.bytesTotal, | ||||||
|                         notificationCallback |                         notificationCallback, | ||||||
|  |                         meta.hlsProgress, | ||||||
|  |                         meta.hlsTotal | ||||||
|                     ) |                     ) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue