some name cleanup, error handling and dont open overlay if click outside text

pull/1428/head
William Jordan-Cooley 1 year ago
parent 6d7ef49d91
commit 31b77c6d99

@ -70,8 +70,8 @@ class Choreographer {
void send(BuildContext context) { void send(BuildContext context) {
if (isFetching) return; if (isFetching) return;
if (pangeaController.subscriptionController.canSendStatus == if (pangeaController.subscriptionController.subscriptionStatus ==
CanSendStatus.showPaywall) { SubscriptionStatus.showPaywall) {
OverlayUtil.showPositionedCard( OverlayUtil.showPositionedCard(
context: context, context: context,
cardToShow: PaywallCard( cardToShow: PaywallCard(
@ -245,10 +245,10 @@ class Choreographer {
}) async { }) async {
try { try {
if (errorService.isError) return; if (errorService.isError) return;
final CanSendStatus canSendStatus = final SubscriptionStatus canSendStatus =
pangeaController.subscriptionController.canSendStatus; pangeaController.subscriptionController.subscriptionStatus;
if (canSendStatus != CanSendStatus.subscribed || if (canSendStatus != SubscriptionStatus.subscribed ||
(!igcEnabled && !itEnabled) || (!igcEnabled && !itEnabled) ||
(!isAutoIGCEnabled && !manual && choreoMode != ChoreoMode.it)) { (!isAutoIGCEnabled && !manual && choreoMode != ChoreoMode.it)) {
return; return;

@ -63,10 +63,13 @@ class StartIGCButtonState extends State<StartIGCButton>
bool get itEnabled => widget.controller.choreographer.itEnabled; bool get itEnabled => widget.controller.choreographer.itEnabled;
bool get igcEnabled => widget.controller.choreographer.igcEnabled; bool get igcEnabled => widget.controller.choreographer.igcEnabled;
CanSendStatus get canSendStatus =>
widget.controller.pangeaController.subscriptionController.canSendStatus; SubscriptionStatus get subscriptionStatus => widget
.controller.pangeaController.subscriptionController.subscriptionStatus;
bool get grammarCorrectionEnabled => bool get grammarCorrectionEnabled =>
(itEnabled || igcEnabled) && canSendStatus == CanSendStatus.subscribed; (itEnabled || igcEnabled) &&
subscriptionStatus == SubscriptionStatus.subscribed;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -23,7 +23,7 @@ import 'package:http/http.dart';
import 'package:purchases_flutter/purchases_flutter.dart'; import 'package:purchases_flutter/purchases_flutter.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
enum CanSendStatus { enum SubscriptionStatus {
subscribed, subscribed,
dimissedPaywall, dimissedPaywall,
showPaywall, showPaywall,
@ -227,11 +227,13 @@ class SubscriptionController extends BaseController {
setState(null); setState(null);
} }
CanSendStatus get canSendStatus => isSubscribed /// if the user is subscribed, returns subscribed
? CanSendStatus.subscribed /// if the user has dismissed the paywall, returns dismissed
SubscriptionStatus get subscriptionStatus => isSubscribed
? SubscriptionStatus.subscribed
: _shouldShowPaywall : _shouldShowPaywall
? CanSendStatus.showPaywall ? SubscriptionStatus.showPaywall
: CanSendStatus.dimissedPaywall; : SubscriptionStatus.dimissedPaywall;
DateTime? get _lastDismissedPaywall { DateTime? get _lastDismissedPaywall {
final lastDismissed = _pangeaController.pStoreService.read( final lastDismissed = _pangeaController.pStoreService.read(
@ -249,6 +251,7 @@ class SubscriptionController extends BaseController {
return backoff; return backoff;
} }
/// whether or not the paywall should be shown
bool get _shouldShowPaywall { bool get _shouldShowPaywall {
return initialized.isCompleted && return initialized.isCompleted &&
!isSubscribed && !isSubscribed &&

@ -47,9 +47,11 @@ class PangeaTextController extends TextEditingController {
debugger(when: kDebugMode); debugger(when: kDebugMode);
return; return;
} }
final CanSendStatus canSendStatus =
choreographer.pangeaController.subscriptionController.canSendStatus; // show the paywall if appropriate
if (canSendStatus == CanSendStatus.showPaywall && if (choreographer
.pangeaController.subscriptionController.subscriptionStatus ==
SubscriptionStatus.showPaywall &&
!choreographer.isFetching && !choreographer.isFetching &&
text.isNotEmpty) { text.isNotEmpty) {
OverlayUtil.showPositionedCard( OverlayUtil.showPositionedCard(
@ -63,11 +65,18 @@ class PangeaTextController extends TextEditingController {
); );
} }
// if there is no igc text data, then don't do anything
if (choreographer.igc.igcTextData == null) return; if (choreographer.igc.igcTextData == null) return;
// debugPrint( // debugPrint(
// "onInputTap matches are ${choreographer.igc.igcTextData?.matches.map((e) => e.match.rule.id).toList().toString()}"); // "onInputTap matches are ${choreographer.igc.igcTextData?.matches.map((e) => e.match.rule.id).toList().toString()}");
// if user is just trying to get their cursor into the text input field to add soemthing,
// then don't interrupt them
if (selection.baseOffset >= text.length) {
return;
}
final int tokenIndex = choreographer.igc.igcTextData!.tokenIndexByOffset( final int tokenIndex = choreographer.igc.igcTextData!.tokenIndexByOffset(
selection.baseOffset, selection.baseOffset,
); );
@ -147,9 +156,9 @@ class PangeaTextController extends TextEditingController {
// debugPrint("composing after ${value.composing.textAfter(value.text)}"); // debugPrint("composing after ${value.composing.textAfter(value.text)}");
// } // }
final CanSendStatus canSendStatus = final SubscriptionStatus canSendStatus = choreographer
choreographer.pangeaController.subscriptionController.canSendStatus; .pangeaController.subscriptionController.subscriptionStatus;
if (canSendStatus == CanSendStatus.showPaywall && if (canSendStatus == SubscriptionStatus.showPaywall &&
!choreographer.isFetching && !choreographer.isFetching &&
text.isNotEmpty) { text.isNotEmpty) {
return TextSpan( return TextSpan(

@ -1,3 +1,4 @@
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
@ -11,6 +12,7 @@ class ErrorReporter {
void onErrorCallback(Object error, [StackTrace? stackTrace]) async { void onErrorCallback(Object error, [StackTrace? stackTrace]) async {
Logs().e(message ?? 'Error caught', error, stackTrace); Logs().e(message ?? 'Error caught', error, stackTrace);
// #Pangea // #Pangea
try {
// Attempt to retrieve the L10n instance using the current context // Attempt to retrieve the L10n instance using the current context
final L10n? l10n = L10n.of(context); final L10n? l10n = L10n.of(context);
@ -21,8 +23,6 @@ class ErrorReporter {
// Exits early to prevent further execution // Exits early to prevent further execution
return; return;
} }
try {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
@ -32,6 +32,12 @@ class ErrorReporter {
); );
} catch (err) { } catch (err) {
debugPrint("Failed to show error snackbar."); debugPrint("Failed to show error snackbar.");
} finally {
ErrorHandler.logError(
e: error,
s: stackTrace,
m: message ?? 'Error caught',
);
} }
} }
// final text = '$error\n${stackTrace ?? ''}'; // final text = '$error\n${stackTrace ?? ''}';

Loading…
Cancel
Save