Skip to content

Commit

Permalink
Merge branch 'fix-rtl-empty-repo-message'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Pabon committed Oct 24, 2024
2 parents e6a0795 + 9d4ff59 commit c48ec88
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 210 deletions.
43 changes: 31 additions & 12 deletions lib/app/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import 'package:url_launcher/url_launcher_string.dart';
import '../../generated/l10n.dart';
import '../cubits/cubits.dart';
import '../models/models.dart';
import '../utils/click_counter.dart';
import '../utils/platform/platform.dart';
import '../utils/share_token.dart';
import '../utils/utils.dart';
import '../widgets/notification_badge.dart';
import '../widgets/widgets.dart';
Expand Down Expand Up @@ -387,7 +385,7 @@ class _MainPageState extends State<MainPage>
);
}

Widget buildMainWidget() {
Widget buildMainWidget(TextDirection directionality) {
return widget.reposCubit.builder((repos) {
final currentRepo = repos.currentRepo;
final currentRepoCubit = currentRepo?.cubit;
Expand Down Expand Up @@ -430,11 +428,12 @@ class _MainPageState extends State<MainPage>
final navigationPath = currentRepo.cubit.state.currentFolder.path;
currentRepo.cubit.navigateTo(navigationPath);

return _repositoryContentBuilder(currentRepo);
return _repositoryContentBuilder(currentRepo, directionality);
}

if (currentRepo is MissingRepoEntry) {
return MissingRepositoryState(
directionality: directionality,
repositoryLocation: currentRepo.location,
errorMessage: currentRepo.error,
errorDescription: currentRepo.errorDescription,
Expand All @@ -446,6 +445,7 @@ class _MainPageState extends State<MainPage>
// This is a general purpose error state.
// errorDescription is required, but nullable.
return ErrorState(
directionality: directionality,
errorMessage: currentRepo.error,
errorDescription: currentRepo.errorDescription,
onBackToList: () => repos.setCurrent(null),
Expand All @@ -456,6 +456,7 @@ class _MainPageState extends State<MainPage>
return repos.repos.isNotEmpty
? SizedBox.shrink()
: NoRepositoriesState(
directionality: directionality,
onCreateRepoPressed: _createRepo,
onImportRepoPressed: _importRepo,
);
Expand Down Expand Up @@ -485,7 +486,11 @@ class _MainPageState extends State<MainPage>
alignment: AlignmentDirectional.bottomEnd,
children: <Widget>[
Column(
children: [Expanded(child: buildMainWidget())],
children: [
Expanded(
child: buildMainWidget(Directionality.of(context)),
)
],
),
const ListenerThatRunsFunctionsWithBuildContext(),
],
Expand Down Expand Up @@ -604,17 +609,21 @@ class _MainPageState extends State<MainPage>
return Container();
}

Widget _repositoryContentBuilder(OpenRepoEntry repo) =>
Widget _repositoryContentBuilder(
OpenRepoEntry repo,
TextDirection directionality,
) =>
BlocBuilder<RepoCubit, RepoState>(
bloc: repo.cubit,
builder: (context, state) => _selectLayoutWidget(),
builder: (context, state) => _selectLayoutWidget(directionality),
);

Widget _selectLayoutWidget() {
Widget _selectLayoutWidget(TextDirection directionality) {
final current = _currentRepo;

if (current == null || current is LoadingRepoEntry) {
return NoRepositoriesState(
directionality: directionality,
onCreateRepoPressed: _createRepo,
onImportRepoPressed: _importRepo,
);
Expand All @@ -624,20 +633,26 @@ class _MainPageState extends State<MainPage>
if (!current.cubit.state.canRead) {
return LockedRepositoryState(
parentContext: context,
directionality: directionality,
repoCubit: current.cubit,
masterKey: widget.settings.masterKey,
passwordHasher: PasswordHasher(widget.session),
);
}

_appSettingsIconFocus.unfocus();
return _contentBrowser(current.cubit);
return _contentBrowser(current.cubit, directionality);
}

return Center(child: Text(S.current.messageErrorUnhandledState));
return Center(
child: Text(
S.current.messageErrorUnhandledState,
textDirection: directionality,
),
);
}

Widget _contentBrowser(RepoCubit repo) {
Widget _contentBrowser(RepoCubit repo, TextDirection directionality) {
Widget child;
final folder = repo.state.currentFolder;

Expand All @@ -646,7 +661,11 @@ class _MainPageState extends State<MainPage>
child = const Center(child: CircularProgressIndicator());
} else {
_fabFocus.requestFocus();
child = NoContentsState(repository: repo, path: folder.path);
child = NoContentsState(
directionality: directionality,
repository: repo,
path: folder.path,
);
}
} else {
child = _contentsList(repo);
Expand Down
79 changes: 43 additions & 36 deletions lib/app/widgets/states/error_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import '../../utils/utils.dart';

class ErrorState extends HookWidget {
const ErrorState({
required this.directionality,
required this.errorMessage,
this.errorDescription,
required this.onBackToList,
super.key,
});

final TextDirection directionality;
final String errorMessage;
final String? errorDescription;

Expand All @@ -22,49 +24,54 @@ class ErrorState extends HookWidget {
final reloadButtonFocus = useFocusNode(debugLabel: 'reload_button_focus');
reloadButtonFocus.requestFocus();

return Center(
return Directionality(
textDirection: directionality,
child: Center(
child: SingleChildScrollView(
reverse: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
reverse: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageMainMessage(
errorMessage,
style: context.theme.appTextStyle.bodyLarge
.copyWith(color: Constants.dangerColor),
tags: {
Constants.inlineTextColor:
InlineTextStyles.color(Colors.black),
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold
},
),
),
if (errorDescription != null) const SizedBox(height: 10.0),
if (errorDescription != null)
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageMainMessage(
errorMessage,
style: context.theme.appTextStyle.bodyLarge
.copyWith(color: Constants.dangerColor),
child: Fields.inPageSecondaryMessage(
errorDescription!,
tags: {
Constants.inlineTextColor:
InlineTextStyles.color(Colors.black),
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold
Constants.inlineTextBold: InlineTextStyles.bold,
Constants.inlineTextIcon:
InlineTextStyles.icon(Icons.south)
},
),
),
if (errorDescription != null) const SizedBox(height: 10.0),
if (errorDescription != null)
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageSecondaryMessage(
errorDescription!,
tags: {
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold,
Constants.inlineTextIcon:
InlineTextStyles.icon(Icons.south)
},
),
),
Dimensions.spacingVerticalDouble,
Fields.inPageButton(
onPressed: onBackToList,
text: S.current.actionBack,
focusNode: reloadButtonFocus,
autofocus: true,
)
],
)));
Dimensions.spacingVerticalDouble,
Fields.inPageButton(
onPressed: onBackToList,
text: S.current.actionBack,
focusNode: reloadButtonFocus,
autofocus: true,
)
],
),
),
),
);
}
}
100 changes: 54 additions & 46 deletions lib/app/widgets/states/locked_repository_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class LockedRepositoryState extends HookWidget
with AppLogger, RepositoryActionsMixin {
const LockedRepositoryState({
required this.parentContext,
required this.directionality,
required this.repoCubit,
required this.masterKey,
required this.passwordHasher,
});

final BuildContext parentContext;
final TextDirection directionality;
final RepoCubit repoCubit;
final MasterKey masterKey;
final PasswordHasher passwordHasher;
Expand All @@ -31,52 +33,58 @@ class LockedRepositoryState extends HookWidget

unlockButtonFocus.requestFocus();

return Center(
return Directionality(
textDirection: directionality,
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Align(
alignment: AlignmentDirectional.center,
child: Fields.placeholderWidget(
assetName: Constants.assetLockedRepository,
assetHeight: lockedRepoImageHeight)),
Dimensions.spacingVerticalDouble,
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageMainMessage(S.current.messageLockedRepository,
style: context.theme.appTextStyle.bodyLarge,
tags: {
Constants.inlineTextColor:
InlineTextStyles.color(Colors.black),
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold
})),
Dimensions.spacingVertical,
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageSecondaryMessage(
S.current.messageInputPasswordToUnlock,
tags: {
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold,
})),
Dimensions.spacingVerticalDouble,
Fields.inPageButton(
onPressed: () async {
await unlockRepository(
parentContext,
repoCubit,
masterKey,
passwordHasher,
);
},
leadingIcon: const Icon(Icons.lock_open_rounded),
text: S.current.actionUnlock,
focusNode: unlockButtonFocus,
autofocus: true)
],
)));
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Align(
alignment: AlignmentDirectional.center,
child: Fields.placeholderWidget(
assetName: Constants.assetLockedRepository,
assetHeight: lockedRepoImageHeight)),
Dimensions.spacingVerticalDouble,
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageMainMessage(
S.current.messageLockedRepository,
style: context.theme.appTextStyle.bodyLarge,
tags: {
Constants.inlineTextColor:
InlineTextStyles.color(Colors.black),
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold
})),
Dimensions.spacingVertical,
Align(
alignment: AlignmentDirectional.center,
child: Fields.inPageSecondaryMessage(
S.current.messageInputPasswordToUnlock,
tags: {
Constants.inlineTextSize: InlineTextStyles.size(),
Constants.inlineTextBold: InlineTextStyles.bold,
})),
Dimensions.spacingVerticalDouble,
Fields.inPageButton(
onPressed: () async {
await unlockRepository(
parentContext,
repoCubit,
masterKey,
passwordHasher,
);
},
leadingIcon: const Icon(Icons.lock_open_rounded),
text: S.current.actionUnlock,
focusNode: unlockButtonFocus,
autofocus: true)
],
),
),
),
);
}
}
Loading

0 comments on commit c48ec88

Please sign in to comment.