Fix Android File Downloading Stuck Notification / Small Settings Font Tweaks

This commit is contained in:
Sarah Jamie Lewis 2023-05-18 12:05:14 -07:00 committed by Gitea
parent 67a99c903a
commit ea22864341
4 changed files with 46 additions and 46 deletions

View File

@ -84,6 +84,7 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
Log.i(TAG, "startCwtch success, starting coroutine AppbusEvent loop...") Log.i(TAG, "startCwtch success, starting coroutine AppbusEvent loop...")
val downloadIDs = mutableMapOf<String, Int>() val downloadIDs = mutableMapOf<String, Int>()
val downloadFinishedIDs = mutableMapOf<String, Int>()
var flags = PendingIntent.FLAG_UPDATE_CURRENT var flags = PendingIntent.FLAG_UPDATE_CURRENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags = flags or PendingIntent.FLAG_IMMUTABLE flags = flags or PendingIntent.FLAG_IMMUTABLE
@ -167,32 +168,36 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
val title = data.getString("NameSuggestion"); val title = data.getString("NameSuggestion");
val progress = data.getString("Progress").toInt(); val progress = data.getString("Progress").toInt();
val progressMax = data.getString("FileSizeInChunks").toInt(); val progressMax = data.getString("FileSizeInChunks").toInt();
if (!downloadIDs.containsKey(fileKey)) {
downloadIDs.put(fileKey, downloadIDs.count()); // if we have seen a download finished update for this key then ignore it
} if (!downloadFinishedIDs.containsKey(fileKey)) {
var dlID = downloadIDs.get(fileKey); if (!downloadIDs.containsKey(fileKey)) {
if (dlID == null) { downloadIDs.put(fileKey, downloadIDs.count());
dlID = 0; }
} var dlID = downloadIDs.get(fileKey);
if (progress >= 0) { if (dlID == null) {
val channelId = dlID = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { }
createDownloadNotificationChannel(fileKey, fileKey) if (progress >= 0) {
} else { val channelId =
// If earlier version channel ID is not used if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context) createDownloadNotificationChannel(fileKey, fileKey)
"" } else {
}; // If earlier version channel ID is not used
val newNotification = NotificationCompat.Builder(applicationContext, channelId) // https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
.setOngoing(true) ""
.setContentTitle("Downloading")//todo: translate };
.setContentText(title) val newNotification = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(android.R.drawable.stat_sys_download) .setOngoing(true)
.setProgress(progressMax, progress, false) .setContentTitle("Downloading")//todo: translate
.setSound(null) .setContentText(title)
//.setSilent(true) .setSmallIcon(android.R.drawable.stat_sys_download)
.build(); .setProgress(progressMax, progress, false)
notificationManager.notify(dlID, newNotification); .setSound(null)
//.setSilent(true)
.build();
notificationManager.notify(dlID, newNotification);
}
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.d("FlwtchWorker->FileDownloadProgressUpdate", e.toString() + " :: " + e.getStackTrace()); Log.d("FlwtchWorker->FileDownloadProgressUpdate", e.toString() + " :: " + e.getStackTrace());
@ -216,6 +221,8 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
Files.delete(sourcePath); Files.delete(sourcePath);
} }
} }
// Suppress future notifications...
downloadFinishedIDs.put(fileKey, downloadIDs.count());
if (downloadIDs.containsKey(fileKey)) { if (downloadIDs.containsKey(fileKey)) {
notificationManager.cancel(downloadIDs.get(fileKey) ?: 0); notificationManager.cancel(downloadIDs.get(fileKey) ?: 0);
} }

View File

@ -26,7 +26,8 @@ class TextMessage extends Message {
value: this.metadata, value: this.metadata,
builder: (bcontext, child) { builder: (bcontext, child) {
var formatMessages = Provider.of<Settings>(bcontext).isExperimentEnabled(FormattingExperiment); var formatMessages = Provider.of<Settings>(bcontext).isExperimentEnabled(FormattingExperiment);
return compileMessageContentWidget(context, false, content, FocusNode(), formatMessages, false);; return compileMessageContentWidget(context, false, content, FocusNode(), formatMessages, false);
;
}); });
} }

