4
2
Fork 0

Merge branch 'master' into feat/integrating-login-manager-into-ui

pull/34/head
Sudharshan S. 2019-03-16 13:45:54 +08:00
commit 9cf83b1179
Signed by: sudharshan
GPG Key ID: C861C97AAF3D9559
12 changed files with 166 additions and 65 deletions

View File

@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
@ -38,9 +38,9 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.frontendflutter"
applicationId "com.example.frontend_flutter"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.frontend_flutter">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -1,11 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.frontendflutter">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
package="com.example.frontend_flutter">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
@ -20,7 +14,7 @@
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing

View File

@ -1,4 +1,4 @@
package com.example.frontendflutter
package com.example.frontend_flutter
import android.os.Bundle

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.frontend_flutter">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

View File

@ -8,11 +8,10 @@
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1D547E90F722854B2C3D347C /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B27C5B5B302B9C8D66A5022B /* Pods_Runner.framework */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4A87800125259F21EA397584 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6FE3C699402F0E32606816A /* Pods_Runner.framework */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@ -40,7 +39,6 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
@ -54,7 +52,7 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B27C5B5B302B9C8D66A5022B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B6FE3C699402F0E32606816A /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -64,24 +62,17 @@
files = (
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
1D547E90F722854B2C3D347C /* Pods_Runner.framework in Frameworks */,
4A87800125259F21EA397584 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
26159A4E8E6A21A39E397E40 /* Pods */ = {
3C2104CC54E5750CA9176AF4 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Pods;
sourceTree = "<group>";
};
4368F97CE29347CAC7FC8E34 /* Frameworks */ = {
isa = PBXGroup;
children = (
B27C5B5B302B9C8D66A5022B /* Pods_Runner.framework */,
B6FE3C699402F0E32606816A /* Pods_Runner.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@ -89,7 +80,6 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
@ -106,8 +96,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
26159A4E8E6A21A39E397E40 /* Pods */,
4368F97CE29347CAC7FC8E34 /* Frameworks */,
A499F57F5AB3D2693A0FFE91 /* Pods */,
3C2104CC54E5750CA9176AF4 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -142,6 +132,13 @@
name = "Supporting Files";
sourceTree = "<group>";
};
A499F57F5AB3D2693A0FFE91 /* Pods */ = {
isa = PBXGroup;
children = (
);
name = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -149,14 +146,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
5B4D3E92DCF006575E5AFE5C /* [CP] Check Pods Manifest.lock */,
4AF5A5E3C092161B3709E551 /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
B2F80DD54B692A84C4FCFFD7 /* [CP] Embed Pods Frameworks */,
C020B601BDFB105B408890B1 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
@ -209,7 +206,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -231,7 +227,7 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
};
5B4D3E92DCF006575E5AFE5C /* [CP] Check Pods Manifest.lock */ = {
4AF5A5E3C092161B3709E551 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
@ -263,20 +259,26 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
B2F80DD54B692A84C4FCFFD7 /* [CP] Embed Pods Frameworks */ = {
C020B601BDFB105B408890B1 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${PODS_ROOT}/GoogleWebRTC/Frameworks/frameworks/WebRTC.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework",
"${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FMDB.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/WebRTC.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;

View File

@ -1,6 +1,6 @@
// Overall sensible settings for development
final String baseUrlCore = "http://localhost:10200";
final String baseUrlSignaling = "http://localhost:10201";
final String baseUrlLogin = "http://localhost:8080";
final String baseUrlCore = "http://localhost/core";
final String baseUrlSignaling = "http://localhost/signal";
final String baseUrlLogin = "http://localhost/login";
final String globalUserId = "u-fb91825f564a3cc110f11836fedea6f4";

View File

@ -3,15 +3,22 @@ import "package:http/http.dart" as http;
import "dart:convert";
import "../models/user_model.dart";
import "../services/cache_http.dart";
import "../../settings.dart";
class ContactApiProvider {
Future<List<User>> fetchContacts() async {
final response = await http.get("$baseUrlCore/user/$globalUserId/contact");
CacheHttp cache = CacheHttp();
return jsonDecode(response.body)
.map<User>((user) => User.fromJson(user))
.toList();
Future<List<User>> fetchContacts() async {
try {
final responseBody =
await this.cache.fetch("$baseUrlCore/user/$globalUserId/contact/");
return jsonDecode(responseBody)
.map<User>((user) => User.fromJson(user))
.toList();
} catch (e) {
throw e;
}
}
void createContact(User user) async =>

View File

@ -5,9 +5,13 @@ import "dart:convert";
import "../models/conversation_model.dart";
import "../models/user_model.dart";
import "../services/cache_http.dart";
import "../../settings.dart";
class ConversationApiProvider {
CacheHttp cache = CacheHttp();
Future<Conversation> createConversation(String title) async {
final response = await http.post("$baseUrlCore/user/conversation",
headers: {"Content-Type": "application/json"},
@ -20,27 +24,39 @@ class ConversationApiProvider {
await http.delete("$baseUrlCore/user/conversation/$id");
Future<List<Conversation>> fetchConversations() async {
final response =
await http.get("$baseUrlCore/user/$globalUserId/conversation");
return jsonDecode(response.body)
.map<Conversation>(
(conversation) => Conversation.fromJson(conversation))
.toList();
try {
final responseBody = await this
.cache
.fetch("$baseUrlCore/user/$globalUserId/conversation/");
return jsonDecode(responseBody)
.map<Conversation>(
(conversation) => Conversation.fromJson(conversation))
.toList();
} catch (e) {
throw e;
}
}
Future<Conversation> fetchConversation(String id) async {
final response = await http.get("baseUrlCore/user/conversation/$id");
return Conversation.fromJson(jsonDecode(response.body));
try {
final responseBody =
await this.cache.fetch("$baseUrlCore/user/conversation/$id");
return Conversation.fromJson(jsonDecode(responseBody));
} catch (e) {
throw e;
}
}
Future<List<User>> fetchConversationMembers(String id) async {
final response = await http
.get("$baseUrlCore/user/$globalUserId/conversation/$id/member");
return jsonDecode(response.body)
.map<User>((user) => User.fromJson(user))
.toList();
try {
final responseBody = await this
.cache
.fetch("$baseUrlCore/user/$globalUserId/conversation/$id/member/");
return jsonDecode(responseBody)
.map<User>((user) => User.fromJson(user))
.toList();
} catch (e) {
throw e;
}
}
}

View File

@ -3,9 +3,12 @@ import "dart:convert";
import "package:http/http.dart" as http;
import "../models/user_model.dart";
import "../services/cache_http.dart";
import "../../settings.dart";
class UserApiProvider {
CacheHttp cache;
Future<User> createUser(User user) async {
// Prob need to add the headers
final response = await http.post("$baseUrlCore/user",
@ -15,15 +18,21 @@ class UserApiProvider {
}
Future<User> fetchUserByPhone(String phoneNumber) async {
final uri = Uri.https(baseUrlCore, "/user", {"phone_number": phoneNumber});
final response = await http.get(uri);
return User.fromJson(jsonDecode(response.body));
try {
final responseBody =
await this.cache.fetch("$baseUrlCore/user?phone_number=$phoneNumber");
return User.fromJson(jsonDecode(responseBody));
} catch (e) {
throw e;
}
}
Future<User> fetchUserById(String id) async {
final response = await http.get("$baseUrlCore/user/id/$id");
return User.fromJson(jsonDecode(response.body));
try {
final responseBody = await this.cache.fetch("$baseUrlCore/user/id/$id");
return User.fromJson(jsonDecode(responseBody));
} catch (e) {
throw e;
}
}
}

View File

@ -0,0 +1,58 @@
import "dart:async";
import "dart:core";
import "package:http/http.dart" as http;
import 'package:sqflite/sqflite.dart';
class CacheHttp {
Database db;
bool hasInit = false;
// Call this immediately after instantiating new CacheManager
Future<void> init() async {
var dbPath = await getDatabasesPath();
String path = dbPath + "/cache.db";
this.db = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
// When creating the db, create the table
await db.execute(
'CREATE TABLE cache (url TEXT PRIMARY KEY, resource TEXT NOT NULL)');
});
}
// Returns raw response body
Future<String> fetch(String url, {bool update = false}) async {
if (!this.hasInit) {
this.hasInit = true;
await this.init();
}
try {
final response = await http.get(url);
if (response.statusCode < 200 || response.statusCode >= 300) {
// Unsuccessful response, use cache
final body = await this.getCache(url);
return body;
} else {
await this.db.rawInsert(
"INSERT INTO cache (url, resource) VALUES (?, ?) ON CONFLICT(url) DO UPDATE SET resource = ?",
[url, response.body, response.body]);
return response.body;
}
} catch (e) {
final body = await this.getCache(url);
return body;
}
}
Future<String> getCache(String url) async {
List<Map> cached = await this
.db
.rawQuery("SELECT resource FROM cache WHERE url = ?", [url]);
if (cached.length > 0) {
// Something exists in the cache
return cached[0]["resource"]; // Return the first result
} else {
throw 404;
}
}
}

View File

@ -16,6 +16,7 @@ dependencies:
pin_code_text_field: ^1.1.3
flutter_svg: ^0.10.3
shared_preferences: ^0.5.1
sqflite: ^1.1.0
dev_dependencies:
flutter_test: