update the way of retrieving default column counts

This commit is contained in:
tibbi 2017-06-18 23:33:52 +02:00
parent a2e9c53d8e
commit a3876f67cd
4 changed files with 41 additions and 7 deletions

View file

@ -161,23 +161,53 @@ class Config(context: Context) : BaseConfig(context) {
set(showMedia) = prefs.edit().putInt(SHOW_MEDIA, showMedia).apply()
var dirColumnCnt: Int
get() = prefs.getInt(getDirectoryColumnsField(), context.resources.getInteger(R.integer.directory_columns_vertical_scroll))
get() = prefs.getInt(getDirectoryColumnsField(), getDefaultDirectoryColumnCount())
set(dirColumnCnt) = prefs.edit().putInt(getDirectoryColumnsField(), dirColumnCnt).apply()
private fun getDirectoryColumnsField(): String {
val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
return if (isPortrait) DIR_COLUMN_CNT else DIR_LANDSCAPE_COLUMN_CNT
return if (isPortrait) {
if (scrollHorizontally) {
DIR_HORIZONTAL_COLUMN_CNT
} else {
DIR_COLUMN_CNT
}
} else {
if (scrollHorizontally) {
DIR_LANDSCAPE_HORIZONTAL_COLUMN_CNT
} else {
DIR_LANDSCAPE_COLUMN_CNT
}
}
}
private fun getDefaultDirectoryColumnCount() = context.resources.getInteger(if (scrollHorizontally) R.integer.directory_columns_horizontal_scroll
else R.integer.directory_columns_vertical_scroll)
var mediaColumnCnt: Int
get() = prefs.getInt(getMediaColumnsField(), context.resources.getInteger(R.integer.media_columns_vertical_scroll))
get() = prefs.getInt(getMediaColumnsField(), getDefaultMediaColumnCount())
set(mediaColumnCnt) = prefs.edit().putInt(getMediaColumnsField(), mediaColumnCnt).apply()
private fun getMediaColumnsField(): String {
val isPortrait = context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
return if (isPortrait) MEDIA_COLUMN_CNT else MEDIA_LANDSCAPE_COLUMN_CNT
return if (isPortrait) {
if (scrollHorizontally) {
MEDIA_HORIZONTAL_COLUMN_CNT
} else {
MEDIA_COLUMN_CNT
}
} else {
if (scrollHorizontally) {
MEDIA_LANDSCAPE_HORIZONTAL_COLUMN_CNT
} else {
MEDIA_LANDSCAPE_COLUMN_CNT
}
}
}
private fun getDefaultMediaColumnCount() = context.resources.getInteger(if (scrollHorizontally) R.integer.media_columns_horizontal_scroll
else R.integer.media_columns_vertical_scroll)
var directories: String
get() = prefs.getString(DIRECTORIES, "")
set(directories) = prefs.edit().putString(DIRECTORIES, directories).apply()

View file

@ -17,8 +17,12 @@ val DARK_BACKGROUND = "dark_background"
val PINNED_FOLDERS = "pinned_folders"
val DIR_COLUMN_CNT = "dir_column_cnt"
val DIR_LANDSCAPE_COLUMN_CNT = "dir_landscape_column_cnt"
val DIR_HORIZONTAL_COLUMN_CNT = "dir_horizontal_column_cnt"
val DIR_LANDSCAPE_HORIZONTAL_COLUMN_CNT = "dir_landscape_horizontal_column_cnt"
val MEDIA_COLUMN_CNT = "media_column_cnt"
val MEDIA_LANDSCAPE_COLUMN_CNT = "media_landscape_column_cnt"
val MEDIA_HORIZONTAL_COLUMN_CNT = "media_horizontal_column_cnt"
val MEDIA_LANDSCAPE_HORIZONTAL_COLUMN_CNT = "media_landscape_horizontal_column_cnt"
val SHOW_ALL = "show_all" // display images and videos from all folders together
val SHOW_MEDIA = "show_media"
val SAVE_FOLDER_PREFIX = "folder2_"

View file

@ -1,6 +1,6 @@
<resources>
<integer name="directory_columns_vertical_scroll">3</integer>
<integer name="directory_columns_horizontal_scroll">5</integer>
<integer name="directory_columns_horizontal_scroll">3</integer>
<integer name="media_columns_vertical_scroll">5</integer>
<integer name="media_columns_horizontal_scroll">6</integer>
<integer name="media_columns_horizontal_scroll">5</integer>
</resources>

View file

@ -1,6 +1,6 @@
<resources>
<integer name="directory_columns_vertical_scroll">2</integer>
<integer name="directory_columns_horizontal_scroll">4</integer>
<integer name="directory_columns_horizontal_scroll">3</integer>
<integer name="media_columns_vertical_scroll">3</integer>
<integer name="media_columns_horizontal_scroll">4</integer>
</resources>