Skip to content

Commit

Permalink
android notif [nfc]: Fold NotificationHelper into NotificationUiManager
Browse files Browse the repository at this point in the history
There's hardly anything left in this file, after zulip#4842 made it
unnecessary to maintain our own data structure of conversations
because we can use the system's data structures of active
notifications.  Fold what little is left into the main file that
uses it (indeed the only file that uses its one nontrivial item.)

Also add some javadoc while we're at it.
  • Loading branch information
gnprice committed Nov 16, 2021
1 parent 5c8d62a commit 2893db0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.media.AudioAttributes
import android.net.Uri
import android.os.Build
Expand All @@ -24,6 +26,9 @@ import com.zulipmobile.BuildConfig
import com.zulipmobile.R
import com.zulipmobile.ZLog
import me.leolin.shortcutbadger.ShortcutBadger
import java.io.IOException
import java.io.InputStream
import java.net.URL

// This file maintains the notifications in the UI, using data from FCM messages.
//
Expand All @@ -46,6 +51,12 @@ import me.leolin.shortcutbadger.ShortcutBadger
// The main entry point is `onReceived`, which is called when we receive
// an FCM message.

/** An Android logging tag for our notifications code. */
// (This doesn't particularly belong in this file, but it belongs somewhere
// in the notifications package.)
@JvmField
val TAG = "ZulipNotif"

/** The channel ID we use for our one notification channel, which we use for all notifications. */
private val CHANNEL_ID = "default"

Expand Down Expand Up @@ -226,6 +237,19 @@ private fun extractMessageKey(fcmMessage: MessageFcmMessage): String {
return messageKey
}

/** Fetch an image from the given URL. (We use this for sender avatars.) */
fun fetchBitmap(url: URL): Bitmap? {
return try {
val connection = url.openConnection()
connection.useCaches = true
(connection.content as? InputStream)
?.let { BitmapFactory.decodeStream(it) }
} catch (e: IOException) {
ZLog.e(TAG, e)
null
}
}

/** Handle a MessageFcmMessage, adding or extending notifications in the UI. */
private fun updateNotification(
context: Context, fcmMessage: MessageFcmMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.facebook.react.bridge.*;
import com.google.firebase.iid.FirebaseInstanceId;

import static com.zulipmobile.notifications.NotificationHelper.TAG;
import static com.zulipmobile.notifications.NotificationUiManager.TAG;

class NotificationsModule extends ReactContextBaseJavaModule {

Expand Down

0 comments on commit 2893db0

Please sign in to comment.