update settings for requesting location permission & saving user preference
This commit is contained in:
parent
9751746822
commit
cc41804745
|
@ -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"
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="32" />
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -204,6 +204,21 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_save_media_location_holder"
|
||||
style="@style/SettingsHolderCheckboxStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||
android:id="@+id/settings_save_media_location"
|
||||
style="@style/SettingsCheckboxStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save_photo_location" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_flip_photos_holder"
|
||||
style="@style/SettingsHolderCheckboxStyle"
|
||||
|
|
Loading…
Reference in New Issue