Skip to content

Commit

Permalink
Merge pull request #10 from Thesmader/development
Browse files Browse the repository at this point in the history
Version 1.1.2+5
  • Loading branch information
Chinmay-KB authored May 3, 2020
2 parents 30c8625 + e06575a commit 801890c
Show file tree
Hide file tree
Showing 36 changed files with 528 additions and 394 deletions.
7 changes: 5 additions & 2 deletions gogrocy/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ if (flutterVersionName == null) {

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
//apply plugin: 'com.google.firebase.crashlytics'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
Expand Down Expand Up @@ -85,8 +85,11 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//implementation 'com.google.firebase:firebase-analytics:17.4.0'
//implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-messaging:20.1.6'

}
apply plugin: 'com.google.gms.google-services'
11 changes: 11 additions & 0 deletions gogrocy/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand All @@ -27,5 +31,12 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions gogrocy/android/app/src/main/res/values/color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorAccent">#5FD900</color>
</resources>
6 changes: 3 additions & 3 deletions gogrocy/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.0'
//classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta02'
}
}

Expand Down
15 changes: 15 additions & 0 deletions gogrocy/lib/core/models/place_order.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class PlaceOrder {
bool success;

PlaceOrder({this.success});

PlaceOrder.fromJson(Map<String, dynamic> json) {
success = json['success'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['success'] = this.success;
return data;
}
}
15 changes: 15 additions & 0 deletions gogrocy/lib/core/services/analytics_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
import 'package:flutter/material.dart';

class AnalyticsService {
final FirebaseAnalytics _analytics = FirebaseAnalytics();

FirebaseAnalyticsObserver getAnalyticsObserver() =>
FirebaseAnalyticsObserver(analytics: _analytics);

Future setUserProperties({@required String userId}) async {
await _analytics.setUserId(userId);
}

}
53 changes: 30 additions & 23 deletions gogrocy/lib/core/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:gogrocy/core/models/orders.dart';
import 'package:gogrocy/core/models/ProductsByCity.dart';
import 'package:gogrocy/core/models/cart_edit.dart';
import 'package:gogrocy/core/models/cart_list.dart';
import 'package:gogrocy/core/models/place_order.dart';
import 'package:gogrocy/core/models/product.dart';
import 'package:gogrocy/core/models/signup_model.dart';
import 'package:gogrocy/core/models/user.dart';
Expand Down Expand Up @@ -158,21 +159,22 @@ class Apis {
}

Future<CartEdit> editCartList(
{@required String product_id, @required String quantity}) async {
Map<String, String> body = {"product_id": product_id, "quantity": quantity};
{@required String productId, @required String quantity}) async {
Map<String, String> body = {"product_id": productId, "quantity": quantity};
String jwt = await _sharedPrefsService.getJWT();
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(editCart,
headers: {
'Authorization': 'Bearer $jwt',
},
body: body);
print(response.body);
return CartEdit.fromJson(json.decode(response.body));
} else
(print("Network failure"));
print("Network failure");
}

Future<bool> placeOrder({@required String addressId}) async {
Expand All @@ -182,27 +184,35 @@ class Apis {
String jwt = await _sharedPrefsService.getJWT();
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(orderRequest,
headers: {
'Authorization': 'Bearer $jwt',
},
body: body);
return true;
try{
var response = await client.post(orderRequest,
headers: {
'Authorization': 'Bearer $jwt',
},
body: body);
if(PlaceOrder.fromJson(json.decode(response.body)).success)
return true;
else return false;
}
catch(e)
{
print(e);
return false;
}
} else
return false;
}

