Added early basic media viewing in Talk
This commit is contained in:
@ -1,7 +1,12 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatResponse.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class RichObjectStringProcessor {
|
||||
static String parse(String message, Map<String, RichObjectString>? data) {
|
||||
static String parseTextPreview(String message, Map<String, RichObjectString>? data) {
|
||||
if(data == null) return message;
|
||||
|
||||
data.forEach((key, value) {
|
||||
@ -10,4 +15,31 @@ class RichObjectStringProcessor {
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
static Future<Widget> parseAnyToWidget(String message, Map<String, RichObjectString>? data) async {
|
||||
if(data == null) return Text(message);
|
||||
if(!message.contains(RegExp("{file}"))) return Text(parseTextPreview(message, data));
|
||||
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
Widget? back;
|
||||
data.forEach((key, value) {
|
||||
back = CachedNetworkImage(
|
||||
errorWidget: (context, url, error) {
|
||||
return Text("Datei: ${value.name}", style: const TextStyle(fontWeight: FontWeight.bold));
|
||||
},
|
||||
alignment: Alignment.center,
|
||||
placeholder: (context, url) {
|
||||
return const Padding(padding: EdgeInsets.all(10), child: CircularProgressIndicator());
|
||||
},
|
||||
fadeInDuration: const Duration(seconds: 1),
|
||||
imageUrl: "https://cloud.marianum-fulda.de/core/preview?fileId=${value.id}&x=110&y=-1&a=1",
|
||||
httpHeaders: {
|
||||
"Authorization": "Basic ${base64.encode(utf8.encode("${preferences.getString("username")}:${preferences.getString("password")}"))}"
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
return back ?? Text("NOPE");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user