mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	fixes wrong getBroadcast calls from imageNotification (#585)
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							79705df499
						
					
				
				
					commit
					cc43d9daed
				
			| @@ -4,12 +4,11 @@ import android.app.PendingIntent | ||||
| import android.content.BroadcastReceiver | ||||
| import android.content.Context | ||||
| import android.content.Intent | ||||
| import android.net.Uri | ||||
| import android.support.v4.content.FileProvider | ||||
| import eu.kanade.tachiyomi.BuildConfig | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.util.notificationManager | ||||
| import java.io.File | ||||
| import eu.kanade.tachiyomi.Constants.NOTIFICATION_DOWNLOAD_IMAGE_ID as defaultNotification | ||||
|  | ||||
| /** | ||||
|  * The BroadcastReceiver of [ImageNotifier] | ||||
| @@ -18,21 +17,16 @@ import java.io.File | ||||
| class ImageNotificationReceiver : BroadcastReceiver() { | ||||
|     override fun onReceive(context: Context, intent: Intent) { | ||||
|         when (intent.action) { | ||||
|             ACTION_SHARE_IMAGE -> { | ||||
|                 shareImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION)) | ||||
|                 context.notificationManager.cancel(intent.getIntExtra(NOTIFICATION_ID, 5)) | ||||
|             } | ||||
|             ACTION_SHOW_IMAGE -> | ||||
|                 showImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION)) | ||||
|             ACTION_DELETE_IMAGE -> { | ||||
|                 deleteImage(intent.getStringExtra(EXTRA_FILE_LOCATION)) | ||||
|                 context.notificationManager.cancel(intent.getIntExtra(NOTIFICATION_ID, 5)) | ||||
|                 context.notificationManager.cancel(intent.getIntExtra(NOTIFICATION_ID, defaultNotification)) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called to delete image | ||||
|      * | ||||
|      * @param path path of file | ||||
|      */ | ||||
|     private fun deleteImage(path: String) { | ||||
| @@ -40,60 +34,42 @@ class ImageNotificationReceiver : BroadcastReceiver() { | ||||
|         if (file.exists()) file.delete() | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called to start share intent to share image | ||||
|      * @param context context of application | ||||
|      * @param path path of file | ||||
|      */ | ||||
|     private fun shareImage(context: Context, path: String) { | ||||
|         val intent = Intent(Intent.ACTION_SEND).apply { | ||||
|             flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK | ||||
|             putExtra(Intent.EXTRA_STREAM, Uri.parse(path)) | ||||
|             type = "image/*" | ||||
|         } | ||||
|         context.startActivity(Intent.createChooser(intent, context.getString(R.string.action_share))) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Called to show image in gallery application | ||||
|      * @param context context of application | ||||
|      * @param path path of file | ||||
|      */ | ||||
|     private fun showImage(context: Context, path: String) { | ||||
|         val intent = Intent(Intent.ACTION_VIEW).apply { | ||||
|             flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION | ||||
|             val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path)) | ||||
|             setDataAndType(uri, "image/*") | ||||
|         } | ||||
|         context.startActivity(intent) | ||||
|     } | ||||
|  | ||||
|     companion object { | ||||
|         private const val ACTION_SHARE_IMAGE = "eu.kanade.SHARE_IMAGE" | ||||
|  | ||||
|         private const val ACTION_SHOW_IMAGE = "eu.kanade.SHOW_IMAGE" | ||||
|  | ||||
|         private const val ACTION_DELETE_IMAGE = "eu.kanade.DELETE_IMAGE" | ||||
|  | ||||
|         private const val EXTRA_FILE_LOCATION = "file_location" | ||||
|  | ||||
|         private const val NOTIFICATION_ID = "notification_id" | ||||
|  | ||||
|         internal fun shareImageIntent(context: Context, path: String, notificationId: Int): PendingIntent { | ||||
|             val intent = Intent(context, ImageNotificationReceiver::class.java).apply { | ||||
|                 action = ACTION_SHARE_IMAGE | ||||
|                 putExtra(EXTRA_FILE_LOCATION, path) | ||||
|                 putExtra(NOTIFICATION_ID, notificationId) | ||||
|         /** | ||||
|          * Called to start share intent to share image | ||||
|          * | ||||
|          * @param context context of application | ||||
|          * @param path path of file | ||||
|          */ | ||||
|         internal fun shareImageIntent(context: Context, path: String): PendingIntent { | ||||
|             val intent = Intent(Intent.ACTION_SEND).apply { | ||||
|                 val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path)) | ||||
|                 putExtra(Intent.EXTRA_STREAM, uri) | ||||
|                 flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION | ||||
|                 type = "image/*" | ||||
|             } | ||||
|             return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) | ||||
|             return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) | ||||
|         } | ||||
|  | ||||
|         /** | ||||
|          * Called to show image in gallery application | ||||
|          * | ||||
|          * @param context context of application | ||||
|          * @param path path of file | ||||
|          */ | ||||
|         internal fun showImageIntent(context: Context, path: String): PendingIntent { | ||||
|             val intent = Intent(context, ImageNotificationReceiver::class.java).apply { | ||||
|                 action = ACTION_SHOW_IMAGE | ||||
|                 putExtra(EXTRA_FILE_LOCATION, path) | ||||
|             val intent = Intent(Intent.ACTION_VIEW).apply { | ||||
|                 flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION | ||||
|                 val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path)) | ||||
|                 setDataAndType(uri, "image/*") | ||||
|             } | ||||
|             return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) | ||||
|             return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) | ||||
|         } | ||||
|  | ||||
|         internal fun deleteImageIntent(context: Context, path: String, notificationId: Int): PendingIntent { | ||||
|   | ||||
| @@ -62,7 +62,7 @@ class ImageNotifier(private val context: Context) { | ||||
|             // Share action | ||||
|             addAction(R.drawable.ic_share_grey_24dp, | ||||
|                     context.getString(R.string.action_share), | ||||
|                     ImageNotificationReceiver.shareImageIntent(context, file.absolutePath, notificationId)) | ||||
|                     ImageNotificationReceiver.shareImageIntent(context, file.absolutePath)) | ||||
|             // Delete action | ||||
|             addAction(R.drawable.ic_delete_grey_24dp, | ||||
|                     context.getString(R.string.action_delete), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user