Improved DEFAULT_COLUMNS_COUNT for different orientations

This commit is contained in:
merkost 2023-07-16 10:10:51 +10:00
parent 8895d70e4f
commit edf31d7632
2 changed files with 18 additions and 5 deletions

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.commons.helpers
import android.content.Context
import android.content.res.Configuration
import android.os.Environment
import android.text.format.DateFormat
import com.simplemobiletools.commons.R
@ -556,8 +557,14 @@ open class BaseConfig(val context: Context) {
set(viewType) = prefs.edit().putInt(VIEW_TYPE, viewType).apply()
var contactsGridColumnCnt: Int
get() = prefs.getInt(CONTACTS_GRID_COLUMN_COUNT, CONTACTS_GRID_DEFAULT_COLUMNS_COUNT)
set(contactsGridColumnCnt) = prefs.edit().putInt(CONTACTS_GRID_COLUMN_COUNT, contactsGridColumnCnt).apply()
get() = prefs.getInt(
valueByConfiguration(CONTACTS_GRID_COLUMN_COUNT_PORTRAIT, CONTACTS_GRID_COLUMN_COUNT_LANDSCAPE),
valueByConfiguration(CONTACTS_GRID_DEFAULT_COLUMNS_COUNT_PORTRAIT, CONTACTS_GRID_DEFAULT_COLUMNS_COUNT_LANDSCAPE)
)
set(contactsGridColumnCnt) = prefs.edit().putInt(
valueByConfiguration(CONTACTS_GRID_COLUMN_COUNT_PORTRAIT, CONTACTS_GRID_COLUMN_COUNT_LANDSCAPE),
contactsGridColumnCnt
).apply()
var autoBackup: Boolean
get() = prefs.getBoolean(AUTO_BACKUP, false)
@ -574,5 +581,9 @@ open class BaseConfig(val context: Context) {
var lastAutoBackupTime: Long
get() = prefs.getLong(LAST_AUTO_BACKUP_TIME, 0L)
set(lastAutoBackupTime) = prefs.edit().putLong(LAST_AUTO_BACKUP_TIME, lastAutoBackupTime).apply()
}
private fun <T> valueByConfiguration(portraitValue: T, landScapeValue: T): T {
val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
return if (isPortrait) portraitValue else landScapeValue
}
}

View file

@ -186,14 +186,16 @@ const val MERGE_DUPLICATE_CONTACTS = "merge_duplicate_contacts"
const val FAVORITES_CONTACTS_ORDER = "favorites_contacts_order"
const val FAVORITES_CUSTOM_ORDER_SELECTED = "favorites_custom_order_selected"
const val VIEW_TYPE = "view_type"
const val CONTACTS_GRID_COLUMN_COUNT = "favourites_column_count"
const val CONTACTS_GRID_COLUMN_COUNT_PORTRAIT = "contacts_grid_column_count_portrait"
const val CONTACTS_GRID_COLUMN_COUNT_LANDSCAPE = "contacts_grid_column_count_landscape"
const val AUTO_BACKUP = "auto_backup"
const val AUTO_BACKUP_FOLDER = "auto_backup_folder"
const val AUTO_BACKUP_FILENAME = "auto_backup_filename"
const val LAST_AUTO_BACKUP_TIME = "last_auto_backup_time"
// contact grid view constants
const val CONTACTS_GRID_DEFAULT_COLUMNS_COUNT = 3
const val CONTACTS_GRID_DEFAULT_COLUMNS_COUNT_PORTRAIT = 3
const val CONTACTS_GRID_DEFAULT_COLUMNS_COUNT_LANDSCAPE = 5
const val CONTACTS_GRID_MIN_COLUMNS_COUNT = 1
const val CONTACTS_GRID_MAX_COLUMNS_COUNT = 10