Skip to content

Commit

Permalink
Merge pull request #250 from shiosyakeyakini-info/feature/fix_246
Browse files Browse the repository at this point in the history
Feature/fix 246
  • Loading branch information
shiosyakeyakini-info authored Aug 13, 2023
2 parents c914910 + 74a0f70 commit 78fc98a
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 44 deletions.
12 changes: 12 additions & 0 deletions lib/model/general_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ enum AutomaticPush {
const AutomaticPush(this.displayName);
}

enum TabPosition {
top("上"),
bottom("下");

final String displayName;

const TabPosition(this.displayName);
}

@freezed
class GeneralSettings with _$GeneralSettings {
const factory GeneralSettings({
Expand All @@ -57,6 +66,9 @@ class GeneralSettings with _$GeneralSettings {

/// リアクション済みノートを短くする
@Default(true) bool enableFavoritedRenoteElipsed,

/// タブの位置
@Default(TabPosition.top) TabPosition tabPosition,
}) = _GeneralSettings;

factory GeneralSettings.fromJson(Map<String, dynamic> json) =>
Expand Down
43 changes: 36 additions & 7 deletions lib/model/general_settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ mixin _$GeneralSettings {
/// リアクション済みノートを短くする
bool get enableFavoritedRenoteElipsed => throw _privateConstructorUsedError;

/// タブの位置
TabPosition get tabPosition => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$GeneralSettingsCopyWith<GeneralSettings> get copyWith =>
Expand All @@ -63,7 +66,8 @@ abstract class $GeneralSettingsCopyWith<$Res> {
AutomaticPush automaticPush,
bool enableAnimatedMFM,
bool enableLongTextElipsed,
bool enableFavoritedRenoteElipsed});
bool enableFavoritedRenoteElipsed,
TabPosition tabPosition});
}

/// @nodoc
Expand All @@ -88,6 +92,7 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings>
Object? enableAnimatedMFM = null,
Object? enableLongTextElipsed = null,
Object? enableFavoritedRenoteElipsed = null,
Object? tabPosition = null,
}) {
return _then(_value.copyWith(
lightColorThemeId: null == lightColorThemeId
Expand Down Expand Up @@ -126,6 +131,10 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings>
? _value.enableFavoritedRenoteElipsed
: enableFavoritedRenoteElipsed // ignore: cast_nullable_to_non_nullable
as bool,
tabPosition: null == tabPosition
? _value.tabPosition
: tabPosition // ignore: cast_nullable_to_non_nullable
as TabPosition,
) as $Val);
}
}
Expand All @@ -147,7 +156,8 @@ abstract class _$$_GeneralSettingsCopyWith<$Res>
AutomaticPush automaticPush,
bool enableAnimatedMFM,
bool enableLongTextElipsed,
bool enableFavoritedRenoteElipsed});
bool enableFavoritedRenoteElipsed,
TabPosition tabPosition});
}

/// @nodoc
Expand All @@ -170,6 +180,7 @@ class __$$_GeneralSettingsCopyWithImpl<$Res>
Object? enableAnimatedMFM = null,
Object? enableLongTextElipsed = null,
Object? enableFavoritedRenoteElipsed = null,
Object? tabPosition = null,
}) {
return _then(_$_GeneralSettings(
lightColorThemeId: null == lightColorThemeId
Expand Down Expand Up @@ -208,6 +219,10 @@ class __$$_GeneralSettingsCopyWithImpl<$Res>
? _value.enableFavoritedRenoteElipsed
: enableFavoritedRenoteElipsed // ignore: cast_nullable_to_non_nullable
as bool,
tabPosition: null == tabPosition
? _value.tabPosition
: tabPosition // ignore: cast_nullable_to_non_nullable
as TabPosition,
));
}
}
Expand All @@ -224,7 +239,8 @@ class _$_GeneralSettings implements _GeneralSettings {
this.automaticPush = AutomaticPush.none,
this.enableAnimatedMFM = true,
this.enableLongTextElipsed = false,
this.enableFavoritedRenoteElipsed = true});
this.enableFavoritedRenoteElipsed = true,
this.tabPosition = TabPosition.top});

