From 015b1cccba97a50162fe392b0f893050a1ffcf0b Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 9 Apr 2020 11:55:24 -0300 Subject: [PATCH 1/7] added specific error notification id, based on the Stoyr's index in the StoryRepository --- .../compose/frame/FrameSaveNotifier.kt | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt index 418c63a15..a32c49f7d 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt @@ -12,6 +12,7 @@ import com.automattic.portkey.R import com.automattic.portkey.compose.ComposeLoopFrameActivity import com.automattic.portkey.compose.frame.FrameSaveService.SaveResultReason.SaveSuccess import com.automattic.portkey.compose.frame.FrameSaveService.StorySaveResult +import com.automattic.portkey.compose.story.StoryIndex import com.automattic.portkey.util.KEY_STORY_SAVE_RESULT import java.util.Random @@ -141,7 +142,7 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame Math.ceil((getCurrentOverallProgress() * 100).toDouble()).toInt(), false ) - doNotify(notificationData.notificationId.toLong(), notificationBuilder.build()) + doNotify(notificationData.notificationId, notificationBuilder.build()) } @Synchronized private fun setProgressForMediaItem(id: String, progress: Float) { @@ -171,12 +172,12 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame // TODO: uncomment these lines when migrating code to WPAndroid @Synchronized private fun doNotify( - id: Long, + id: Int, notification: Notification // notificationType: NotificationType? ) { try { - notificationManager.notify(id.toInt(), notification) + notificationManager.notify(id, notification) // TODO track notification when integrating in WPAndroid // note: commented out code left on purpose // if (notificationType != null) { @@ -232,7 +233,7 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame startOrUpdateForegroundNotification(title) } - // TODO change signature to receive a CPT (Post) as parameter instead of a plain String + // TODO WPANDROID: change signature to receive a CPT (Post) as parameter instead of a plain String @Synchronized private fun startOrUpdateForegroundNotification(title: String?) { updateNotificationBuilder(title) if (notificationData.notificationId == 0) { @@ -243,10 +244,15 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame ) } else { // service was already started, let's just modify the notification - doNotify(notificationData.notificationId.toLong(), notificationBuilder.build()) + doNotify(notificationData.notificationId, notificationBuilder.build()) } } + // TODO WPANDROID: we'll need the SiteModel and we can base the notification error IDs on the site ID plus + // PostModel id, the same we do for failed to upload Posts in WPAndroid's UploadService + // For now we will use the StoryIndex that comes with the StorySaveResult, as we can rest assured + // the storyIndex will remain accurate for as long as the notification lives (i.e. we'll cancel it on + // open or when the Composer activity is loaded with the corresponding Story) fun updateNotificationErrorForStoryFramesSave( // mediaList: List, // site: SiteModel, @@ -261,7 +267,7 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame ) // val notificationId = getNotificationIdForMedia(site) - val notificationId = getNotificationIdForError() + val notificationId = getNotificationIdForError(storySaveResult.storyIndex) // Tap notification intent (open the media browser) val notificationIntent = Intent(context, ComposeLoopFrameActivity::class.java) val bundle = Bundle() @@ -278,8 +284,9 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame val pendingIntent = PendingIntent.getActivity( context, - notificationId.toInt(), - notificationIntent, PendingIntent.FLAG_ONE_SHOT + notificationId, + notificationIntent, + PendingIntent.FLAG_ONE_SHOT ) notificationBuilder.setSmallIcon(android.R.drawable.stat_notify_error) @@ -318,8 +325,11 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame doNotify(notificationId, notificationBuilder.build()) // , notificationType) } - fun getNotificationIdForError(): Long { - return BASE_MEDIA_ERROR_NOTIFICATION_ID.toLong() + fun getNotificationIdForError(storyIdx: StoryIndex): Int { + // TODO WPANDROID we keep the base number because we'll use SiteId and PostModel id's to identify the error + // notification as well, and as such we are using a different base number to avoid collision of notification + // ids. + return BASE_MEDIA_ERROR_NOTIFICATION_ID + storyIdx } companion object { From 3cfb65c15b0baec7d3c341e02c87cd0144df3bc0 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 9 Apr 2020 18:51:16 -0300 Subject: [PATCH 2/7] added structure and functionality to hold how many different Stories we're saving concurrently, to show the right progress notifications --- .../portkey/compose/frame/FrameSaveManager.kt | 4 +- .../compose/frame/FrameSaveNotifier.kt | 66 +++++++++++++++++-- .../portkey/compose/frame/FrameSaveService.kt | 34 ++++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 90 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt index c52cf871d..361806522 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveManager.kt @@ -54,12 +54,12 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope { return frames.mapIndexed { index, frame -> async { yield() - saveLoopFrame(context, frame, index) + saveStoryFrame(context, frame, index) } }.awaitAll().filterNotNull() } - private suspend fun saveLoopFrame( + private suspend fun saveStoryFrame( context: Context, frame: StoryFrameItem, frameIndex: FrameIndex diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt index a32c49f7d..88cd43e91 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt @@ -28,6 +28,8 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame internal var notificationId: Int = 0 internal var totalMediaItems: Int = 0 internal var currentMediaItem: Int = 0 + internal var currentStoriesToQtyUploadingMap= HashMap() // keep amount of items being uploaded + // for multiple concurrent stories internal val mediaItemToProgressMap = HashMap() } @@ -66,8 +68,18 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame // set the Notification's title and prepare the Notifications message text, // i.e. "Saving story... 3 frames remaining" if (notificationData.totalMediaItems > 0) { - // only media items are being uploaded - // check if special case for ONE media item + updateNotificationTitle(title) + notificationBuilder.setContentText(buildNotificationSubtitleForFrameSaveProcess()) + } + } + + private fun updateNotificationTitle(title: String?) { + // if there are frames of more than 1 concurrent Story being saved, show plural title + if (notificationData.currentStoriesToQtyUploadingMap.size > 1) { + notificationBuilder.setContentTitle(buildNotificationTitleForFrameSaveProcess( + context.getString(R.string.story_saving_title_several)) + ) + } else { if (title != null) { notificationBuilder.setContentTitle(buildNotificationTitleForFrameSaveProcess(title)) } else { @@ -75,7 +87,6 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame context.getString(R.string.story_saving_untitled)) ) } - notificationBuilder.setContentText(buildNotificationSubtitleForFrameSaveProcess()) } } @@ -103,14 +114,20 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame } } - @Synchronized fun incrementUploadedMediaCountFromProgressNotification(id: String, success: Boolean = false) { + @Synchronized fun incrementUploadedMediaCountFromProgressNotification( + storyIndex: StoryIndex, + title: String?, + id: String, + success: Boolean = false + ) { + decrementCurrentUploadingItemQtyForStory(storyIndex) notificationData.currentMediaItem++ if (success) { setProgressForMediaItem(id, 1f) } if (!removeNotificationAndStopForegroundServiceIfNoItemsInQueue()) { // update Notification now - updateForegroundNotification() + updateForegroundNotification(title) } } @@ -217,7 +234,13 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame } } - @Synchronized fun addStoryPageInfoToForegroundNotification(idList: List, title: String) { + @Synchronized fun addStoryPageInfoToForegroundNotification( + storyIndex: StoryIndex, + idList: List, + title: String + ) { + // keep our story current uploads quantity map updated + incrementCurrentUploadingItemQtyForStory(storyIndex) notificationData.totalMediaItems += idList.size // setup progresses for each media item for (id in idList) { @@ -226,13 +249,42 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame startOrUpdateForegroundNotification(title) } - @Synchronized fun addStoryPageInfoToForegroundNotification(id: String, title: String) { + @Synchronized fun addStoryPageInfoToForegroundNotification(storyIndex: StoryIndex, id: String, title: String) { + // keep our story current uploads quantity map updated + incrementCurrentUploadingItemQtyForStory(storyIndex) notificationData.totalMediaItems++ // setup progress for media item setProgressForMediaItem(id, 0.0f) startOrUpdateForegroundNotification(title) } + @Synchronized fun incrementCurrentUploadingItemQtyForStory(storyIndex: StoryIndex) { + val currentAmount = getCurrentUploadingItemQtyForStory(storyIndex) + notificationData.currentStoriesToQtyUploadingMap.put(storyIndex, currentAmount + 1) + } + + @Synchronized fun decrementCurrentUploadingItemQtyForStory(storyIndex: StoryIndex) { + var currentAmount = getCurrentUploadingItemQtyForStory(storyIndex) + if (currentAmount > 0) { + currentAmount-- + } + if (currentAmount == 0) { + // remove the entry altogether + notificationData.currentStoriesToQtyUploadingMap.remove(storyIndex) + } else { + // otherwise update the value + notificationData.currentStoriesToQtyUploadingMap.put(storyIndex, currentAmount) + } + } + + @Synchronized fun getCurrentUploadingItemQtyForStory(storyIndex: StoryIndex): Int { + val currentUploadingQtyForStory = notificationData.currentStoriesToQtyUploadingMap.get(storyIndex) + if (currentUploadingQtyForStory != null) { + return currentUploadingQtyForStory + } + return 0 + } + // TODO WPANDROID: change signature to receive a CPT (Post) as parameter instead of a plain String @Synchronized private fun startOrUpdateForegroundNotification(title: String?) { updateNotificationBuilder(title) diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt index d7bb148f3..c0f958f06 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveService.kt @@ -215,38 +215,56 @@ class FrameSaveService : Service() { private val frameSaveManager: FrameSaveManager ) : FrameSaveProgressListener { val storySaveResult = StorySaveResult() + val title = + StoryRepository.getStoryAtIndex(storyIndex).title ?: context.getString(R.string.story_saving_untitled) // FrameSaveProgressListener overrides override fun onFrameSaveStart(frameIndex: FrameIndex) { Log.d("PORTKEY", "START save frame idx: " + frameIndex) frameSaveNotifier.addStoryPageInfoToForegroundNotification( - frameIndex.toString(), - StoryRepository.getStoryAtIndex(storyIndex).title ?: context.getString(R.string.story_saving_untitled) + storyIndex, + mediaIdFromStoryAndFrameIndex(storyIndex, frameIndex), + title ) } override fun onFrameSaveProgress(frameIndex: FrameIndex, progress: Double) { Log.d("PORTKEY", "PROGRESS save frame idx: " + frameIndex + " %: " + progress) - frameSaveNotifier.updateNotificationProgressForMedia(frameIndex.toString(), progress.toFloat()) + frameSaveNotifier.updateNotificationProgressForMedia( + mediaIdFromStoryAndFrameIndex(storyIndex, frameIndex), + progress.toFloat()) } override fun onFrameSaveCompleted(frameIndex: FrameIndex) { Log.d("PORTKEY", "END save frame idx: " + frameIndex) - frameSaveNotifier.incrementUploadedMediaCountFromProgressNotification(frameIndex.toString(), true) + frameSaveNotifier.incrementUploadedMediaCountFromProgressNotification( + storyIndex, + title, + mediaIdFromStoryAndFrameIndex(storyIndex, frameIndex), + true + ) // add success data to StorySaveResult storySaveResult.frameSaveResult.add(FrameSaveResult(frameIndex, SaveSuccess)) } override fun onFrameSaveCanceled(frameIndex: FrameIndex) { // remove one from the count - frameSaveNotifier.incrementUploadedMediaCountFromProgressNotification(frameIndex.toString()) + frameSaveNotifier.incrementUploadedMediaCountFromProgressNotification( + storyIndex, + title, + mediaIdFromStoryAndFrameIndex(storyIndex, frameIndex) + ) // add error data to StorySaveResult storySaveResult.frameSaveResult.add(FrameSaveResult(frameIndex, SaveError(REASON_CANCELLED))) } override fun onFrameSaveFailed(frameIndex: FrameIndex, reason: String?) { // remove one from the count - frameSaveNotifier.incrementUploadedMediaCountFromProgressNotification(frameIndex.toString()) + frameSaveNotifier.incrementUploadedMediaCountFromProgressNotification( + storyIndex, + title, + mediaIdFromStoryAndFrameIndex(storyIndex, frameIndex) + ) // add error data to StorySaveResult storySaveResult.frameSaveResult.add(FrameSaveResult(frameIndex, SaveError(reason))) } @@ -269,6 +287,10 @@ class FrameSaveService : Service() { fun onCancel() { frameSaveManager.onCancel() } + + private fun mediaIdFromStoryAndFrameIndex(storyIndex: Int, frameIndex: Int): String { + return storyIndex.toString() + "-" + frameIndex.toString() + } } companion object { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b362440c..a3a1b5b1c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,6 +85,7 @@ Untitled Saving "%1$s"... + several stories 1 page remaining %1$d pages remaining Uploading "%1$s"... From a4355d0a4151420415915df3c9f62e9a3ad852ae Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 9 Apr 2020 19:21:28 -0300 Subject: [PATCH 3/7] added onNewIntent override, so we can reload the Activity when it's on the foregorund and we tap on a new error notification --- .../compose/ComposeLoopFrameActivity.kt | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt index a10c181bb..1723fd234 100644 --- a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt +++ b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt @@ -304,40 +304,7 @@ class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelectorTapped // also, update the UI updateFlashModeSelectionIcon() - photoEditorView.postDelayed({ - if (intent.hasExtra(KEY_STORY_SAVE_RESULT)) { - val storySaveResult = intent.getSerializableExtra(KEY_STORY_SAVE_RESULT) as StorySaveResult? - if (storySaveResult != null && - StoryRepository.getStoryAtIndex(storySaveResult.storyIndex).frames.size > 0) { - // dismiss the error notification - // TODO use NativeNotificationUtils.dismissNotification() when migrating to WPAndroid - intent.action?.let { - val notificationManager = NotificationManagerCompat.from(this) - notificationManager.cancel(it.toInt()) - } - - // if the StoryRepository contains a story, load it right away to continue editing - // TODO check pages in this Story and mark them errored according to the StorySaveResult - // see https://github.com/Automattic/portkey-android/issues/285 for details - Log.d("PORTKEY", "Being passed a SaveResult, render the Story") - storyViewModel.loadStory(storySaveResult.storyIndex) - onStoryFrameSelected(0, 0) - } else { - // TODO couldn't find the story frames? Show some Error Dialog - we can't recover here - } - } else { - launchCameraPreview() - storyViewModel.uiState.observe(this, Observer { - // if no frames in Story, launch the capture mode - if (storyViewModel.getCurrentStorySize() == 0) { - photoEditor.clearAllViews() - launchCameraPreview() - // finally, delete the captured media - deleteCapturedMedia() - } - }) - } - }, SURFACE_MANAGER_READY_LAUNCH_DELAY) + onLoadFromIntent(intent) } else { currentOriginalCapturedFile = savedInstanceState.getSerializable(STATE_KEY_CURRENT_ORIGINAL_CAPTURED_FILE) as File? @@ -359,6 +326,48 @@ class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelectorTapped } } + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + onLoadFromIntent(intent) + } + + private fun onLoadFromIntent(intent: Intent) { + photoEditorView.postDelayed({ + if (intent.hasExtra(KEY_STORY_SAVE_RESULT)) { + val storySaveResult = intent.getSerializableExtra(KEY_STORY_SAVE_RESULT) as StorySaveResult? + if (storySaveResult != null && + StoryRepository.getStoryAtIndex(storySaveResult.storyIndex).frames.size > 0) { + // dismiss the error notification + // TODO use NativeNotificationUtils.dismissNotification() when migrating to WPAndroid + intent.action?.let { + val notificationManager = NotificationManagerCompat.from(this) + notificationManager.cancel(it.toInt()) + } + + // if the StoryRepository contains a story, load it right away to continue editing + // TODO check pages in this Story and mark them errored according to the StorySaveResult + // see https://github.com/Automattic/portkey-android/issues/285 for details + Log.d("PORTKEY", "Being passed a SaveResult, render the Story") + storyViewModel.loadStory(storySaveResult.storyIndex) + onStoryFrameSelected(0, 0) + } else { + // TODO couldn't find the story frames? Show some Error Dialog - we can't recover here + } + } else { + launchCameraPreview() + storyViewModel.uiState.observe(this, Observer { + // if no frames in Story, launch the capture mode + if (storyViewModel.getCurrentStorySize() == 0) { + photoEditor.clearAllViews() + launchCameraPreview() + // finally, delete the captured media + deleteCapturedMedia() + } + }) + } + }, SURFACE_MANAGER_READY_LAUNCH_DELAY) + } + override fun onDestroy() { doUnbindService() EventBus.getDefault().unregister(this) From b3761cb32c6c55a1dbd1a566ca6ad92ef4264eae Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Thu, 9 Apr 2020 19:44:01 -0300 Subject: [PATCH 4/7] fixed lint warning --- .../com/automattic/portkey/compose/frame/FrameSaveNotifier.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt index 88cd43e91..5437d2504 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt @@ -28,7 +28,7 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame internal var notificationId: Int = 0 internal var totalMediaItems: Int = 0 internal var currentMediaItem: Int = 0 - internal var currentStoriesToQtyUploadingMap= HashMap() // keep amount of items being uploaded + internal var currentStoriesToQtyUploadingMap = HashMap() // keep amount of items being uploaded // for multiple concurrent stories internal val mediaItemToProgressMap = HashMap() } From 4686956a628794e744c6da3c81e7e17b2af229dd Mon Sep 17 00:00:00 2001 From: mzorz Date: Wed, 15 Apr 2020 10:04:48 -0300 Subject: [PATCH 5/7] use easier to read isNotEmpty() Co-Authored-By: Joel Dean --- .../com/automattic/portkey/compose/ComposeLoopFrameActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt index 1723fd234..e6c031242 100644 --- a/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt +++ b/app/src/main/java/com/automattic/portkey/compose/ComposeLoopFrameActivity.kt @@ -336,7 +336,7 @@ class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelectorTapped if (intent.hasExtra(KEY_STORY_SAVE_RESULT)) { val storySaveResult = intent.getSerializableExtra(KEY_STORY_SAVE_RESULT) as StorySaveResult? if (storySaveResult != null && - StoryRepository.getStoryAtIndex(storySaveResult.storyIndex).frames.size > 0) { + StoryRepository.getStoryAtIndex(storySaveResult.storyIndex).frames.isNotEmpty()) { // dismiss the error notification // TODO use NativeNotificationUtils.dismissNotification() when migrating to WPAndroid intent.action?.let { From 03f31b5ab7b2df26cfe6860245a68c30d4bec329 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 15 Apr 2020 10:07:35 -0300 Subject: [PATCH 6/7] renamed param --- .../com/automattic/portkey/compose/frame/FrameSaveNotifier.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt index b795ccadd..f44f3d340 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt @@ -374,11 +374,11 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame doNotify(notificationId, notificationBuilder.build()) // , notificationType) } - fun getNotificationIdForError(storyIdx: StoryIndex): Int { + fun getNotificationIdForError(storyIndex: StoryIndex): Int { // TODO WPANDROID we keep the base number because we'll use SiteId and PostModel id's to identify the error // notification as well, and as such we are using a different base number to avoid collision of notification // ids. - return BASE_MEDIA_ERROR_NOTIFICATION_ID + storyIdx + return BASE_MEDIA_ERROR_NOTIFICATION_ID + storyIndex } companion object { From 1725a804b54a333a33594868200119afbd1a24a6 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 15 Apr 2020 10:19:04 -0300 Subject: [PATCH 7/7] made title not null and removed a couple of unused methods --- .../compose/frame/FrameSaveNotifier.kt | 34 ++++--------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt index f44f3d340..b1f348858 100644 --- a/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt +++ b/app/src/main/java/com/automattic/portkey/compose/frame/FrameSaveNotifier.kt @@ -58,12 +58,12 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame } } - private fun updateForegroundNotification(title: String? = null) { + private fun updateForegroundNotification(title: String) { updateNotificationBuilder(title) updateNotificationProgress() } - private fun updateNotificationBuilder(title: String?) { + private fun updateNotificationBuilder(title: String) { // set the Notification's title and prepare the Notifications message text, // i.e. "Saving story... 3 frames remaining" if (notificationData.totalMediaItems > 0) { @@ -72,20 +72,14 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame } } - private fun updateNotificationTitle(title: String?) { + private fun updateNotificationTitle(title: String) { // if there are frames of more than 1 concurrent Story being saved, show plural title if (notificationData.currentStoriesToQtyUploadingMap.size > 1) { notificationBuilder.setContentTitle(buildNotificationTitleForFrameSaveProcess( context.getString(R.string.story_saving_title_several)) ) } else { - if (title != null) { - notificationBuilder.setContentTitle(buildNotificationTitleForFrameSaveProcess(title)) - } else { - notificationBuilder.setContentTitle(buildNotificationTitleForFrameSaveProcess( - context.getString(R.string.story_saving_untitled)) - ) - } + notificationBuilder.setContentTitle(buildNotificationTitleForFrameSaveProcess(title)) } } @@ -115,7 +109,7 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame @Synchronized fun incrementUploadedMediaCountFromProgressNotification( storyIndex: StoryIndex, - title: String?, + title: String, id: String, success: Boolean = false ) { @@ -217,22 +211,6 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame notificationData.totalMediaItems = totalMediaItems } - @Synchronized fun removeMediaInfoFromForegroundNotification(idList: List) { - if (notificationData.totalMediaItems >= idList.size) { - notificationData.totalMediaItems -= idList.size - // update Notification now - updateForegroundNotification(null) - } - } - - @Synchronized fun removeOneMediaItemInfoFromForegroundNotification() { - if (notificationData.totalMediaItems >= 1) { - notificationData.totalMediaItems-- - // update Notification now - updateForegroundNotification(null) - } - } - @Synchronized fun addStoryPageInfoToForegroundNotification( storyIndex: StoryIndex, idList: List, @@ -285,7 +263,7 @@ class FrameSaveNotifier(private val context: Context, private val service: Frame } // TODO WPANDROID: change signature to receive a CPT (Post) as parameter instead of a plain String - @Synchronized private fun startOrUpdateForegroundNotification(title: String?) { + @Synchronized private fun startOrUpdateForegroundNotification(title: String) { updateNotificationBuilder(title) if (notificationData.notificationId == 0) { notificationData.notificationId = Random().nextInt()