|
|
@ -43,30 +43,33 @@ import static org.floens.chan.utils.AndroidUtils.getAppContext; |
|
|
|
import static org.floens.chan.utils.AndroidUtils.getString; |
|
|
|
import static org.floens.chan.utils.AndroidUtils.getString; |
|
|
|
|
|
|
|
|
|
|
|
public class ImageSaver implements ImageSaveTask.ImageSaveTaskCallback { |
|
|
|
public class ImageSaver implements ImageSaveTask.ImageSaveTaskCallback { |
|
|
|
|
|
|
|
public static final int MAX_RENAME_TRIES = 500; |
|
|
|
private static final String TAG = "ImageSaver"; |
|
|
|
private static final String TAG = "ImageSaver"; |
|
|
|
private static final int NOTIFICATION_ID = 3; |
|
|
|
private static final int NOTIFICATION_ID = 3; |
|
|
|
private static final int MAX_NAME_LENGTH = 50; |
|
|
|
private static final int MAX_NAME_LENGTH = 50; |
|
|
|
private static final Pattern REPEATED_UNDERSCORES_PATTERN = Pattern.compile("_+"); |
|
|
|
private static final Pattern REPEATED_UNDERSCORES_PATTERN = Pattern.compile("_+"); |
|
|
|
private static final Pattern SAFE_CHARACTERS_PATTERN = Pattern.compile("[^a-zA-Z0-9._]"); |
|
|
|
private static final Pattern SAFE_CHARACTERS_PATTERN = Pattern.compile("[^a-zA-Z0-9._]"); |
|
|
|
private static final ImageSaver instance = new ImageSaver(); |
|
|
|
private static final ImageSaver instance = new ImageSaver(); |
|
|
|
public static final int MAX_RENAME_TRIES = 500; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private NotificationManager notificationManager; |
|
|
|
private NotificationManager notificationManager; |
|
|
|
private ExecutorService executor = Executors.newSingleThreadExecutor(); |
|
|
|
private ExecutorService executor = Executors.newSingleThreadExecutor(); |
|
|
|
private int doneTasks = 0; |
|
|
|
private int doneTasks = 0; |
|
|
|
private int totalTasks = 0; |
|
|
|
private int totalTasks = 0; |
|
|
|
private Toast toast; |
|
|
|
private Toast toast; |
|
|
|
|
|
|
|
private String boardName; |
|
|
|
|
|
|
|
|
|
|
|
public static ImageSaver getInstance() { |
|
|
|
|
|
|
|
return instance; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ImageSaver() { |
|
|
|
private ImageSaver() { |
|
|
|
EventBus.getDefault().register(this); |
|
|
|
EventBus.getDefault().register(this); |
|
|
|
notificationManager = (NotificationManager) getAppContext().getSystemService(Context.NOTIFICATION_SERVICE); |
|
|
|
notificationManager = (NotificationManager) getAppContext().getSystemService(Context.NOTIFICATION_SERVICE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ImageSaver getInstance() { |
|
|
|
|
|
|
|
return instance; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void startDownloadTask(Context context, final ImageSaveTask task) { |
|
|
|
public void startDownloadTask(Context context, final ImageSaveTask task) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boardName = task.getBoardName(); |
|
|
|
PostImage postImage = task.getPostImage(); |
|
|
|
PostImage postImage = task.getPostImage(); |
|
|
|
String name = ChanSettings.saveOriginalFilename.get() ? postImage.originalName : postImage.filename; |
|
|
|
String name = ChanSettings.saveOriginalFilename.get() ? postImage.originalName : postImage.filename; |
|
|
|
String fileName = filterName(name + "." + postImage.extension); |
|
|
|
String fileName = filterName(name + "." + postImage.extension); |
|
|
@ -123,7 +126,11 @@ public class ImageSaver implements ImageSaveTask.ImageSaveTaskCallback { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public File getSaveLocation() { |
|
|
|
public File getSaveLocation() { |
|
|
|
return new File(ChanSettings.saveLocation.get()); |
|
|
|
if (ChanSettings.saveBoardFolder.get()) { |
|
|
|
|
|
|
|
return new File(ChanSettings.saveLocation.get() + File.separator + boardName); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return new File(ChanSettings.saveLocation.get()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|