[network/kdeconnect-android] src/main/java/org/kde/kdeconnect/plugins/share: Migrate UploadNotification to Kotlin

Simon Redman <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 91b8e88b215de46ad813f00838aa89c1f1607355 by Simon Redman, on behalf of TPJ Schikhof.
Committed on 17/08/2026 at 21:11.
Pushed by sredman into branch 'master'.

Migrate UploadNotification to Kotlin

D  +0    -94   src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.java
A  +90   -0    src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.kt

https://invent.kde.org/network/kdeconnect-android/-/commit/91b8e88b215de46ad813f00838aa89c1f1607355

diff --git a/src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.java b/src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.java
deleted file mode 100644
index b471c3c65..000000000
--- a/src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2019 Erik Duisters <[email protected]>
- *
- * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
- */
-
-package org.kde.kdeconnect.plugins.share;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.content.SharedPreferences;
-
-import androidx.core.app.NotificationCompat;
-import androidx.core.content.ContextCompat;
-import androidx.preference.PreferenceManager;
-
-import org.kde.kdeconnect.Device;
-import org.kde.kdeconnect.helpers.NotificationHelper;
-import org.kde.kdeconnect_tp.R;
-
-class UploadNotification {
-    private final NotificationManager notificationManager;
-    private NotificationCompat.Builder builder;
-    private final int notificationId;
-    private final Device device;
-    private final long jobId;
-
-    UploadNotification(Device device, long jobId) {
-        this.device = device;
-        this.jobId = jobId;
-
-        notificationId = (int) System.currentTimeMillis();
-        notificationManager = ContextCompat.getSystemService(device.getContext(), NotificationManager.class);
-        builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER_UPLOAD)
-                .setSmallIcon(android.R.drawable.stat_sys_upload)
-                .setAutoCancel(true)
-                .setOngoing(true)
-                .setProgress(100, 0, true);
-        addCancelAction();
-    }
-
-    void addCancelAction() {
-        Intent cancelIntent = new Intent(device.getContext(), ShareBroadcastReceiver.class);
-        cancelIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
-        cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE);
-        cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId);
-        cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA, device.getDeviceId());
-        PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(device.getContext(), 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
-
-        builder.addAction(R.drawable.ic_reject_pairing_24dp, device.getContext().getString(R.string.cancel), cancelPendingIntent);
-    }
-
-    public void setTitle(String title) {
-        builder.setContentTitle(title);
-        builder.setTicker(title);
-    }
-
-    public void setProgress(int progress, String progressMessage) {
-        builder.setProgress( 100, progress, false);
-        builder.setContentText(progressMessage);
-        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(progressMessage));
-    }
-
-    public void setFinished(String message) {
-        builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER_UPLOAD);
-        builder.setContentTitle(message)
-                .setTicker(message)
-                .setSmallIcon(android.R.drawable.stat_sys_upload_done)
-                .setAutoCancel(true)
-                .setOngoing(false);
-
-        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(device.getContext());
-        if (prefs.getBoolean("share_notification_preference", true)) {
-            builder.setDefaults(Notification.DEFAULT_ALL);
-        }
-    }
-
-    public void setFailed(String message) {
-        setFinished(message);
-        builder.setSmallIcon(android.R.drawable.stat_notify_error)
-                .setChannelId(NotificationHelper.Channels.FILETRANSFER_ERROR);
-    }
-
-    public void cancel() {
-        notificationManager.cancel(notificationId);
-    }
-
-    void show() {
-        notificationManager.notify(notificationId, builder.build());
-    }
-}
-
diff --git a/src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.kt b/src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.kt
new file mode 100644
index 000000000..e8acbb4d0
--- /dev/null
+++ b/src/main/java/org/kde/kdeconnect/plugins/share/UploadNotification.kt
@@ -0,0 +1,90 @@
+/*
+ * SPDX-FileCopyrightText: 2019 Erik Duisters <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
+ */
+package org.kde.kdeconnect.plugins.share
+
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.content.Intent
+import androidx.core.app.NotificationCompat
+import androidx.core.content.ContextCompat
+import androidx.preference.PreferenceManager
+import org.kde.kdeconnect.Device
+import org.kde.kdeconnect.helpers.NotificationHelper
+
+internal class UploadNotification {
+    private val device: Device
+    private val jobId: Long
+
+    constructor(device: Device, jobId: Long) {
+        this.device = device
+        this.jobId = jobId
+        notificationId = System.currentTimeMillis().toInt()
+        notificationManager = ContextCompat.getSystemService(device.context, NotificationManager::class.java)!!
+        builder = NotificationCompat.Builder(device.context, NotificationHelper.Channels.FILETRANSFER_UPLOAD)
+            .setSmallIcon(android.R.drawable.stat_sys_upload)
+            .setAutoCancel(true)
+            .setOngoing(true)
+            .setProgress(100, 0, true)
+        addCancelAction()
+    }
+
+    private val notificationManager: NotificationManager
+    private var builder: NotificationCompat.Builder
+    private val notificationId: Int
+
+    fun addCancelAction() {
+        val cancelIntent = Intent(device.context, ShareBroadcastReceiver::class.java)
+        cancelIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
+        cancelIntent.action = SharePlugin.ACTION_CANCEL_SHARE
+        cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId)
+        cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA, device.deviceId)
+        val flags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
+        val cancelPendingIntent = PendingIntent.getBroadcast(device.context, 0, cancelIntent, flags)
+
+        builder.addAction(org.kde.kdeconnect_tp.R.drawable.ic_reject_pairing_24dp, device.context.getString(org.kde.kdeconnect_tp.R.string.cancel), cancelPendingIntent)
+    }
+
+    fun setTitle(title: String) {
+        builder.setContentTitle(title)
+        builder.setTicker(title)
+    }
+
+    fun setProgress(progress: Int, progressMessage: String) {
+        builder.setProgress(100, progress, false)
+        builder.setContentText(progressMessage)
+        builder.setStyle(NotificationCompat.BigTextStyle().bigText(progressMessage))
+    }
+
+    fun setFinished(message: String) {
+        builder = NotificationCompat.Builder(device.context, NotificationHelper.Channels.FILETRANSFER_UPLOAD)
+        builder.setContentTitle(message)
+            .setTicker(message)
+            .setSmallIcon(android.R.drawable.stat_sys_upload_done)
+            .setAutoCancel(true)
+            .setOngoing(false)
+
+        val prefs = PreferenceManager.getDefaultSharedPreferences(device.context)
+        if (prefs.getBoolean("share_notification_preference", true)) {
+            builder.setDefaults(Notification.DEFAULT_ALL)
+        }
+    }
+
+    fun setFailed(message: String) {
+        setFinished(message)
+        builder.setSmallIcon(android.R.drawable.stat_notify_error)
+            .setChannelId(NotificationHelper.Channels.FILETRANSFER_ERROR)
+    }
+
+    fun cancel() {
+        notificationManager.cancel(notificationId)
+    }
+
+    fun show() {
+        notificationManager.notify(notificationId, builder.build())
+    }
+}
+
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.