Skip to content

Commit

Permalink
1.1.0 (#12)
Browse files Browse the repository at this point in the history
* Added the Calendar screen.
* Added a date picker on the New Booking screen.
* Several bug fixes and usability improvements.
  • Loading branch information
mototeam authored Oct 6, 2022
1 parent ac9c914 commit 72dba1d
Show file tree
Hide file tree
Showing 38 changed files with 1,800 additions and 573 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ _Note: You will need a WordPress website and the Hotel Booking plugin from MotoP

## Build and Release

### Prepare
1. Update version name and build number in `pubspec.yaml`.

### Build and Release for iOS

1. Run `flutter build ipa` to produce a build archive.
Expand Down Expand Up @@ -79,6 +82,7 @@ _Note: You will need a WordPress website and the Hotel Booking plugin from MotoP
## Resources
1. https://docs.flutter.dev/get-started/install
1. https://fonts.google.com/icons
1. https://api.flutter.dev/flutter/material/Colors-class.html
1. https://motopress.github.io/hotel-booking-rest-api/

## Contributions
Expand Down
3 changes: 3 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
end
end
end
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ SPEC CHECKSUMS:
shared_preferences: 5033afbb22d372e15aff8ff766df9021b845f273
url_launcher: b6e016d912f04be9f5bf6e8e82dc599b7ba59649

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
PODFILE CHECKSUM: 9c777f85f6c89e1175d6bb20a1c5cf95455188a3

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
2 changes: 1 addition & 1 deletion lib/controller/accommodation_type_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AccommodationTypeController extends BasicController{

final uri = super.getUriHttps( queryEndpoint, queryParameters);

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers,
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/basic_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BasicController {
return finalPath;
}

Uri getUriHttps( [ String pathSegment = '', Map<String, String>? queryParameters ] ) {
Uri getUriHttps( [ String pathSegment = '', Map<String, dynamic>? queryParameters ] ) {

Uri uriHttps = Uri.https(
getAuthority(),
Expand Down
6 changes: 3 additions & 3 deletions lib/controller/booking_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BookingController extends BasicController{

final uri = super.getUriHttps( queryEndpoint, queryParameters);

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers,
Expand Down Expand Up @@ -53,7 +53,7 @@ class BookingController extends BasicController{

final uri = super.getUriHttps( queryEndpoint );

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.post(
uri,
headers: headers,
Expand Down Expand Up @@ -91,7 +91,7 @@ class BookingController extends BasicController{

final uri = super.getUriHttps( queryEndpoint, queryParameters);

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.delete(
uri,
headers: headers,
Expand Down
42 changes: 39 additions & 3 deletions lib/controller/bookings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BookingsController extends BasicController{
}
);

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers
Expand All @@ -67,7 +67,7 @@ class BookingsController extends BasicController{
}
);

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers
Expand Down Expand Up @@ -95,7 +95,7 @@ class BookingsController extends BasicController{

final uri = super.getUriHttps( _queryEndpoint );

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.post(
uri,
headers: headers,
Expand All @@ -115,4 +115,40 @@ class BookingsController extends BasicController{

}

/*
* https://domain.com/wp-json/mphb/v1/bookings
*/
Future<List<Booking>> wpGetAllBookings( int offset, int limit, Map filters ) async {

final headers = super.getHeaders();

final queryParameters = <String, String> {
'per_page': limit.toString(),
'offset': offset.toString(),
'_embed' : 'accommodation'
};

final uri = super.getUriHttps( _queryEndpoint, {
...queryParameters,
...filters,
}
);

//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers
);

if ( response.statusCode == HttpStatus.OK ) {

return compute( BookingsController_parseBookings, response.body );

} else {

throw Exception('Request failed with status: ${response.statusCode}.');
}

}

}
4 changes: 2 additions & 2 deletions lib/controller/payment_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PaymentController extends BasicController{

final uri = super.getUriHttps( queryEndpoint );

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers,
Expand Down Expand Up @@ -50,7 +50,7 @@ class PaymentController extends BasicController{

final uri = super.getUriHttps( queryEndpoint );

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.post(
uri,
headers: headers,
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/payments_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PaymentsController extends BasicController{
}
);

print( Uri.decodeFull(uri.toString()) );
//print( Uri.decodeFull(uri.toString()) );
final response = await http.get(
uri,
headers: headers
Expand Down
23 changes: 18 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:mphb_app/screens/form.dart';
import 'package:mphb_app/screens/home.dart';
import 'package:mphb_app/local_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() async {

Expand All @@ -24,10 +25,16 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
],
supportedLocales: [
Locale('en', 'US'),
Locale('en', 'GB'),
],
theme: ThemeData(
primarySwatch: Colors.indigo,
scaffoldBackgroundColor: const Color(0xFFF3F4F6),
scaffoldBackgroundColor: const Color(0xFFF4F5F8),
visualDensity: VisualDensity.adaptivePlatformDensity,
appBarTheme: AppBarTheme(
backgroundColor: Colors.white,
Expand All @@ -36,15 +43,21 @@ class MyApp extends StatelessWidget {
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
primary: Colors.indigo.shade900,
primary: Colors.indigo.shade600,
)
),
chipTheme: ChipTheme.of(context).copyWith(
backgroundColor: Colors.white,
selectedColor: Colors.indigo.shade100,
secondarySelectedColor: Colors.indigo.shade100,
secondaryLabelStyle: TextStyle(color: Colors.black),
),

),
initialRoute: LocalStorage().hasData() ? '/home' : '/login',
routes: {
'/home': (context) => const MyHomePage(),
'/login': (context) => const MyCustomForm(),
'/home': (context) => const HomePage(),
'/login': (context) => const LoginForm(),
},
);
}
Expand Down
32 changes: 16 additions & 16 deletions lib/models/accommodation_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ class Accommodation_Type {

return Accommodation_Type(

id: json['id'],
title: json['title'],
description: json['description'],
excerpt: json['excerpt'],
adults: json['adults'],
children: json['children'],
total_capacity: json['total_capacity'],
bed_type: json['bed_type'],
size: json['size'],
view: json['view'],
services: json['services'],
categories: json['categories'],
tags: json['tags'],
amenities: json['amenities'],
attributes: json['attributes'],
images: json['images'],
id: json['id'] ?? 0,
title: json['title'] ?? '',
description: json['description'] ?? '',
excerpt: json['excerpt'] ?? '',
adults: json['adults'] ?? 0,
children: json['children'] ?? 0,
total_capacity: json['total_capacity'] ?? 0,
bed_type: json['bed_type'] ?? '',
size: json['size'] ?? 0,
view: json['view'] ?? '',
services: json['services'] ?? [],
categories: json['categories'] ?? [],
tags: json['tags'] ?? [],
amenities: json['amenities'] ?? [],
attributes: json['attributes'] ?? [],
images: json['images'] ?? [],
);
}

Expand Down
66 changes: 36 additions & 30 deletions lib/models/bookings_filters.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
import 'package:intl/intl.dart';
import 'package:flutter/foundation.dart';
import 'package:mphb_app/models/enum/date_range.dart';
import 'package:mphb_app/utils/date_utils.dart';

class Bookings_Filters {

final List<String> post_status = <String>[];
List<String> post_status;

String date_range = '';
String date_range;

String searchTerm = '';
String searchTerm;

//now
final now = DateTime.now();

DateTime getDate(DateTime d) => DateTime(d.year, d.month, d.day);

//today
String get todayStart => getDate(now).toIso8601String();
String get todayEnd => getDate(now).add(
Duration(hours: 23, minutes: 59, seconds: 59 )).toIso8601String();

//this week
String get firstDayOfWeek => getDate(now.subtract(
Duration(days: now.weekday - 1))).toIso8601String();
String get lastDayOfWeek => getDate(now.
add(Duration(days: DateTime.daysPerWeek - now.weekday))).
add(Duration(hours: 23, minutes: 59, seconds: 59 )).toIso8601String();

//this month
String get firstDayOfMonth => DateTime(now.year, now.month, 1).toIso8601String();
String get lastDayOfMonth => DateTime(now.year, now.month + 1, 1, 0, 0, -1).toIso8601String();
Bookings_Filters():
post_status = [],
date_range = '',
searchTerm = '';

Map<String, String> toMap() {

Expand All @@ -41,16 +26,16 @@ class Bookings_Filters {
if ( ! date_range.isEmpty ) {
switch (date_range) {
case DateRangeEnum.TODAY:
map['after'] = todayStart;
map['before'] = todayEnd;
map['after'] = DateUtils.todayStart;
map['before'] = DateUtils.todayEnd;
break;
case DateRangeEnum.THIS_WEEK:
map['after'] = firstDayOfWeek;
map['before'] = lastDayOfWeek;
map['after'] = DateUtils.firstDayOfWeek;
map['before'] = DateUtils.lastDayOfWeek;
break;
case DateRangeEnum.THIS_MONTH:
map['after'] = firstDayOfMonth;
map['before'] = lastDayOfMonth;
map['after'] = DateUtils.firstDayOfMonth;
map['before'] = DateUtils.lastDayOfMonth;
break;
}
}
Expand All @@ -70,4 +55,25 @@ class Bookings_Filters {
);
}

Bookings_Filters clone() {

Bookings_Filters clone = new Bookings_Filters();

clone.post_status = []..addAll( post_status );
clone.date_range = date_range;
clone.searchTerm = searchTerm;

return clone;
}

bool equals( Bookings_Filters obj ) {

return (
date_range == obj.date_range &&
searchTerm == obj.searchTerm &&
listEquals( post_status, obj.post_status )
);
}


}
Loading

0 comments on commit 72dba1d

Please sign in to comment.