Skip to content

Commit

Permalink
di ImageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerInk committed Aug 2, 2021
1 parent 23110b7 commit c05f29a
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 46 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/freed/ActivityAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import freed.utils.HideNavBarHelper;
import freed.utils.Log;
import freed.utils.PermissionManager;
import hilt.ImageManagerEntryPoint;
import hilt.PermissionManagerEntryPoint;

/**
Expand Down Expand Up @@ -69,7 +70,7 @@ public static PermissionManager permissionManager()
PermissionManager permissionManager;
@Inject
public SettingsManager settingsManager;

@Inject protected ImageManager imageManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -101,13 +102,12 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
ImageManager.getInstance(); // init it
}

@Override
protected void onDestroy() {
ImageManager.cancelImageSaveTasks();
ImageManager.cancelImageLoadTasks();
imageManager.cancelImageSaveTasks();
imageManager.cancelImageLoadTasks();
settingsManager.release();
context = null;
super.onDestroy();
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/freed/FreedApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import dagger.hilt.android.EntryPointAccessors;
import dagger.hilt.android.HiltAndroidApp;
import freed.file.FileListController;
import freed.image.ImageManager;
import freed.settings.SettingsManager;
import freed.viewer.helper.BitmapHelper;
import hilt.BitmapHelperEntryPoint;
import hilt.FileListControllerEntryPoint;
import hilt.ImageManagerEntryPoint;
import hilt.SettingsManagerEntryPoint;

@HiltAndroidApp
Expand Down Expand Up @@ -47,6 +49,11 @@ public static BitmapHelper bitmapHelper()
return getEntryPointFromApplication(BitmapHelperEntryPoint.class).bitmapHelper();
}

public static ImageManager imageManager()
{
return getEntryPointFromApplication(ImageManagerEntryPoint.class).imageManager();
}

public static <T> T getEntryPointFromApplication(Class<T> entryPoint) {
return EntryPointAccessors.fromApplication(context, entryPoint);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/freed/cam/ActivityFreeDcamMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void run() {
SetNightOverlay();
if (!FileListController.needStorageAccessFrameWork) {
if (permissionManager.isPermissionGranted(PermissionManager.Permissions.SdCard) && (fileListController.getFiles() == null || fileListController.getFiles().size() == 0))
ImageManager.putImageLoadTask(new LoadFreeDcamDcimDirsFilesRunner());
imageManager.putImageLoadTask(new LoadFreeDcamDcimDirsFilesRunner());
}
else
{
if (fileListController.getFiles() == null || fileListController.getFiles().size() == 0)
ImageManager.putImageLoadTask(new LoadFreeDcamDcimDirsFilesRunner());
imageManager.putImageLoadTask(new LoadFreeDcamDcimDirsFilesRunner());
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Date;
import java.util.List;

import freed.ActivityAbstract;
import freed.FreedApplication;
import freed.cam.ActivityFreeDcamMain;
import freed.cam.apis.basecamera.CameraThreadHandler;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class PictureModule extends ModuleAbstract<Camera1> implements Camera.Pic
protected long startcapturetime;
private boolean isBurstCapture = false;
protected PreviewController previewController;
protected ImageManager imageManager;


public PictureModule(Camera1 cameraUiWrapper, Handler mBackgroundHandler, Handler mainHandler)
Expand All @@ -76,6 +78,7 @@ public PictureModule(Camera1 cameraUiWrapper, Handler mBackgroundHandler, Handle
name = FreedApplication.getStringFromRessources(R.string.module_picture);
this.cameraHolder = cameraUiWrapper.getCameraHolder();
previewController = ActivityFreeDcamMain.previewController();
imageManager = FreedApplication.imageManager();
}

@Override
Expand Down Expand Up @@ -336,7 +339,7 @@ protected void saveJpeg(byte[] data, File file)
ImageSaveTask task = new ImageSaveTask(this);
task.setBytesTosave(data,ImageSaveTask.JPEG);
task.setFilePath(file, settingsManager.GetWriteExternal());
ImageManager.putImageSaveTask(task);
imageManager.putImageSaveTask(task);
}

protected void saveDng(byte[] data, File file)
Expand Down Expand Up @@ -385,6 +388,6 @@ protected void saveDng(byte[] data, File file)
task.setBytesTosave(data,ImageSaveTask.RAW10);
if (!settingsManager.getGlobal(SettingKeys.LOCATION_MODE).get().equals(FreedApplication.getStringFromRessources(R.string.off_)))
task.setLocation(locationManager.getCurrentLocation());
ImageManager.putImageSaveTask(task);
imageManager.putImageSaveTask(task);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.ArrayList;
import java.util.List;

import freed.ActivityAbstract;
import freed.FreedApplication;
import freed.cam.apis.camera2.modules.helper.RdyToSaveImg;
import freed.image.EmptyTask;
import freed.image.ImageManager;
Expand All @@ -23,11 +25,13 @@ public class CaptureController extends CameraCaptureSession.CaptureCallback
private final String TAG = CaptureController.class.getSimpleName();
private List<StillImageCapture> imageCaptures;
private RdyToSaveImg rdyToSaveImg;
protected ImageManager imageManager;

public CaptureController(RdyToSaveImg rdyToSaveImg)
{
imageCaptures = new ArrayList<>();
this.rdyToSaveImg = rdyToSaveImg;
imageManager = FreedApplication.imageManager();
}

public List<StillImageCapture> getImageCaptures() {
Expand Down Expand Up @@ -64,7 +68,7 @@ public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest requ
ImageTask task = imageCapture.getSaveTask();
imageCapture.resetTask();
if (task != null && !(task instanceof EmptyTask)) {
ImageManager.putImageSaveTask(task);
imageManager.putImageSaveTask(task);
Log.d(TAG, "Put task to Queue");
}
}
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/freed/cam/apis/sonyremote/CameraHolderSony.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.io.IOException;
import java.util.Set;

import freed.ActivityAbstract;
import freed.FreedApplication;
import freed.cam.apis.basecamera.CameraHolderAbstract;
import freed.cam.apis.basecamera.CameraWrapperInterface;
import freed.cam.apis.basecamera.FocusEvents;
Expand Down Expand Up @@ -76,12 +78,14 @@ public interface I_CameraShotMode

private SimpleRemoteApi mRemoteApi;
private PreviewStreamDrawer mLiveviewSurface;
private ImageManager imageManager;

public CameraHolderSony(Context context, PreviewStreamDrawer simpleStreamSurfaceView, CameraWrapperInterface cameraUiWrapper)
{
super(cameraUiWrapper);
this.context = context;
mLiveviewSurface = simpleStreamSurfaceView;
imageManager = FreedApplication.imageManager();
}

public void setRemoteApi(SimpleRemoteApi remoteApi)
Expand Down Expand Up @@ -135,7 +139,7 @@ public void StartPreview()
@Override
public void StopPreview()
{
ImageManager.putImageLoadTask(new StopPreviewRunner(mRemoteApi));
imageManager.putImageLoadTask(new StopPreviewRunner(mRemoteApi));
}

/**
Expand Down Expand Up @@ -181,33 +185,33 @@ private void closeConnection() {

public void TakePicture(I_PictureCallback pictureCallback)
{
ImageManager.putImageLoadTask(new ActTakePictureRunner(mRemoteApi,pictureCallback,((ParameterHandler)cameraUiWrapper.getParameterHandler())));
imageManager.putImageLoadTask(new ActTakePictureRunner(mRemoteApi,pictureCallback,((ParameterHandler)cameraUiWrapper.getParameterHandler())));
}

public void startContShoot(I_PictureCallback pictureCallback)
{
ImageManager.putImageLoadTask(new StartContShotRunner(mRemoteApi));
imageManager.putImageLoadTask(new StartContShotRunner(mRemoteApi));
}

public void stopContShoot(I_PictureCallback pictureCallback)
{
ImageManager.putImageLoadTask(new StopContShotRunner(mRemoteApi));
imageManager.putImageLoadTask(new StopContShotRunner(mRemoteApi));
}

public void startBulbCapture(I_PictureCallback pictureCallback)
{
ImageManager.putImageLoadTask(new StartBulbCaptureRunner(mRemoteApi));
imageManager.putImageLoadTask(new StartBulbCaptureRunner(mRemoteApi));
}

public void stopBulbCapture(I_PictureCallback pictureCallback)
{
ImageManager.putImageLoadTask(new StopBulbCaptureRunner(mRemoteApi));
imageManager.putImageLoadTask(new StopBulbCaptureRunner(mRemoteApi));
}


public void SetShootMode(final String mode)
{
ImageManager.putImageLoadTask(new SetShootModeRunner(mRemoteApi,mode));
imageManager.putImageLoadTask(new SetShootModeRunner(mRemoteApi,mode));
}

public void StartRecording()
Expand Down
35 changes: 14 additions & 21 deletions app/src/main/java/freed/image/ImageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,46 @@
import freed.utils.Log;

public class ImageManager {

private static ImageManager imageManager = new ImageManager();

public static ImageManager getInstance()
{
return imageManager;
}


private final String TAG = ImageManager.class.getSimpleName();
private final ImageSaveManager imageSaveManager;
private final ImageLoadManager imageLoadManager;

private final int KEEP_ALIVE_TIME = 500;

private ImageManager()
public ImageManager()
{
imageSaveManager = new ImageSaveManager();
imageLoadManager = new ImageLoadManager();
}

public static void putImageSaveTask(ImageTask task)
public void putImageSaveTask(ImageTask task)
{
imageManager.imageSaveManager.imageSaveExecutor.execute(task);
imageSaveManager.imageSaveExecutor.execute(task);
}

public static void cancelImageSaveTasks()
public void cancelImageSaveTasks()
{
synchronized (imageManager) {
imageManager.imageSaveManager.cancel();
synchronized (imageSaveManager) {
imageSaveManager.cancel();
}
}

public static void putImageLoadTask(ImageTask runnable)
public void putImageLoadTask(ImageTask runnable)
{
imageManager.imageLoadManager.imageLoadExecutor.execute(runnable);
imageLoadManager.imageLoadExecutor.execute(runnable);
}

public static void cancelImageLoadTasks()
public void cancelImageLoadTasks()
{
synchronized (imageManager) {
imageManager.imageLoadManager.cancel();
synchronized (imageLoadManager) {
imageLoadManager.cancel();
}
}

public static void removeImageLoadTask(ImageTask task)
public void removeImageLoadTask(ImageTask task)
{
imageManager.imageLoadManager.removeTaskFromQueue(task);
imageLoadManager.removeTaskFromQueue(task);
}

private class ImageSaveManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.troop.freedcam.R;

import freed.ActivityAbstract;
import freed.FreedApplication;
import freed.image.ImageManager;
import freed.utils.Log;
import freed.viewer.gridview.BitmapLoadRunnable;
Expand Down Expand Up @@ -67,7 +69,7 @@ public static void setGridModelToView(ImageView gridImageView, GridImageViewMode
return;
if (gridImageViewModel.bitmapLoadRunnable != null) {
gridImageViewModel.bitmapLoadRunnable.stopProgessbar();
ImageManager.removeImageLoadTask(gridImageViewModel.bitmapLoadRunnable);
FreedApplication.imageManager().removeImageLoadTask(gridImageViewModel.bitmapLoadRunnable);
}

gridImageView.setImageBitmap(null);
Expand All @@ -77,7 +79,7 @@ public static void setGridModelToView(ImageView gridImageView, GridImageViewMode
gridImageViewModel.setProgressBarVisible(true);
try {
gridImageViewModel.bitmapLoadRunnable = new BitmapLoadRunnable(gridImageView,gridImageViewModel);
ImageManager.putImageLoadTask(gridImageViewModel.bitmapLoadRunnable);
FreedApplication.imageManager().putImageLoadTask(gridImageViewModel.bitmapLoadRunnable);
}
catch (NullPointerException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ public class GridViewFragmentModelView extends ViewModel

private final IntentSenderModel intentSenderModel;
private FileListController fileListController;
private ImageManager imageManager;


@Inject
public GridViewFragmentModelView(FileListController fileListController)
public GridViewFragmentModelView(FileListController fileListController, ImageManager imageManager)
{
viewStateModel = new ViewStateModel();
filesHolderModel = new FilesHolderModel();
this.fileListController = fileListController;
this.imageManager = imageManager;
buttonFiletype = new ButtonFileTypeModel(this);
buttonDoAction = new ButtonDoAction();
buttonOptions = new ButtonOptionsModel(onDeltedButtonClick,onStackClick,onRawToDngClick,onDngStackClick,this);
Expand Down Expand Up @@ -446,7 +448,7 @@ else if (requestMode == RequestModes.delete)

public void deleteFiles()
{
ImageManager.cancelImageLoadTasks();
imageManager.cancelImageLoadTasks();
urisToDelte.clear();
if (filesSelectedList.get(0).getHolderType() == FileHolder.class)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

import java.util.ArrayList;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;
import freed.ActivityAbstract;
import freed.ActivityInterface;
import freed.ActivityInterface.I_OnActivityResultCallback;
Expand All @@ -54,6 +57,7 @@
/**
* Created by troop on 11.12.2015.
*/
@AndroidEntryPoint
public class GridViewFragment extends Fragment implements I_OnActivityResultCallback
{

Expand All @@ -71,6 +75,7 @@ public class GridViewFragment extends Fragment implements I_OnActivityResultCall
private ScreenSlideFragment.ButtonClick onGridItemClick;

public int DEFAULT_ITEM_TO_SET = 0;
@Inject ImageManager imageManager;

public View GetGridItem(int position)
{
Expand Down Expand Up @@ -159,7 +164,7 @@ public void onResume() {
@Override
public void onPause() {
super.onPause();
ImageManager.cancelImageLoadTasks();
imageManager.cancelImageLoadTasks();
}

@Override
Expand Down
Loading

0 comments on commit c05f29a

Please sign in to comment.