Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
🔀 Merge 'develop' into 'feature/emoji-font'
Browse files Browse the repository at this point in the history
  • Loading branch information
999eagle committed Apr 26, 2019
2 parents 4653bd9 + 665e1f2 commit dafa68d
Show file tree
Hide file tree
Showing 120 changed files with 6,245 additions and 1,138 deletions.
12 changes: 11 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<uses-feature
android:name="android.hardware.camera.any"
android:name="android.hardware.camera"
android:required="false"/>
<uses-feature
android:name="android.hardware.camera.autofocus"
Expand Down Expand Up @@ -55,6 +55,16 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
Expand Down
116 changes: 116 additions & 0 deletions android/app/src/main/java/com/example/openbook/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,129 @@
package social.openbook.app;

import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {

public static final String SHARE_STREAM = "openbook.social/receive_share";

private EventChannel.EventSink eventSink = null;
private List<Intent> intentBacklog = new ArrayList<>();
private boolean streamCanceled = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);

new EventChannel(getFlutterView(), SHARE_STREAM).setStreamHandler(
new EventChannel.StreamHandler() {
@Override
public void onListen(Object args, final EventChannel.EventSink events) {
eventSink = events;
streamCanceled = false;
for (int i = 0; i < intentBacklog.size(); i++) {
sendIntent(intentBacklog.remove(i));
}
}

@Override
public void onCancel(Object args) {
eventSink = null;
streamCanceled = true;
}
}
);

sendIntent(getIntent());
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
sendIntent(intent);
}

private void sendIntent(Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SEND)) {
if (eventSink == null) {
if (!streamCanceled && !intentBacklog.contains(intent)) {
intentBacklog.add(intent);
}
return;
}

Map<String, String> args = new HashMap<>();
if (intent.getType().startsWith("image/")) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
uri = copyImageToTempFile(uri);
args.put("path", uri.toString());
} else if (intent.getType().startsWith("text/")) {
args.put("text", intent.getStringExtra(Intent.EXTRA_TEXT));
} else {
Log.w(getClass().getSimpleName(), "unknown intent type \"" + intent.getType() + "\" received, ignoring");
return;
}
Log.i(getClass().getSimpleName(), "sending intent to flutter");
eventSink.success(args);
}
}

