store the amount of columns

This commit is contained in:
tibbi 2016-12-11 21:54:40 +01:00
parent 72381ba53d
commit 9bb9e3496c
8 changed files with 24 additions and 11 deletions

View File

@ -62,7 +62,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mToBeDeleted = ArrayList<String>() mToBeDeleted = ArrayList<String>()
directories_holder.setOnRefreshListener({ getDirectories() }) directories_holder.setOnRefreshListener({ getDirectories() })
mDirs = ArrayList<Directory>() mDirs = ArrayList<Directory>()
handleZooming()
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -120,6 +119,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
showAllMedia() showAllMedia()
else else
getDirectories() getDirectories()
handleZooming()
} else { } else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION) ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION)
} }
@ -234,17 +234,18 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun handleZooming() { private fun handleZooming() {
val layoutManager = directories_grid.layoutManager as GridLayoutManager val layoutManager = directories_grid.layoutManager as GridLayoutManager
layoutManager.spanCount = mConfig.dirColumnCnt
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener { MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener {
override fun zoomIn() { override fun zoomIn() {
if (layoutManager.spanCount > 1) { if (layoutManager.spanCount > 1) {
layoutManager.spanCount-- mConfig.dirColumnCnt = --layoutManager.spanCount
DirectoryAdapter.actMode?.finish() DirectoryAdapter.actMode?.finish()
} }
} }
override fun zoomOut() { override fun zoomOut() {
if (layoutManager.spanCount < 10) { if (layoutManager.spanCount < 10) {
layoutManager.spanCount++ mConfig.dirColumnCnt = ++layoutManager.spanCount
DirectoryAdapter.actMode?.finish() DirectoryAdapter.actMode?.finish()
} }
} }

View File

@ -50,7 +50,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false) mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false)
} }
handleZooming()
media_holder.setOnRefreshListener({ getMedia() }) media_holder.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY) mPath = intent.getStringExtra(DIRECTORY)
mMedia = ArrayList<Medium>() mMedia = ArrayList<Medium>()
@ -69,6 +68,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
val dirName = getHumanizedFilename(mPath) val dirName = getHumanizedFilename(mPath)
title = if (mShowAll) resources.getString(R.string.all_folders) else dirName title = if (mShowAll) resources.getString(R.string.all_folders) else dirName
getMedia() getMedia()
handleZooming()
} else { } else {
finish() finish()
} }
@ -203,17 +203,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun handleZooming() { private fun handleZooming() {
val layoutManager = media_grid.layoutManager as GridLayoutManager val layoutManager = media_grid.layoutManager as GridLayoutManager
layoutManager.spanCount = mConfig.mediaColumnCnt
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener { MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener {
override fun zoomIn() { override fun zoomIn() {
if (layoutManager.spanCount > 1) { if (layoutManager.spanCount > 1) {
layoutManager.spanCount-- mConfig.mediaColumnCnt = --layoutManager.spanCount
MediaAdapter.actMode?.finish() MediaAdapter.actMode?.finish()
} }
} }
override fun zoomOut() { override fun zoomOut() {
if (layoutManager.spanCount < 10) { if (layoutManager.spanCount < 10) {
layoutManager.spanCount++ mConfig.mediaColumnCnt = ++layoutManager.spanCount
MediaAdapter.actMode?.finish() MediaAdapter.actMode?.finish()
} }
} }

View File

@ -2,9 +2,10 @@ package com.simplemobiletools.gallery.helpers
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import com.simplemobiletools.gallery.R
import java.util.* import java.util.*
class Config private constructor(context: Context) { class Config private constructor(val context: Context) {
private val mPrefs: SharedPreferences private val mPrefs: SharedPreferences
companion object { companion object {
@ -100,4 +101,12 @@ class Config private constructor(context: Context) {
var showMedia: Int var showMedia: Int
get() = mPrefs.getInt(SHOW_MEDIA, IMAGES_AND_VIDEOS) get() = mPrefs.getInt(SHOW_MEDIA, IMAGES_AND_VIDEOS)
set(showMedia) = mPrefs.edit().putInt(SHOW_MEDIA, showMedia).apply() set(showMedia) = mPrefs.edit().putInt(SHOW_MEDIA, showMedia).apply()
var dirColumnCnt: Int
get() = mPrefs.getInt(DIR_COLUMN_CNT, context.resources.getInteger(R.integer.directory_columns))
set(dirColumnCnt) = mPrefs.edit().putInt(DIR_COLUMN_CNT, dirColumnCnt).apply()
var mediaColumnCnt: Int
get() = mPrefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns))
set(mediaColumnCnt) = mPrefs.edit().putInt(MEDIA_COLUMN_CNT, mediaColumnCnt).apply()
} }

View File

@ -13,6 +13,8 @@ val AUTOPLAY_VIDEOS = "autoplay_videos"
val TREE_URI = "tree_uri" val TREE_URI = "tree_uri"
val DISPLAY_FILE_NAMES = "display_file_names" val DISPLAY_FILE_NAMES = "display_file_names"
val PINNED_FOLDERS = "pinned_folders" val PINNED_FOLDERS = "pinned_folders"
val DIR_COLUMN_CNT = "dir_column_cnt"
val MEDIA_COLUMN_CNT = "media_column_cnt"
val SHOW_ALL = "show_all" // display images and videos from all folders together val SHOW_ALL = "show_all" // display images and videos from all folders together
val SHOW_MEDIA = "show_media" val SHOW_MEDIA = "show_media"

View File

@ -12,6 +12,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="vertical" android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.GridLayoutManager" app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="@integer/photo_columns"/> app:spanCount="@integer/media_columns"/>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>

View File

@ -1,4 +1,4 @@
<resources> <resources>
<integer name="directory_columns">3</integer> <integer name="directory_columns">3</integer>
<integer name="photo_columns">5</integer> <integer name="media_columns">5</integer>
</resources> </resources>

View File

@ -1,4 +1,4 @@
<resources> <resources>
<integer name="directory_columns">4</integer> <integer name="directory_columns">4</integer>
<integer name="photo_columns">7</integer> <integer name="media_columns">7</integer>
</resources> </resources>

View File

@ -1,4 +1,4 @@
<resources> <resources>
<integer name="directory_columns">2</integer> <integer name="directory_columns">2</integer>
<integer name="photo_columns">3</integer> <integer name="media_columns">3</integer>
</resources> </resources>