Skip to content

Commit

Permalink
Sang/postcard/download postcard (#1232)
Browse files Browse the repository at this point in the history
* Update Postcard Detail Pop-up

* Update Api and Auth Interceptor

* Update Asset

* Call Http post

* Add FileHelper

* Update

* Implement for stamp preview

* Add Callback

* Update Asset

* Update

* Use Image Gallery Saver

* Support iOS

* Update Permisstion and perm decs

* Update

* Update

* add HttpHelper

* Fix lint

* Update Colors

* Fix comment
  • Loading branch information
ppupha authored Sep 14, 2023
1 parent 81e31c4 commit 0cf3f64
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 80 deletions.
39 changes: 27 additions & 12 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bitmark.autonomy_flutter"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="com.bitmark.autonomy_flutter">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<queries>
<intent>
Expand All @@ -18,12 +19,12 @@
</queries>

<application
tools:replace="android:label"
android:name=".app.AutonomyApp"
android:icon="${appIcon}"
android:label="@string/app_name"
android:roundIcon="${appIconRound}"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
tools:replace="android:label">
<!--
- Enable usesCleartextTraffic only to allow make connection to localhost
- It will be used to rendering model viewer for 3d artworks.
Expand All @@ -46,16 +47,16 @@

<activity
android:name=".AuthenticatorActivity"
android:theme="@style/NormalTheme"
android:exported="false" />
android:exported="false"
android:theme="@style/NormalTheme" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:screenOrientation="portrait"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">

<!--
Expand Down Expand Up @@ -149,19 +150,33 @@
<!-- Branch App Links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="link.autonomy.io" />
<data android:scheme="https" android:host="autonomy-app.app.link" />
<data android:scheme="https" android:host="autonomy-app-alternate.app.link" />

<data
android:host="link.autonomy.io"
android:scheme="https" />
<data
android:host="autonomy-app.app.link"
android:scheme="https" />
<data
android:host="autonomy-app-alternate.app.link"
android:scheme="https" />
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="autonomy-app.test.app.link" />
<data android:scheme="https" android:host="autonomy-app-alternate.test.app.link" />

<data
android:host="autonomy-app.test.app.link"
android:scheme="https" />
<data
android:host="autonomy-app-alternate.test.app.link"
android:scheme="https" />
</intent-filter>
</activity>
<!--
Expand Down
3 changes: 3 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<string>This app requires access to the photo library.</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allow to give Autonomy permission to save your stamp to your photos.</string>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
Expand Down
132 changes: 80 additions & 52 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dart:collection';
import 'dart:convert';

import 'package:after_layout/after_layout.dart';
import 'package:autonomy_flutter/common/environment.dart';
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/model/play_control_model.dart';
import 'package:autonomy_flutter/model/shared_postcard.dart';
Expand Down Expand Up @@ -42,6 +41,7 @@ import 'package:autonomy_flutter/util/distance_formater.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/moma_style_color.dart';
import 'package:autonomy_flutter/util/postcard_extension.dart';
import 'package:autonomy_flutter/util/share_helper.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:autonomy_flutter/view/artwork_common_widget.dart';
Expand All @@ -64,8 +64,6 @@ import 'package:nft_collection/models/provenance.dart';
import 'package:nft_collection/widgets/nft_collection_bloc.dart';
import 'package:nft_collection/widgets/nft_collection_bloc_event.dart';
import 'package:share/share.dart';
import 'package:social_share/social_share.dart';
import 'package:url_launcher/url_launcher.dart';

class PostcardDetailPagePayload extends ArtworkDetailPayload {
final bool isFromLeaderboard;
Expand Down Expand Up @@ -143,32 +141,8 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
);
}

void _manualShare(String caption, String url) async {
final encodeCaption = Uri.encodeQueryComponent(caption);
final twitterUrl =
"${SocialApp.twitterPrefix}?url=$url&text=$encodeCaption";
final twitterUri = Uri.parse(twitterUrl);
launchUrl(twitterUri, mode: LaunchMode.externalApplication);
}