private Uri copyImageToTempFile(Uri imageUri) {
try {
InputStream inputStream;
if (imageUri.getScheme().equals("content")) {
inputStream = this.getContentResolver().openInputStream(imageUri);
} else {
inputStream = new FileInputStream(new File(imageUri.getPath()));
}
Bitmap bmp = BitmapFactory.decodeStream(inputStream);
inputStream.close();
if (bmp == null) return null;

ByteArrayOutputStream imageDataStream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, imageDataStream);

File imageFile = createTemporaryFile(".jpeg");
FileOutputStream fileOutput = new FileOutputStream(imageFile);
fileOutput.write(imageDataStream.toByteArray());
inputStream.close();
fileOutput.close();

return Uri.fromFile(imageFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private File createTemporaryFile(String extension) {
try {
String name = UUID.randomUUID().toString();
return File.createTempFile(name, extension, this.getExternalFilesDir(Environment.DIRECTORY_PICTURES));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Binary file added assets/images/icons/expand-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ios/OneSignalNotificationServiceExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.0.21</string>
<string>0.0.34</string>
<key>CFBundleVersion</key>
<string>21</string>
<string>34</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
10 changes: 8 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ PODS:
- OneSignal (2.9.5)
- path_provider (0.0.1):
- Flutter
- share (0.5.2):
- Flutter
- sqflite (0.0.1):
- Flutter
- FMDB (~> 2.7.2)
Expand All @@ -37,7 +39,7 @@ PODS:

DEPENDENCIES:
- device_info (from `.symlinks/plugins/device_info/ios`)
- Flutter (from `.symlinks/flutter/ios-release`)
- Flutter (from `.symlinks/flutter/ios`)
- flutter_exif_rotation (from `.symlinks/plugins/flutter_exif_rotation/ios`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- image_cropper (from `.symlinks/plugins/image_cropper/ios`)
Expand All @@ -46,6 +48,7 @@ DEPENDENCIES:
- OneSignal (< 3.0, >= 2.9.5)
- onesignal (from `.symlinks/plugins/onesignal/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- share (from `.symlinks/plugins/share/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- uni_links (from `.symlinks/plugins/uni_links/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)
Expand All @@ -62,7 +65,7 @@ EXTERNAL SOURCES:
device_info:
:path: ".symlinks/plugins/device_info/ios"
Flutter:
:path: ".symlinks/flutter/ios-release"
:path: ".symlinks/flutter/ios"
flutter_exif_rotation:
:path: ".symlinks/plugins/flutter_exif_rotation/ios"
flutter_secure_storage:
Expand All @@ -77,6 +80,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/onesignal/ios"
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
share:
:path: ".symlinks/plugins/share/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/ios"
uni_links:
Expand All @@ -99,6 +104,7 @@ SPEC CHECKSUMS:
OneSignal: ccdeb961882f8668305e5b694e2cb7cb325fc907
onesignal: c2122c20ffcb03d65445f3e0b49273c10f9c37a6
path_provider: 09407919825bfe3c2deae39453b7a5b44f467873
share: 222b5dcc8031238af9d7de91149df65bad1aef75
sqflite: d1612813fa7db7c667bed9f1d1b508deffc56999
TOCropViewController: 0a075f02c253e88095143bbac7b013fc6fba5090
uni_links: 5ee5240df5cbffc52d9e7f8017a576b6a6bc5141
Expand Down
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios-release/Flutter.framework",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand Down
8 changes: 6 additions & 2 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.21</string>
<string>0.0.34</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>21</string>
<string>34</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
Expand All @@ -35,6 +35,10 @@
<string>We use this permissions to allow you to choose a profile picture or share existing photos in your library.</string>
<key>NSCameraUsageDescription</key>
<string>We use this permissions to allow you to share photos taken within the application.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>OneSignal, our current push notification library includes code that can use your location, we have disabled this and are waiting on them to update their library to remove this permission completely.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>OneSignal, our current push notification library includes code that can use your location, we have disabled this and are waiting on them to update their library to remove this permission completely.</string>
<key>NSMicrophoneUsageDescription</key>
<string>We use this permission to record audio when you take a video within the application.</string>
<key>NSPhotoLibraryUsageDescription</key>
Expand Down
19 changes: 19 additions & 0 deletions lib/libs/future_queue.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'dart:async';

class FutureQueue {
Future _next = new Future.value(null);

/// Request [operation] to be run exclusively.
///
/// Waits for all previously requested operations to complete,
/// then runs the operation and completes the returned future with the
/// result.
/// All creds to https://stackoverflow.com/a/42091982/2608145
Future<T> run<T>(Future<T> operation()) {
var completer = new Completer<T>();
_next.whenComplete(() {
completer.complete(new Future<T>.sync(operation));
});
return _next = completer.future;
}
}
4 changes: 2 additions & 2 deletions lib/libs/pretty_count.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
String getPrettyCount(int value) {
String postfix;
double finalValue = value.toDouble();
double finalValue;

if (value < 0) {
throw 'Invalid value';
Expand All @@ -17,5 +17,5 @@ String getPrettyCount(int value) {
finalValue = value / 1000000000;
}

return finalValue.toString() + postfix;
return finalValue.round().toString() + postfix;
}
3 changes: 2 additions & 1 deletion lib/models/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Badge {
static BadgeKeyword _getBadgeKeywordEnum(keyword) {

switch(keyword) {
case 'ANGEL': return BadgeKeyword.angel; break;
case 'VERIFIED': return BadgeKeyword.verified; break;
case 'FOUNDER': return BadgeKeyword.founder; break;
case 'GOLDEN_FOUNDER': return BadgeKeyword.golden_founder; break;
Expand All @@ -38,4 +39,4 @@ class Badge {
}
}

enum BadgeKeyword { verified, founder, golden_founder, diamond_founder, super_founder, none }
enum BadgeKeyword { angel, verified, founder, golden_founder, diamond_founder, super_founder, none }
18 changes: 18 additions & 0 deletions lib/models/badges_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:Openbook/models/badge.dart';

class BadgesList {
final List<Badge> badges;

BadgesList({
this.badges,
});

factory BadgesList.fromJson(List<dynamic> parsedJson) {
List<Badge> badges =
parsedJson.map((badgeJson) => Badge.fromJson(badgeJson)).toList();

return new BadgesList(
badges: badges,
);
}
}
10 changes: 9 additions & 1 deletion lib/models/community.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Community extends UpdatableModel<Community> {
return result;
}

static void clearCache() {
factory.clearCache();
}

final int id;
final User creator;
String name;
Expand Down Expand Up @@ -108,6 +112,10 @@ class Community extends UpdatableModel<Community> {
return type == CommunityType.private;
}

bool isPublic() {
return type == CommunityType.public;
}

bool isAdministrator(User user) {
CommunityMembership membership = getMembershipForUser(user);
if (membership == null) return false;
Expand Down Expand Up @@ -244,7 +252,7 @@ class Community extends UpdatableModel<Community> {
class CommunityFactory extends UpdatableModelFactory<Community> {
@override
SimpleCache<int, Community> cache =
LruCache(storage: UpdatableModelSimpleStorage(size: 50));
SimpleCache(storage: UpdatableModelSimpleStorage(size: 200));

@override
Community makeFromJson(Map json) {
Expand Down
2 changes: 1 addition & 1 deletion lib/models/notifications/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OBNotification extends UpdatableModel<OBNotification> {
class NotificationFactory extends UpdatableModelFactory<OBNotification> {
@override
SimpleCache<int, OBNotification> cache =
SimpleCache(storage: UpdatableModelSimpleStorage(size: 20));
SimpleCache(storage: UpdatableModelSimpleStorage(size: 120));

@override
OBNotification makeFromJson(Map json) {
Expand Down
2 changes: 1 addition & 1 deletion lib/models/notifications/post_comment_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PostCommentNotification {
}

static PostComment _parsePostComment(Map postCommentData) {
return PostComment.fromJson(postCommentData);
return PostComment.fromJSON(postCommentData);
}

int getPostCreatorId() {
Expand Down
Loading

0 comments on commit dafa68d

Please sign in to comment.