diff --git a/app/src/main/java/com/zhongjh/cameraapp/configuration/GifSizeFilter.java b/app/src/main/java/com/zhongjh/cameraapp/configuration/GifSizeFilter.java index 6f228bae..9721f9eb 100644 --- a/app/src/main/java/com/zhongjh/cameraapp/configuration/GifSizeFilter.java +++ b/app/src/main/java/com/zhongjh/cameraapp/configuration/GifSizeFilter.java @@ -27,6 +27,8 @@ import com.zhongjh.albumcamerarecorder.album.utils.PhotoMetadataUtils; import com.zhongjh.cameraapp.R; +import org.jetbrains.annotations.NotNull; + import java.util.HashSet; import java.util.Set; @@ -50,7 +52,7 @@ public Set constraintTypes() { } @Override - public IncapableCause filter(Context context, MultiMedia item) { + public IncapableCause filter(@NotNull Context context, @NotNull MultiMedia item) { if (!needFiltering(context, item)) { return null; } diff --git a/app/src/main/java/com/zhongjh/cameraapp/configuration/Glide4Engine.java b/app/src/main/java/com/zhongjh/cameraapp/configuration/Glide4Engine.java index 674a7cf0..c7805be0 100644 --- a/app/src/main/java/com/zhongjh/cameraapp/configuration/Glide4Engine.java +++ b/app/src/main/java/com/zhongjh/cameraapp/configuration/Glide4Engine.java @@ -26,6 +26,8 @@ import com.zhongjh.albumcamerarecorder.album.engine.ImageEngine; import com.zhongjh.cameraapp.R; +import org.jetbrains.annotations.NotNull; + /** * {@link ImageEngine} implementation using Glide. @@ -34,7 +36,7 @@ public class Glide4Engine implements ImageEngine { @Override - public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { + public void loadThumbnail(@NotNull Context context, int resize, @NotNull Drawable placeholder, @NotNull ImageView imageView, @NotNull Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) @@ -46,8 +48,8 @@ public void loadThumbnail(Context context, int resize, Drawable placeholder, Ima } @Override - public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, - Uri uri) { + public void loadGifThumbnail(@NotNull Context context, int resize, @NotNull Drawable placeholder, @NotNull ImageView imageView, + @NotNull Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) @@ -59,7 +61,7 @@ public void loadGifThumbnail(Context context, int resize, Drawable placeholder, } @Override - public void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { + public void loadImage(@NotNull Context context, int resizeX, int resizeY, @NotNull ImageView imageView, @NotNull Uri uri) { Glide.with(context) .load(uri) .apply(new RequestOptions() @@ -71,7 +73,7 @@ public void loadImage(Context context, int resizeX, int resizeY, ImageView image } @Override - public void loadUrlImage(Context context, ImageView imageView, String url) { + public void loadUrlImage(@NotNull Context context, @NotNull ImageView imageView, @NotNull String url) { Glide.with(context) .load(url) .apply(new RequestOptions() @@ -82,7 +84,7 @@ public void loadUrlImage(Context context, ImageView imageView, String url) { } @Override - public void loadUriImage(Context context, ImageView imageView, Uri uri) { + public void loadUriImage(@NotNull Context context, @NotNull ImageView imageView, @NotNull Uri uri) { Glide.with(context) .load(uri) .apply(new RequestOptions() @@ -93,7 +95,7 @@ public void loadUriImage(Context context, ImageView imageView, Uri uri) { } @Override - public void loadDrawableImage(Context context, ImageView imageView, Integer resourceId) { + public void loadDrawableImage(@NotNull Context context, @NotNull ImageView imageView, int resourceId) { Glide.with(context) .load(resourceId) .apply(new RequestOptions() @@ -104,7 +106,7 @@ public void loadDrawableImage(Context context, ImageView imageView, Integer reso } @Override - public void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { + public void loadGifImage(@NotNull Context context, int resizeX, int resizeY, @NotNull ImageView imageView, @NotNull Uri uri) { Glide.with(context) .asGif() .load(uri) diff --git a/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java b/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java index 245b7f9c..521447d8 100644 --- a/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java +++ b/app/src/main/java/com/zhongjh/cameraapp/phone/MainActivity.java @@ -24,9 +24,9 @@ import com.zhongjh.albumcamerarecorder.settings.RecorderSetting; import com.zhongjh.cameraapp.BaseActivity; import com.zhongjh.cameraapp.R; -import com.zhongjh.cameraapp.configuration.ImageCompressionLuBan; import com.zhongjh.cameraapp.configuration.GifSizeFilter; import com.zhongjh.cameraapp.configuration.Glide4Engine; +import com.zhongjh.cameraapp.configuration.ImageCompressionLuBan; import com.zhongjh.cameraapp.databinding.ActivityMainBinding; import com.zhongjh.common.entity.LocalFile; import com.zhongjh.common.entity.MediaExtraInfo; @@ -220,15 +220,11 @@ protected void openMain(int alreadyImageCount, int alreadyVideoCount, int alread // 是否压缩图片 if (mBinding.cbIsCompressImage.isChecked()) { mGlobalSetting.setOnImageCompressionInterface(new ImageCompressionLuBan()); - } else { - mGlobalSetting.setOnImageCompressionInterface(null); } // 是否压缩视频 if (mBinding.cbIsCompressVideo.isChecked()) { mGlobalSetting.videoCompress(new VideoCompressManager()); - } else { - mGlobalSetting.videoCompress(null); } // 自定义路径,如果其他子权限设置了路径,那么以子权限为准 @@ -274,7 +270,7 @@ private void initForResult() { mGlobalSetting.forResult(new OnResultCallbackListener() { @Override - public void onResult(List result) { + public void onResult(@NotNull List result) { for (LocalFile localFile : result) { Log.i(TAG, "onResult id:" + localFile.getId()); Log.d(TAG, "onResult 绝对路径:" + localFile.getPath()); @@ -295,10 +291,12 @@ public void onResult(List result) { Log.d(TAG, "onResult 具体类型:" + localFile.getMimeType()); // 某些手机拍摄没有自带宽高,那么我们可以自己获取 if (localFile.getWidth() == 0 && localFile.isVideo()) { - MediaExtraInfo mediaExtraInfo = MediaUtils.getVideoSize(getApplication(), localFile.getPath()); - localFile.setWidth(mediaExtraInfo.getWidth()); - localFile.setHeight(mediaExtraInfo.getHeight()); - localFile.setDuration(mediaExtraInfo.getDuration()); + if (localFile.getPath() != null) { + MediaExtraInfo mediaExtraInfo = MediaUtils.getVideoSize(getApplication(), localFile.getPath()); + localFile.setWidth(mediaExtraInfo.getWidth()); + localFile.setHeight(mediaExtraInfo.getHeight()); + localFile.setDuration(mediaExtraInfo.getDuration()); + } } Log.d(TAG, "onResult 宽高: " + localFile.getWidth() + "x" + localFile.getHeight()); Log.d(TAG, UriUtils.uriToFile(getApplicationContext(), localFile.getUri()).getPath()); @@ -307,7 +305,7 @@ public void onResult(List result) { } @Override - public void onResultFromPreview(List result, boolean apply) { + public void onResultFromPreview(@NotNull List result, boolean apply) { if (apply) { for (MultiMedia multiMedia : result) { // 绝对路径,AndroidQ如果存在不属于自己App下面的文件夹则无效 diff --git a/common/src/main/java/com/zhongjh/common/entity/LocalFile.kt b/common/src/main/java/com/zhongjh/common/entity/LocalFile.kt index fe50296e..d348e72e 100644 --- a/common/src/main/java/com/zhongjh/common/entity/LocalFile.kt +++ b/common/src/main/java/com/zhongjh/common/entity/LocalFile.kt @@ -66,8 +66,8 @@ open class LocalFile : Parcelable { constructor() /** - * 从localFile赋值到另外一个新的localFile - * 之所以这样做是因为Parcelable如果使用的是看似父类其实是子类就会出问题 + * 从 localFile 赋值到另外一个新的 localFile + * 之所以这样做是因为 Parcelable 如果使用的是看似父类其实是子类就会出问题 */ constructor(localFile: LocalFile) : super() { id = localFile.id @@ -85,14 +85,24 @@ open class LocalFile : Parcelable { /** * 赋值一个新的path,借由这个新的path,修改相关参数 */ - constructor(context: Context, mediaStoreCompat: MediaStoreCompat, localFile: LocalFile, compressionFile: File) : super() { + constructor( + context: Context, + mediaStoreCompat: MediaStoreCompat, + localFile: LocalFile, + compressionFile: File + ) : super() { updateFile(context, mediaStoreCompat, localFile, compressionFile) } /** * 修改新的file */ - fun updateFile(context: Context, mediaStoreCompat: MediaStoreCompat, localFile: LocalFile, compressionFile: File) { + fun updateFile( + context: Context, + mediaStoreCompat: MediaStoreCompat, + localFile: LocalFile, + compressionFile: File + ) { id = localFile.id this.path = compressionFile.absolutePath this.uri = mediaStoreCompat.getUri(compressionFile.absolutePath) @@ -102,7 +112,8 @@ open class LocalFile : Parcelable { oldPath = localFile.oldPath oldUri = localFile.oldUri if (isImageOrGif()) { - val imageWidthAndHeight: IntArray = MediaUtils.getImageWidthAndHeight(compressionFile.absolutePath) + val imageWidthAndHeight: IntArray = + MediaUtils.getImageWidthAndHeight(compressionFile.absolutePath) height = imageWidthAndHeight[1] width = imageWidthAndHeight[0] } else if (isVideo()) { diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/ImageEngine.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/ImageEngine.kt index c6f45985..63c0b751 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/ImageEngine.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/ImageEngine.kt @@ -1,33 +1,17 @@ -/* - * Copyright 2017 Zhihu Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.zhongjh.albumcamerarecorder.album.engine; +package com.zhongjh.albumcamerarecorder.album.engine -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.widget.ImageView; +import android.content.Context +import android.graphics.drawable.Drawable +import android.net.Uri +import android.widget.ImageView /** * 图片不同加载方式 - * Image loader interface. There are predefined {@link com.zhongjh.albumcamerarecorder.album.engine.impl.GlideEngine} - * and {@link com.zhongjh.albumcamerarecorder.album.engine.impl.PicassoEngine}. + * Image loader interface. There are predefined [com.zhongjh.albumcamerarecorder.album.engine.impl.GlideEngine] + * and [com.zhongjh.albumcamerarecorder.album.engine.impl.PicassoEngine]. * @author zhongjh */ -public interface ImageEngine { - +interface ImageEngine { /** * 加载静态图像资源的缩略图 * 大部分场景用于相册 @@ -38,7 +22,13 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param uri 加载图像的URI */ - void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri); + fun loadThumbnail( + context: Context, + resize: Int, + placeholder: Drawable, + imageView: ImageView, + uri: Uri + ) /** * 加载GIF图像资源的缩略图。如果只是一个缩略图,你不必加载动画gif @@ -50,7 +40,13 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param uri 加载图像的URI */ - void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri); + fun loadGifThumbnail( + context: Context, + resize: Int, + placeholder: Drawable, + imageView: ImageView, + uri: Uri + ) /** * 加载静态图像资源 @@ -62,7 +58,7 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param uri 加载图像的URI */ - void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri); + fun loadImage(context: Context, resizeX: Int, resizeY: Int, imageView: ImageView, uri: Uri) /** * 加载静态图像资源 @@ -72,7 +68,7 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param url 加载图像的url */ - void loadUrlImage(Context context, ImageView imageView, String url); + fun loadUrlImage(context: Context, imageView: ImageView, url: String) /** * 加载静态图像资源 @@ -82,7 +78,7 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param uri 加载图像的uri */ - void loadUriImage(Context context, ImageView imageView, Uri uri); + fun loadUriImage(context: Context, imageView: ImageView, uri: Uri) /** * 加载静态图像资源 @@ -92,7 +88,7 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param resourceId 资源id图片 */ - void loadDrawableImage(Context context, ImageView imageView ,Integer resourceId); + fun loadDrawableImage(context: Context, imageView: ImageView, resourceId: Int) /** * 加载GIF图像资源。 @@ -103,7 +99,13 @@ public interface ImageEngine { * @param imageView ImageView控件 * @param uri 加载图像的uri */ - void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri); + fun loadGifImage( + context: Context, + resizeX: Int, + resizeY: Int, + imageView: ImageView, + uri: Uri + ) /** * 此实现是否支持动态GIF @@ -111,5 +113,5 @@ public interface ImageEngine { * * @return true支持动画gif,false不支持动画gif。 */ - boolean supportAnimatedGif(); -} + fun supportAnimatedGif(): Boolean +} \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/GlideEngine.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/GlideEngine.kt index d10c7310..c8ad7e7d 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/GlideEngine.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/GlideEngine.kt @@ -1,110 +1,102 @@ -/* - * Copyright 2017 Zhihu Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.zhongjh.albumcamerarecorder.album.engine.impl; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.widget.ImageView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.Priority; -import com.zhongjh.albumcamerarecorder.album.engine.ImageEngine; +package com.zhongjh.albumcamerarecorder.album.engine.impl +import android.content.Context +import android.graphics.drawable.Drawable +import android.net.Uri +import android.widget.ImageView +import com.bumptech.glide.Glide +import com.bumptech.glide.Priority +import com.zhongjh.albumcamerarecorder.album.engine.ImageEngine /** - * {@link ImageEngine} implementation using Glide. + * [ImageEngine] implementation using Glide. * @author zhongjh */ - -public class GlideEngine implements ImageEngine { - - @Override - public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { +class GlideEngine : ImageEngine { + override fun loadThumbnail( + context: Context, + resize: Int, + placeholder: Drawable, + imageView: ImageView, + uri: Uri + ) { Glide.with(context) - .load(uri) - .asBitmap() // some .jpeg files are actually gif - .placeholder(placeholder) - .override(resize, resize) - .centerCrop() - .into(imageView); + .load(uri) + .asBitmap() // some .jpeg files are actually gif + .placeholder(placeholder) + .override(resize, resize) + .centerCrop() + .into(imageView) } - @Override - public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, - Uri uri) { + override fun loadGifThumbnail( + context: Context, resize: Int, placeholder: Drawable, imageView: ImageView, + uri: Uri + ) { Glide.with(context) - .load(uri) - .asBitmap() - .placeholder(placeholder) - .override(resize, resize) - .centerCrop() - .into(imageView); + .load(uri) + .asBitmap() + .placeholder(placeholder) + .override(resize, resize) + .centerCrop() + .into(imageView) } - @Override - public void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { + override fun loadImage( + context: Context, + resizeX: Int, + resizeY: Int, + imageView: ImageView, + uri: Uri + ) { Glide.with(context) - .load(uri) - .override(resizeX, resizeY) - .priority(Priority.HIGH) - .fitCenter() - .into(imageView); + .load(uri) + .override(resizeX, resizeY) + .priority(Priority.HIGH) + .fitCenter() + .into(imageView) } - @Override - public void loadUrlImage(Context context, ImageView imageView, String url) { + override fun loadUrlImage(context: Context, imageView: ImageView, url: String) { Glide.with(context) - .load(url) - .priority(Priority.HIGH) - .fitCenter() - .into(imageView); + .load(url) + .priority(Priority.HIGH) + .fitCenter() + .into(imageView) } - @Override - public void loadUriImage(Context context, ImageView imageView, Uri uri) { + override fun loadUriImage(context: Context, imageView: ImageView, uri: Uri) { Glide.with(context) - .load(uri) - .priority(Priority.HIGH) - .fitCenter() - .into(imageView); + .load(uri) + .priority(Priority.HIGH) + .fitCenter() + .into(imageView) } - @Override - public void loadDrawableImage(Context context, ImageView imageView,Integer resourceId) { + override fun loadDrawableImage(context: Context, imageView: ImageView, resourceId: Int) { Glide.with(context) - .load(resourceId) - .priority(Priority.HIGH) - .fitCenter() - .into(imageView); + .load(resourceId) + .priority(Priority.HIGH) + .fitCenter() + .into(imageView) } - @Override - public void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { + override fun loadGifImage( + context: Context, + resizeX: Int, + resizeY: Int, + imageView: ImageView, + uri: Uri + ) { Glide.with(context) - .load(uri) - .asGif() - .override(resizeX, resizeY) - .priority(Priority.HIGH) - .into(imageView); + .load(uri) + .asGif() + .override(resizeX, resizeY) + .priority(Priority.HIGH) + .into(imageView) } - @Override - public boolean supportAnimatedGif() { - return true; + override fun supportAnimatedGif(): Boolean { + return true } - -} +} \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/PicassoEngine.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/PicassoEngine.kt index feff91d5..47563eef 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/PicassoEngine.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/engine/impl/PicassoEngine.kt @@ -1,81 +1,75 @@ -/* - * Copyright 2017 Zhihu Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.zhongjh.albumcamerarecorder.album.engine.impl; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.widget.ImageView; - -import com.squareup.picasso.Picasso; -import com.zhongjh.albumcamerarecorder.album.engine.ImageEngine; +package com.zhongjh.albumcamerarecorder.album.engine.impl +import android.content.Context +import android.graphics.drawable.Drawable +import android.net.Uri +import android.widget.ImageView +import com.squareup.picasso.Picasso +import com.zhongjh.albumcamerarecorder.album.engine.ImageEngine /** - * {@link ImageEngine} implementation using Picasso. + * [ImageEngine] implementation using Picasso. * @author zhongjh */ -public class PicassoEngine implements ImageEngine { - - @Override - public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { +class PicassoEngine : ImageEngine { + + override fun loadThumbnail( + context: Context, + resize: Int, + placeholder: Drawable, + imageView: ImageView, + uri: Uri + ) { Picasso.with(context).load(uri).placeholder(placeholder) - .resize(resize, resize) - .centerCrop() - .into(imageView); + .resize(resize, resize) + .centerCrop() + .into(imageView) } - @Override - public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, - Uri uri) { - loadThumbnail(context, resize, placeholder, imageView, uri); + override fun loadGifThumbnail( + context: Context, resize: Int, placeholder: Drawable, imageView: ImageView, + uri: Uri + ) { + loadThumbnail(context, resize, placeholder, imageView, uri) } - @Override - public void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { + override fun loadImage( + context: Context, + resizeX: Int, + resizeY: Int, + imageView: ImageView, + uri: Uri + ) { Picasso.with(context).load(uri).resize(resizeX, resizeY).priority(Picasso.Priority.HIGH) - .centerInside().into(imageView); + .centerInside().into(imageView) } - @Override - public void loadUrlImage(Context context, ImageView imageView, String url) { + override fun loadUrlImage(context: Context, imageView: ImageView, url: String) { Picasso.with(context).load(url).priority(Picasso.Priority.HIGH) - .centerInside().into(imageView); + .centerInside().into(imageView) } - @Override - public void loadUriImage(Context context, ImageView imageView, Uri uri) { + override fun loadUriImage(context: Context, imageView: ImageView, uri: Uri) { Picasso.with(context).load(uri).priority(Picasso.Priority.HIGH) - .centerInside().into(imageView); + .centerInside().into(imageView) } - @Override - public void loadDrawableImage(Context context, ImageView imageView, Integer resourceId) { + override fun loadDrawableImage(context: Context, imageView: ImageView, resourceId: Int) { Picasso.with(context).load(resourceId).priority(Picasso.Priority.HIGH) - .centerInside().into(imageView); + .centerInside().into(imageView) } - @Override - public void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { - loadImage(context, resizeX, resizeY, imageView, uri); + override fun loadGifImage( + context: Context, + resizeX: Int, + resizeY: Int, + imageView: ImageView, + uri: Uri + ) { + loadImage(context, resizeX, resizeY, imageView, uri) } - @Override - public boolean supportAnimatedGif() { - return false; + override fun supportAnimatedGif(): Boolean { + return false } - -} +} \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt index dc2ec84f..5d01e565 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt @@ -1,139 +1,104 @@ -/* - * Copyright (C) 2014 nohana, Inc. - * Copyright 2017 Zhihu Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.zhongjh.albumcamerarecorder.album.entity; - -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.os.Parcel; -import android.os.Parcelable; +package com.zhongjh.albumcamerarecorder.album.entity -import androidx.annotation.NonNull; - -import com.zhongjh.albumcamerarecorder.R; -import com.zhongjh.albumcamerarecorder.album.loader.AlbumLoader; +import android.content.Context +import android.database.Cursor +import android.net.Uri +import android.os.Parcel +import android.os.Parcelable +import com.zhongjh.albumcamerarecorder.R +import com.zhongjh.albumcamerarecorder.album.loader.AlbumLoader /** * 专辑 * @author zhihu */ -public class Album implements Parcelable { - public static final Creator CREATOR = new Creator() { - @NonNull - @Override - public Album createFromParcel(Parcel source) { - return new Album(source); - } - - @Override - public Album[] newArray(int size) { - return new Album[size]; - } - }; - public static final String ALBUM_ID_ALL = String.valueOf(-1); - public static final String ALBUM_NAME_ALL = "All"; - - private final String mId; - private final Uri mCoverUri; - private final String mDisplayName; - private long mCount; - - Album(String id, Uri coverUri, String albumName, long count) { - mId = id; - mCoverUri = coverUri; - mDisplayName = albumName; - mCount = count; - } - - Album(Parcel source) { - mId = source.readString(); - mCoverUri = source.readParcelable(Uri.class.getClassLoader()); - mDisplayName = source.readString(); - mCount = source.readLong(); - } - - /** - * {@link Cursor} 构建一个新的实体 {@link Album} - * 此方法不负责管理光标资源,如关闭、迭代等。 - */ - public static Album valueOf(Cursor cursor) { - String column = cursor.getString(cursor.getColumnIndex(AlbumLoader.COLUMN_URI)); - return new Album( - cursor.getString(cursor.getColumnIndex("bucket_id")), - Uri.parse(column != null ? column : ""), - cursor.getString(cursor.getColumnIndex("bucket_display_name")), - cursor.getLong(cursor.getColumnIndex(AlbumLoader.COLUMN_COUNT))); +class Album : Parcelable { + + val id: String? + val coverUri: Uri? + private val displayName: String? + var count: Long + private set + + internal constructor(id: String?, coverUri: Uri?, albumName: String?, count: Long) { + this.id = id + this.coverUri = coverUri + displayName = albumName + this.count = count } - @Override - public int describeContents() { - return 0; + internal constructor(source: Parcel) { + id = source.readString() + coverUri = source.readParcelable(Uri::class.java.classLoader) + displayName = source.readString() + count = source.readLong() } - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(mId); - dest.writeParcelable(mCoverUri, 0); - dest.writeString(mDisplayName); - dest.writeLong(mCount); + override fun describeContents(): Int { + return 0 } - public String getId() { - return mId; - } - - public Uri getCoverUri() { - return mCoverUri; - } - - public long getCount() { - return mCount; + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeString(id) + dest.writeParcelable(coverUri, 0) + dest.writeString(displayName) + dest.writeLong(count) } /** * * 数量添加一个,目前是考虑如果有拍照功能,就数量+1 - * @deprecated 作废,拍照已经独立出来 */ - public void addCaptureCount() { - mCount++; + @Deprecated("作废,拍照已经独立出来", ReplaceWith("count++")) + fun addCaptureCount() { + count++ } /** * 显示名称,可能返回“全部” * @return 返回名称 */ - public String getDisplayName(Context context) { - if (isAll()) { - return context.getString(R.string.z_multi_library_album_name_all); - } - return mDisplayName; + fun getDisplayName(context: Context): String? { + return if (isAll) { + context.getString(R.string.z_multi_library_album_name_all) + } else displayName } /** * 判断如果id = -1的话,就是查询全部的意思 * @return 是否全部 */ - public boolean isAll() { - return ALBUM_ID_ALL.equals(mId); - } + val isAll: Boolean + get() = ALBUM_ID_ALL == id + val isEmpty: Boolean + get() = count == 0L - public boolean isEmpty() { - return mCount == 0; - } + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(source: Parcel): Album { + return Album(source) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + + const val ALBUM_ID_ALL: String = (-1).toString() + const val ALBUM_NAME_ALL = "All" + + /** + * [Cursor] 构建一个新的实体 [Album] + * 此方法不负责管理光标资源,如关闭、迭代等。 + */ + @JvmStatic + fun valueOf(cursor: Cursor): Album { + val column = cursor.getString(cursor.getColumnIndex(AlbumLoader.COLUMN_URI)) + return Album( + cursor.getString(cursor.getColumnIndex("bucket_id")), + Uri.parse(column ?: ""), + cursor.getString(cursor.getColumnIndex("bucket_display_name")), + cursor.getLong(cursor.getColumnIndex(AlbumLoader.COLUMN_COUNT)) + ) + } + } } \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/SelectedCountMessage.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/SelectedCountMessage.kt index 22fcf80b..24675810 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/SelectedCountMessage.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/SelectedCountMessage.kt @@ -1,50 +1,23 @@ -package com.zhongjh.albumcamerarecorder.album.entity; +package com.zhongjh.albumcamerarecorder.album.entity /** * 这是选择当前数据,如果最大值时展现相应信息 * @author zhongjh * @date 2021/7/15 */ -public class SelectedCountMessage { - +class SelectedCountMessage { /** * 是否已经最大值 */ - private boolean maxSelectableReached; + var isMaxSelectableReached = false /** * 类型 image、video、image_video */ - private String type; + lateinit var type: String /** * 最大的数量 */ - private int maxCount; - - public boolean isMaxSelectableReached() { - return maxSelectableReached; - } - - public void setMaxSelectableReached(boolean maxSelectableReached) { - this.maxSelectableReached = maxSelectableReached; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public int getMaxCount() { - return maxCount; - } - - public void setMaxCount(int maxCount) { - this.maxCount = maxCount; - } - - -} + var maxCount = 0 +} \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/filter/BaseFilter.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/filter/BaseFilter.kt index db60a10e..4d49ac25 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/filter/BaseFilter.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/filter/BaseFilter.kt @@ -1,53 +1,21 @@ -/* - * Copyright 2017 Zhihu Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.zhongjh.albumcamerarecorder.album.filter; - -import android.content.Context; +package com.zhongjh.albumcamerarecorder.album.filter -import com.zhongjh.common.entity.IncapableCause; -import com.zhongjh.common.entity.MultiMedia; -import com.zhongjh.common.enums.MimeType; - -import java.util.Set; +import android.content.Context +import com.zhongjh.common.entity.IncapableCause +import com.zhongjh.common.entity.MultiMedia +import com.zhongjh.common.enums.MimeType /** * Filter for choosing . You can add multiple Filters through * @author zhongjh */ -@SuppressWarnings("unused") -public abstract class BaseFilter { - /** - * Convenient constant for a minimum value. - */ - public static final int MIN = 0; - /** - * Convenient constant for a maximum value. - */ - public static final int MAX = Integer.MAX_VALUE; - /** - * Convenient constant for 1024. - */ - public static final int K = 1024; - +abstract class BaseFilter { /** * Against what mime types this filter applies. * 针对这个过滤器应用的mime类型。 * @return MimeType */ - protected abstract Set constraintTypes(); + protected abstract fun constraintTypes(): Set /** * Invoked for filtering each item. @@ -55,19 +23,28 @@ public abstract class BaseFilter { * 调用以过滤每个项。 * @param context 上下文 * @param item item - * @return null if selectable, {@link IncapableCause} if not selectable. + * @return null if selectable, [IncapableCause] if not selectable. */ - public abstract IncapableCause filter(Context context, MultiMedia item); + abstract fun filter(context: Context, item: MultiMedia): IncapableCause? /** - * Whether an {@link MultiMedia} need filtering. + * Whether an [MultiMedia] need filtering. */ - protected boolean needFiltering(Context context, MultiMedia item) { - for (MimeType type : constraintTypes()) { - if (type.checkType(context.getContentResolver(), item.getUri())) { - return true; + protected fun needFiltering(context: Context, item: MultiMedia): Boolean { + for (type in constraintTypes()) { + if (type.checkType(context.contentResolver, item.uri)) { + return true } } - return false; + return false + } + + + companion object { + + /** + * Convenient constant for 1024. + */ + const val K = 1024 } -} +} \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/listener/OnSelectedListener.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/listener/OnSelectedListener.kt index 5616ee93..19078f98 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/listener/OnSelectedListener.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/listener/OnSelectedListener.kt @@ -1,18 +1,3 @@ -/* - * Copyright 2017 Zhihu Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.zhongjh.albumcamerarecorder.album.listener import com.zhongjh.common.entity.LocalFile diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/model/SelectedItemCollection.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/model/SelectedItemCollection.java index 8318ccb1..6eaa1cbf 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/model/SelectedItemCollection.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/model/SelectedItemCollection.java @@ -339,21 +339,27 @@ public IncapableCause newIncapableCause(MultiMedia item, boolean maxSelectableRe private String getCause(int maxSelectable, boolean isMashup, String type) { String cause = ""; if (isMashup) { - if (type.equals(IMAGE_VIDEO)) { - cause = mContext.getResources().getString( - R.string.z_multi_library_error_over_count, - maxSelectable - ); - } else if (type.equals(IMAGE)) { - cause = mContext.getResources().getString( - R.string.z_multi_library_error_over_count_image, - maxSelectable - ); - } else if (type.equals(VIDEO)) { - cause = mContext.getResources().getString( - R.string.z_multi_library_error_over_count_video, - maxSelectable - ); + switch (type) { + case IMAGE_VIDEO: + cause = mContext.getResources().getString( + R.string.z_multi_library_error_over_count, + maxSelectable + ); + break; + case IMAGE: + cause = mContext.getResources().getString( + R.string.z_multi_library_error_over_count_image, + maxSelectable + ); + break; + case VIDEO: + cause = mContext.getResources().getString( + R.string.z_multi_library_error_over_count_video, + maxSelectable + ); + break; + default: + break; } } else { cause = mContext.getResources().getString( diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/utils/AlbumCompressFileTask.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/utils/AlbumCompressFileTask.kt index 3189e924..ecbb4f6d 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/utils/AlbumCompressFileTask.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/utils/AlbumCompressFileTask.kt @@ -1,122 +1,105 @@ -package com.zhongjh.albumcamerarecorder.album.utils; - -import android.content.Context; -import android.os.Build; -import android.util.Log; - -import com.zhongjh.albumcamerarecorder.camera.util.FileUtil; -import com.zhongjh.albumcamerarecorder.settings.GlobalSpec; -import com.zhongjh.common.entity.LocalFile; -import com.zhongjh.common.listener.VideoEditListener; -import com.zhongjh.common.utils.MediaStoreCompat; -import com.zhongjh.common.utils.UriUtils; - -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; +package com.zhongjh.albumcamerarecorder.album.utils + +import android.content.Context +import android.os.Build +import android.util.Log +import com.zhongjh.albumcamerarecorder.camera.util.FileUtil +import com.zhongjh.albumcamerarecorder.settings.GlobalSpec +import com.zhongjh.common.entity.LocalFile +import com.zhongjh.common.listener.VideoEditListener +import com.zhongjh.common.utils.MediaStoreCompat +import com.zhongjh.common.utils.UriUtils +import java.io.File +import java.io.IOException +import java.util.* /** * 这是相册界面和预览界面共用的一个异步线程逻辑 + * @param globalSpec 公共配置 + * @param pictureMediaStoreCompat 图片文件配置路径 + * @param videoMediaStoreCompat 录像文件配置路径 * * @author zhongjh * @date 2022/2/9 */ -public class AlbumCompressFileTask { - - private final Context mContext; - private final String mTag; - private final Class mClsKey; - /** - * 公共配置 - */ - private final GlobalSpec mGlobalSpec; - /** - * 图片文件配置路径 - */ - private final MediaStoreCompat mPictureMediaStoreCompat; - /** - * 录像文件配置路径 - */ - private final MediaStoreCompat mVideoMediaStoreCompat; - - public AlbumCompressFileTask(Context context, String tag, Class clsKey, GlobalSpec globalSpec, - MediaStoreCompat pictureMediaStoreCompat, MediaStoreCompat videoMediaStoreCompat) { - mContext = context; - mTag = tag; - mClsKey = clsKey; - mGlobalSpec = globalSpec; - mPictureMediaStoreCompat = pictureMediaStoreCompat; - mVideoMediaStoreCompat = videoMediaStoreCompat; - } - - public ArrayList compressFileTaskDoInBackground(ArrayList localFiles) { +class AlbumCompressFileTask( + private val context: Context, private val tag: String, private val clsKey: Class<*>, + private val globalSpec: GlobalSpec, + private val pictureMediaStoreCompat: MediaStoreCompat, + private val videoMediaStoreCompat: MediaStoreCompat +) { + fun compressFileTaskDoInBackground(localFiles: ArrayList): ArrayList { // 将 缓存文件 拷贝到 配置目录 - ArrayList newLocalFiles = new ArrayList<>(); - for (LocalFile item : localFiles) { + val newLocalFiles = ArrayList() + for (item in localFiles) { // 判断是否需要压缩 - LocalFile isCompressItem = isCompress(item); + val isCompressItem = isCompress(item) if (isCompressItem != null) { - newLocalFiles.add(isCompressItem); - continue; + newLocalFiles.add(isCompressItem) + continue } // 开始压缩逻辑,获取真实路径 - String path = getPath(item); - + val path = getPath(item) if (path != null) { - String newFileName = getNewFileName(item, path); - File newFile = getNewFile(item, path, newFileName); - + val newFileName = getNewFileName(item, path) + val newFile = getNewFile(item, path, newFileName) if (newFile.exists()) { - LocalFile localFile; - if (item.isImage()) { - localFile = new LocalFile(mContext, mPictureMediaStoreCompat, item, newFile); - } else { - localFile = new LocalFile(mContext, mVideoMediaStoreCompat, item, newFile); - } - newLocalFiles.add(localFile); - Log.d(mTag, "存在直接使用"); + val localFile: LocalFile = + if (item.isImage()) { + LocalFile(context, pictureMediaStoreCompat, item, newFile) + } else { + LocalFile(context, videoMediaStoreCompat, item, newFile) + } + newLocalFiles.add(localFile) + Log.d(tag, "存在直接使用") } else { if (item.isImage()) { // 处理是否压缩图片 - File compressionFile = handleImage(path); + val compressionFile = handleImage(path) // 移动到新的文件夹 - FileUtil.copy(compressionFile, newFile); - newLocalFiles.add(new LocalFile(mContext, mPictureMediaStoreCompat, item, newFile)); - Log.d(mTag, "不存在新建文件"); + FileUtil.copy(compressionFile, newFile) + newLocalFiles.add( + LocalFile( + context, + pictureMediaStoreCompat, + item, + newFile + ) + ) + Log.d(tag, "不存在新建文件") } else if (item.isVideo()) { - if (mGlobalSpec.isCompressEnable() && mGlobalSpec.getVideoCompressCoordinator() != null) { + if (globalSpec.isCompressEnable) { // 压缩视频 - mGlobalSpec.getVideoCompressCoordinator().setVideoCompressListener(mClsKey, new VideoEditListener() { - @Override - public void onFinish() { - LocalFile localFile = new LocalFile(mContext, mVideoMediaStoreCompat, item, newFile); - newLocalFiles.add(localFile); - Log.d(mTag, "不存在新建文件"); - } - - @Override - public void onProgress(int progress, long progressTime) { - } - - @Override - public void onCancel() { - - } - - @Override - public void onError(@NotNull String message) { - } - }); - mGlobalSpec.getVideoCompressCoordinator().compressAsync(mClsKey, path, newFile.getPath()); + globalSpec.videoCompressCoordinator?.setVideoCompressListener( + clsKey, + object : VideoEditListener { + override fun onFinish() { + val localFile = LocalFile( + context, + videoMediaStoreCompat, + item, + newFile + ) + newLocalFiles.add(localFile) + Log.d(tag, "不存在新建文件") + } + + override fun onProgress(progress: Int, progressTime: Long) {} + override fun onCancel() {} + override fun onError(message: String) {} + }) + globalSpec.videoCompressCoordinator?.compressAsync( + clsKey, + path, + newFile.path + ) } } } } } - return newLocalFiles; + return newLocalFiles } /** @@ -125,22 +108,23 @@ public class AlbumCompressFileTask { * @param path 图片真实路径 * @return 压缩后的文件 */ - public File handleImage(String path) { - File oldFile = new File(path); + fun handleImage(path: String): File { + val oldFile = File(path) // 根据类型压缩 - File compressionFile; - if (mGlobalSpec.getImageCompressionInterface() != null) { + var compressionFile: File + if (globalSpec.imageCompressionInterface != null) { // 压缩图片 try { - compressionFile = mGlobalSpec.getImageCompressionInterface().compressionFile(mContext, oldFile); - } catch (IOException e) { - compressionFile = oldFile; - e.printStackTrace(); + compressionFile = + globalSpec.imageCompressionInterface!!.compressionFile(context, oldFile) + } catch (e: IOException) { + compressionFile = oldFile + e.printStackTrace() } } else { - compressionFile = oldFile; + compressionFile = oldFile } - return compressionFile; + return compressionFile } /** @@ -148,16 +132,16 @@ public class AlbumCompressFileTask { * * @return 返回对象为null就需要压缩,否则不需要压缩 */ - public LocalFile isCompress(LocalFile item) { + fun isCompress(item: LocalFile): LocalFile? { // 判断是否需要压缩 - if (item.isVideo() && mGlobalSpec.getVideoCompressCoordinator() == null) { - return item; + return if (item.isVideo() && globalSpec.videoCompressCoordinator == null) { + item } else if (item.isGif()) { - return item; - } else if (item.isImage() && mGlobalSpec.getImageCompressionInterface() == null) { - return item; + item + } else if (item.isImage() && globalSpec.imageCompressionInterface == null) { + item } else { - return null; + null } } @@ -165,36 +149,36 @@ public class AlbumCompressFileTask { * 返回当前处理的LocalFile的真实路径 * * @param item 当前处理的LocalFile - * @return 真实路径 + * @return 真实路径,有可能因为转不成uri转不成file返回null */ - public String getPath(LocalFile item) { - String path = null; - if (item.getPath() == null) { - File file = UriUtils.uriToFile(mContext, item.getUri()); + fun getPath(item: LocalFile): String? { + var path: String? = null + if (item.path == null) { + val file = UriUtils.uriToFile(context, item.uri) if (file != null) { - path = file.getAbsolutePath(); + path = file.absolutePath } } else { - path = item.getPath(); + path = item.path } if (path != null) { // 判断是否Android 29 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // 29以上的版本都必须是私有的或者公共目录 - File cacheFile = null; + var cacheFile: File? = null if (item.isImage()) { - cacheFile = mPictureMediaStoreCompat.createFile(0, true, getNameSuffix(path)); + cacheFile = pictureMediaStoreCompat.createFile(0, true, getNameSuffix(path)) } else if (item.isVideo()) { - cacheFile = mVideoMediaStoreCompat.createFile(1, true, getNameSuffix(path)); + cacheFile = videoMediaStoreCompat.createFile(1, true, getNameSuffix(path)) } // >=29 的需要通过uri获取公共目录的文件,并且拷贝到私有目录 if (cacheFile != null) { - FileUtil.copy(mContext, item.getUri(), cacheFile); - path = cacheFile.getAbsolutePath(); + FileUtil.copy(context, item.uri, cacheFile) + path = cacheFile.absolutePath } } } - return path; + return path } /** @@ -204,32 +188,30 @@ public class AlbumCompressFileTask { * @param path 真实路径 * @return 返回迁移后的file的名称 */ - public String getNewFileName(LocalFile item, String path) { + fun getNewFileName(item: LocalFile, path: String): String { // 移动文件,获取文件名称 - String newFileName = path.substring(path.lastIndexOf(File.separator)); - - String[] newFileNames = newFileName.split("\\."); + var newFileName = path.substring(path.lastIndexOf(File.separator)) + val newFileNames = newFileName.split("\\.").toTypedArray() // 设置压缩后的照片名称,id_CMP - newFileName = item.getId() + "_CMP"; - if (newFileNames.length > 1) { + newFileName = item.id.toString() + "_CMP" + if (newFileNames.size > 1) { // 设置后缀名 - newFileName = newFileName + "." + newFileNames[1]; + newFileName = newFileName + "." + newFileNames[1] } - return newFileName; + return newFileName } /** * @return 获取后缀名 */ - public String getNameSuffix(String path) { + fun getNameSuffix(path: String): String { // 获取文件名称 - String newFileName = path.substring(path.lastIndexOf(File.separator)); - String[] newFileNames = newFileName.split("\\."); - if (newFileNames.length > 1) { + val newFileName = path.substring(path.lastIndexOf(File.separator)) + val newFileNames = newFileName.split("\\.").toTypedArray() + return if (newFileNames.size > 1) { // 返回后缀名 - return newFileNames[1]; - } - return ""; + newFileNames[1] + } else "" } /** @@ -240,16 +222,15 @@ public class AlbumCompressFileTask { * @param newFileName 迁移后的file的名称 * @return 返回迁移后的file */ - public File getNewFile(LocalFile item, String path, String newFileName) { - File newFile; - if (item.isImage()) { - newFile = mPictureMediaStoreCompat.fineFile(newFileName, 0, false); + fun getNewFile(item: LocalFile, path: String?, newFileName: String?): File { + val newFile: File + newFile = if (item.isImage()) { + pictureMediaStoreCompat.fineFile(newFileName!!, 0, false) } else if (item.isVideo()) { - newFile = mVideoMediaStoreCompat.fineFile(newFileName, 1, false); + videoMediaStoreCompat.fineFile(newFileName!!, 1, false) } else { - newFile = new File(path); + File(path) } - return newFile; + return newFile } - -} +} \ No newline at end of file diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraFragment.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraFragment.java index db6aa5e2..5d9c425c 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraFragment.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/camera/CameraFragment.java @@ -289,7 +289,7 @@ public void captureSuccess(ArrayList localFiles) { private void initCameraLayoutCaptureListener() { mCameraLayout.setCaptureListener(new CaptureListener() { @Override - public void remove(List captureData) { + public void remove(@NotNull List captureData) { // 判断如果删除光图片的时候,母窗体启动滑动 if (captureData.size() <= 0) { mActivity.showHideTableLayout(true); @@ -297,7 +297,7 @@ public void remove(List captureData) { } @Override - public void add(List captureDatas) { + public void add(@NotNull List captureDatas) { if (captureDatas.size() > 0) { // 母窗体禁止滑动 mActivity.showHideTableLayout(false); diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/listener/OnResultCallbackListener.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/listener/OnResultCallbackListener.kt index 433e0623..5fa9eaba 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/listener/OnResultCallbackListener.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/listener/OnResultCallbackListener.kt @@ -15,7 +15,7 @@ interface OnResultCallbackListener { * * @param result 控件返回的相关数据 */ - fun onResult(result: List?) + fun onResult(result: List) /** * return LocalMedia result @@ -23,5 +23,5 @@ interface OnResultCallbackListener { * @param result 控件返回的相关数据,跟九宫格挂钩 * @param apply 是否预览界面点击了同意 */ - fun onResultFromPreview(result: List?, apply: Boolean) + fun onResultFromPreview(result: List, apply: Boolean) } \ No newline at end of file