diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 424721c88..4348a2b49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.helpers import android.content.Context +import android.content.res.Configuration import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.helpers.BaseConfig @@ -160,12 +161,22 @@ class Config(context: Context) : BaseConfig(context) { set(showMedia) = prefs.edit().putInt(SHOW_MEDIA, showMedia).apply() var dirColumnCnt: Int - get() = prefs.getInt(DIR_COLUMN_CNT, context.resources.getInteger(R.integer.directory_columns)) - set(dirColumnCnt) = prefs.edit().putInt(DIR_COLUMN_CNT, dirColumnCnt).apply() + get() = prefs.getInt(getDirectoryColumnsField(), context.resources.getInteger(R.integer.directory_columns)) + 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 + } var mediaColumnCnt: Int - get() = prefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns)) - set(mediaColumnCnt) = prefs.edit().putInt(MEDIA_COLUMN_CNT, mediaColumnCnt).apply() + get() = prefs.getInt(getMediaColumnsField(), context.resources.getInteger(R.integer.media_columns)) + 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 + } var directories: String get() = prefs.getString(DIRECTORIES, "") diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 21dc7c6de..7b0ae967a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -16,7 +16,9 @@ val DISPLAY_FILE_NAMES = "display_file_names" 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 MEDIA_COLUMN_CNT = "media_column_cnt" +val MEDIA_LANDSCAPE_COLUMN_CNT = "media_landscape_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_"