Skip to content

Commit

Permalink
Fix issue #324 Customized translator settings not applied on Applicat…
Browse files Browse the repository at this point in the history
…ion Restart.
  • Loading branch information
j-fbriere committed Jun 18, 2024
1 parent a189bac commit 7b2ebd7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/47.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Implement feature #316 Add fixupx.com as supported link.
* Implement PR #323 Put newly saved tweets to the top of the saved view.
* Fix issue #324 Customized translator settings not applied on Application Restart.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/default.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Implement feature #316 Add fixupx.com as supported link.
* Implement PR #323 Put newly saved tweets to the top of the saved view.
* Fix issue #324 Customized translator settings not applied on Application Restart.
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import 'package:squawker/utils/accent_util.dart';
import 'package:squawker/utils/data_service.dart';
import 'package:squawker/utils/iterables.dart';
import 'package:squawker/utils/misc.dart';
import 'package:squawker/utils/translation.dart';
import 'package:squawker/utils/urls.dart';
import 'package:timeago/timeago.dart' as timeago;

Expand Down Expand Up @@ -239,6 +240,8 @@ Future<void> main() async {

AppHttpClient.setProxy(prefService.get(optionProxy));

TranslationAPI.setTranslationHostsFromStr(prefService.get(optionTranslators));

runApp(PrefService(
service: prefService,
child: MultiProvider(
Expand Down
4 changes: 2 additions & 2 deletions lib/settings/_general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class SettingsGeneralFragment extends StatelessWidget {
subtitle: Text(L10n.of(context).translators_description),
onTap: () async {
BasePrefService prefs = PrefService.of(context);
List<Map<String,dynamic>> translationHosts = TranslationAPI.readTranslationHosts(translationHosts: prefs.get(optionTranslators));
List<Map<String,dynamic>> translationHosts = TranslationAPI.translationHosts();
var result = await showDialog<bool>(
barrierDismissible: false,
context: context,
Expand All @@ -216,7 +216,7 @@ class SettingsGeneralFragment extends StatelessWidget {
}
);
if (result == true) {
String s = TranslationAPI.updateTranslationHosts(translationHosts);
String s = TranslationAPI.setTranslationHosts(translationHosts);
prefs.set(optionTranslators, s);
}
},
Expand Down
20 changes: 13 additions & 7 deletions lib/utils/translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class TranslationAPI {
'iw': 'he'
};

static List<Map<String,dynamic>> translationHosts() {
_translation_hosts ??= default_translation_hosts;
return _translation_hosts!;
}

static int translationHostsLength() {
_translation_hosts ??= default_translation_hosts;
return _translation_hosts!.length;
Expand All @@ -73,21 +78,22 @@ class TranslationAPI {
return translationHost();
}

static String updateTranslationHosts(List<Map<String,dynamic>> translationHosts) {
static String setTranslationHosts(List<Map<String,dynamic>>? translationHosts) {
_translation_hosts = translationHosts;
_translation_hosts ??= default_translation_hosts;
return jsonEncode(_translation_hosts);
}

static List<Map<String,dynamic>> readTranslationHosts({String? translationHosts}) {
if (translationHosts != null) {
static List<Map<String,dynamic>> setTranslationHostsFromStr(String? translationHosts) {
if (translationHosts == null) {
_translation_hosts = default_translation_hosts;
}
else {
List<Map<String,dynamic>> lst = [];
for (dynamic item in jsonDecode(translationHosts)) {
lst.add(item);
}
return lst;
}
if (_translation_hosts == null) {
return default_translation_hosts;
_translation_hosts = lst;
}
return _translation_hosts!;
}
Expand Down

0 comments on commit 7b2ebd7

Please sign in to comment.