Skip to content

Commit

Permalink
Merge pull request #1 from zhihu/master
Browse files Browse the repository at this point in the history
Merge to upstream master
  • Loading branch information
yccheok authored Sep 11, 2019
2 parents 87ca7be + 3ddaf23 commit c74fa78
Show file tree
Hide file tree
Showing 41 changed files with 257 additions and 144 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ android:
components:
- tools
- platform-tools
- build-tools-27.0.3
- android-27
- build-tools-28.0.3
- android-28
- extra-android-m2repository

jdk:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.novoda:bintray-release:0.8.1'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.novoda:bintray-release:0.9.1'
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jun 27 11:32:18 CST 2018
#Thu Aug 22 11:37:43 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
19 changes: 8 additions & 11 deletions matisse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ apply plugin: 'com.novoda.bintray-release'
apply plugin: 'checkstyle'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 28
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
Expand All @@ -34,15 +34,12 @@ android {
}
}

ext.supportLibVersion = '27.1.1'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.android.support:support-v4:${supportLibVersion}"
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:support-annotations:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "androidx.annotation:annotation:1.0.1"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation 'it.sephiroth.android.library.imagezoom:library:1.0.4'

compileOnly 'com.github.bumptech.glide:glide:3.7.0'
Expand All @@ -55,7 +52,7 @@ publish {
userOrg = 'zhihu'
groupId = 'com.zhihu.android'
artifactId = 'matisse'
publishVersion = '0.5.2-beta3'
publishVersion = '0.5.3-beta2'
desc = 'A well-designed local image selector for Android'
website = 'https://www.zhihu.com/'
}
Expand All @@ -81,4 +78,4 @@ task checkstyle(type:Checkstyle) {
showViolations true
classpath = files()
source 'src/main/java'
}
}
4 changes: 2 additions & 2 deletions matisse/src/main/java/com/zhihu/matisse/Matisse.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.zhihu.matisse.ui.MatisseActivity;

Expand Down
25 changes: 24 additions & 1 deletion matisse/src/main/java/com/zhihu/matisse/MimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.content.ContentResolver;
import android.net.Uri;
import android.text.TextUtils;
import android.support.v4.util.ArraySet;
import androidx.collection.ArraySet;
import android.webkit.MimeTypeMap;

import com.zhihu.matisse.internal.utils.PhotoMetadataUtils;
Expand Down Expand Up @@ -110,10 +110,33 @@ public static Set<MimeType> ofImage() {
return EnumSet.of(JPEG, PNG, GIF, BMP, WEBP);
}

public static Set<MimeType> ofImage(boolean onlyGif) {
return EnumSet.of(GIF);
}

public static Set<MimeType> ofGif(){
return ofImage(true);
}

public static Set<MimeType> ofVideo() {
return EnumSet.of(MPEG, MP4, QUICKTIME, THREEGPP, THREEGPP2, MKV, WEBM, TS, AVI);
}

public static boolean isImage(String mimeType) {
if (mimeType == null) return false;
return mimeType.startsWith("image");
}

public static boolean isVideo(String mimeType) {
if (mimeType == null) return false;
return mimeType.startsWith("video");
}

public static boolean isGif(String mimeType) {
if (mimeType == null) return false;
return mimeType.equals(MimeType.GIF.toString());
}

private static Set<String> arraySetOf(String... suffixes) {
return new ArraySet<>(Arrays.asList(suffixes));
}
Expand Down
14 changes: 7 additions & 7 deletions matisse/src/main/java/com/zhihu/matisse/SelectionCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.StyleRes;
import android.support.v4.app.Fragment;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.StyleRes;
import androidx.fragment.app.Fragment;

