Skip to content

Commit

Permalink
Merge pull request #33 from luke-/10-share-dialog
Browse files Browse the repository at this point in the history
Implement share_intent for image
  • Loading branch information
PrimozRatej authored Feb 8, 2023
2 parents a2d1f44 + 1d03f93 commit 3ee1f3b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
6 changes: 6 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<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>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
12 changes: 11 additions & 1 deletion android/app/src/main/kotlin/com/humhub/humhub/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package com.humhub.app

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK

class MainActivity: FlutterActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
if (intent.getIntExtra("org.chromium.chrome.extra.TASK_ID", -1) == this.taskId) {
this.finish()
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
super.onCreate(savedInstanceState)
}
}
33 changes: 31 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:humhub/util/redirect_handler.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';

void main() {
runApp(const ProviderScope(child: MyApp()));
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
StreamSubscription? intentDataStreamSubscription;
List<SharedMediaFile>? sharedFiles;

@override
void initState() {
super.initState();
intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
.listen((List<SharedMediaFile> value) {
setState(() {
sharedFiles = value;
});
});

// For sharing images coming from outside the app while the app is closed
ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
setState(() {
sharedFiles = value;
});
});
}

@override
Widget build(BuildContext context) {
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_inappwebview:
dependency: "direct main"
description:
name: flutter_inappwebview
url: "https://pub.dartlang.org"
source: hosted
version: "5.7.2+3"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -226,6 +233,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
receive_sharing_intent:
dependency: "direct main"
description:
name: receive_sharing_intent
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.5"
riverpod:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies:
flutter_riverpod: ^2.1.3
permission_handler: ^10.2.0
flutter_secure_storage: ^7.0.1
flutter_inappwebview: ^5.7.2+3
receive_sharing_intent: ^1.4.5

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 3ee1f3b

Please sign in to comment.