Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest Develop 20240724 #2530

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:label="talawa"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:enableOnBackInvokedCallback="true"
tools:replace="android:label">
<activity
android:name=".MainActivity"
Expand Down
Binary file added assets/images/defaultImg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:talawa/services/org_service.dart';
import 'package:talawa/services/post_service.dart';
import 'package:talawa/services/session_manager.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/services/third_party_service/connectivity_service.dart';
import 'package:talawa/services/third_party_service/multi_media_pick_service.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/utils/queries.dart';
Expand All @@ -30,6 +31,7 @@ import 'package:talawa/view_model/after_auth_view_models/feed_view_models/organi
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/edit_profile_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/profile_view_models/profile_page_view_model.dart';
import 'package:talawa/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart';
import 'package:talawa/view_model/connectivity_view_model.dart';
import 'package:talawa/view_model/lang_view_model.dart';
import 'package:talawa/view_model/main_screen_view_model.dart';
import 'package:talawa/view_model/pre_auth_view_models/login_view_model.dart';
Expand Down Expand Up @@ -68,6 +70,9 @@ final queries = locator<Queries>();
///GetIt for Connectivity.
final connectivity = locator<Connectivity>();

///GetIt for ConnectivityService.
final connectivityService = locator<ConnectivityService>();

///GetIt for OrganizationService.
final organizationService = locator<OrganizationService>();

