From cccced8db85621e4f886f1eb354f06bafae5c206 Mon Sep 17 00:00:00 2001 From: wangshouheng Date: Thu, 14 Oct 2021 17:59:53 +0800 Subject: [PATCH] fix: https://github.com/zhihu/Matisse/issues/812 --- matisse/build.gradle | 2 +- .../matisse/internal/model/AlbumMediaCollection.java | 9 ++++++++- .../matisse/internal/ui/MediaSelectionFragment.java | 2 +- sample/build.gradle | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/matisse/build.gradle b/matisse/build.gradle index 266c5921d..b5bdef5f6 100644 --- a/matisse/build.gradle +++ b/matisse/build.gradle @@ -37,7 +37,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "androidx.appcompat:appcompat:1.1.0" + implementation "androidx.appcompat:appcompat:1.3.1" implementation "androidx.annotation:annotation:1.1.0" implementation "androidx.recyclerview:recyclerview:1.0.0" implementation 'it.sephiroth.android.library.imagezoom:library:1.0.4' diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/model/AlbumMediaCollection.java b/matisse/src/main/java/com/zhihu/matisse/internal/model/AlbumMediaCollection.java index fa25939ec..3961df529 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/model/AlbumMediaCollection.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/model/AlbumMediaCollection.java @@ -21,6 +21,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; @@ -76,7 +77,13 @@ public void onLoaderReset(Loader loader) { public void onCreate(@NonNull FragmentActivity context, @NonNull AlbumMediaCallbacks callbacks) { mContext = new WeakReference(context); - mLoaderManager = context.getSupportLoaderManager(); + mLoaderManager = LoaderManager.getInstance(context); + mCallbacks = callbacks; + } + + public void onCreate(@NonNull Fragment fragment, @NonNull AlbumMediaCallbacks callbacks) { + mContext = new WeakReference(fragment.getContext()); + mLoaderManager = LoaderManager.getInstance(fragment); mCallbacks = callbacks; } diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/ui/MediaSelectionFragment.java b/matisse/src/main/java/com/zhihu/matisse/internal/ui/MediaSelectionFragment.java index 86c46e2f7..69c5926c3 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/ui/MediaSelectionFragment.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/ui/MediaSelectionFragment.java @@ -109,7 +109,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing); mRecyclerView.addItemDecoration(new MediaGridInset(spanCount, spacing, false)); mRecyclerView.setAdapter(mAdapter); - mAlbumMediaCollection.onCreate(getActivity(), this); + mAlbumMediaCollection.onCreate(this, this); mAlbumMediaCollection.load(album, selectionSpec.capture); } diff --git a/sample/build.gradle b/sample/build.gradle index 7573b3c60..9e9b50a59 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -41,7 +41,7 @@ dependencies { // implementation 'com.zhihu.android:matisse:0.5.2' implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "androidx.appcompat:appcompat:1.1.0" + implementation "androidx.appcompat:appcompat:1.3.1" implementation "androidx.recyclerview:recyclerview:1.0.0" implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar' implementation 'io.reactivex.rxjava2:rxjava:2.2.12'