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

Upgrade appCompat version for using ActivityResultLauncher #878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions matisse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'checkstyle'

android {
compileSdkVersion 29
buildToolsVersion '29.0.2'
buildToolsVersion '29.0.3'

defaultConfig {
minSdkVersion 14
Expand All @@ -37,9 +37,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "androidx.annotation:annotation:1.4.0"
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'it.sephiroth.android.library.imagezoom:library:1.0.4'

compileOnly 'com.github.bumptech.glide:glide:4.9.0'
Expand Down
10 changes: 4 additions & 6 deletions matisse/src/main/java/com/zhihu/matisse/SelectionCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Build;

import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -348,7 +350,7 @@ public SelectionCreator setOnCheckedListener(@Nullable OnCheckedListener listene
*
* @param requestCode Identity of the request Activity or Fragment.
*/
public void forResult(int requestCode) {
public void forResult(ActivityResultLauncher<Intent> activityResultLauncher) {
Activity activity = mMatisse.getActivity();
if (activity == null) {
return;
Expand All @@ -357,11 +359,7 @@ public void forResult(int requestCode) {
Intent intent = new Intent(activity, MatisseActivity.class);

Fragment fragment = mMatisse.getFragment();
if (fragment != null) {
fragment.startActivityForResult(intent, requestCode);
} else {
activity.startActivityForResult(intent, requestCode);
}
activityResultLauncher.launch(intent);
}

public SelectionCreator showPreview(boolean showPreview) {
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.0"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'
implementation 'io.reactivex.rxjava2:rxjava:2.2.12'
Expand Down
32 changes: 20 additions & 12 deletions sample/src/main/java/com/zhihu/matisse/sample/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
Expand All @@ -28,6 +29,10 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -48,6 +53,18 @@ public class SampleActivity extends AppCompatActivity implements View.OnClickLis

private UriAdapter mAdapter;

ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
mAdapter.setData(Matisse.obtainResult(result.getData()), Matisse.obtainPathResult(result.getData()));
Log.e("OnActivityResult ", String.valueOf(Matisse.obtainOriginalState(result.getData())));
}
}
});

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -104,7 +121,7 @@ private void startAction(View v) {
.setOnCheckedListener(isChecked -> {
Log.e("isChecked", "onCheck: isChecked=" + isChecked);
})
.forResult(REQUEST_CODE_CHOOSE);
.forResult(activityResultLauncher);
break;
case R.id.dracula:
Matisse.from(SampleActivity.this)
Expand All @@ -116,7 +133,7 @@ private void startAction(View v) {
.originalEnable(true)
.maxOriginalSize(10)
.imageEngine(new PicassoEngine())
.forResult(REQUEST_CODE_CHOOSE);
.forResult(activityResultLauncher);
break;
case R.id.only_gif:
Matisse.from(SampleActivity.this)
Expand All @@ -133,23 +150,14 @@ private void startAction(View v) {
.originalEnable(true)
.maxOriginalSize(10)
.autoHideToolbarOnSingleTap(true)
.forResult(REQUEST_CODE_CHOOSE);
.forResult(activityResultLauncher);
break;
default:
break;
}
mAdapter.setData(null, null);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
mAdapter.setData(Matisse.obtainResult(data), Matisse.obtainPathResult(data));
Log.e("OnActivityResult ", String.valueOf(Matisse.obtainOriginalState(data)));
}
}

private static class UriAdapter extends RecyclerView.Adapter<UriAdapter.UriViewHolder> {

private List<Uri> mUris;
Expand Down