Skip to content

Commit

Permalink
Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Dec 12, 2024
1 parent 90063fa commit 20c8882
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ios_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Publish to App Store Connect

on:
push:
branches:
- main
workflow_dispatch:
on: push

jobs:
ios_deploy:
Expand Down
53 changes: 39 additions & 14 deletions app/lib/ui/flow/home/components/no_internet_connection_hint.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:style/animations/fade_in_switcher.dart';
Expand All @@ -13,7 +13,7 @@ class NoInternetConnectionHint extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final showHint = ref.read(
final showHint = ref.watch(
homeViewStateNotifier.select(
(value) =>
!value.hasInternet &&
Expand All @@ -33,22 +33,47 @@ class NoInternetConnectionHint extends ConsumerWidget {
color: context.colorScheme.outline,
),
),
child: Row(
child: Column(
children: [
SvgPicture.asset(
Assets.images.icNoInternet,
height: 50,
width: 50,
Row(
children: [
SvgPicture.asset(
Assets.images.icNoInternet,
height: 50,
width: 50,
),
const SizedBox(width: 16),
Expanded(
child: Text(
context.l10n.no_internet_connection_message,
style: AppTextStyles.body2.copyWith(
letterSpacing: 0.05,
color: context.colorScheme.textPrimary,
),
),
),
],
),
const SizedBox(width: 16),
Expanded(
child: Text(
context.l10n.no_internet_connection_message,
style: AppTextStyles.body2.copyWith(
letterSpacing: 0.05,
color: context.colorScheme.textPrimary,
const SizedBox(height: 16),
FilledButton(
onPressed: () {
ref
.read(homeViewStateNotifier.notifier)
.loadMedias(reload: true);
},
style: FilledButton.styleFrom(
backgroundColor: context.colorScheme.containerLow,
foregroundColor: context.colorScheme.textPrimary,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: const Size(double.maxFinite, 40),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
context.l10n.common_retry,
style: AppTextStyles.button,
),
),
],
),
Expand Down
16 changes: 12 additions & 4 deletions app/lib/ui/flow/home/home_screen_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,11 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
selectedMedias: {},
actionError: null,
);
_backUpFolderId ??= await _googleDriveService.getBackUpFolderId();
if (_backUpFolderId == null) {
_backUpFolderId = await _googleDriveService.getBackUpFolderId();
} else {
await _connectivityHandler.checkInternetAccess();
}
_mediaProcessRepo.uploadMedia(
medias: selectedMedias,
provider: MediaProvider.googleDrive,
Expand Down Expand Up @@ -472,7 +476,7 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
selectedMedias: {},
actionError: null,
);
await _connectivityHandler.lookUpDropbox();
await _connectivityHandler.checkInternetAccess();
_mediaProcessRepo.uploadMedia(
medias: selectedMedias,
provider: MediaProvider.dropbox,
Expand Down Expand Up @@ -500,7 +504,11 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>

state = state.copyWith(selectedMedias: {}, actionError: null);

_backUpFolderId ??= await _googleDriveService.getBackUpFolderId();
if (_backUpFolderId == null) {
_backUpFolderId = await _googleDriveService.getBackUpFolderId();
} else {
await _connectivityHandler.checkInternetAccess();
}

_mediaProcessRepo.downloadMedia(
folderId: _backUpFolderId!,
Expand Down Expand Up @@ -529,7 +537,7 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>

state = state.copyWith(selectedMedias: {}, actionError: null);

await _connectivityHandler.lookUpDropbox();
await _connectivityHandler.checkInternetAccess();

_mediaProcessRepo.downloadMedia(
folderId: ProviderConstants.backupFolderPath,
Expand Down
4 changes: 2 additions & 2 deletions app/lib/ui/flow/media_preview/media_preview_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class MediaPreviewStateNotifier extends StateNotifier<MediaPreviewState> {

state = state.copyWith(actionError: null);

await _connectivityHandler.lookUpDropbox();
await _connectivityHandler.checkInternetAccess();

_mediaProcessRepo.uploadMedia(
folderId: ProviderConstants.backupFolderPath,
Expand Down Expand Up @@ -320,7 +320,7 @@ class MediaPreviewStateNotifier extends StateNotifier<MediaPreviewState> {

state = state.copyWith(actionError: null);

await _connectivityHandler.lookUpDropbox();
await _connectivityHandler.checkInternetAccess();

_mediaProcessRepo.downloadMedia(
folderId: ProviderConstants.backupFolderPath,
Expand Down
27 changes: 16 additions & 11 deletions data/lib/handlers/connectivity_handler.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import 'dart:io';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../apis/network/urls.dart';
import '../errors/app_error.dart';

final connectivityHandlerProvider = Provider<ConnectivityHandler>((ref) {
return ConnectivityHandler();
});

class ConnectivityHandler {
Future<void> lookUpDropbox() async {
await InternetAddress.lookup(BaseURL.dropboxV2);
}

Future<void> lookUpGoogleDrive() async {
await InternetAddress.lookup(BaseURL.googleDriveV3);
}

// This method is used to check internet connection
Future<bool> hasInternetAccess() async {
try {
final result = await InternetAddress.lookup('example.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return true; // Internet access
}
} on SocketException catch (_) {
return false; // No Internet access
return false;
}
return false;
}

// This method is used to check internet connection and throw an exception if there is no internet connection
Future<void> checkInternetAccess() async {
try {
final result = await InternetAddress.lookup('example.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
return; // Internet access
}
} on SocketException catch (_) {
throw NoConnectionError();
}
throw NoConnectionError();
}
}

0 comments on commit 20c8882

Please sign in to comment.