feat: Store the avatar path also in the shared preferences
This commit is contained in:
		
							parent
							
								
									79938aa177
								
							
						
					
					
						commit
						6896b928e8
					
				| @ -32,6 +32,7 @@ const val SHARED_PREFERENCES_KEY = "me.polynom.moxplatform_android" | |||||||
| const val SHARED_PREFERENCES_YOU_KEY = "you" | const val SHARED_PREFERENCES_YOU_KEY = "you" | ||||||
| const val SHARED_PREFERENCES_MARK_AS_READ_KEY = "mark_as_read" | const val SHARED_PREFERENCES_MARK_AS_READ_KEY = "mark_as_read" | ||||||
| const val SHARED_PREFERENCES_REPLY_KEY = "reply" | const val SHARED_PREFERENCES_REPLY_KEY = "reply" | ||||||
|  | const val SHARED_PREFERENCES_AVATAR_KEY = "avatar_path" | ||||||
| 
 | 
 | ||||||
| // TODO: Maybe try again to rewrite the entire plugin in Kotlin | // TODO: Maybe try again to rewrite the entire plugin in Kotlin | ||||||
| //const val METHOD_CHANNEL_KEY = "me.polynom.moxplatform_android" | //const val METHOD_CHANNEL_KEY = "me.polynom.moxplatform_android" | ||||||
|  | |||||||
| @ -285,7 +285,7 @@ import kotlin.jvm.functions.Function1; | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void setNotificationSelfAvatar(@NonNull String path) { |     public void setNotificationSelfAvatar(@NonNull String path) { | ||||||
|         NotificationDataManager.INSTANCE.setAvatarPath(path); |         NotificationDataManager.INSTANCE.setAvatarPath(context, path); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -103,10 +103,11 @@ class NotificationReceiver : BroadcastReceiver() { | |||||||
|                     setName(NotificationDataManager.getYou(context)) |                     setName(NotificationDataManager.getYou(context)) | ||||||
| 
 | 
 | ||||||
|                     // Set an avatar, if we have one |                     // Set an avatar, if we have one | ||||||
|                     if (NotificationDataManager.avatarPath != null) { |                     val avatarPath = NotificationDataManager.getAvatarPath(context) | ||||||
|  |                     if (avatarPath != null) { | ||||||
|                         setIcon( |                         setIcon( | ||||||
|                             Icon.createWithAdaptiveBitmap( |                             Icon.createWithAdaptiveBitmap( | ||||||
|                                 BitmapFactory.decodeFile(NotificationDataManager.avatarPath) |                                 BitmapFactory.decodeFile(avatarPath) | ||||||
|                             ) |                             ) | ||||||
|                         ) |                         ) | ||||||
|                     } |                     } | ||||||
|  | |||||||
| @ -24,7 +24,9 @@ object NotificationDataManager { | |||||||
|     private var you: String? = null |     private var you: String? = null | ||||||
|     private var markAsRead: String? = null |     private var markAsRead: String? = null | ||||||
|     private var reply: String? = null |     private var reply: String? = null | ||||||
|     var avatarPath: String? = null | 
 | ||||||
|  |     private var fetchedAvatarPath = false | ||||||
|  |     private var avatarPath: String? = null | ||||||
| 
 | 
 | ||||||
|     private fun getString(context: Context, key: String, fallback: String): String { |     private fun getString(context: Context, key: String, fallback: String): String { | ||||||
|         return context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)!!.getString(key, fallback)!! |         return context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)!!.getString(key, fallback)!! | ||||||
| @ -66,6 +68,23 @@ object NotificationDataManager { | |||||||
|         setString(context, SHARED_PREFERENCES_REPLY_KEY, value) |         setString(context, SHARED_PREFERENCES_REPLY_KEY, value) | ||||||
|         reply = value |         reply = value | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     fun getAvatarPath(context: Context): String? { | ||||||
|  |         if (avatarPath == null && !fetchedAvatarPath) { | ||||||
|  |             val path = getString(context, SHARED_PREFERENCES_AVATAR_KEY, "") | ||||||
|  |             if (path.isNotEmpty()) { | ||||||
|  |                 avatarPath = path | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return avatarPath | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fun setAvatarPath(context: Context, value: String) { | ||||||
|  |         setString(context, SHARED_PREFERENCES_AVATAR_KEY, value) | ||||||
|  |         fetchedAvatarPath = true | ||||||
|  |         avatarPath = value | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Show a messaging style notification described by @notification. | /// Show a messaging style notification described by @notification. | ||||||
| @ -144,10 +163,11 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif | |||||||
|         setName(NotificationDataManager.getYou(context)) |         setName(NotificationDataManager.getYou(context)) | ||||||
| 
 | 
 | ||||||
|         // Set an avatar, if we have one |         // Set an avatar, if we have one | ||||||
|         if (NotificationDataManager.avatarPath != null) { |         val avatarPath = NotificationDataManager.getAvatarPath(context) | ||||||
|  |         if (avatarPath != null) { | ||||||
|             setIcon( |             setIcon( | ||||||
|                 IconCompat.createWithAdaptiveBitmap( |                 IconCompat.createWithAdaptiveBitmap( | ||||||
|                     BitmapFactory.decodeFile(NotificationDataManager.avatarPath), |                     BitmapFactory.decodeFile(avatarPath), | ||||||
|                 ), |                 ), | ||||||
|             ) |             ) | ||||||
|         } |         } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user