View File

@ -24,6 +24,7 @@ final TextStyle defaultMessageTextStyle = TextStyle(fontFamily: "Inter", fontWei
final TextStyle defaultFormLabelTextStyle = TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: 20); final TextStyle defaultFormLabelTextStyle = TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: 20);
final TextStyle defaultTextStyle = TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w500, fontSize: 12); final TextStyle defaultTextStyle = TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w500, fontSize: 12);
final TextStyle defaultTextButtonStyle = defaultTextStyle.copyWith(fontWeight: FontWeight.bold); final TextStyle defaultTextButtonStyle = defaultTextStyle.copyWith(fontWeight: FontWeight.bold);
final TextStyle defaultDropDownMenuItemTextStyle = TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: 16);
final themes = { final themes = {
cwtch_theme: {mode_light: CwtchLight(), mode_dark: CwtchDark()}, cwtch_theme: {mode_light: CwtchLight(), mode_dark: CwtchDark()},
@ -205,8 +206,8 @@ ThemeData mkThemeData(Settings opaque) {
textTheme: TextTheme( textTheme: TextTheme(
// NOTE: The following font scales were arrived at after consulting the material text scale // NOTE: The following font scales were arrived at after consulting the material text scale
// docs: https://m3.material.io/styles/typography/type-scale-tokens and some trial and error // docs: https://m3.material.io/styles/typography/type-scale-tokens and some trial and error
displayMedium: TextStyle(fontFamily: "Inter", fontSize: opaque.fontScaling * 16.0, color: opaque.current().mainTextColor),
displaySmall: TextStyle(fontFamily: "Inter", fontSize: opaque.fontScaling * 14.0, color: opaque.current().mainTextColor), displaySmall: TextStyle(fontFamily: "Inter", fontSize: opaque.fontScaling * 14.0, color: opaque.current().mainTextColor),
displayMedium: TextStyle(fontFamily: "Inter", fontSize: opaque.fontScaling * 16.0, color: opaque.current().mainTextColor),
displayLarge: TextStyle(fontFamily: "Inter", fontSize: opaque.fontScaling * 18.0, color: opaque.current().mainTextColor), displayLarge: TextStyle(fontFamily: "Inter", fontSize: opaque.fontScaling * 18.0, color: opaque.current().mainTextColor),
titleSmall: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 16.0, color: opaque.current().mainTextColor), titleSmall: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 16.0, color: opaque.current().mainTextColor),
titleLarge: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 18.0, color: opaque.current().mainTextColor), titleLarge: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 18.0, color: opaque.current().mainTextColor),
@ -218,8 +219,8 @@ ThemeData mkThemeData(Settings opaque) {
headlineMedium: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 26.0, color: opaque.current().mainTextColor), headlineMedium: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 26.0, color: opaque.current().mainTextColor),
headlineLarge: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 28.0, color: opaque.current().mainTextColor), headlineLarge: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: opaque.fontScaling * 28.0, color: opaque.current().mainTextColor),
labelSmall: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w100, fontSize: opaque.fontScaling * 14.0, color: opaque.current().mainTextColor), labelSmall: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w100, fontSize: opaque.fontScaling * 14.0, color: opaque.current().mainTextColor),
labelLarge: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w200, fontSize: opaque.fontScaling * 16.0, color: opaque.current().mainTextColor), labelMedium: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w300, fontSize: opaque.fontScaling * 16.0, color: opaque.current().mainTextColor),
labelMedium: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w300, fontSize: opaque.fontScaling * 18.0, color: opaque.current().mainTextColor), labelLarge: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.w200, fontSize: opaque.fontScaling * 18.0, color: opaque.current().mainTextColor),
), ),
switchTheme: SwitchThemeData( switchTheme: SwitchThemeData(
overlayColor: MaterialStateProperty.all(opaque.current().defaultButtonActiveColor), overlayColor: MaterialStateProperty.all(opaque.current().defaultButtonActiveColor),

View File

@ -128,7 +128,8 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
items: AppLocalizations.supportedLocales.map<DropdownMenuItem<String>>((Locale value) { items: AppLocalizations.supportedLocales.map<DropdownMenuItem<String>>((Locale value) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: value.toString(), value: value.toString(),
child: Text(key: Key("dropdownLanguage" + value.languageCode), getLanguageFull(context, value.languageCode, value.countryCode)), child: Text(
key: Key("dropdownLanguage" + value.languageCode), getLanguageFull(context, value.languageCode, value.countryCode), style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)),
); );
}).toList()))), }).toList()))),
SwitchListTile( SwitchListTile(
@ -165,7 +166,7 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
items: themes.keys.map<DropdownMenuItem<String>>((String themeId) { items: themes.keys.map<DropdownMenuItem<String>>((String themeId) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: themeId, value: themeId,
child: Text(getThemeName(context, themeId)), //"ddi_$themeId", key: Key("ddi_$themeId")), child: Text(getThemeName(context, themeId), style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)), //"ddi_$themeId", key: Key("ddi_$themeId")),
); );
}).toList())), }).toList())),
leading: Icon(Icons.palette, color: settings.current().mainTextColor), leading: Icon(Icons.palette, color: settings.current().mainTextColor),
@ -185,7 +186,7 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
items: Settings.uiColumnModeOptions(false).map<DropdownMenuItem<String>>((DualpaneMode value) { items: Settings.uiColumnModeOptions(false).map<DropdownMenuItem<String>>((DualpaneMode value) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: value.toString(), value: value.toString(),
child: Text(Settings.uiColumnModeToString(value, context)), child: Text(Settings.uiColumnModeToString(value, context), style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)),
); );
}).toList()))), }).toList()))),
ListTile( ListTile(
@ -193,7 +194,6 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
AppLocalizations.of(context)!.settingUIColumnLandscape, AppLocalizations.of(context)!.settingUIColumnLandscape,
textWidthBasis: TextWidthBasis.longestLine, textWidthBasis: TextWidthBasis.longestLine,
softWrap: true, softWrap: true,
style: TextStyle(color: settings.current().mainTextColor),
), ),
leading: Icon(Icons.stay_primary_landscape, color: settings.current().mainTextColor), leading: Icon(Icons.stay_primary_landscape, color: settings.current().mainTextColor),
trailing: Container( trailing: Container(
@ -210,10 +210,7 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
items: Settings.uiColumnModeOptions(true).map<DropdownMenuItem<String>>((DualpaneMode value) { items: Settings.uiColumnModeOptions(true).map<DropdownMenuItem<String>>((DualpaneMode value) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
value: value.toString(), value: value.toString(),
child: Text( child: Text(Settings.uiColumnModeToString(value, context), overflow: TextOverflow.ellipsis, style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)),
Settings.uiColumnModeToString(value, context),
overflow: TextOverflow.ellipsis,
),
); );
}).toList())))), }).toList())))),
ListTile( ListTile(
@ -305,10 +302,7 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
items: NotificationPolicy.values.map<DropdownMenuItem<NotificationPolicy>>((NotificationPolicy value) { items: NotificationPolicy.values.map<DropdownMenuItem<NotificationPolicy>>((NotificationPolicy value) {
return DropdownMenuItem<NotificationPolicy>( return DropdownMenuItem<NotificationPolicy>(
value: value, value: value,
child: Text( child: Text(Settings.notificationPolicyToString(value, context), overflow: TextOverflow.ellipsis, style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)),
Settings.notificationPolicyToString(value, context),
overflow: TextOverflow.ellipsis,
),
); );
}).toList())), }).toList())),
leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor), leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),
@ -328,10 +322,7 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
items: NotificationContent.values.map<DropdownMenuItem<NotificationContent>>((NotificationContent value) { items: NotificationContent.values.map<DropdownMenuItem<NotificationContent>>((NotificationContent value) {
return DropdownMenuItem<NotificationContent>( return DropdownMenuItem<NotificationContent>(
value: value, value: value,
child: Text( child: Text(Settings.notificationContentToString(value, context), overflow: TextOverflow.ellipsis, style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)),
Settings.notificationContentToString(value, context),
overflow: TextOverflow.ellipsis,
),
); );
}).toList())), }).toList())),
leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor), leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),