Skip to content

Commit

Permalink
feat: Initial Android and Ios Flutte App
Browse files Browse the repository at this point in the history
  • Loading branch information
elblogbruno committed Feb 15, 2021
1 parent e1180e4 commit 92b0422
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 164 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Created by https://www.toptal.com/developers/gitignore/api/images,video
# Edit at https://www.toptal.com/developers/gitignore?templates=images,video


*.jks
key.properties

/Python Server/app/.idea
/Python Server/app/image_tagging/temp_image_folder
/Python Server/app/__pycache__

*.zip
*.log
*.json
Expand Down
19 changes: 16 additions & 3 deletions flutter-android-ios-app/notion_ai_my_mind/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
Expand All @@ -40,16 +46,23 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.elblogbruno.notion_ai_my_mind"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" tools:node="replace"/>
<application
Expand All @@ -15,7 +16,7 @@
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="standard"
android:launchMode="singleTask"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
Expand Down
5 changes: 5 additions & 0 deletions flutter-android-ios-app/notion_ai_my_mind/lib/Arguments.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Arguments{
final String url;
final bool isImage;
Arguments(this.url,this.isImage);
}
160 changes: 110 additions & 50 deletions flutter-android-ios-app/notion_ai_my_mind/lib/api/api.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'dart:convert';

import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:path/path.dart';
import 'package:async/async.dart';
import 'dart:io';

import 'package:url_launcher/url_launcher.dart';

class Api {

Future<String> getMindUrl() async {
Expand All @@ -30,37 +33,82 @@ class Api {
try {
RegExp exp = new RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+');
Iterable<RegExpMatch> matches = exp.allMatches(urlToAdd);

print(matches.length);
if (matches == null) {
print("No match");

} else {
final matchedText = matches.elementAt(1).group(0);
print("Match: " + matchedText); // my

String title = matchedText + " added to your mind from Phone";
String _serverUrl = await getServerUrl();
String finalUrl = _serverUrl + "add_url_to_mind?url="+matchedText+"&title="+title;
print("Final sharing url: " + finalUrl);
http.Response response = await http.get(finalUrl);

if (response.statusCode == 200) {
return "200";
} else {
return '-1';
}
if(matches.length == 0) //means no url extracted on the text. it is just text.
{
String title = "unknown url added to your mind from Phone";
String _serverUrl = await getServerUrl();
String finalUrl = _serverUrl + "add_text_to_mind?url=" + title + "&text=" + urlToAdd;
print("Final sharing url: " + finalUrl);
http.Response response = await http.get(finalUrl);

if (response.statusCode == 200) {
return '200';
} else {
return '-1';
}
}
else if(urlToAdd == matches.first.group(0)) {
print(matches.first.group(0));

final matchedText = matches.first.group(0);
print("Match: " + matchedText); // my

String title = matchedText + " added to your mind from Phone";
String _serverUrl = await getServerUrl();
String finalUrl = _serverUrl + "add_url_to_mind?url=" + matchedText + "&title=" + title;
print("Final sharing url: " + finalUrl);
http.Response response = await http.get(finalUrl);


if (response.statusCode == 200) {
return '200';
} else {
return '-1';
}
}else{
print(matches.first.group(0));

final matchedText = matches.first.group(0);
print("Match: " + matchedText); // my

String _serverUrl = await getServerUrl();
String finalUrl = _serverUrl + "add_text_to_mind?url=" + matchedText + "&text=" + urlToAdd;

print("Final sharing url: " + finalUrl);
http.Response response = await http.get(finalUrl);

if (response.statusCode == 200) {
return '200';
} else {
return '-1';
}
}

}

} catch (_) {
return 'error';
} catch (e) {

Fluttertoast.showToast(msg: "Error: $e",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM);

return '-1';
}
}

Future<String> addImageToMind(String urlToAdd) async {
try {

String title = urlToAdd + " added to your mind from Phone";
String _serverUrl = await getServerUrl();
String finalUrl = _serverUrl + "add_image_to_mind?url="+urlToAdd+"&image_src="+title+"&image_src_url="+title;

print("Final sharing url: " + finalUrl);

http.Response response = await http.get(finalUrl);

if (response.statusCode == 200) {
Expand All @@ -73,22 +121,10 @@ class Api {
}
}

setServerUrl(String value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("url", value);
}


Future<String> getServerUrl() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString("url") ?? 'name';
}



Future<String> uploadImage(File imageFile) async {
var stream = new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
/*var length = await imageFile.length();
var length = await imageFile.length();

String _serverUrl = await getServerUrl();
String uploadURL = _serverUrl + "upload_file";
Expand All @@ -108,36 +144,60 @@ class Api {
return '200';
} else {
return '-1';
}*/
}
}

Future<String> addContentToMind(String url,bool isImage) async{

addUrlToMind(url).then((String result){
print(result);
return result;
});
/*if(url != null){
print("addContentToMind: " + url + " " + isImage.toString());
String response = "Content is invalid or no content was added";
if(url != null){
print("Widget url: " + url);
if(isImage){
print("Widget is image");
var myFile = new File(url);
uploadImage(myFile).then((String result){
print(result);
return result;
});
return uploadImage(myFile);
}else{
print("Widget is url");
addUrlToMind(url).then((String result){
print(result);
return result;
});
return addUrlToMind(url);
}
}else{
print("Widget url is null");
}*/
return response;
}
}


setServerUrl(String value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();

if (value[value.length-1] != "/"){
value = value + "/";
}

await prefs.setString("url", value);
}


Future<String> getServerUrl() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString("url") ?? 'name';
}




return "Content is invalid or no content was added";
launchSettings() async {
String _serverUrl = await getServerUrl();
launchURL(_serverUrl);
}
launchRepo() async {
launchURL("https://github.com/elblogbruno/NotionAI-MyMind");
}

launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}
Loading

0 comments on commit 92b0422

Please sign in to comment.