-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
android add native contact implementation
- Loading branch information
1 parent
f53668f
commit eaf9892
Showing
33 changed files
with
838 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
package="com.example.fst_app_flutter"> | ||
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android" package="com.example.fst_app_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"/> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_CONTACTS"/> | ||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/> | ||
<application> | ||
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> | ||
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> | ||
</provider> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
android/app/src/main/java/com/example/fst_app_flutter/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import androidx.annotation.NonNull; | ||
import io.flutter.embedding.android.FlutterActivity; | ||
import io.flutter.embedding.engine.FlutterEngine; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
public class MainActivity extends FlutterActivity { | ||
private static final String CHANNEL = "com.example.fst_app_flutter/contacts"; | ||
|
||
@Override | ||
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
super.configureFlutterEngine(flutterEngine); | ||
new MethodChannel( | ||
flutterEngine.getDartExecutor().getBinaryMessenger(), | ||
CHANNEL | ||
) | ||
.setMethodCallHandler( | ||
(call, result) -> { | ||
// Note: this method is invoked on the main thread. | ||
// TODO | ||
} | ||
); | ||
} | ||
|
||
|
||
} |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/example/fst_app_flutter/NativeContact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.fst_app_flutter; | ||
|
||
public class NativeContact { | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
android/app/src/main/kotlin/com/example/fst_app_flutter/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<paths xmlns:android="http:https://schemas.android.com/apk/res/android"> | ||
<cache-path name="external_files" path="."/> | ||
</paths> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
package="com.example.fst_app_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"/> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ':app' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target 'Runner' do | ||
use_frameworks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import 'dart:math'; | ||
import 'dart:typed_data'; | ||
import 'package:flutter_contact/contact.dart'; | ||
import 'package:fst_app_flutter/models/from_postgres/contact/contact_type.dart'; | ||
import 'package:fst_app_flutter/models/from_postgres/contact/department.dart'; | ||
import 'package:fst_app_flutter/models/from_postgres/contact/platform.dart'; | ||
|
||
class Contact { | ||
int _id; | ||
String _name; | ||
String _website; | ||
String _email; | ||
String _fax; | ||
String _description; | ||
Department _department; | ||
ContactType _contactType; | ||
List<_PhoneNumber> _phones; | ||
|
||
int get id => _id; | ||
|
||
String get name => _name; | ||
|
||
String get website => _website; | ||
|
||
String get email => _email; | ||
|
||
String get fax => _fax; | ||
|
||
String get description => _description; | ||
|
||
Department get department => _department; | ||
|
||
ContactType get contactType => _contactType; | ||
|
||
List<_PhoneNumber> get phones => _phones; | ||
|
||
Contact(dynamic contact) { | ||
List<_PhoneNumber> phones = | ||
List.generate(contact['phone_contact_set'].length, (i) { | ||
return _PhoneNumber(contact['phone_contact_set'][i]); | ||
}); | ||
Department department; | ||
switch (contact['department']) { | ||
case 'CHEM': | ||
department = Department.CHEM; | ||
break; | ||
case 'COMP': | ||
department = Department.COMP; | ||
break; | ||
case 'GEO': | ||
department = Department.GEO; | ||
break; | ||
case 'LIFE': | ||
department = Department.LIFE; | ||
break; | ||
case 'MATH': | ||
department = Department.MATH; | ||
break; | ||
case 'PHYS': | ||
department = Department.PHYS; | ||
break; | ||
default: | ||
department = Department.OTHER; | ||
break; | ||
} | ||
ContactType contactType; | ||
switch (contact['contact_type']) { | ||
case 'EMERGENCY': | ||
contactType = ContactType.EMERGENCY; | ||
break; | ||
case 'OFFICE': | ||
contactType = ContactType.OFFICE; | ||
break; | ||
case 'FACULTY_STAFF': | ||
contactType = ContactType.FACULTY_STAFF; | ||
break; | ||
default: | ||
contactType = ContactType.OTHER; | ||
break; | ||
} | ||
_id = contact['id']; | ||
_name = contact['name']; | ||
_website = contact['website']; | ||
_email = contact['email']; | ||
_fax = contact['fax']; | ||
_description = contact['description']; | ||
_department = department; | ||
_contactType = contactType; | ||
_phones = phones; | ||
} | ||
|
||
Map<String, Object> toNativeMap() { | ||
int id = Random().nextInt(9999); | ||
return { | ||
//'identifier': id.toString(), | ||
"displayName": name, | ||
'givenName': name.split(' ')[1], | ||
'middleName': name.split(' ').length == 4 ? _name.split(' ')[2] : '', | ||
'familyName': name.split(' ').length == 4 | ||
? name.split(' ')[3] | ||
: name.split(' ')[2], | ||
'prefix': name.split(' ')[0], | ||
'suffix': '', | ||
'company': '', | ||
'jobTitle': '', | ||
'avatar': Uint8List(0), | ||
'note': description, | ||
"linkedContactIds": <String>[], | ||
'dates': <ContactDate>[], | ||
'emails': email != '' | ||
? <Map>[ | ||
{'label': 'work', 'value': email} | ||
] | ||
: <Map>[], | ||
'phones': List<Map>.generate(phones.length, | ||
(i) => {'label': 'work', 'value': phones[i].phone})..addAll(List<Map>.generate(fax!= ''?1:0, (i) => {'label':'fax work', 'value':fax})), | ||
"socialProfiles": <Map>[], | ||
'postalAddresses': <PostalAddress>[], | ||
"urls": website != '' | ||
? <Map>[ | ||
{'label': 'website', 'value': website} | ||
] | ||
: <Map>[], | ||
//"unifiedContactId": id.toString(), | ||
//"singleContactId": id.toString(), | ||
"otherKeys": {}, | ||
"label": '', | ||
"date": DateTime.now().toIso8601String(), | ||
"lastModified": DateTime.now().toIso8601String(), | ||
"street": '', | ||
"city": '', | ||
"postcode": '', | ||
"region": '', | ||
"country": '', | ||
'keys': ContactKeys.empty(ContactMode.single) | ||
}; | ||
} | ||
} | ||
|
||
class _PhoneNumber { | ||
int _id; | ||
int _contactID; | ||
String _phone; | ||
Platform _platforms; | ||
|
||
int get id => _id; | ||
int get contactID => _contactID; | ||
String get phone => _phone; | ||
Platform get platforms => _platforms; | ||
|
||
_PhoneNumber(dynamic phoneSet) { | ||
Platform platform; | ||
switch (phoneSet['platforms']) { | ||
case 'WHATSAPP': | ||
platform = Platform.WHATSAPP; | ||
break; | ||
default: | ||
platform = Platform.TEXT_CALL; | ||
break; | ||
} | ||
_id = phoneSet['id']; | ||
_contactID = phoneSet['contact']; | ||
_phone = phoneSet['phone']; | ||
_platforms = platform; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum ContactType { EMERGENCY, OFFICE, FACULTY_STAFF, OTHER } | ||
|
||
extension ContactTypeShortString on ContactType { | ||
String asString() { | ||
return this.toString().split('.').last; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum Department { CHEM, COMP, GEO, LIFE, MATH, PHYS, OTHER } | ||
|
||
extension DepartmentShortString on Department { | ||
String asString() { | ||
return this.toString().split('.').last; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum Platform { TEXT_CALL, WHATSAPP } | ||
|
||
extension PlatformShortString on Platform { | ||
String asString() { | ||
return this.toString().split('.').last; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.