factory _$_GeneralSettings.fromJson(Map<String, dynamic> json) =>
_$$_GeneralSettingsFromJson(json);
Expand Down Expand Up @@ -269,9 +285,14 @@ class _$_GeneralSettings implements _GeneralSettings {
@JsonKey()
final bool enableFavoritedRenoteElipsed;

/// タブの位置
@override
@JsonKey()
final TabPosition tabPosition;

@override
String toString() {
return 'GeneralSettings(lightColorThemeId: $lightColorThemeId, darkColorThemeId: $darkColorThemeId, themeColorSystem: $themeColorSystem, nsfwInherit: $nsfwInherit, enableDirectReaction: $enableDirectReaction, automaticPush: $automaticPush, enableAnimatedMFM: $enableAnimatedMFM, enableLongTextElipsed: $enableLongTextElipsed, enableFavoritedRenoteElipsed: $enableFavoritedRenoteElipsed)';
return 'GeneralSettings(lightColorThemeId: $lightColorThemeId, darkColorThemeId: $darkColorThemeId, themeColorSystem: $themeColorSystem, nsfwInherit: $nsfwInherit, enableDirectReaction: $enableDirectReaction, automaticPush: $automaticPush, enableAnimatedMFM: $enableAnimatedMFM, enableLongTextElipsed: $enableLongTextElipsed, enableFavoritedRenoteElipsed: $enableFavoritedRenoteElipsed, tabPosition: $tabPosition)';
}

@override
Expand All @@ -298,7 +319,9 @@ class _$_GeneralSettings implements _GeneralSettings {
(identical(other.enableFavoritedRenoteElipsed,
enableFavoritedRenoteElipsed) ||
other.enableFavoritedRenoteElipsed ==
enableFavoritedRenoteElipsed));
enableFavoritedRenoteElipsed) &&
(identical(other.tabPosition, tabPosition) ||
other.tabPosition == tabPosition));
}

@JsonKey(ignore: true)
Expand All @@ -313,7 +336,8 @@ class _$_GeneralSettings implements _GeneralSettings {
automaticPush,
enableAnimatedMFM,
enableLongTextElipsed,
enableFavoritedRenoteElipsed);
enableFavoritedRenoteElipsed,
tabPosition);

@JsonKey(ignore: true)
@override
Expand All @@ -339,7 +363,8 @@ abstract class _GeneralSettings implements GeneralSettings {
final AutomaticPush automaticPush,
final bool enableAnimatedMFM,
final bool enableLongTextElipsed,
final bool enableFavoritedRenoteElipsed}) = _$_GeneralSettings;
final bool enableFavoritedRenoteElipsed,
final TabPosition tabPosition}) = _$_GeneralSettings;

factory _GeneralSettings.fromJson(Map<String, dynamic> json) =
_$_GeneralSettings.fromJson;
Expand Down Expand Up @@ -375,6 +400,10 @@ abstract class _GeneralSettings implements GeneralSettings {
/// リアクション済みノートを短くする
bool get enableFavoritedRenoteElipsed;
@override

/// タブの位置
TabPosition get tabPosition;
@override
@JsonKey(ignore: true)
_$$_GeneralSettingsCopyWith<_$_GeneralSettings> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
9 changes: 9 additions & 0 deletions lib/model/general_settings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class GeneralSettingsPageState extends ConsumerState<GeneralSettingsPage> {
bool enableAnimatedMFM = true;
bool enableLongTextElipsed = false;
bool enableFavoritedRenoteElipsed = true;
TabPosition tabPosition = TabPosition.top;

@override
void initState() {
Expand Down Expand Up @@ -54,6 +55,7 @@ class GeneralSettingsPageState extends ConsumerState<GeneralSettingsPage> {
enableAnimatedMFM = settings.enableAnimatedMFM;
enableLongTextElipsed = settings.enableLongTextElipsed;
enableFavoritedRenoteElipsed = settings.enableFavoritedRenoteElipsed;
tabPosition = settings.tabPosition;
});
}

Expand All @@ -68,7 +70,8 @@ class GeneralSettingsPageState extends ConsumerState<GeneralSettingsPage> {
automaticPush: automaticPush,
enableAnimatedMFM: enableAnimatedMFM,
enableFavoritedRenoteElipsed: enableFavoritedRenoteElipsed,
enableLongTextElipsed: enableLongTextElipsed),
enableLongTextElipsed: enableLongTextElipsed,
tabPosition: tabPosition),
);
}

Expand Down Expand Up @@ -96,6 +99,7 @@ class GeneralSettingsPageState extends ConsumerState<GeneralSettingsPage> {
const Padding(padding: EdgeInsets.only(top: 10)),
const Text("閲覧注意のついたノートの表示"),
DropdownButton<NSFWInherit>(
isExpanded: true,
items: [
for (final element in NSFWInherit.values)
DropdownMenuItem(
Expand All @@ -114,6 +118,7 @@ class GeneralSettingsPageState extends ConsumerState<GeneralSettingsPage> {
const Padding(padding: EdgeInsets.only(top: 10)),
const Text("一覧の自動更新"),
DropdownButton<AutomaticPush>(
isExpanded: true,
items: [
for (final element in AutomaticPush.values)
DropdownMenuItem(
Expand Down Expand Up @@ -157,6 +162,25 @@ class GeneralSettingsPageState extends ConsumerState<GeneralSettingsPage> {
}),
title: const Text("長いノートを省略します。"),
),
const Padding(padding: EdgeInsets.only(top: 10)),
const Text("タブの位置"),
DropdownButton<TabPosition>(
isExpanded: true,
items: [
for (final element in TabPosition.values)
DropdownMenuItem(
value: element,
child: Text("${element.displayName}に表示する"),
)
],
value: tabPosition,
onChanged: (value) => setState(
() {
tabPosition = value ?? TabPosition.top;
save();
},
),
),
],
),
),
Expand Down
101 changes: 65 additions & 36 deletions lib/view/time_line_page/time_line_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:auto_route/auto_route.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:miria/model/general_settings.dart';
import 'package:miria/model/tab_setting.dart';
import 'package:miria/model/tab_type.dart';
import 'package:miria/providers.dart';
Expand Down Expand Up @@ -39,6 +40,8 @@ class TimeLinePageState extends ConsumerState<TimeLinePage> {
late final PageController pageController;
late final List<TimelineScrollController> scrollControllers;

final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();

@override
void initState() {
tabSettings = ref.read(
Expand Down Expand Up @@ -146,6 +149,48 @@ class TimeLinePageState extends ConsumerState<TimeLinePage> {
));
}

Widget buildAppbar() {
return AppBar(
title: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: tabSettings
.mapIndexed(
(index, tabSetting) => Ink(
color: tabSetting == currentTabSetting
? AppTheme.of(context).currentDisplayTabColor
: Colors.transparent,
child: AccountScope(
account: tabSetting.account,
child: IconButton(
icon: TabIconView(
icon: tabSetting.icon,
color: tabSetting == currentTabSetting
? Theme.of(context).primaryColor
: Colors.white,
),
onPressed: () => tabSetting == currentTabSetting
? reload()
: pageController.jumpToPage(index),
),
),
),
)
.toList(),
),
),
actions: [
AccountScope(
account: currentTabSetting.account,
child: const NotificationIcon(),
),
],
leading: IconButton(
onPressed: () => scaffoldKey.currentState?.openDrawer(),
icon: const Icon(Icons.menu)),
);
}

@override
Widget build(BuildContext context) {
final socketTimelineBase = ref.watch(currentTabSetting.timelineProvider);
Expand All @@ -154,45 +199,21 @@ class TimeLinePageState extends ConsumerState<TimeLinePage> {
: null;

return Scaffold(
appBar: AppBar(
title: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: tabSettings
.mapIndexed(
(index, tabSetting) => Ink(
color: tabSetting == currentTabSetting
? AppTheme.of(context).currentDisplayTabColor
: Colors.transparent,
child: AccountScope(
account: tabSetting.account,
child: IconButton(
icon: TabIconView(
icon: tabSetting.icon,
color: tabSetting == currentTabSetting
? Theme.of(context).primaryColor
: Colors.white,
),
onPressed: () => tabSetting == currentTabSetting
? reload()
: pageController.jumpToPage(index),
),
),
),
)
.toList(),
),
),
actions: [
AccountScope(
account: currentTabSetting.account,
child: const NotificationIcon(),
),
],
),
key: scaffoldKey,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(0),
child: AppBar(
automaticallyImplyLeading: false,
)),
body: SafeArea(
child: Column(
children: [
if (ref
.read(generalSettingsRepositoryProvider)
.settings
.tabPosition ==
TabPosition.top)
buildAppbar(),
Container(
decoration: BoxDecoration(
border: Border(
Expand Down Expand Up @@ -322,10 +343,18 @@ class TimeLinePageState extends ConsumerState<TimeLinePage> {
],
),
),
if (ref
.read(generalSettingsRepositoryProvider)
.settings
.tabPosition ==
TabPosition.bottom &&
!ref.watch(timelineFocusNode).hasFocus)
buildAppbar(),
],
),
),
resizeToAvoidBottomInset: true,
drawerEnableOpenDragGesture: true,
drawer: CommonDrawer(
initialOpenAccount: currentTabSetting.account,
),
Expand Down

0 comments on commit 78fc98a

Please sign in to comment.