diff --git a/app/build.gradle b/app/build.gradle index 7a6984e..82e7456 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,8 +18,8 @@ android { //There are no CERT files because If the mini sdk version is 23+, the AGP will ignore the V1 scheme signature. minSdkVersion 23 targetSdkVersion 29 - versionCode 14 - versionName "1.1.3" + versionCode 16 + versionName "1.1.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryActivity.java b/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryActivity.java index 089fae2..dff26c3 100644 --- a/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryActivity.java +++ b/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryActivity.java @@ -1,18 +1,20 @@ package com.hainaos.vc.activity.category.local; import android.content.Intent; +import android.os.Build; import android.text.TextUtils; import android.view.View; +import androidx.annotation.RequiresApi; import androidx.lifecycle.Observer; import androidx.recyclerview.widget.DefaultItemAnimator; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.hainaos.vc.R; import com.hainaos.vc.adapter.VideoAdapter; import com.hainaos.vc.base.mvvm.BaseMvvmActivity; import com.hainaos.vc.bean.BaseResponse; import com.hainaos.vc.bean.CategoryInfo; +import com.hainaos.vc.bean.CategoryVideoInfo; import com.hainaos.vc.bean.LocalVideoInfo; import com.hainaos.vc.bean.VideoListData; import com.hainaos.vc.databinding.ActivityCategoryLocalBinding; @@ -27,6 +29,9 @@ import com.hjq.toast.Toaster; import java.io.File; import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class LocalCategoryActivity extends BaseMvvmActivity { private static final String TAG = "LocalCategoryActivity"; @@ -72,13 +77,13 @@ public class LocalCategoryActivity extends BaseMvvmActivity>() { + @RequiresApi(api = Build.VERSION_CODES.N) @Override public void onChanged(BaseResponse baseResponse) { if (baseResponse.code == 200) { + List categoryVideoInfos = baseResponse.data.getData(); + Map coverMap = categoryVideoInfos.stream().collect(Collectors.toMap(categoryVideoInfo -> FileUtils.getFileNamefromURL(categoryVideoInfo.getFile_url()), CategoryVideoInfo::getCover)); + mVideoAdapter.setCoverMap(coverMap); mViewModel.getVideoList(mCategoryInfo.getFolder()); } else { Toaster.show("密码错误,请重新输入"); diff --git a/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryViewModel.java b/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryViewModel.java index 71556f2..ec4572f 100644 --- a/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryViewModel.java +++ b/app/src/main/java/com/hainaos/vc/activity/category/local/LocalCategoryViewModel.java @@ -34,7 +34,7 @@ import wseemann.media.FFmpegMediaMetadataRetriever; public class LocalCategoryViewModel extends BaseViewModel { - private static final String TAG = "CategoryViewModel"; + private static final String TAG = "LocalCategoryViewModel"; @Override public ActivityCategoryLocalBinding getVDBinding() { @@ -113,19 +113,23 @@ public class LocalCategoryViewModel extends BaseViewModel { private static final String TAG = "CategoryActivity"; + private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE); + + private CategoryInfo mCategoryInfo; private String mPasswd = ""; private CategoryVideoAdapter mCategoryVideoAdapter; @@ -114,6 +119,7 @@ public class CategoryVideoActivity extends BaseMvvmActivity categoryVideoInfos = videoListData.getData(); mCategoryVideoAdapter.setData(categoryVideoInfos); + if (categoryVideoInfos == null || categoryVideoInfos.isEmpty()) { mViewDataBinding.clNodata.setVisibility(View.VISIBLE); mViewDataBinding.rvVideo.setVisibility(View.GONE); diff --git a/app/src/main/java/com/hainaos/vc/activity/category/online/CategoryVideoViewModel.java b/app/src/main/java/com/hainaos/vc/activity/category/online/CategoryVideoViewModel.java index 6c6e474..63c2a22 100644 --- a/app/src/main/java/com/hainaos/vc/activity/category/online/CategoryVideoViewModel.java +++ b/app/src/main/java/com/hainaos/vc/activity/category/online/CategoryVideoViewModel.java @@ -27,7 +27,7 @@ import io.reactivex.rxjava3.disposables.Disposable; public class CategoryVideoViewModel extends BaseViewModel { - private static final String TAG = "CategoryViewModel"; + private static final String TAG = "CategoryVideoViewModel"; @Override public ActivityCategoryVideoBinding getVDBinding() { diff --git a/app/src/main/java/com/hainaos/vc/activity/player/DecryptionPlayerActivity.java b/app/src/main/java/com/hainaos/vc/activity/player/DecryptionPlayerActivity.java index 3ce3987..7cd423a 100644 --- a/app/src/main/java/com/hainaos/vc/activity/player/DecryptionPlayerActivity.java +++ b/app/src/main/java/com/hainaos/vc/activity/player/DecryptionPlayerActivity.java @@ -3,6 +3,7 @@ package com.hainaos.vc.activity.player; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; +import android.util.Log; import android.view.View; import com.google.android.exoplayer2.ExoPlayer; @@ -75,6 +76,7 @@ public class DecryptionPlayerActivity extends BaseMvvmActivity { private static final String TAG = "VideoAdapter"; + + private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE); + + private Activity mContext; private ArrayList mLocalVideoInfos; private onItemLongClickListener onItemLongClickListener; + private Map mCoverMap; + public VideoAdapter() { } @@ -49,6 +62,11 @@ public class VideoAdapter extends RecyclerView.Adapter this.mLocalVideoInfos = path; } + public void setCoverMap(Map coverMap) { + mCoverMap = coverMap; + notifyDataSetChanged(); + } + private static class VideoResult { long time; Bitmap frame; @@ -72,6 +90,7 @@ public class VideoAdapter extends RecyclerView.Adapter @NonNull @Override public VideoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Aria.download(this).register(); VideoHolder holder = new VideoHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_video_file, parent, false)); return holder; } @@ -81,16 +100,40 @@ public class VideoAdapter extends RecyclerView.Adapter LocalVideoInfo localVideoInfo = mLocalVideoInfos.get(position); final String localPath = localVideoInfo.getLocalPath(); Log.e(TAG, "onBindViewHolder: " + localPath); - holder.title.setText(FileUtils.getFileName(localPath)); + String videoFileName = FileUtils.getFileName(localPath); + holder.title.setText(videoFileName); File file = new File(localPath); if (file.exists()) { holder.iv_status.setVisibility(View.GONE); - Glide.with(mContext).load(file).error(R.mipmap.ic_launcher).into(holder.video_image); - holder.duration.setText(TimeUtils.TimeFormat(localVideoInfo.getDuration() * 1000)); + if (file.getName().endsWith(".hnv")) { + String dirPaht = file.getParent(); + Log.e(TAG, "onBindViewHolder: dirPaht = " + dirPaht); + if (mCoverMap != null) { + String coverUrl = mCoverMap.get(videoFileName); + Log.e(TAG, "onBindViewHolder: coverUrl = " + coverUrl); + if (!TextUtils.isEmpty(coverUrl)) { + String coverName = FileUtils.getFileNamefromURL(coverUrl); + Log.e(TAG, "onBindViewHolder: coverName = " + coverName); + File coverFile = new File(dirPaht + File.separator + coverName); + Log.e(TAG, "onBindViewHolder: coverFile = " + coverFile.getAbsolutePath()); + if (coverFile.exists()) { + Glide.with(mContext).load(coverFile).centerCrop().error(R.drawable.picture_split).into(holder.video_image); + } else { + FileUtils.ariaDownloadCover(mContext, coverFile.getParent(), coverUrl); + } + } else { + holder.video_image.setImageDrawable(mContext.getDrawable(R.drawable.picture_split)); + } + } else { + holder.video_image.setImageDrawable(mContext.getDrawable(R.drawable.picture_split)); + } + } else { + Glide.with(mContext).load(file).centerCrop().error(R.drawable.picture_split).into(holder.video_image); + holder.duration.setText(TimeUtils.TimeFormat(localVideoInfo.getDuration() * 1000)); + } } else { holder.iv_status.setVisibility(View.VISIBLE); - } holder.iv_status.setOnClickListener(new View.OnClickListener() { @@ -194,4 +237,29 @@ public class VideoAdapter extends RecyclerView.Adapter void onScanCompleted(Bitmap bitmap); } + //在这里处理任务执行中的状态,如进度进度条的刷新 + @Download.onTaskRunning + void running(DownloadTask task) { + Log.e(TAG, "running: " + "正在下载:" + task.getState() + "-" + task.getPercent() + "--" + task.getExtendField()); + + notifyDataSetChanged(); + } + + @Download.onTaskComplete + void taskComplete(DownloadTask task) { + //在这里处理任务完成的状态 + Log.e(TAG, "taskComplete: " + task.getFilePath()); + notifyDataSetChanged(); + } + + @Download.onTaskFail + void taskFail(DownloadTask task, Exception e) { + try { + Log.e(TAG, "taskFail: e " + e.getMessage()); + } catch (Exception ex) { + Log.e(TAG, "taskFail: ex " + ex.getMessage()); + } + + notifyDataSetChanged(); + } } diff --git a/app/src/main/java/com/hainaos/vc/network/NetInterfaceManager.java b/app/src/main/java/com/hainaos/vc/network/NetInterfaceManager.java index 6a25de6..e76b6a7 100644 --- a/app/src/main/java/com/hainaos/vc/network/NetInterfaceManager.java +++ b/app/src/main/java/com/hainaos/vc/network/NetInterfaceManager.java @@ -243,7 +243,7 @@ public class NetInterfaceManager { public Observable> getVideoListObservable(String category_uuid, String password) { String bearerToken = LoginUtils.getInstance().getBearerToken(); return getVideoApi() - .getVideoList(bearerToken, category_uuid, password) + .getVideoList(bearerToken, category_uuid, password, 20) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } diff --git a/app/src/main/java/com/hainaos/vc/network/api/VideoApi.java b/app/src/main/java/com/hainaos/vc/network/api/VideoApi.java index cea34e7..40de544 100644 --- a/app/src/main/java/com/hainaos/vc/network/api/VideoApi.java +++ b/app/src/main/java/com/hainaos/vc/network/api/VideoApi.java @@ -24,7 +24,8 @@ public interface VideoApi { Observable> getVideoList( @Header("Authorization") String token, @Query("category_uuid") String category_uuid, - @Query("password") String password + @Query("password") String password, + @Query("page_size") int page_size ); @FormUrlEncoded diff --git a/app/src/main/java/com/hainaos/vc/utils/FileUtils.java b/app/src/main/java/com/hainaos/vc/utils/FileUtils.java index a19961b..d779b56 100644 --- a/app/src/main/java/com/hainaos/vc/utils/FileUtils.java +++ b/app/src/main/java/com/hainaos/vc/utils/FileUtils.java @@ -160,6 +160,45 @@ public class FileUtils { } } + public static void ariaDownload(Context context, String dirName, String url) { + String downLoadPath = getHainaVideoPath(context) + dirName + File.separator; + File dirFile = new File(downLoadPath); + if (!dirFile.exists()) { + Log.e(TAG, "ariaDownload: mkdirs = " + dirFile.mkdirs()); + } + String fileName = getFileNamefromURL(url); + File file = new File(downLoadPath + fileName); + if (file.exists() && !file.isDirectory()) { + Log.e("ariaDownload", url + " pic exists, skip"); + } else { + Aria.download(context) + .load(url) //读取下载地址 + .setFilePath(file.getAbsolutePath()) +// .ignoreFilePathOccupy() + .setExtendField(url) + .create(); //启动下载} + } + } + + public static void ariaDownloadCover(Context context, String coverPath, String url) { + File dirFile = new File(coverPath); + if (!dirFile.exists()) { + Log.e(TAG, "ariaDownload: mkdirs = " + dirFile.mkdirs()); + } + String fileName = getFileNamefromURL(url); + File file = new File(coverPath + File.separator + fileName); + if (file.exists() && !file.isDirectory()) { + Log.e("ariaDownload", url + " pic exists, skip"); + } else { + Aria.download(context) + .load(url) //读取下载地址 + .setFilePath(file.getAbsolutePath()) +// .ignoreFilePathOccupy() + .setExtendField(url) + .create(); //启动下载} + } + } + public static void ariaDownload(Context context, String url, AppInfo appInfo) { Log.e(TAG, "ariaDownload: " + appInfo); AriaDownloadInfo ariaDownloadInfo = AriaDownloadInfo.toAriaDownloadInfo(appInfo); diff --git a/app/src/main/res/drawable-hdpi/picture_split.png b/app/src/main/res/drawable-hdpi/picture_split.png new file mode 100644 index 0000000..8a95223 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/picture_split.png differ diff --git a/app/src/main/res/layout/activity_category_local.xml b/app/src/main/res/layout/activity_category_local.xml index 7dc3b27..078592a 100644 --- a/app/src/main/res/layout/activity_category_local.xml +++ b/app/src/main/res/layout/activity_category_local.xml @@ -71,10 +71,10 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/cl_title"> - + + + + - + diff --git a/app/src/main/res/layout/item_video_file.xml b/app/src/main/res/layout/item_video_file.xml index c3f4cab..9d28862 100644 --- a/app/src/main/res/layout/item_video_file.xml +++ b/app/src/main/res/layout/item_video_file.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" - android:scaleType="centerCrop" + android:scaleType="centerInside" app:is_cover_src="true" />