diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 7c5cc07ca..b43f09faa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -15,6 +15,7 @@ import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.dialogs.ResizeDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.theartofdev.edmodo.cropper.CropImageView import kotlinx.android.synthetic.main.activity_edit.* diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 4b113535f..8966b55bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -20,6 +20,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.launchAbout import com.simplemobiletools.gallery.extensions.launchCamera import com.simplemobiletools.gallery.extensions.launchSettings diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 6b7e6e29b..005070fbb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -18,10 +18,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog -import com.simplemobiletools.gallery.extensions.getHumanizedFilename -import com.simplemobiletools.gallery.extensions.launchAbout -import com.simplemobiletools.gallery.extensions.launchCamera -import com.simplemobiletools.gallery.extensions.launchSettings +import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.views.MyScalableRecyclerView diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index f610c134e..86da33c0d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -5,6 +5,7 @@ import android.view.View import android.widget.AdapterView import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.activity_settings.* class SettingsActivity : SimpleActivity() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt index 9165dec3c..935ef564f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt @@ -2,13 +2,9 @@ package com.simplemobiletools.gallery.activities import android.os.Bundle import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.gallery.helpers.Config open class SimpleActivity : BaseSimpleActivity() { - lateinit var config: Config - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - config = Config.newInstance(applicationContext) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 27c61a373..2d89a18e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -23,8 +23,8 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.createSelector -import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item.view.* import kotlinx.android.synthetic.main.directory_tmb.view.* @@ -36,7 +36,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList() - val config = Config.newInstance(activity) + val config = activity.config var pinnedFolders = config.pinnedFolders companion object { @@ -66,8 +66,8 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, RecyclerView.Adapter() { val multiSelector = MultiSelector() val views = ArrayList() - val config = Config.newInstance(activity) + val config = activity.config companion object { var actMode: ActionMode? = null @@ -62,8 +61,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } init { - foregroundColor = Config.newInstance(activity).primaryColor - backgroundColor = Config.newInstance(activity).backgroundColor + foregroundColor = config.primaryColor + backgroundColor = config.backgroundColor } val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index c6f1a70fb..1aedc5873 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -6,9 +6,9 @@ import com.simplemobiletools.commons.extensions.isGif import com.simplemobiletools.commons.extensions.isImageFast import com.simplemobiletools.commons.extensions.isVideoFast import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getHumanizedFilename import com.simplemobiletools.gallery.extensions.getParents -import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.gallery.helpers.VIDEOS @@ -19,18 +19,13 @@ import java.util.* class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, val isPickImage: Boolean, val callback: (dirs: ArrayList) -> Unit) : AsyncTask>() { - lateinit var mConfig: Config - - override fun onPreExecute() { - super.onPreExecute() - mConfig = Config.newInstance(context) - } + var config = context.config override fun doInBackground(vararg params: Void): ArrayList { val directories = LinkedHashMap() val media = ArrayList() - val showMedia = mConfig.showMedia - val fileSorting = mConfig.fileSorting + val showMedia = config.showMedia + val fileSorting = config.fileSorting val parents = context.getParents(isPickImage, isPickVideo) parents.mapNotNull { File(it).listFiles() } @@ -71,7 +66,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va directory.addSize(size) } else { var dirName = context.getHumanizedFilename(parentDir) - if (mConfig.getIsFolderHidden(parentDir)) { + if (config.getIsFolderHidden(parentDir)) { dirName += " ${context.resources.getString(R.string.hidden)}" } @@ -82,7 +77,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val dirs = ArrayList(directories.values.filter { File(it.path).exists() }) filterDirectories(dirs) - Directory.sorting = mConfig.directorySorting + Directory.sorting = config.directorySorting dirs.sort() return movePinnedToFront(dirs) @@ -90,7 +85,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va private fun movePinnedToFront(dirs: ArrayList): ArrayList { val foundFolders = ArrayList() - val pinnedFolders = mConfig.pinnedFolders + val pinnedFolders = config.pinnedFolders dirs.forEach { if (pinnedFolders.contains(it.path)) foundFolders.add(it) } dirs.removeAll(foundFolders) @@ -104,14 +99,14 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } private fun filterDirectories(dirs: MutableList) { - if (!mConfig.showHiddenFolders) { + if (!config.showHiddenFolders) { removeHiddenFolders(dirs) removeNoMediaFolders(dirs) } } private fun removeHiddenFolders(dirs: MutableList) { - val hiddenDirs = mConfig.hiddenFolders + val hiddenDirs = config.hiddenFolders val ignoreDirs = dirs.filter { hiddenDirs.contains(it.path) } dirs.removeAll(ignoreDirs) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 8a93acf32..4bc5042da 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -5,8 +5,12 @@ import android.os.AsyncTask import com.simplemobiletools.commons.extensions.isGif import com.simplemobiletools.commons.extensions.isImageFast import com.simplemobiletools.commons.extensions.isVideoFast +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getParents -import com.simplemobiletools.gallery.helpers.* +import com.simplemobiletools.gallery.helpers.IMAGES +import com.simplemobiletools.gallery.helpers.IMAGES_AND_VIDEOS +import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED +import com.simplemobiletools.gallery.helpers.VIDEOS import com.simplemobiletools.gallery.models.Medium import java.io.File import java.util.* @@ -14,15 +18,14 @@ import java.util.* class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo: Boolean = false, val isPickImage: Boolean = false, val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : AsyncTask>() { - lateinit var mConfig: Config + var config = context.config var showMedia = IMAGES_AND_VIDEOS var fileSorting = 0 override fun onPreExecute() { super.onPreExecute() - mConfig = Config.newInstance(context) - showMedia = mConfig.showMedia - fileSorting = mConfig.fileSorting + showMedia = config.showMedia + fileSorting = config.fileSorting } override fun doInBackground(vararg params: Void): ArrayList { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt index f747a1dc5..33040623f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt @@ -7,6 +7,7 @@ import android.view.View import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.* import kotlinx.android.synthetic.main.dialog_change_sorting.view.* @@ -19,7 +20,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting: } init { - config = Config.newInstance(activity) + config = activity.config view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null) AlertDialog.Builder(activity) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt index 44025680f..d2d83e2ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.commons.asynctasks.CopyMoveTask import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.helpers.Config +import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.dialog_copy_move.view.* import java.io.File import java.util.* @@ -65,11 +65,10 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList, val c return@setOnClickListener } - val config = Config.newInstance(context) if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) { context.toast(R.string.copying) val pair = Pair, File>(files, destinationDir) - CopyMoveTask(context, false, config.treeUri, true, copyMoveListener).execute(pair) + CopyMoveTask(context, false, context.config.treeUri, true, copyMoveListener).execute(pair) dismiss() } else { if (context.isPathOnSD(sourcePath) || context.isPathOnSD(destinationPath)) { @@ -79,7 +78,7 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList, val c context.toast(R.string.moving) val pair = Pair, File>(files, destinationDir) - CopyMoveTask(context, true, config.treeUri, true, copyMoveListener).execute(pair) + CopyMoveTask(context, true, context.config.treeUri, true, copyMoveListener).execute(pair) dismiss() } else { val updatedFiles = ArrayList(files.size * 2) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt index 6a825dee7..d5139a49e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt @@ -10,7 +10,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask -import com.simplemobiletools.gallery.helpers.Config +import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.dialog_album_picker.view.* class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String) -> Unit) { @@ -39,7 +39,7 @@ class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String) fun showOtherFolder() { val initialPath = Environment.getExternalStorageDirectory().toString() - val showHidden = Config.newInstance(activity).showHiddenFolders + val showHidden = activity.config.showHiddenFolders FilePickerDialog(activity, initialPath, false, showHidden, true) { callback.invoke(it) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt index d193d1dae..a485974ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt @@ -6,7 +6,7 @@ import android.view.WindowManager import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.helpers.Config +import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.rename_directory.view.* import java.io.File import java.util.* @@ -49,7 +49,7 @@ class RenameDirectoryDialog(val activity: SimpleActivity, val dir: File, val cal if (activity.isShowingPermDialog(dir)) return@setOnClickListener - val document = context.getFileDocument(dir.absolutePath, Config.newInstance(context).treeUri) + val document = context.getFileDocument(dir.absolutePath, context.config.treeUri) if (document.canWrite()) document.renameTo(newDirName) sendSuccess(updatedFiles, newDir) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt index 845344a4f..58e3fe532 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt @@ -6,7 +6,7 @@ import android.view.WindowManager import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.helpers.Config +import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.rename_file.view.* import java.io.File @@ -57,7 +57,7 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val callbac if (activity.isShowingPermDialog(file)) return@setOnClickListener - val document = context.getFileDocument(file.absolutePath, Config.newInstance(context).treeUri) + val document = context.getFileDocument(file.absolutePath, context.config.treeUri) if (document.canWrite()) document.renameTo(newFile.name) sendSuccess(file, newFile) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index ffb7f1564..52cc053e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -44,8 +44,8 @@ fun Context.launchSettings() { fun Context.getParents(isPickImage: Boolean, isPickVideo: Boolean): ArrayList { val uri = MediaStore.Files.getContentUri("external") - val where = "${getWhereCondition(this, isPickImage, isPickVideo)} GROUP BY ( ${MediaStore.Files.FileColumns.PARENT} " - val args = getArgs(this, isPickImage, isPickVideo) + val where = "${getWhereCondition(isPickImage, isPickVideo)} GROUP BY ( ${MediaStore.Files.FileColumns.PARENT} " + val args = getArgs(isPickImage, isPickVideo) val columns = arrayOf(MediaStore.Files.FileColumns.PARENT, MediaStore.Images.Media.DATA) var cursor: Cursor? = null val parents = ArrayList() @@ -64,8 +64,8 @@ fun Context.getParents(isPickImage: Boolean, isPickVideo: Boolean): ArrayList { - val showMedia = Config.newInstance(context).showMedia +fun Context.getArgs(isPickImage: Boolean, isPickVideo: Boolean): Array { + val showMedia = config.showMedia return if (isPickImage || showMedia == IMAGES) { arrayOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE.toString()) } else if (isPickVideo || showMedia == VIDEOS) { @@ -83,3 +83,5 @@ private fun getArgs(context: Context, isPickImage: Boolean, isPickVideo: Boolean arrayOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE.toString(), MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO.toString()) } } + +val Context.config: Config get() = Config.newInstance(this) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index e6c0a4f57..6e0b9627d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -15,9 +15,9 @@ import android.view.animation.AnimationUtils import android.widget.SeekBar import android.widget.TextView import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getNavBarHeight import com.simplemobiletools.gallery.extensions.hasNavBar -import com.simplemobiletools.gallery.helpers.Config import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.pager_video_item.view.* @@ -90,7 +90,7 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C super.setMenuVisibility(menuVisible) mIsFragmentVisible = menuVisible if (menuVisible) { - if (context != null && Config.newInstance(context).autoplayVideos) { + if (context != null && context.config.autoplayVideos) { playVideo() } } else { @@ -276,7 +276,7 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C } override fun onCompletion(mp: MediaPlayer) { - if (Config.newInstance(context).loopVideos) { + if (context.config.loopVideos) { playVideo() } else { mSeekBar!!.progress = mSeekBar!!.max @@ -367,7 +367,7 @@ class VideoFragment : ViewPagerFragment(), View.OnClickListener, SurfaceHolder.C setupTimeHolder() setProgress(mCurrTime) - if (mIsFragmentVisible && Config.newInstance(context).autoplayVideos) + if (mIsFragmentVisible && context.config.autoplayVideos) playVideo() } }