Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-697 Save .catrobat-image file in a separate folder #1324

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import androidx.exifinterface.media.ExifInterface
import id.zelory.compressor.Compressor
import org.catrobat.paintroid.command.serialization.CommandSerializer
import org.catrobat.paintroid.common.CATROBAT_IMAGE_ENDING
import org.catrobat.paintroid.common.Constants.DOWNLOADS_DIRECTORY
import org.catrobat.paintroid.common.Constants.ANDROID_DIRECTORY
import org.catrobat.paintroid.common.Constants.PICTURES_DIRECTORY
import org.catrobat.paintroid.common.MAX_LAYERS
import org.catrobat.paintroid.common.TEMP_IMAGE_DIRECTORY_NAME
Expand Down Expand Up @@ -437,7 +437,7 @@ object FileIO {
val contentUri = MediaStore.Downloads.EXTERNAL_CONTENT_URI
getUriForFilename(contentUri, filename, resolver)
} else {
val file = File(DOWNLOADS_DIRECTORY, filename)
val file = File(ANDROID_DIRECTORY, filename)
return if (file.exists()) {
Uri.fromFile(file)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import android.graphics.RectF
import android.graphics.Bitmap
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.Input
Expand Down Expand Up @@ -63,7 +62,8 @@ import org.catrobat.paintroid.command.implementation.SprayCommand
import org.catrobat.paintroid.command.implementation.ClipboardCommand
import org.catrobat.paintroid.command.implementation.TextToolCommand
import org.catrobat.paintroid.command.implementation.SmudgePathCommand
import org.catrobat.paintroid.common.Constants.DOWNLOADS_DIRECTORY
import org.catrobat.paintroid.common.CATROBAT_IMAGE_STORAGE
import org.catrobat.paintroid.common.Constants.ANDROID_DIRECTORY
import org.catrobat.paintroid.common.SPECIFIC_FILETYPE_SHARED_PREFERENCES_NAME
import org.catrobat.paintroid.iotasks.OpenRasterFileFormatConversion
import org.catrobat.paintroid.contract.MainActivityContracts
Expand Down Expand Up @@ -163,7 +163,7 @@ open class CommandSerializer(private val activityContext: Context, private val c
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val contentValues = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS)
put(MediaStore.Images.Media.RELATIVE_PATH, CATROBAT_IMAGE_STORAGE)
}
contentResolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)?.let { uri ->
contentResolver.openOutputStream(uri)?.use { stream ->
Expand All @@ -172,10 +172,10 @@ open class CommandSerializer(private val activityContext: Context, private val c
}
}
} else {
if (!(DOWNLOADS_DIRECTORY.exists() || DOWNLOADS_DIRECTORY.mkdirs())) {
if (!(ANDROID_DIRECTORY.exists() || ANDROID_DIRECTORY.mkdirs())) {
return null
}
val imageFile = File(DOWNLOADS_DIRECTORY, fileName)
val imageFile = File(ANDROID_DIRECTORY, fileName)
FileOutputStream(imageFile).use { fileStream ->
writeToStream(fileStream)
returnUri = Uri.fromFile(imageFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ const val TEMP_IMAGE_PATH = "$TEMP_IMAGE_DIRECTORY_NAME/$TEMP_IMAGE_NAME.$CATROB
const val TEMP_IMAGE_TEMP_PATH = "$TEMP_IMAGE_DIRECTORY_NAME/${TEMP_IMAGE_NAME}1.$CATROBAT_IMAGE_ENDING"
const val SPECIFIC_FILETYPE_SHARED_PREFERENCES_NAME = "Ownfiletypepreferences"
const val ANIMATION_DURATION: Long = 250
const val CATROBAT_IMAGE_STORAGE = "Android/media/org.catrobat.paintroid"

object Constants {
@JvmField
val PICTURES_DIRECTORY = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
@JvmField
val DOWNLOADS_DIRECTORY = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS)
val ANDROID_DIRECTORY = File(Environment.getExternalStorageDirectory(), CATROBAT_IMAGE_STORAGE)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import android.provider.MediaStore
import android.util.Log
import org.catrobat.paintroid.FileIO.enableAlpha
import org.catrobat.paintroid.MainActivity
import org.catrobat.paintroid.common.CATROBAT_IMAGE_STORAGE
import org.catrobat.paintroid.contract.LayerContracts
import org.catrobat.paintroid.model.Layer
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -93,11 +94,11 @@ class OpenRasterFileFormatConversion private constructor() {
val bitmapThumbArray = bosThumb.toByteArray()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
contentValues.put(MediaStore.Files.FileColumns.DISPLAY_NAME, fileName)
contentValues.put(MediaStore.Files.FileColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS)
contentValues.put(MediaStore.Files.FileColumns.RELATIVE_PATH, CATROBAT_IMAGE_STORAGE)
contentValues.put(MediaStore.Files.FileColumns.MIME_TYPE, "application/applefile")
imageUri = resolver?.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)
} else {
val imageRoot = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
val imageRoot = Environment.getExternalStoragePublicDirectory(CATROBAT_IMAGE_STORAGE)
if (!imageRoot.exists() && !imageRoot.mkdirs()) {
imageRoot.mkdirs()
}
Expand Down