use a helper extension for getting the default filename

This commit is contained in:
tibbi 2018-02-10 14:05:26 +01:00
parent a1782dfb91
commit d904ac47c9
2 changed files with 2 additions and 8 deletions

View File

@ -45,7 +45,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.8.3' implementation 'com.simplemobiletools:commons:3.11.2'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion" releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"

View File

@ -14,9 +14,6 @@ import com.simplemobiletools.draw.views.MyCanvas
import kotlinx.android.synthetic.main.dialog_save_image.view.* import kotlinx.android.synthetic.main.dialog_save_image.view.*
import java.io.File import java.io.File
import java.io.OutputStream import java.io.OutputStream
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Date
class SaveImageDialog(val activity: SimpleActivity, val suggestedExtension: String, val curPath: String, val canvas: MyCanvas, class SaveImageDialog(val activity: SimpleActivity, val suggestedExtension: String, val curPath: String, val canvas: MyCanvas,
callback: (path: String, extension: String) -> Unit) { callback: (path: String, extension: String) -> Unit) {
@ -107,10 +104,7 @@ class SaveImageDialog(val activity: SimpleActivity, val suggestedExtension: Stri
} }
private fun getInitialFilename(): String { private fun getInitialFilename(): String {
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm") val defaultFilename = "image_${activity.getCurrentFormattedDateTime()}"
val formatted = simpleDateFormat.format(Date(System.currentTimeMillis()))
val defaultFilename = "image_$formatted"
return if (curPath.isEmpty()) defaultFilename else curPath.getFilenameFromPath().substring(0, curPath.getFilenameFromPath().lastIndexOf(".")) return if (curPath.isEmpty()) defaultFilename else curPath.getFilenameFromPath().substring(0, curPath.getFilenameFromPath().lastIndexOf("."))
} }
} }