Skip to content

Commit

Permalink
Add a setting for flagpunchy feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dasmikko committed Feb 26, 2023
1 parent 05d406b commit fd6c25e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/controllers/settingsController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ class SettingsController extends GetxController {
final RxBool useDevAPI = false.obs;
var apiEnv = 'knockout'.obs;
final showNSFWThreads = false.obs;
final flagPunchy = false.obs;
RxString apiEndpoint = 'https://knockyauth.rekna.xyz/'.obs;
}
9 changes: 5 additions & 4 deletions lib/helpers/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,15 @@ class KnockoutAPI {

Future<void> newPost(dynamic content, int? threadId) async {
try {
await _request(type: 'post', url: 'post', data: {
'displayCountryInfo': false,
'appName': 'knocky',
final SettingsController settingsController =
Getx.Get.put(SettingsController());
await _request(type: 'post', url: 'v2/posts', data: {
'display_country': settingsController.flagPunchy.value,
'app_name': 'knocky',
'content': content.toString(),
'thread_id': threadId,
}, headers: {
'content-type': 'application/json; charset=UTF-8',
'content-format-version': '1'
});
} on DioError catch (e) {
onDioErrorHandler(e);
Expand Down
6 changes: 6 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ void main() async {
settingsController.showNSFWThreads.value = prefs.read('showNSFW');
}

if (!prefs.hasData('flagPunchy')) {
await prefs.write('flagPunchy', false);
} else {
settingsController.flagPunchy.value = prefs.read('flagPunchy');
}

if (prefs.hasData('apiEndpoint')) {
settingsController.apiEndpoint.value = prefs.read('apiEndpoint');
}
Expand Down
6 changes: 6 additions & 0 deletions lib/main_nonfdroid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ void main() async {
settingsController.showNSFWThreads.value = prefs.read('showNSFW');
}

if (!prefs.hasData('flagPunchy')) {
await prefs.write('flagPunchy', false);
} else {
settingsController.flagPunchy.value = prefs.read('flagPunchy');
}

if (prefs.hasData('apiEndpoint')) {
settingsController.apiEndpoint.value = prefs.read('apiEndpoint');
}
Expand Down
31 changes: 30 additions & 1 deletion lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class SettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final SettingsController settingsController = Get.put(SettingsController());
print(FlavorConfig.instance.variables["allowUpdater"]);

return Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -130,6 +129,36 @@ class SettingsScreen extends StatelessWidget {
},
),

/**
* User experience
*/

Divider(),
ListTile(
dense: true,
title: Text(
'User experience',
style: TextStyle(
color: Colors.grey,
),
),
),
Obx(
() => SwitchListTile(
title: Text('FlagPunchy'),
subtitle: Text(
"Show which country you're posting from",
style: TextStyle(color: Colors.grey),
),
value: settingsController.flagPunchy.value,
onChanged: (bool value) {
settingsController.flagPunchy.value = value;
GetStorage prefs = GetStorage();
prefs.write('flagPunchy', value);
},
),
),

/**
* API
*/
Expand Down

0 comments on commit fd6c25e

Please sign in to comment.