void _shareTwitter(AssetToken token) {
final prefix = Environment.tokenWebviewPrefix;
final url = '$prefix/token/${token.id}';
final caption = widget.payload.twitterCaption ?? token.twitterCaption;
SocialShare.checkInstalledAppsForShare().then((data) {
if (data?[SocialApp.twitter]) {
SocialShare.shareTwitter(caption, url: url);
} else {
_manualShare(caption, url);
}
});
_metricClient.addEvent(MixpanelEvent.share, data: {
"id": token.id,
"to": "Twitter",
"caption": caption,
"title": token.title,
"artistID": token.artistID,
});
shareToTwitter(token: token, twitterCaption: widget.payload.twitterCaption);
}

Future<void> _youDidIt(BuildContext context, AssetToken asset) async {
Expand Down Expand Up @@ -435,7 +409,8 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
child: Semantics(
label: 'artworkDotIcon',
child: IconButton(
onPressed: () => _showArtworkOptionsDialog(asset),
onPressed: () =>
_showArtworkOptionsDialog(context, asset),
constraints: const BoxConstraints(
maxWidth: 44,
maxHeight: 44,
Expand Down Expand Up @@ -809,21 +784,86 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
);
}

bool _isHidden(AssetToken token) {
return _configurationService
.getTempStorageHiddenTokenIDs()
.contains(token.id);
}

Future _showArtworkOptionsDialog(AssetToken asset) async {
Future _showArtworkOptionsDialog(
BuildContext context, AssetToken asset) async {
final theme = Theme.of(context);
if (!mounted) return;
final isHidden = _isHidden(asset);
UIHelper.showDrawerAction(
const isHidden = false;
UIHelper.showPostcardDrawerAction(
context,
options: [
OptionItem(
title: isHidden ? 'unhide_aw'.tr() : 'hide_aw'.tr(),
icon: const Icon(AuIcon.hidden_artwork),
title: 'share_on_'.tr(),
icon: SvgPicture.asset(
'assets/images/globe.svg',
width: 24,
height: 24,
),
iconOnProcessing: SvgPicture.asset(
'assets/images/globe.svg',
width: 24,
height: 24,
colorFilter: const ColorFilter.mode(
AppColor.disabledColor,
BlendMode.srcIn,
),
),
onTap: () {
_shareTwitter(asset);
Navigator.of(context).pop();
},
),
if (asset.stampIndex >= 0)
OptionItem(
title: 'download_stamp'.tr(),
icon: SvgPicture.asset(
'assets/images/download.svg',
width: 24,
height: 24,
),
iconOnProcessing: SvgPicture.asset('assets/images/download.svg',
width: 24,
height: 24,
colorFilter: const ColorFilter.mode(
AppColor.disabledColor, BlendMode.srcIn)),
onTap: () async {
try {
await _postcardService.downloadStamp(
tokenId: asset.tokenId!, stampIndex: asset.stampIndex);
if (!mounted) return;
Navigator.of(context).pop();
await UIHelper.showPostcardStampSaved(context);
} catch (e) {
log.info("Download stamp failed: error ${e.toString()}");
if (!mounted) return;
Navigator.of(context).pop();
switch (e.runtimeType) {
case MediaPermissionException:
await UIHelper.showPostcardStampPhotoAccessFailed(context);
break;
default:
if (!mounted) return;
await UIHelper.showPostcardStampSavedFailed(context);
}
}
},
),
OptionItem(
title: 'hide'.tr(),
titleStyle: theme.textTheme.moMASans700Black16
.copyWith(fontSize: 18, color: MoMAColors.moMA3),
titleStyleOnPrecessing: theme.textTheme.moMASans700Black16.copyWith(
fontSize: 18, color: const Color.fromRGBO(245, 177, 177, 1)),
icon: SvgPicture.asset(
"assets/images/postcard_hide.svg",
colorFilter:
const ColorFilter.mode(MoMAColors.moMA3, BlendMode.srcIn),
),
iconOnProcessing: SvgPicture.asset(
"assets/images/postcard_hide.svg",
colorFilter: const ColorFilter.mode(
Color.fromRGBO(245, 177, 177, 1), BlendMode.srcIn),
),
onTap: () async {
await _configurationService
.updateTempStorageHiddenTokenIDs([asset.id], !isHidden);
Expand All @@ -839,18 +879,6 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
});
},
),
OptionItem(
title: 'share_on_'.tr(),
icon: SvgPicture.asset(
'assets/images/Share.svg',
width: 24,
height: 24,
),
onTap: () async {
_shareTwitter(asset);
Navigator.of(context).pop();
},
),
],
);
}
Expand Down
Loading

0 comments on commit 0cf3f64

Please sign in to comment.