import com.zhihu.matisse.engine.ImageEngine;
import com.zhihu.matisse.filter.Filter;
Expand Down Expand Up @@ -237,7 +237,7 @@ public SelectionCreator maxOriginalSize(int size) {

/**
* Capture strategy provided for the location to save photos including internal and external
* storage and also a authority for {@link android.support.v4.content.FileProvider}.
* storage and also a authority for {@link androidx.core.content.FileProvider}.
*
* @param captureStrategy {@link CaptureStrategy}, needed only when capturing is enabled.
* @return {@link SelectionCreator} for fluent API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import androidx.annotation.Nullable;

import com.zhihu.matisse.R;
import com.zhihu.matisse.internal.loader.AlbumLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.zhihu.matisse.internal.entity;

import android.content.Context;
import android.support.annotation.IntDef;
import android.support.v4.app.FragmentActivity;
import androidx.annotation.IntDef;
import androidx.fragment.app.FragmentActivity;
import android.widget.Toast;

import com.zhihu.matisse.internal.ui.widget.IncapableDialog;
Expand Down
23 changes: 4 additions & 19 deletions matisse/src/main/java/com/zhihu/matisse/internal/entity/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import androidx.annotation.Nullable;

import com.zhihu.matisse.MimeType;

Expand Down Expand Up @@ -102,30 +102,15 @@ public boolean isCapture() {
}

public boolean isImage() {
if (mimeType == null) return false;
return mimeType.equals(MimeType.JPEG.toString())
|| mimeType.equals(MimeType.PNG.toString())
|| mimeType.equals(MimeType.GIF.toString())
|| mimeType.equals(MimeType.BMP.toString())
|| mimeType.equals(MimeType.WEBP.toString());
return MimeType.isImage(mimeType);
}

public boolean isGif() {
if (mimeType == null) return false;
return mimeType.equals(MimeType.GIF.toString());
return MimeType.isGif(mimeType);
}

public boolean isVideo() {
if (mimeType == null) return false;
return mimeType.equals(MimeType.MPEG.toString())
|| mimeType.equals(MimeType.MP4.toString())
|| mimeType.equals(MimeType.QUICKTIME.toString())
|| mimeType.equals(MimeType.THREEGPP.toString())
|| mimeType.equals(MimeType.THREEGPP2.toString())
|| mimeType.equals(MimeType.MKV.toString())
|| mimeType.equals(MimeType.WEBM.toString())
|| mimeType.equals(MimeType.TS.toString())
|| mimeType.equals(MimeType.AVI.toString());
return MimeType.isVideo(mimeType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package com.zhihu.matisse.internal.entity;

import android.content.pm.ActivityInfo;
import android.support.annotation.StyleRes;

import androidx.annotation.StyleRes;

import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.R;
Expand Down Expand Up @@ -108,6 +109,10 @@ public boolean onlyShowVideos() {
return showSingleMediaType && MimeType.ofVideo().containsAll(mimeTypeSet);
}

public boolean onlyShowGif() {
return showSingleMediaType && MimeType.ofGif().equals(mimeTypeSet);
}

private static final class InstanceHolder {
private static final SelectionSpec INSTANCE = new SelectionSpec();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import android.database.MergeCursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.content.CursorLoader;
import androidx.loader.content.CursorLoader;

import com.zhihu.matisse.internal.entity.Album;
import com.zhihu.matisse.internal.entity.SelectionSpec;
Expand All @@ -38,12 +38,14 @@ public class AlbumLoader extends CursorLoader {
"bucket_id",
"bucket_display_name",
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.MIME_TYPE,
COLUMN_COUNT};
private static final String[] PROJECTION = {
MediaStore.Files.FileColumns._ID,
"bucket_id",
"bucket_display_name",
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.MIME_TYPE,
"COUNT(*) AS " + COLUMN_COUNT};

// === params for showSingleMediaType: false ===
Expand All @@ -70,6 +72,18 @@ private static String[] getSelectionArgsForSingleMediaType(int mediaType) {
}
// =============================================

// === params for showSingleMediaType: true ===
private static final String SELECTION_FOR_SINGLE_MEDIA_GIF_TYPE =
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " AND " + MediaStore.MediaColumns.SIZE + ">0"
+ " AND " + MediaStore.MediaColumns.MIME_TYPE + "=?"
+ ") GROUP BY (bucket_id";

private static String[] getSelectionArgsForSingleMediaGifType(int mediaType) {
return new String[]{String.valueOf(mediaType), "image/gif"};
}
// =============================================

private static final String BUCKET_ORDER_BY = "datetaken DESC";

private AlbumLoader(Context context, String selection, String[] selectionArgs) {
Expand All @@ -79,7 +93,10 @@ private AlbumLoader(Context context, String selection, String[] selectionArgs) {
public static CursorLoader newInstance(Context context) {
String selection;
String[] selectionArgs;
if (SelectionSpec.getInstance().onlyShowImages()) {
if (SelectionSpec.getInstance().onlyShowGif()) {
selection = SELECTION_FOR_SINGLE_MEDIA_GIF_TYPE;
selectionArgs = getSelectionArgsForSingleMediaGifType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
}else if (SelectionSpec.getInstance().onlyShowImages()) {
selection = SELECTION_FOR_SINGLE_MEDIA_TYPE;
selectionArgs = getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
} else if (SelectionSpec.getInstance().onlyShowVideos()) {
Expand All @@ -106,7 +123,7 @@ public Cursor loadInBackground() {
allAlbumCoverPath = albums.getString(albums.getColumnIndex(MediaStore.MediaColumns.DATA));
}
}
allAlbum.addRow(new String[]{Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath,
allAlbum.addRow(new String[]{Album.ALBUM_ID_ALL, Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, allAlbumCoverPath, "",
String.valueOf(totalCount)});

return new MergeCursor(new Cursor[]{allAlbum, albums});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import android.database.MergeCursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.content.CursorLoader;

import androidx.loader.content.CursorLoader;

import com.zhihu.matisse.internal.entity.Album;
import com.zhihu.matisse.internal.entity.Item;
Expand Down Expand Up @@ -93,6 +94,32 @@ private static String[] getSelectionAlbumArgsForSingleMediaType(int mediaType, S
}
// ===============================================================

// === params for album ALL && showSingleMediaType: true && MineType=="image/gif"
private static final String SELECTION_ALL_FOR_GIF =
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " AND "
+ MediaStore.MediaColumns.MIME_TYPE + "=?"
+ " AND " + MediaStore.MediaColumns.SIZE + ">0";

private static String[] getSelectionArgsForGifType(int mediaType) {
return new String[]{String.valueOf(mediaType), "image/gif"};
}
// ===============================================================

// === params for ordinary album && showSingleMediaType: true && MineType=="image/gif" ===
private static final String SELECTION_ALBUM_FOR_GIF =
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " AND "
+ " bucket_id=?"
+ " AND "
+ MediaStore.MediaColumns.MIME_TYPE + "=?"
+ " AND " + MediaStore.MediaColumns.SIZE + ">0";

private static String[] getSelectionAlbumArgsForGifType(int mediaType, String albumId) {
return new String[]{String.valueOf(mediaType), albumId, "image/gif"};
}
// ===============================================================

private static final String ORDER_BY = MediaStore.Images.Media.DATE_TAKEN + " DESC";
private final boolean mEnableCapture;

Expand All @@ -107,7 +134,10 @@ public static CursorLoader newInstance(Context context, Album album, boolean cap
boolean enableCapture;

if (album.isAll()) {
if (SelectionSpec.getInstance().onlyShowImages()) {
if (SelectionSpec.getInstance().onlyShowGif()) {
selection = SELECTION_ALL_FOR_GIF;
selectionArgs = getSelectionArgsForGifType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
} else if (SelectionSpec.getInstance().onlyShowImages()) {
selection = SELECTION_ALL_FOR_SINGLE_MEDIA_TYPE;
selectionArgs = getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
} else if (SelectionSpec.getInstance().onlyShowVideos()) {
Expand All @@ -119,7 +149,10 @@ public static CursorLoader newInstance(Context context, Album album, boolean cap
}
enableCapture = capture;
} else {
if (SelectionSpec.getInstance().onlyShowImages()) {
if (SelectionSpec.getInstance().onlyShowGif()) {
selection = SELECTION_ALBUM_FOR_GIF;
selectionArgs = getSelectionAlbumArgsForGifType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE, album.getId());
} else if (SelectionSpec.getInstance().onlyShowImages()) {
selection = SELECTION_ALBUM_FOR_SINGLE_MEDIA_TYPE;
selectionArgs = getSelectionAlbumArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE,
album.getId());
Expand Down
Loading

0 comments on commit c74fa78

Please sign in to comment.