Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Aug 13, 2024
2 parents 8e9c5fb + c7805a8 commit 995e4fa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
20 changes: 12 additions & 8 deletions lib/app/cubits/repo_creation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import 'dart:io' show File;

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../models/auth_mode.dart';
import '../models/local_secret.dart';
import '../models/repo_location.dart';
import '../utils/extensions.dart';
import '../utils/log.dart';
import 'package:ouisync/ouisync.dart' show AccessMode, ShareToken;

import '../../generated/l10n.dart';
import '../models/auth_mode.dart';
import '../models/local_secret.dart';
import '../models/repo_entry.dart';
import '../models/repo_location.dart';
import '../utils/dialogs.dart';
import '../utils/log.dart';
import '../utils/strings.dart';
import 'repos.dart';

Expand All @@ -27,7 +27,7 @@ class RepoCreationState {
final bool useCacheServers;

RepoCreationState({
this.accessMode = AccessMode.write,
this.accessMode = AccessMode.blind,
this.loading = false,
this.localSecretMode = initialLocalSecretMode,
this.substate = const RepoCreationPending(),
Expand Down Expand Up @@ -138,11 +138,15 @@ class RepoCreationCubit extends Cubit<RepoCreationState> with AppLogger {
}

final ReposCubit reposCubit;

final nameController = TextEditingController();
final positiveButtonFocusNode = FocusNode();

@override
Future<void> close() async {
nameController.dispose();
positiveButtonFocusNode.dispose();

await super.close();
}

Expand All @@ -168,7 +172,7 @@ class RepoCreationCubit extends Cubit<RepoCreationState> with AppLogger {

void acceptSuggestedName() {
nameController.text = state.suggestedName;
nameController.selectAll();
positiveButtonFocusNode.requestFocus();
}

void setUseCacheServers(bool value) {
Expand Down Expand Up @@ -254,7 +258,7 @@ class RepoCreationCubit extends Cubit<RepoCreationState> with AppLogger {
Future<R> _loading<R>(Future<R> Function() f) async {
try {
emit(state.copyWith(loading: true));
return await f();
return await Dialogs.executeFutureWithLoadingDialog(null, f.call());
} finally {
emit(state.copyWith(loading: false));
}
Expand Down
35 changes: 23 additions & 12 deletions lib/app/utils/dialogs.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:async';

import 'package:build_context_provider/build_context_provider.dart';
import 'package:flutter/material.dart';

import '../../generated/l10n.dart';
Expand All @@ -7,7 +10,7 @@ import 'utils.dart';

abstract class Dialogs {
static Future<T> executeFutureWithLoadingDialog<T>(
BuildContext context,
BuildContext? context,
Future<T> future,
) async {
_showLoadingDialog(context);
Expand All @@ -17,19 +20,27 @@ abstract class Dialogs {
return result;
}

static _showLoadingDialog(BuildContext context) {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => Center(
child: const CircularProgressIndicator.adaptive(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
static void _showLoadingDialog(BuildContext? context) => context != null
? _loadingDialog(context)
: WidgetsBinding.instance
.addPostFrameCallback((_) => BuildContextProvider()(_loadingDialog));

static Future<void> _loadingDialog(BuildContext context) => showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => Center(
child: const CircularProgressIndicator.adaptive(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
),
);
}
);

static _hideLoadingDialog(BuildContext? context) => context != null
? _popDialog(context)
: BuildContextProvider()
.call((globalContext) => _popDialog(globalContext));

static _hideLoadingDialog(context) =>
static void _popDialog(BuildContext context) =>
Navigator.of(context, rootNavigator: true).pop();

static Future<bool?> alertDialogWithActions({
Expand Down
22 changes: 12 additions & 10 deletions lib/app/widgets/repo_creation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class RepoCreation extends StatelessWidget {
if (creationState.token != null)
..._buildTokenLabel(context, creationState),
..._buildNameField(context, creationState),
if (creationState.accessMode == AccessMode.write)
_buildUseCacheServersSwitch(context, creationState),
_buildUseCacheServersSwitch(context, creationState),
RepoSecurity(securityCubit),
],
);
Expand All @@ -108,6 +107,8 @@ class RepoCreation extends StatelessWidget {
securityState.isValid
? () => creationCubit.save()
: null,
autofocus: true,
focusNode: creationCubit.positiveButtonFocusNode,
),
),
];
Expand Down Expand Up @@ -170,7 +171,6 @@ class RepoCreation extends StatelessWidget {
hintText: S.current.messageRepositoryName,
errorText: state.nameError,
autovalidateMode: AutovalidateMode.onUserInteraction,
autofocus: true,
textInputAction: TextInputAction.next,
),
Visibility(
Expand All @@ -190,13 +190,15 @@ class RepoCreation extends StatelessWidget {
BuildContext context,
RepoCreationState state,
) =>
CustomAdaptiveSwitch(
key: ValueKey('use-cache-servers'),
value: state.useCacheServers,
title: S.current.messageUseCacheServers,
contentPadding: EdgeInsets.zero,
onChanged: (value) => creationCubit.setUseCacheServers(value),
);
state.accessMode == AccessMode.write
? CustomAdaptiveSwitch(
key: ValueKey('use-cache-servers'),
value: state.useCacheServers,
title: S.current.messageUseCacheServers,
contentPadding: EdgeInsets.zero,
onChanged: (value) => creationCubit.setUseCacheServers(value),
)
: SizedBox.shrink();

TextStyle _smallMessageStyle(BuildContext context) =>
context.theme.appTextStyle.bodySmall.copyWith(color: Colors.black54);
Expand Down
15 changes: 11 additions & 4 deletions lib/app/widgets/switches/custom_adaptive_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ class CustomAdaptiveSwitch extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
title,
style: TextStyle(
fontSize: context.theme.appTextStyle.titleMedium.fontSize),
Flexible(
child: Text(
title,
textAlign: TextAlign.end,
softWrap: true,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: context.theme.appTextStyle.titleMedium.fontSize,
),
),
),
SizedBox(
width: 12.0,
Expand Down

0 comments on commit 995e4fa

Please sign in to comment.