Expand All @@ -84,7 +89,7 @@ final sessionManager = locator<SessionManager>();
///
/// **returns**:
/// None
void setupLocator() {
Future<void> setupLocator() async {
//services
locator.registerSingleton(NavigationService());

Expand Down Expand Up @@ -117,9 +122,13 @@ void setupLocator() {
//databaseMutationFunction
locator.registerSingleton(DataBaseMutationFunctions());

locator.registerSingleton(ConnectivityService());

//queries
locator.registerSingleton(Queries());

locator.registerFactory(() => AppConnectivity());

//Page viewModels
locator.registerFactory(() => DemoViewModel());
// locator.registerFactory(() => OrganizationFeedViewModel());
Expand Down
92 changes: 42 additions & 50 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart' as path;
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:talawa/constants/custom_theme.dart';
import 'package:talawa/constants/quick_actions.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/asymetric_keys/asymetric_keys.dart';
Expand All @@ -17,6 +16,7 @@ import 'package:talawa/plugins/fetch_plugin_list.dart';
import 'package:talawa/router.dart' as router;
import 'package:talawa/utils/app_localization.dart';
import 'package:talawa/view_model/base_view_model.dart';
import 'package:talawa/view_model/connectivity_view_model.dart';
import 'package:talawa/view_model/lang_view_model.dart';
import 'package:talawa/view_model/theme_view_model.dart';
import 'package:talawa/views/base_view.dart';
Expand All @@ -39,6 +39,7 @@ Future<void> main() async {
await Hive.openBox('url');

setupLocator();

// The runApp() function takes the given Widget and makes it the root of the widget tree.
runApp(MyApp());
}
Expand Down Expand Up @@ -118,55 +119,46 @@ class _MyAppState extends State<MyApp> {
return BaseView<AppTheme>(
onModelReady: (model) => model.initialize(),
builder: (context, model, child) {
return MaterialApp(
locale: langModel.appLocal,
supportedLocales: [
const Locale('en', 'US'),
const Locale('es', 'ES'),
const Locale('fr', 'FR'),
const Locale('hi', 'IN'),
const Locale('zh', 'CN'),
const Locale('de', 'DE'),
const Locale('ja', 'JP'),
const Locale('pt', 'PT'),
],
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
title: 'Talawa',
theme: Provider.of<AppTheme>(context).isdarkTheme
? TalawaTheme.darkTheme
: TalawaTheme.lightTheme,
debugShowCheckedModeBanner: false,
navigatorKey: navigationService.navigatorKey,
onGenerateRoute: router.generateRoute,
localeResolutionCallback:
(Locale? locale, Iterable<Locale> supportedLocales) {
if (locale == null) {
debugPrint("*language locale is null!!!");
return supportedLocales.first;
}
for (final Locale supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode ||
supportedLocale.countryCode == locale.countryCode) {
return supportedLocale;
}
}
return supportedLocales.first;
},
initialRoute: '/',
onGenerateInitialRoutes: (String initialRouteName) {
return [
router.generateRoute(
RouteSettings(
name: '/',
arguments: mainScreenQuickActionindex,
),
),
];
return BaseView<AppConnectivity>(
onModelReady: (connectivityModel) =>
connectivityModel.initialise(),
builder: (context, connectivityModel, child) {
return MaterialApp(
locale: langModel.appLocal,
supportedLocales: [
const Locale('en', 'US'),
const Locale('es', 'ES'),
const Locale('fr', 'FR'),
const Locale('hi', 'IN'),
const Locale('zh', 'CN'),
const Locale('de', 'DE'),
const Locale('ja', 'JP'),
const Locale('pt', 'PT'),
],
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
title: 'Talawa',
theme: Provider.of<AppTheme>(context).theme,
debugShowCheckedModeBanner: false,
navigatorKey: navigationService.navigatorKey,
onGenerateRoute: router.generateRoute,
localeResolutionCallback: langModel.localeResoultion,
initialRoute: '/',
onGenerateInitialRoutes: (String initialRouteName) {
return [
router.generateRoute(
RouteSettings(
name: '/',
arguments: mainScreenQuickActionindex,
),
),
];
},
);
},
);
},
Expand Down
54 changes: 54 additions & 0 deletions lib/models/events/event_venue.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/// The `Venue` class represents a venue for events.
class Venue {
/// Constructs a `Venue` instance.
///
/// [id] is the unique identifier of the venue.
/// [capacity] is the maximum number of people the venue can accommodate.
/// [description] provides additional details about the venue.
/// [imageUrl] is the URL of the venue's image.
/// [name] is the name of the venue.
/// [organizationId] is the identifier of the organization to which the venue belongs.
Venue({
this.id,
this.capacity,
this.description,
this.imageUrl,
this.name,
this.organizationId,
});

/// Creates a `Venue` instance from a JSON object.
///
/// The [json] parameter is a map containing the venue data.
///
/// Returns an instance of `Venue`.
factory Venue.fromJson(Map<String, dynamic> json) {
return Venue(
id: json['_id'] as String?,
capacity: json['capacity'] as int?,
description: json['description'] as String?,
imageUrl: json['imageUrl'] as String? ?? '',
name: json['name'] as String?,
organizationId:
(json['organization'] as Map<String, dynamic>?)?['_id'] as String?,
);
}

/// The unique identifier of the venue.
final String? id;

/// The maximum number of people the venue can accommodate.
final int? capacity;

/// Provides additional details about the venue.
final String? description;

/// The URL of the venue's image.
final String? imageUrl;

/// The name of the venue.
final String? name;

/// The identifier of the organization to which the venue belongs.
final String? organizationId;
}
8 changes: 4 additions & 4 deletions lib/services/database_mutation_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/utils/queries.dart';
import 'package:talawa/view_model/connectivity_view_model.dart';

/// DataBaseMutationFunctions class provides different services that are under the context of graphQL mutations and queries.
///
Expand Down Expand Up @@ -34,8 +35,10 @@ class DataBaseMutationFunctions {
/// **returns**:
/// None
void init() {
graphqlConfig.getOrgUrl();
clientNonAuth = graphqlConfig.clientToQuery();
clientAuth = graphqlConfig.authClient();
print('ajkjkdjkjkdjieiejie');
_query = Queries();
}

Expand Down Expand Up @@ -104,10 +107,7 @@ class DataBaseMutationFunctions {
debugPrint(exception.linkException.toString());
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => navigationService.showTalawaErrorSnackBar(
"Server not running/wrong url",
MessageType.info,
),
(_) => AppConnectivity.showSnackbar(isOnline: false),
);
}
return false;
Expand Down
1 change: 1 addition & 0 deletions lib/services/event_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:talawa/widgets/custom_progress_dialog.dart';
class EventService {
EventService() {
_eventStream = _eventStreamController.stream.asBroadcastStream();
print(_eventStream);
_currentOrg = _userConfig.currentOrg;
_userConfig.initialiseStream();
setOrgStreamSubscription();
Expand Down
116 changes: 116 additions & 0 deletions lib/services/third_party_service/connectivity_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:http/http.dart' as http;
import 'package:talawa/locator.dart';

/// This class provides services related to network connectivity monitoring and handling.
///
/// It includes methods for:
/// * Initializing the network service - [initConnectivity]
/// * Monitoring connectivity changes - [enableSubscription]
/// * Handling online and offline states - [handleOnline], [handleOffline]
/// * Checking reachability of a given URI - [isReachable]
/// * Handling the device's connectivity status - [handleConnection]
/// * Checking if the device has any type of network connection - [hasConnection]
class ConnectivityService {
/// Stream controller for network status changes.
late StreamController<ConnectivityResult> connectionStatusController;

/// Getter for the stream of connection status changes.
Stream<ConnectivityResult> get connectionStream =>
connectionStatusController.stream;

/// Checks the current internet connectivity status of the device.
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<ConnectivityResult>`: indicates if the url is reachable.
Future<ConnectivityResult> getConnectionType() async {
final result = await connectivity.checkConnectivity();
return result;
}

/// Client to access internet.
late final http.Client _client;

/// This function initializes connectivity monitoring.
///
/// **params**:
/// * `client`: An instance of `http.Client` to make the HTTP request.
///
/// **returns**:
/// None
Future<void> initConnectivity({required http.Client client}) async {
_client = client;
connectionStatusController = StreamController<ConnectivityResult>();

/// Listen for future changes in connectivity
enableSubscription();
}

/// This function enables the subscription to connectivity changes.
///
/// **params**:
/// None
///
/// **returns**:
/// None
Future<void> enableSubscription() async {
connectivity.onConnectivityChanged.listen(
(ConnectivityResult result) {
print(result);
connectionStatusController.add(result);
},
onError: (error) {
// Handle errors during listening for changes
print('Error listening for connectivity changes: $error');
},
);
}

/// This function checks if a given URI is reachable within a specified timeout period.
///
/// Specifically designed to
///
/// **params**:
/// * `client`: An instance of `http.Client` to make the HTTP request.
/// * `uriString`: An optional `String` specifying the URI to check.
/// Defaults to 'org link' if not provided.
///
/// **returns**:
/// * `Future<bool>`: indicates if the url is reachable.
Future<bool> isReachable({
http.Client? client,
String? uriString,
}) async {
try {
client ??= _client;
await client
.get(Uri.parse(uriString ?? graphqlConfig.httpLink.uri.toString()))
.timeout(const Duration(seconds: 30));
return true;
} catch (e) {
print('Timeout while checking reachability: $e');
return false;
}
}

/// This function checks if the device currently has any type of network connection.
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<bool>`: indicating whether the device has a network connection.
Future<bool> hasConnection() async {
try {
final result = await getConnectionType();
return result != ConnectivityResult.none;
} catch (e) {
return false;
}
}
}
2 changes: 1 addition & 1 deletion lib/services/user_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class UserConfig {
_currentUser = User(id: 'null', authToken: 'null');
return false;
}
databaseFunctions.initClientNonAuth();
databaseFunctions.init();
await sessionManager.refreshSession();
// generate access token
graphqlConfig.getToken().then((value) async {
Expand Down
Loading
Loading