Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for media not reloading after album change #874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions matisse/src/main/java/com/zhihu/matisse/ui/MatisseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import com.zhihu.matisse.internal.utils.PhotoMetadataUtils;

import com.zhihu.matisse.internal.utils.SingleMediaScanner;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

/**
Expand Down Expand Up @@ -93,6 +95,8 @@ public class MatisseActivity extends AppCompatActivity implements
private CheckRadioView mOriginal;
private boolean mOriginalEnable;

private WeakReference<Fragment> fragmentRef;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// programmatically set theme before super.onCreate()
Expand Down Expand Up @@ -393,7 +397,17 @@ private void onAlbumSelected(Album album) {
} else {
mContainer.setVisibility(View.VISIBLE);
mEmptyView.setVisibility(View.GONE);

if (fragmentRef != null && fragmentRef.get() != null) {
getSupportFragmentManager()
.beginTransaction()
.remove(fragmentRef.get())
.commitAllowingStateLoss();
}

Fragment fragment = MediaSelectionFragment.newInstance(album);
fragmentRef = new WeakReference<>(fragment);

getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container, fragment, MediaSelectionFragment.class.getSimpleName())
Expand Down