Future<ProductsByCity> getProductsByCity() async {
Map<String, String> body = {
"city": await _sharedPrefsService.getCity(),
// TODO: Add city here from SharedPrefs
};
String jwt = await _sharedPrefsService.getJWT();
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(getProductsByCityRequest,
headers: {
Expand All @@ -217,13 +227,12 @@ class Apis {
Future<ProductsByCity> getProductsByCityCategory(String cat_id) async {
Map<String, String> body = {
"city": await _sharedPrefsService.getCity(),
// TODO: Add city here from SharedPrefs
"cat_id": cat_id
};
String jwt = await _sharedPrefsService.getJWT();
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(getCategoriesByCityRequest,
headers: {
Expand All @@ -238,13 +247,12 @@ class Apis {
Future<ProductsByCity> searchProductByCity(String query) async {
Map<String, String> body = {
"city": await _sharedPrefsService.getCity(),
// TODO: Add city here from SharedPrefs
"query": query
};
String jwt = await _sharedPrefsService.getJWT();
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(searchByCity,
headers: {
Expand All @@ -259,7 +267,7 @@ class Apis {
Future<List<Product>> getAllProducts() async {
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var products = List<Product>();
var response = await client.post(allProducts);
Expand All @@ -280,9 +288,8 @@ class Apis {
String jwt = await _sharedPrefsService.getJWT();
Map<String, String> body = {
"city": await _sharedPrefsService.getCity(),
// TODO: Add city here from SharedPrefs
};
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var products = List<Product>();
var response = await client.post(allProducts,
Expand All @@ -307,7 +314,7 @@ class Apis {
var client = new http.Client();
bool connectionState = await checkStatus();
String jwt = await _sharedPrefsService.getJWT();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var address = List<Address>();
var response = await client.post(getAddress, headers: {
Expand All @@ -330,7 +337,7 @@ class Apis {
var client = new http.Client();
bool connectionState = await checkStatus();
String jwt = await _sharedPrefsService.getJWT();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(getOrderRequest, headers: {
'Content-Type': 'application/json',
Expand All @@ -348,7 +355,7 @@ class Apis {
var client = http.Client();
bool connectionState = await checkStatus();
String jwt = await _sharedPrefsService.getJWT();
if (connectionState) //TODO: Add a proper else return
if (connectionState)
{
var response = await client.post(cartList, headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions gogrocy/lib/core/services/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class AuthenticationService {
print(currentUser.uid + " " + currentUser.phoneNumber);
return currentUser != null;
} catch (e) {
print(e.message);
return e.message;
print(e);
return e;
}
}

Expand Down
50 changes: 49 additions & 1 deletion gogrocy/lib/core/services/firebase_messaging_service.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';

class FirebaseMessagingService {
static final FirebaseMessaging fcmInstance = FirebaseMessaging();

static Future<String> getToken() async {
Future<String> getToken() async {
var token = await fcmInstance.getToken();
print("Firebase Token is $token");
return token;
}

void initializeNotifications(BuildContext context) {
fcmInstance.configure(onMessage: (Map<String, dynamic> message) async {
print('onMessage');
showDialog(
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']),
),
actions: <Widget>[
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
);
}, onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
}, onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
});
fcmInstance.subscribeToTopic('pests');
fcmInstance.subscribeToTopic('weather');
print('FCM Configured!');
}

static void reSubscribeWeatherHandler() {
fcmInstance.subscribeToTopic('weather');
}

static void reSubscribePestHandler() {
fcmInstance.subscribeToTopic('pests');
}

static void unsubscribePestHandler() {
fcmInstance.unsubscribeFromTopic('pests');
}

static void unsubscribeWeatherHandler() {
fcmInstance.unsubscribeFromTopic('weather');
}
}
4 changes: 2 additions & 2 deletions gogrocy/lib/core/viewModels/cart_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class CartViewModel extends BaseModel {
print(
"Updating API calledUpdating API calledUpdating API calledUpdating API calledUpdating API called");
cartEditResponse =
await _apis.editCartList(product_id: productId, quantity: quantity);
await _apis.editCartList(productId: productId, quantity: quantity);
cartList = await _apis.getCartList();
setState(ViewState.Idle);
}
}

Future editCartList(String product_id, String quantity) async {
setState(ViewState.Busy);
await _apis.editCartList(product_id: product_id, quantity: quantity);
await _apis.editCartList(productId: product_id, quantity: quantity);
setState(ViewState.Idle);
}
}
10 changes: 5 additions & 5 deletions gogrocy/lib/core/viewModels/login_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class LoginModel extends BaseModel {
@required String phoneNumber,
@required String countryCode}) async {
//var internetStatus = await checkInternetStatus();
setState(ViewState.Busy);
//setState(ViewState.Busy);

//var finalNumber = countryCode + " " + phoneNumber;

var result = await authenticationService.verifyPhoneNumber(
context, phoneNumber, countryCode);

setState(ViewState.Idle);
//setState(ViewState.Idle);

if (result is bool) {
if (result) {
Expand All @@ -69,13 +69,13 @@ class LoginModel extends BaseModel {
@required String countryCode}) async {
setState(ViewState.Busy);

/*var result = */
var result =
await authenticationService.signInWithOtp(
authenticationService.verificationId, otp);

setState(ViewState.Idle);

/*if (result is bool) {
if (result is bool) {
if (result) {
print('login success with otp');
navigationService.goBack();
Expand All @@ -96,7 +96,7 @@ class LoginModel extends BaseModel {
content: Text('Login Unsuccessful'),
),
);
}*/
}
}

Future<User> loginWithApi(
Expand Down
Loading

0 comments on commit 801890c

Please sign in to comment.