diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/CommentsFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/CommentsFragment.kt index 97d5200e37095d00a5dd7502e593d2862c413f88..eb1bb34b00ce5fd25a64d39f09f6393c74be1132 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/CommentsFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/CommentsFragment.kt @@ -154,33 +154,35 @@ class CommentsFragment : MainFragment() { } private fun onDelete(comment: IPlatformComment) { - val processHandle = StatePolycentric.instance.processHandle ?: return - if (comment !is PolycentricPlatformComment) { - return - } - - val index = _comments.indexOf(comment) - if (index != -1) { - _comments.removeAt(index) - _adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index)) - - StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) { - try { - processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock) - } catch (e: Throwable) { - Logger.e(TAG, "Failed to delete event.", e); - return@launch; - } + UIDialogs.showConfirmationDialog(context, "Are you sure you want to delete this comment?", { + val processHandle = StatePolycentric.instance.processHandle ?: return@showConfirmationDialog + if (comment !is PolycentricPlatformComment) { + return@showConfirmationDialog + } - try { - Logger.i(TAG, "Started backfill"); - processHandle.fullyBackfillServersAnnounceExceptions(); - Logger.i(TAG, "Finished backfill"); - } catch (e: Throwable) { - Logger.e(TAG, "Failed to fully backfill servers.", e); + val index = _comments.indexOf(comment) + if (index != -1) { + _comments.removeAt(index) + _adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index)) + + StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) { + try { + processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock) + } catch (e: Throwable) { + Logger.e(TAG, "Failed to delete event.", e); + return@launch + } + + try { + Logger.i(TAG, "Started backfill"); + processHandle.fullyBackfillServersAnnounceExceptions(); + Logger.i(TAG, "Finished backfill"); + } catch (e: Throwable) { + Logger.e(TAG, "Failed to fully backfill servers.", e); + } } } - } + }) } fun onBackPressed(): Boolean { diff --git a/app/src/main/java/com/futo/platformplayer/views/segments/CommentsList.kt b/app/src/main/java/com/futo/platformplayer/views/segments/CommentsList.kt index 29adc859c7bca8d373cfb6acea94bbd958af5764..e377d81d84b89736b3d832c9f7f1eadcf02d9f03 100644 --- a/app/src/main/java/com/futo/platformplayer/views/segments/CommentsList.kt +++ b/app/src/main/java/com/futo/platformplayer/views/segments/CommentsList.kt @@ -111,33 +111,35 @@ class CommentsList : ConstraintLayout { } private fun onDelete(comment: IPlatformComment) { - val processHandle = StatePolycentric.instance.processHandle ?: return - if (comment !is PolycentricPlatformComment) { - return - } - - val index = _comments.indexOf(comment) - if (index != -1) { - _comments.removeAt(index) - _adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index)) - - StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) { - try { - processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock) - } catch (e: Throwable) { - Logger.e(TAG, "Failed to delete event.", e); - return@launch; - } + UIDialogs.showConfirmationDialog(context, "Are you sure you want to delete this comment?", { + val processHandle = StatePolycentric.instance.processHandle ?: return@showConfirmationDialog + if (comment !is PolycentricPlatformComment) { + return@showConfirmationDialog + } - try { - Logger.i(TAG, "Started backfill"); - processHandle.fullyBackfillServersAnnounceExceptions(); - Logger.i(TAG, "Finished backfill"); - } catch (e: Throwable) { - Logger.e(TAG, "Failed to fully backfill servers.", e); + val index = _comments.indexOf(comment) + if (index != -1) { + _comments.removeAt(index) + _adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index)) + + StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) { + try { + processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock) + } catch (e: Throwable) { + Logger.e(TAG, "Failed to delete event.", e); + return@launch; + } + + try { + Logger.i(TAG, "Started backfill"); + processHandle.fullyBackfillServersAnnounceExceptions(); + Logger.i(TAG, "Finished backfill"); + } catch (e: Throwable) { + Logger.e(TAG, "Failed to fully backfill servers.", e); + } } } - } + }) } private fun onScrolled() {