|
|
@@ -1,5 +1,6 @@
|
|
|
package com.datarecovery.master.module.preview;
|
|
|
|
|
|
+
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
@@ -11,10 +12,16 @@ import android.view.SurfaceHolder;
|
|
|
import androidx.annotation.IntDef;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
+import androidx.viewpager2.widget.ViewPager2;
|
|
|
|
|
|
import com.atmob.app.lib.base.BaseActivity;
|
|
|
import com.datarecovery.master.databinding.ActivityPreviewBinding;
|
|
|
+import com.datarecovery.master.utils.ImageDeepDetector;
|
|
|
import com.datarecovery.master.utils.SafeMediaPlayer;
|
|
|
+import com.gyf.immersionbar.ImmersionBar;
|
|
|
+
|
|
|
+import java.lang.ref.WeakReference;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint;
|
|
|
|
|
|
@@ -28,10 +35,25 @@ public class PreviewActivity extends BaseActivity<ActivityPreviewBinding> {
|
|
|
private MediaPlayer mediaPlayer;
|
|
|
private boolean isSurfaceCreated;
|
|
|
|
|
|
+ private PreviewImagePagerAdapter imagePagerAdapter;
|
|
|
+ private ViewPager2.OnPageChangeCallback onPageChangeCallback;
|
|
|
+
|
|
|
@IntDef({TYPE_IMG, TYPE_VIDEO, TYPE_AUDIO})
|
|
|
@interface Type {
|
|
|
}
|
|
|
|
|
|
+ public static void startImagePreView(Context context, List<ImageDeepDetector.ImageFile> imageFileList, int position) {
|
|
|
+ Intent intent = new Intent(context, PreviewActivity.class);
|
|
|
+ intent.putExtra("type", TYPE_IMG);
|
|
|
+ intent.putExtra("position", position);
|
|
|
+ PreviewViewModel.weakReference = new WeakReference<>(imageFileList);
|
|
|
+ if (!(context instanceof Activity)) {
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ }
|
|
|
+ context.startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static void start(Context context, @Type int type, Uri uri) {
|
|
|
Intent intent = new Intent(context, PreviewActivity.class);
|
|
|
intent.putExtra("type", type);
|
|
|
@@ -48,6 +70,11 @@ public class PreviewActivity extends BaseActivity<ActivityPreviewBinding> {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ protected void configImmersion(@NonNull ImmersionBar immersionBar) {
|
|
|
+ immersionBar.statusBarDarkFont(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
protected void initViewModel() {
|
|
|
previewViewModel = getViewModelProvider().get(PreviewViewModel.class);
|
|
|
binding.setPreviewViewModel(previewViewModel);
|
|
|
@@ -58,18 +85,28 @@ public class PreviewActivity extends BaseActivity<ActivityPreviewBinding> {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
initView();
|
|
|
initIntentData();
|
|
|
+ initObserver();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initObserver() {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void initIntentData() {
|
|
|
int type = getIntent().getIntExtra("type", 0);
|
|
|
- Uri uri = getIntent().getParcelableExtra("uri");
|
|
|
- previewViewModel.setPreviewData(type, uri);
|
|
|
-
|
|
|
- if (type == TYPE_VIDEO || type == TYPE_AUDIO) {
|
|
|
- initMediaPlayer(uri);
|
|
|
- }
|
|
|
- if (type == TYPE_VIDEO) {
|
|
|
- initSurfaceView();
|
|
|
+ int position = getIntent().getIntExtra("position", 0);
|
|
|
+ previewViewModel.setPreviewData(type, position);
|
|
|
+ if (type == TYPE_IMG) {
|
|
|
+ initImagePreviewPager();
|
|
|
+ } else {
|
|
|
+ Uri uri = getIntent().getParcelableExtra("uri");
|
|
|
+ previewViewModel.setUri(uri);
|
|
|
+ if (type == TYPE_VIDEO || type == TYPE_AUDIO) {
|
|
|
+ initMediaPlayer(uri);
|
|
|
+ }
|
|
|
+ if (type == TYPE_VIDEO) {
|
|
|
+ initSurfaceView();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -77,6 +114,19 @@ public class PreviewActivity extends BaseActivity<ActivityPreviewBinding> {
|
|
|
addTopStatusBarHeight(binding.previewHeader);
|
|
|
}
|
|
|
|
|
|
+ private void initImagePreviewPager() {
|
|
|
+ imagePagerAdapter = new PreviewImagePagerAdapter(previewViewModel.getImagePreviewList());
|
|
|
+ binding.previewViewPager.setAdapter(imagePagerAdapter);
|
|
|
+ onPageChangeCallback = new ViewPager2.OnPageChangeCallback() {
|
|
|
+ @Override
|
|
|
+ public void onPageSelected(int position) {
|
|
|
+ previewViewModel.setPosition(position);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ binding.previewViewPager.registerOnPageChangeCallback(onPageChangeCallback);
|
|
|
+ binding.previewViewPager.setCurrentItem(previewViewModel.getPosition(), false);
|
|
|
+ }
|
|
|
+
|
|
|
private void initSurfaceView() {
|
|
|
SurfaceHolder holder = binding.previewVideo.getHolder();
|
|
|
holder.addCallback(new SurfaceHolder.Callback() {
|
|
|
@@ -109,4 +159,10 @@ public class PreviewActivity extends BaseActivity<ActivityPreviewBinding> {
|
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ binding.previewViewPager.unregisterOnPageChangeCallback(onPageChangeCallback);
|
|
|
+ }
|
|
|
}
|