-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to share links/media to Thunder on Android (#843)
* init attempt receive share intents android * support for receiving share intents, links as text, text, image files * Rm unused url from _navigateToCreatePostPage * update changelog :receiving share intents (android) * lable in share sheet, deep links chrome override behavior docs, if text is url in receive intents, * support for receiving share intents, links as text, text, image files * grab link title from post url.
- Loading branch information
Showing
11 changed files
with
275 additions
and
54 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
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
33 changes: 32 additions & 1 deletion
33
android/app/src/main/kotlin/com/example/thunder/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
package com.hjiangsu.thunder | ||
|
||
import android.content.Intent | ||
import androidx.annotation.NonNull; | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugins.GeneratedPluginRegistrant | ||
import android.os.Bundle | ||
|
||
class MainActivity: FlutterActivity() { | ||
} | ||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
GeneratedPluginRegistrant.registerWith(flutterEngine); | ||
java.lang.Thread.sleep(1000); | ||
} | ||
/** | ||
* When triggering an implicit deep link, the state of the back stack depends on whether the implicit Intent was launched with the Intent.FLAG_ACTIVITY_NEW_TASK flag: | ||
* | ||
* - If the flag is set, the task back stack is cleared and replaced with the deep link destination. As with explicit deep linking, | ||
* when nesting graphs, the start destination from each level of nesting—that is, the start destination from each element in the | ||
* hierarchy—is also added to the stack. This means that when a user presses the Back button from a deep link destination, they | ||
* navigate back up the navigation stack just as though they entered your app from its entry point. | ||
* - If the flag is not set, you remain on the task stack of the previous app where the implicit deep link was triggered. In this case, | ||
* the Back button takes you back to the previous app, while the Up button starts your app's task on the hierarchical parent destination within your navigation graph. | ||
* | ||
* TLDR: The app that launches your app can change this behavior. | ||
* | ||
* Source: https://developer.android.com/guide/navigation/navigation-deep-link#implicit | ||
*/ | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
if (intent.getIntExtra("org.chromium.chrome.extra.TASK_ID", -1) == this.taskId) { | ||
this.finish() | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
startActivity(intent); | ||
} | ||
super.onCreate(savedInstanceState) | ||
} | ||
} |
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"?> | ||
<resources> | ||
<string name="create_post">Create Post</string> | ||
</resources> |
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
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,50 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:swipeable_page_route/swipeable_page_route.dart'; | ||
import 'package:thunder/account/bloc/account_bloc.dart'; | ||
import 'package:thunder/community/pages/create_post_page.dart'; | ||
import 'package:thunder/core/singletons/lemmy_client.dart'; | ||
import 'package:thunder/feed/feed.dart'; | ||
import 'package:thunder/shared/snackbar.dart'; | ||
import 'package:thunder/thunder/thunder.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
Future<void> navigateToCreatePostPage( | ||
BuildContext context, { | ||
String? text, | ||
File? image, | ||
String? url, | ||
bool? prePopulated, | ||
}) async { | ||
try { | ||
ThunderBloc thunderBloc = context.read<ThunderBloc>(); | ||
AccountBloc accountBloc = context.read<AccountBloc>(); | ||
final bool reduceAnimations = thunderBloc.state.reduceAnimations; | ||
Navigator.of(context).push(SwipeablePageRoute( | ||
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null, | ||
canOnlySwipeFromEdge: true, | ||
backGestureDetectionWidth: 45, | ||
builder: (context) { | ||
return MultiBlocProvider( | ||
providers: [ | ||
BlocProvider(create: (context) => FeedBloc(lemmyClient: LemmyClient.instance)), | ||
BlocProvider<ThunderBloc>.value(value: thunderBloc), | ||
BlocProvider<AccountBloc>.value(value: accountBloc), | ||
], | ||
child: CreatePostPage( | ||
text: text, | ||
image: image, | ||
url: url, | ||
prePopulated: prePopulated, | ||
onUpdateDraft: (p) => {}, | ||
communityId: null, | ||
), | ||
); | ||
}, | ||
)); | ||
} catch (e) { | ||
if (context.mounted) showSnackbar(context, AppLocalizations.of(context)!.unexpectedError); | ||
} | ||
} |
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.