forked from cwtch.im/cwtch-ui
android download notification, also fix updatemessageflags didnt work on android
This commit is contained in:
parent
8fe577afd4
commit
d4aa1cb397
|
@ -60,6 +60,7 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
if (Cwtch.startCwtch(appDir, torPath) != 0.toLong()) return Result.failure()
|
if (Cwtch.startCwtch(appDir, torPath) != 0.toLong()) return Result.failure()
|
||||||
|
|
||||||
Log.i("FlwtchWorker.kt", "startCwtch success, starting coroutine AppbusEvent loop...")
|
Log.i("FlwtchWorker.kt", "startCwtch success, starting coroutine AppbusEvent loop...")
|
||||||
|
val downloadIDs = mutableMapOf<String, Int>()
|
||||||
while(true) {
|
while(true) {
|
||||||
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
|
val evt = MainActivity.AppbusEvent(Cwtch.getAppBusEvent())
|
||||||
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
|
if (evt.EventType == "NewMessageFromPeer" || evt.EventType == "NewMessageFromGroup") {
|
||||||
|
@ -97,10 +98,46 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
.build()
|
.build()
|
||||||
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), handle), newNotification)
|
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), handle), newNotification)
|
||||||
}
|
}
|
||||||
|
} else if (evt.EventType == "FileDownloadProgressUpdate") {
|
||||||
|
try {
|
||||||
|
val data = JSONObject(evt.Data);
|
||||||
|
val fileKey = data.getString("FileKey");
|
||||||
|
val title = data.getString("NameSuggestion");
|
||||||
|
val progress = data.getString("Progress").toInt();
|
||||||
|
val progressMax = data.getString("FileSizeInChunks").toInt();
|
||||||
|
if (!downloadIDs.containsKey(fileKey)) {
|
||||||
|
downloadIDs.put(fileKey, downloadIDs.count());
|
||||||
|
}
|
||||||
|
var dlID = downloadIDs.get(fileKey);
|
||||||
|
if (dlID == null) {
|
||||||
|
dlID = 0;
|
||||||
|
}
|
||||||
|
val channelId =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
createDownloadNotificationChannel(fileKey, fileKey)
|
||||||
|
} else {
|
||||||
|
// If earlier version channel ID is not used
|
||||||
|
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
|
||||||
|
""
|
||||||
|
};
|
||||||
|
val newNotification = NotificationCompat.Builder(applicationContext, channelId)
|
||||||
|
.setOngoing(true)
|
||||||
|
.setContentTitle("Downloading")//todo: translate
|
||||||
|
.setContentText(title)
|
||||||
|
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||||
|
.setProgress(progressMax, progress, false)
|
||||||
|
.setSound(null)
|
||||||
|
//.setSilent(true)
|
||||||
|
.build();
|
||||||
|
notificationManager.notify(dlID, newNotification);
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.i("FlwtchWorker->FileDownloadProgressUpdate", e.toString() + " :: " + e.getStackTrace());
|
||||||
|
}
|
||||||
} else if (evt.EventType == "FileDownloaded") {
|
} else if (evt.EventType == "FileDownloaded") {
|
||||||
Log.i("FlwtchWorker", "file downloaded!");
|
Log.i("FlwtchWorker", "file downloaded!");
|
||||||
val data = JSONObject(evt.Data);
|
val data = JSONObject(evt.Data);
|
||||||
val tempFile = data.getString("TempFile");
|
val tempFile = data.getString("TempFile");
|
||||||
|
val fileKey = data.getString("FileKey");
|
||||||
if (tempFile != "") {
|
if (tempFile != "") {
|
||||||
val filePath = data.getString("FilePath");
|
val filePath = data.getString("FilePath");
|
||||||
Log.i("FlwtchWorker", "moving "+tempFile+" to "+filePath);
|
Log.i("FlwtchWorker", "moving "+tempFile+" to "+filePath);
|
||||||
|
@ -115,6 +152,9 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
Files.delete(sourcePath);
|
Files.delete(sourcePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (downloadIDs.containsKey(fileKey)) {
|
||||||
|
notificationManager.cancel(downloadIDs.get(fileKey)?:0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent().also { intent ->
|
Intent().also { intent ->
|
||||||
|
@ -310,6 +350,15 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
|
||||||
return channelId
|
return channelId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
private fun createDownloadNotificationChannel(channelId: String, channelName: String): String{
|
||||||
|
val chan = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_LOW)
|
||||||
|
chan.lightColor = Color.MAGENTA
|
||||||
|
chan.lockscreenVisibility = Notification.VISIBILITY_PRIVATE
|
||||||
|
notificationManager.createNotificationChannel(chan)
|
||||||
|
return channelId
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KEY_METHOD = "KEY_METHOD"
|
const val KEY_METHOD = "KEY_METHOD"
|
||||||
const val KEY_ARGS = "KEY_ARGS"
|
const val KEY_ARGS = "KEY_ARGS"
|
||||||
|
|
|
@ -60,6 +60,7 @@ class MainActivity: FlutterActivity() {
|
||||||
private var dlToHandle = ""
|
private var dlToHandle = ""
|
||||||
private var dlToFileKey = ""
|
private var dlToFileKey = ""
|
||||||
|
|
||||||
|
// handles clicks received from outside the app (ie, notifications)
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
if (notificationClickChannel == null || intent.extras == null) return
|
if (notificationClickChannel == null || intent.extras == null) return
|
||||||
|
@ -81,6 +82,7 @@ class MainActivity: FlutterActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handles return values from the system file picker
|
||||||
override fun onActivityResult(requestCode: Int, result: Int, intent: Intent?) {
|
override fun onActivityResult(requestCode: Int, result: Int, intent: Intent?) {
|
||||||
if (intent == null || intent!!.getData() == null) {
|
if (intent == null || intent!!.getData() == null) {
|
||||||
Log.i("MainActivity:onActivityResult", "user canceled activity");
|
Log.i("MainActivity:onActivityResult", "user canceled activity");
|
||||||
|
@ -89,15 +91,13 @@ class MainActivity: FlutterActivity() {
|
||||||
|
|
||||||
val filePath = intent!!.getData().toString();
|
val filePath = intent!!.getData().toString();
|
||||||
val manifestPath = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(this.dlToFileKey).toString();
|
val manifestPath = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(this.dlToFileKey).toString();
|
||||||
Log.i("onActivityResult", "got download path: " + filePath);
|
|
||||||
Log.i("onActivityResult", "got manifest path: " + manifestPath);
|
|
||||||
handleCwtch(MethodCall("DownloadFile", mapOf(
|
handleCwtch(MethodCall("DownloadFile", mapOf(
|
||||||
"ProfileOnion" to this.dlToProfile,
|
"ProfileOnion" to this.dlToProfile,
|
||||||
"handle" to this.dlToHandle,
|
"handle" to this.dlToHandle,
|
||||||
"filepath" to filePath,
|
"filepath" to filePath,
|
||||||
"manifestpath" to manifestPath,
|
"manifestpath" to manifestPath,
|
||||||
"filekey" to this.dlToFileKey
|
"filekey" to this.dlToFileKey
|
||||||
)), ErrorLogResult(""));//placeholder; result is never actually invoked
|
)), ErrorLogResult(""));//placeholder; this Result is never actually invoked
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||||
|
|
|
@ -198,7 +198,7 @@ class CwtchGomobile implements Cwtch {
|
||||||
@override
|
@override
|
||||||
void UpdateMessageFlags(String profile, String handle, int index, int flags) {
|
void UpdateMessageFlags(String profile, String handle, int index, int flags) {
|
||||||
print("gomobile.dart UpdateMessageFlags " + index.toString());
|
print("gomobile.dart UpdateMessageFlags " + index.toString());
|
||||||
cwtchPlatform.invokeMethod("UpdateMessageFlags", {"profile": profile, "contact": handle, "index": index, "flags": flags});
|
cwtchPlatform.invokeMethod("UpdateMessageFlags", {"profile": profile, "contact": handle, "midx": index, "flags": flags});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -98,7 +98,7 @@ class FileBubbleState extends State<FileBubble> {
|
||||||
wdgDecorations = Text('Checking download status...' + '\u202F');
|
wdgDecorations = Text('Checking download status...' + '\u202F');
|
||||||
Provider.of<FlwtchState>(context, listen: false).cwtch.CheckDownloadStatus(Provider.of<ProfileInfoState>(context, listen: false).onion, widget.fileKey());
|
Provider.of<FlwtchState>(context, listen: false).cwtch.CheckDownloadStatus(Provider.of<ProfileInfoState>(context, listen: false).onion, widget.fileKey());
|
||||||
} else {
|
} else {
|
||||||
wdgDecorations = Text('Saved to: ' + (path??"null") + '\u202F');
|
wdgDecorations = Text('Saved to: ' + path + '\u202F');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wdgDecorations = Center(
|
wdgDecorations = Center(
|
||||||
|
|
Loading…
Reference in New Issue