Skip to content

Commit

Permalink
兼容android 10
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanTanSheng committed Sep 25, 2019
1 parent 5007991 commit 2020761
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ allprojects {
```gradle
dependencies {
implementation 'com.github.HuanTanSheng:EasyPhotos:3.0.0' //androidx版本,支持android 10,永久维护
implementation 'com.github.HuanTanSheng:EasyPhotos:3.0.1' //androidx版本,支持android 10,永久维护
//implementation 'com.github.HuanTanSheng:EasyPhotos:2.4.5' //还没有升级到androidx的同学可以用这个版本,但不支持android 10,暂停维护
 
Expand Down Expand Up @@ -154,7 +154,7 @@ QQ交流群:[288600953](https://jq.qq.com/?_wv=1027&k=5QGgCDe)


## 更新日志
**3.0.0**
**3.0.1**
- 兼容android 10
- 因为android 10 不支持用path路径显示图片,所以回调取消了单独获取path集合的回调,只保留获取Photo集合的回调,如需使用path,可以在Photo对象中获取
- ImageEngine接口(因为android 10 不支持用path路径显示图片,所以全部改为Uri的形式),望升级用户周知
Expand Down
Binary file modified demo/release/demo-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ private void initAlbum(Context context) {

do {
String id = cursor.getString(idCol);
Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);
String path = cursor.getString(pathCol);
String name = cursor.getString(nameCol);
long dateTime = cursor.getLong(DateCol);
Expand All @@ -138,6 +137,7 @@ private void initAlbum(Context context) {
}

boolean isVideo = type.contains(Type.VIDEO);// 是否是视频
Uri uri = Uri.withAppendedPath(isVideo?MediaStore.Video.Media.EXTERNAL_CONTENT_URI:MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id);

if (Setting.isOnlyVideo() && !isVideo) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ public void onBindViewHolder(@NonNull final PreviewPhotosViewHolder holder, int

if (type.contains(Type.VIDEO)) {
holder.ivPhotoView.setVisibility(View.VISIBLE);
Setting.imageEngine.loadPhoto(holder.ivPhotoView.getContext(), uri,
holder.ivPhotoView);
Setting.imageEngine.loadPhoto(holder.ivPhotoView.getContext(), uri, holder.ivPhotoView);
holder.ivPlay.setVisibility(View.VISIBLE);
holder.ivPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toPlayVideo(v, path, type);
toPlayVideo(v, uri, type);
}
});
} else if (path.endsWith(Type.GIF) || type.endsWith(Type.GIF)) {
Expand All @@ -83,9 +82,10 @@ public void onClick(View v) {
if (ratio > 2.3) {
holder.ivLongPhoto.setVisibility(View.VISIBLE);
holder.ivLongPhoto.setImage(ImageSource.uri(path));
}else {
} else {
holder.ivPhotoView.setVisibility(View.VISIBLE);
Setting.imageEngine.loadPhoto(holder.ivPhotoView.getContext(), uri, holder.ivPhotoView);
Setting.imageEngine.loadPhoto(holder.ivPhotoView.getContext(), uri,
holder.ivPhotoView);
}
}

Expand Down Expand Up @@ -123,10 +123,13 @@ public void onScaleChange(float scaleFactor, float focusX, float focusY) {
});
}

private void toPlayVideo(View v, String path, String type) {
private void toPlayVideo(View v, Uri uri, String type) {
Context context = v.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = getUri(context, path, intent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
intent.setDataAndType(uri, type);
context.startActivity(intent);
}
Expand Down

0 comments on commit 2020761

Please sign in to comment.