Skip to content

Commit

Permalink
fix: auth value for android API 34 (#1055)
Browse files Browse the repository at this point in the history
Signed-off-by: CaiJingLong <[email protected]>
  • Loading branch information
CaiJingLong authored Dec 12, 2023
1 parent 7971752 commit 67c621e
Show file tree
Hide file tree
Showing 54 changed files with 207 additions and 99 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ that can be found in the LICENSE file. -->

To know more about breaking changes, see the [Migration Guide][].

## 3.0.0-dev.5

### Fixes

- Fix `requestPermissionExtend` returns the incorrect status on Android API 34.

## 3.0.0-dev.4

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class PhotoManagerPlugin(
permissionsUtils.withActivity(activity)
.setListener(object : PermissionsListener {
override fun onGranted(needPermissions: MutableList<String>) {
resultHandler.reply(PermissionResult.Authorized.value)
resultHandler.reply(permissionsUtils.getAuthValue(requestType, mediaLocation).value)
}

override fun onDenied(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,55 @@ class PermissionDelegate34 : PermissionDelegate() {
requestType: Int,
mediaLocation: Boolean
) {
LogUtils.debug("requestPermission")
if (havePermissions(context, requestType)) {
permissionsUtils.permissionsListener?.onGranted(mutableListOf())
return
}

LogUtils.info("requestPermission")
var havePermission = true

val containsImage = RequestTypeUtils.containsImage(requestType)
val containsVideo = RequestTypeUtils.containsVideo(requestType)
val containsAudio = RequestTypeUtils.containsAudio(requestType)

val permissions = mutableListOf<String>()
val requiredPermissions = mutableListOf<String>()

if (containsVideo || containsImage) {
permissions.add(mediaVisualUserSelected)
requiredPermissions.add(mediaVisualUserSelected)
// check have media visual user selected permission, the permission does not need to be defined in the manifest.
val haveMediaVisualUserSelected =
havePermissionForUser(context, mediaVisualUserSelected)

havePermission = haveMediaVisualUserSelected

if (mediaLocation) {
permissions.add(mediaLocationPermission)
requiredPermissions.add(mediaLocationPermission)
havePermission = havePermission && havePermission(context, mediaLocationPermission)
}

if (containsVideo) {
permissions.add(mediaVideo)
requiredPermissions.add(mediaVideo)
}

if (containsImage) {
permissions.add(mediaImage)
requiredPermissions.add(mediaImage)
}

}

if (containsAudio) {
permissions.add(mediaAudio)
requiredPermissions.add(mediaAudio)
havePermission = havePermission && havePermission(context, mediaAudio)
}

LogUtils.debug("Current permissions: $permissions")
LogUtils.debug("havePermission: $havePermission")
LogUtils.info("Current permissions: $requiredPermissions")
LogUtils.info("havePermission: $havePermission")

if (havePermission) {
permissionsUtils.permissionsListener?.onGranted(permissions)
permissionsUtils.permissionsListener?.onGranted(requiredPermissions)
} else {
requestPermission(permissionsUtils, permissions)
requestPermission(permissionsUtils, requiredPermissions)
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() {
}

class _SimpleExampleApp extends StatelessWidget {
const _SimpleExampleApp({Key? key}) : super(key: key);
const _SimpleExampleApp();

@override
Widget build(BuildContext context) {
Expand All @@ -59,7 +59,7 @@ class _SimpleExampleApp extends StatelessWidget {
}

class _SimpleExamplePage extends StatefulWidget {
const _SimpleExamplePage({Key? key}) : super(key: key);
const _SimpleExamplePage();

@override
_SimpleExamplePageState createState() => _SimpleExamplePageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/change_notify_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
import 'package:photo_manager/photo_manager.dart';

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

@override
State<ChangeNotifyExample> createState() => _ChangeNotifyExampleState();
Expand Down
4 changes: 2 additions & 2 deletions example/lib/page/copy_to_another_gallery_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import '../util/log.dart';

class CopyToAnotherGalleryPage extends StatefulWidget {
const CopyToAnotherGalleryPage({
Key? key,
super.key,
required this.assetEntity,
}) : super(key: key);
});

final AssetEntity assetEntity;

Expand Down
13 changes: 6 additions & 7 deletions example/lib/page/custom_filter/advance_filter_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:photo_manager_example/page/custom_filter/order_by_action.dart';

class AdvancedCustomFilterPage extends StatefulWidget {
const AdvancedCustomFilterPage({
Key? key,
super.key,
required this.builder,
}) : super(key: key);
});

final Widget Function(BuildContext context, CustomFilter filter) builder;

Expand Down Expand Up @@ -82,11 +82,11 @@ class _AdvancedCustomFilterPageState extends State<AdvancedCustomFilterPage> {

class WhereAction extends StatelessWidget {
const WhereAction({
Key? key,
super.key,
required this.where,
required this.onChanged,
// required this
}) : super(key: key);
});

final List<WhereConditionItem> where;
final ValueChanged<List<WhereConditionItem>> onChanged;
Expand All @@ -113,9 +113,8 @@ class WhereAction extends StatelessWidget {

class _WhereConditionPage extends StatefulWidget {
const _WhereConditionPage({
Key? key,
required this.where,
}) : super(key: key);
});

final List<WhereConditionItem> where;

Expand Down Expand Up @@ -232,7 +231,7 @@ class _WhereConditionPageState extends State<_WhereConditionPage> {
}

class _CreateWhereDialog extends StatefulWidget {
const _CreateWhereDialog({Key? key}) : super(key: key);
const _CreateWhereDialog();

@override
State<_CreateWhereDialog> createState() => _CreateWhereDialogState();
Expand Down
4 changes: 2 additions & 2 deletions example/lib/page/custom_filter/custom_filter_sql_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'order_by_action.dart';

class CustomFilterSqlPage extends StatefulWidget {
const CustomFilterSqlPage({
Key? key,
super.key,
required this.builder,
}) : super(key: key);
});

final Widget Function(BuildContext context, CustomFilter filter) builder;

Expand Down
4 changes: 2 additions & 2 deletions example/lib/page/custom_filter/filter_assets_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:photo_manager_example/page/custom_filter/image_list.dart';

class FilterAssetsContent extends StatelessWidget {
const FilterAssetsContent({
Key? key,
super.key,
required this.filter,
}) : super(key: key);
});
final CustomFilter filter;

Future<List<AssetEntity>> getAssets() async {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/custom_filter/image_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:photo_manager/photo_manager.dart';
import 'package:photo_manager_example/widget/image_item_widget.dart';

class ImageList extends StatelessWidget {
const ImageList({Key? key, required this.list}) : super(key: key);
const ImageList({super.key, required this.list});

final List<AssetEntity> list;

Expand Down
8 changes: 4 additions & 4 deletions example/lib/page/custom_filter/order_by_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Future<void> changeOrderBy(

class OrderByAction extends StatelessWidget {
const OrderByAction({
Key? key,
super.key,
required this.items,
required this.onChanged,
}) : super(key: key);
});

final List<OrderByItem> items;
final ValueChanged<List<OrderByItem>> onChanged;
Expand Down Expand Up @@ -72,9 +72,9 @@ class OrderByAction extends StatelessWidget {

class OrderByActionPage extends StatefulWidget {
const OrderByActionPage({
Key? key,
super.key,
required this.items,
}) : super(key: key);
});

final List<OrderByItem> items;

Expand Down
6 changes: 3 additions & 3 deletions example/lib/page/custom_filter/path_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:photo_manager_example/page/custom_filter/path_page.dart';
class FilterPathList extends StatelessWidget {
final CustomFilter filter;

const FilterPathList({Key? key, required this.filter}) : super(key: key);
const FilterPathList({super.key, required this.filter});

@override
Widget build(BuildContext context) {
Expand All @@ -29,9 +29,9 @@ class FilterPathList extends StatelessWidget {

class PathList extends StatelessWidget {
const PathList({
Key? key,
super.key,
required this.list,
}) : super(key: key);
});

final List<AssetPathEntity> list;

Expand Down
4 changes: 2 additions & 2 deletions example/lib/page/custom_filter/path_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:photo_manager/photo_manager.dart';
import 'package:photo_manager_example/page/custom_filter/image_list.dart';

class PathPage extends StatefulWidget {
const PathPage({Key? key, required this.path}) : super(key: key);
const PathPage({super.key, required this.path});
final AssetPathEntity path;

@override
Expand All @@ -25,7 +25,7 @@ class _PathPageState extends State<PathPage> {
}

class GalleryWidget extends StatefulWidget {
const GalleryWidget({Key? key, required this.path}) : super(key: key);
const GalleryWidget({super.key, required this.path});

final AssetPathEntity path;

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/custom_filter_example_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'custom_filter/custom_filter_sql_page.dart';
import 'custom_filter/filter_assets_page.dart';

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

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../widget/live_photos_widget.dart';
import '../widget/video_widget.dart';

class DetailPage extends StatefulWidget {
const DetailPage({Key? key, required this.entity}) : super(key: key);
const DetailPage({super.key, required this.entity});

final AssetEntity entity;

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/android/column_names_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
import 'package:photo_manager/photo_manager.dart';

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

@override
State<ColumnNamesPage> createState() => _ColumnNamesPageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/create_entity_by_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:photo_manager/photo_manager.dart';
import '../detail_page.dart';

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

@override
State<CreateEntityById> createState() => _CreateEntityByIdState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/custom_filter_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:oktoast/oktoast.dart';
import 'package:photo_manager/photo_manager.dart';

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

@override
State<CustomFilterPage> createState() => _CustomFilterPageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/dev_title_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:photo_manager/photo_manager.dart';
import '../../util/log.dart';

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

@override
State<DevelopingExample> createState() => _DevelopingExampleState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/develop_index_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'issues_page/issue_index_page.dart';
import 'remove_all_android_not_exists_example.dart';

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

@override
State<DeveloperIndexPage> createState() => _DeveloperIndexPageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/ios/create_folder_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';

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

@override
State<CreateFolderExample> createState() => _CreateFolderExampleState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/ios/edit_asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';

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

@override
State<EditAssetPage> createState() => _EditAssetPageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/issues_page/issue_1025.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:photo_manager/photo_manager.dart';
import 'issue_index_page.dart';

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

@override
State<Issue1025Page> createState() => _Issue1025PageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/issues_page/issue_1031.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:photo_manager/photo_manager.dart';
import 'issue_index_page.dart';

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

@override
State<Issue1031Page> createState() => _Issue1031PageState();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/developer/issues_page/issue_1051.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:photo_manager/photo_manager.dart';
import 'package:photo_manager_example/page/developer/issues_page/issue_index_page.dart';

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

@override
State<Issus1051> createState() => _Issus1051State();
Expand Down
Loading

0 comments on commit 67c621e

Please sign in to comment.