|
|
@@ -10,6 +10,7 @@ import com.atmob.common.runtime.ContextUtil;
|
|
|
import com.datarecovery.master.R;
|
|
|
import com.datarecovery.master.utils.BoxingUtil;
|
|
|
import com.datarecovery.master.utils.FileUtil;
|
|
|
+import com.datarecovery.master.utils.FilesSearch;
|
|
|
import com.datarecovery.master.utils.ImageDeepDetector;
|
|
|
import com.datarecovery.master.utils.MediaStoreHelper;
|
|
|
import com.datarecovery.master.utils.ToastUtil;
|
|
|
@@ -26,7 +27,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel;
|
|
|
@HiltViewModel
|
|
|
public class PreviewViewModel extends BaseViewModel {
|
|
|
|
|
|
- public static WeakReference<List<ImageDeepDetector.ImageFile>> weakReference;
|
|
|
+ public static WeakReference<?> weakReference;
|
|
|
private final MutableLiveData<String> title = new MutableLiveData<>();
|
|
|
private final MutableLiveData<Uri> previewUri = new MutableLiveData<>();
|
|
|
private final MutableLiveData<Boolean> isPlaying = new MutableLiveData<>();
|
|
|
@@ -36,6 +37,7 @@ public class PreviewViewModel extends BaseViewModel {
|
|
|
|
|
|
private final MutableLiveData<Boolean> isPlayStart = new MutableLiveData<>();
|
|
|
private final MutableLiveData<ImageDeepDetector.ImageFile> currentImageFile = new MutableLiveData<>();
|
|
|
+ private FilesSearch.DocumentFile currentFileFile;
|
|
|
private int position;
|
|
|
|
|
|
|
|
|
@@ -85,22 +87,55 @@ public class PreviewViewModel extends BaseViewModel {
|
|
|
this.position = position;
|
|
|
switch (type) {
|
|
|
case PreviewActivity.TYPE_AUDIO:
|
|
|
- title.setValue(ContextUtil.getContext().getString(R.string.preview_audio));
|
|
|
+ dealAudioInit();
|
|
|
break;
|
|
|
case PreviewActivity.TYPE_IMG:
|
|
|
dealImageInit();
|
|
|
break;
|
|
|
case PreviewActivity.TYPE_VIDEO:
|
|
|
- title.setValue(ContextUtil.getContext().getString(R.string.preview_video));
|
|
|
+ dealVideoInit();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void dealVideoInit() {
|
|
|
+ title.setValue(ContextUtil.getContext().getString(R.string.preview_video));
|
|
|
+ if (weakReference != null) {
|
|
|
+ this.currentFileFile = (FilesSearch.DocumentFile) weakReference.get();
|
|
|
+ setUri(currentFileFile.getUri());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dealAudioInit() {
|
|
|
+ title.setValue(ContextUtil.getContext().getString(R.string.preview_audio));
|
|
|
+ if (weakReference != null) {
|
|
|
+ this.currentFileFile = (FilesSearch.DocumentFile) weakReference.get();
|
|
|
+ setUri(currentFileFile.getUri());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Uri getUri() {
|
|
|
+ if (type == PreviewActivity.TYPE_IMG) {
|
|
|
+ ImageDeepDetector.ImageFile value = currentImageFile.getValue();
|
|
|
+ if (value != null) {
|
|
|
+ return value.getUri();
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if (type == PreviewActivity.TYPE_AUDIO || type == PreviewActivity.TYPE_VIDEO) {
|
|
|
+ if (currentFileFile != null) {
|
|
|
+ return currentFileFile.getUri();
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
private void dealImageInit() {
|
|
|
title.setValue(ContextUtil.getContext().getString(R.string.preview_img));
|
|
|
if (weakReference != null) {
|
|
|
- this.imagePreviewList = weakReference.get();
|
|
|
+ this.imagePreviewList = (List<ImageDeepDetector.ImageFile>) weakReference.get();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -134,9 +169,12 @@ public class PreviewViewModel extends BaseViewModel {
|
|
|
if (value == null) {
|
|
|
return false;
|
|
|
}
|
|
|
- MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_IMAGE, value.newInputStream(), FileUtil.getCreateFileName(value.getName(), ".jpg"));
|
|
|
+ MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_IMAGE, value.newInputStream(), FileUtil.getExportImageFileName(value.getName()));
|
|
|
} else if (type == PreviewActivity.TYPE_AUDIO) {
|
|
|
-// MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_AUDIO, item.newInputStream(), FileUtil.getCreateFileName(item.getName(), ""));
|
|
|
+ if (currentFileFile == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ MediaStoreHelper.saveToSharedStorage(MediaStoreHelper.TYPE_AUDIO, currentFileFile.newInputStream(), FileUtil.getCreateFileName(currentFileFile.getName(), ""));
|
|
|
}
|
|
|
return true;
|
|
|
}
|