diff --git a/app/build.gradle b/app/build.gradle index fcd06a89..eec54d04 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:4c83ec8740' + implementation 'com.github.fatihergin:Simple-Commons:49f496ea16' implementation 'androidx.documentfile:documentfile:1.0.1' implementation "androidx.exifinterface:exifinterface:1.3.5" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5037bff3..053bf145 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,9 @@ + + + diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt index cf77ea1b..b69afeb4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt @@ -4,15 +4,15 @@ import android.annotation.SuppressLint import android.os.Bundle import com.simplemobiletools.camera.BuildConfig import com.simplemobiletools.camera.R +import com.simplemobiletools.camera.extensions.checkLocationPermission import com.simplemobiletools.camera.extensions.config import com.simplemobiletools.camera.models.CaptureMode import com.simplemobiletools.commons.dialogs.FeatureLockedDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog +import com.simplemobiletools.commons.dialogs.OpenAppSettingsDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.LICENSE_GLIDE -import com.simplemobiletools.commons.helpers.NavigationIcon -import com.simplemobiletools.commons.helpers.isTiramisuPlus +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.RadioItem import kotlinx.android.synthetic.main.activity_settings.* @@ -43,6 +43,7 @@ class SettingsActivity : SimpleActivity() { setupVolumeButtonsAsShutter() setupFlipPhotos() setupSavePhotoMetadata() + setupSaveMediaLocation() setupSavePhotosFolder() setupPhotoQuality() setupCaptureMode() @@ -165,6 +166,34 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupSaveMediaLocation() { + settings_save_media_location.isChecked = config.saveMediaLocation + settings_save_media_location_holder.setOnClickListener { + val willEnableSaveMediaLocation = !config.saveMediaLocation + + if (willEnableSaveMediaLocation) { + if (checkLocationPermission()) { + updateSaveMediaLocationConfig(true) + } else { + handlePermission(PERMISSION_ACCESS_FINE_LOCATION) { _ -> + if (checkLocationPermission()) { + updateSaveMediaLocationConfig(true) + } else { + OpenAppSettingsDialog(activity = this@SettingsActivity, permissionId = R.string.permission_name_location) + } + } + } + } else { + updateSaveMediaLocationConfig(false) + } + } + } + + private fun updateSaveMediaLocationConfig(enabled: Boolean) { + settings_save_media_location.isChecked = enabled + config.saveMediaLocation = enabled + } + private fun setupSavePhotosFolder() { settings_save_photos_label.text = addLockedLabelIfNeeded(R.string.save_photos) settings_save_photos.text = getLastPart(config.savePhotosFolder) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/Context.kt index 4587a5c0..90fa434f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/extensions/Context.kt @@ -2,9 +2,13 @@ package com.simplemobiletools.camera.extensions import android.content.Context import com.simplemobiletools.camera.helpers.Config +import com.simplemobiletools.commons.extensions.hasPermission +import com.simplemobiletools.commons.helpers.PERMISSION_ACCESS_COARSE_LOCATION +import com.simplemobiletools.commons.helpers.PERMISSION_ACCESS_FINE_LOCATION import java.io.File import java.text.SimpleDateFormat -import java.util.* +import java.util.Date +import java.util.Locale val Context.config: Config get() = Config.newInstance(applicationContext) @@ -41,3 +45,7 @@ fun getRandomMediaName(isPhoto: Boolean): String { "VID_$timestamp" } } + +fun Context.checkLocationPermission(): Boolean { + return hasPermission(PERMISSION_ACCESS_FINE_LOCATION) || hasPermission(PERMISSION_ACCESS_COARSE_LOCATION) +} diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt index 01b80789..c2fe1631 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt @@ -68,6 +68,10 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(SAVE_PHOTO_METADATA, true) set(savePhotoMetadata) = prefs.edit().putBoolean(SAVE_PHOTO_METADATA, savePhotoMetadata).apply() + var saveMediaLocation: Boolean + get() = prefs.getBoolean(SAVE_MEDIA_LOCATION, false) + set(saveMediaLocation) = prefs.edit().putBoolean(SAVE_MEDIA_LOCATION, saveMediaLocation).apply() + var photoQuality: Int get() = prefs.getInt(PHOTO_QUALITY, 80) set(photoQuality) = prefs.edit().putInt(PHOTO_QUALITY, photoQuality).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt index 2850e250..194127be 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt @@ -18,6 +18,7 @@ const val BACK_VIDEO_RESOLUTION_INDEX = "back_video_resolution_index_3" const val FRONT_PHOTO_RESOLUTION_INDEX = "front_photo_resolution_index_3" const val FRONT_VIDEO_RESOLUTION_INDEX = "front_video_resolution_index_3" const val SAVE_PHOTO_METADATA = "save_photo_metadata" +const val SAVE_MEDIA_LOCATION = "save_media_location" const val PHOTO_QUALITY = "photo_quality" const val CAPTURE_MODE = "capture_mode" const val TIMER_MODE = "timer_mode" diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 60e0b3aa..e2930245 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -204,6 +204,21 @@ + + + + + +