Skip to content

Commit

Permalink
Add an "Always Show Instance" option for user/magazine names
Browse files Browse the repository at this point in the history
  • Loading branch information
jwr1 committed Mar 19, 2024
1 parent 85b254d commit 857cd3d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
19 changes: 19 additions & 0 deletions lib/src/screens/settings/general_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ class GeneralScreen extends StatelessWidget {
children: [Text(getLangName(controller.defaultCreateLang))],
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child:
Text('Other', style: Theme.of(context).textTheme.titleMedium),
),
ListTile(
title: const Text('Always Show Instance'),
leading: const Icon(Icons.public),
onTap: () {
controller
.updateAlwaysShowInstance(!controller.alwaysShowInstance);
},
trailing: Switch(
value: controller.alwaysShowInstance,
onChanged: controller.updateAlwaysShowInstance,
),
subtitle: const Text(
'When enabled, the instance of a user/magazine will always display instead of an @ button'),
),
],
),
);
Expand Down
25 changes: 18 additions & 7 deletions lib/src/screens/settings/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import 'package:shared_preferences/shared_preferences.dart';

enum ServerSoftware { kbin, mbin, lemmy }

enum NameInstanceDisplay { hide, button, show }

class Server {
final ServerSoftware software;
final String? oauthIdentifier;
Expand Down Expand Up @@ -65,11 +63,8 @@ class SettingsController with ChangeNotifier {
ThemeInfo get theme =>
themes.firstWhere((theme) => theme.name == _accentColor);

late NameInstanceDisplay _usernameInstanceDisplay;
NameInstanceDisplay get usernameInstanceDisplay => _usernameInstanceDisplay;
late NameInstanceDisplay _magazineNameInstanceDisplay;
NameInstanceDisplay get magazineNameInstanceDisplay =>
_magazineNameInstanceDisplay;
late bool _alwaysShowInstance;
bool get alwaysShowInstance => _alwaysShowInstance;

late ActionLocation _feedActionBackToTop;
ActionLocation get feedActionBackToTop => _feedActionBackToTop;
Expand Down Expand Up @@ -132,6 +127,10 @@ class SettingsController with ChangeNotifier {
? prefs.getString("accentColor")!
: "Default";

_alwaysShowInstance = prefs.getBool("alwaysShowInstance") != null
? prefs.getBool("alwaysShowInstance")!
: false;

_feedActionBackToTop = parseEnum(
ActionLocation.values,
ActionLocation.fabMenu,
Expand Down Expand Up @@ -252,6 +251,18 @@ class SettingsController with ChangeNotifier {
await prefs.setString('accentColor', newThemeAccent);
}

Future<void> updateAlwaysShowInstance(bool? newShowDisplayInstance) async {
if (newShowDisplayInstance == null) return;
if (newShowDisplayInstance == _alwaysShowInstance) return;

_alwaysShowInstance = newShowDisplayInstance;

notifyListeners();

final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('alwaysShowInstance', newShowDisplayInstance);
}

Future<void> updateDefaultFeedType(PostType? newDefaultFeedMode) async {
if (newDefaultFeedMode == null) return;
if (newDefaultFeedMode == _defaultFeedType) return;
Expand Down
10 changes: 8 additions & 2 deletions lib/src/widgets/display_name.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:interstellar/src/screens/settings/settings_controller.dart';
import 'package:interstellar/src/widgets/avatar.dart';
import 'package:provider/provider.dart';

class DisplayName extends StatelessWidget {
const DisplayName(this.name, {super.key, this.icon, this.onTap});
Expand All @@ -25,12 +27,16 @@ class DisplayName extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Text(
localName,
localName +
(context.watch<SettingsController>().alwaysShowInstance
? '@${hostName ?? context.watch<SettingsController>().instanceHost}'
: ''),
style: Theme.of(context).textTheme.labelLarge,
),
),
),
if (hostName != null)
if (!context.watch<SettingsController>().alwaysShowInstance &&
hostName != null)
Tooltip(
message: hostName,
triggerMode: TooltipTriggerMode.tap,
Expand Down

0 comments on commit 857cd3d

Please sign in to comment.