From f90e14ac0e965d8436c22520eb488e9fb963dcd8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 1 Dec 2017 19:11:06 +0100 Subject: [PATCH] update commons to 3.0.21 --- app/build.gradle | 2 +- .../com/simplemobiletools/filemanager/App.kt | 9 +--- .../filemanager/activities/MainActivity.kt | 8 +-- .../filemanager/adapters/ItemsAdapter.kt | 12 ++--- .../dialogs/ChangeSortingDialog.kt | 4 +- .../filemanager/dialogs/CompressAsDialog.kt | 35 ++++++------ .../dialogs/CreateNewItemDialog.kt | 46 ++++++++-------- .../filemanager/dialogs/SaveAsDialog.kt | 53 +++++++++---------- .../filemanager/fragments/ItemsFragment.kt | 6 +-- app/src/main/res/values/styles.xml | 4 +- 10 files changed, 85 insertions(+), 94 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0b2281f8..b1691c1c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.0.9' + implementation 'com.simplemobiletools:commons:3.0.21' implementation files('../libs/RootTools.jar') diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/App.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/App.kt index cca032e6..575035ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/App.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/App.kt @@ -2,10 +2,9 @@ package com.simplemobiletools.filemanager import android.app.Application import com.github.ajalt.reprint.core.Reprint +import com.simplemobiletools.commons.extensions.checkUseEnglish import com.simplemobiletools.filemanager.BuildConfig.USE_LEAK_CANARY -import com.simplemobiletools.filemanager.extensions.config import com.squareup.leakcanary.LeakCanary -import java.util.* class App : Application() { override fun onCreate() { @@ -17,11 +16,7 @@ class App : Application() { LeakCanary.install(this) } - if (config.useEnglish) { - val conf = resources.configuration - conf.locale = Locale.ENGLISH - resources.updateConfiguration(conf, resources.displayMetrics) - } + checkUseEnglish() Reprint.initialize(this) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index d9fd656d..c69f118a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -28,7 +28,6 @@ import java.util.* class MainActivity : SimpleActivity() { private val BACK_PRESS_TIMEOUT = 5000 private var wasBackJustPressed = false - private var mStoredUseEnglish = false private lateinit var fragment: ItemsFragment @@ -36,7 +35,7 @@ class MainActivity : SimpleActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - storeStoragePaths() + appLaunched() fragment = (fragment_holder as ItemsFragment).apply { isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER @@ -47,6 +46,7 @@ class MainActivity : SimpleActivity() { if (savedInstanceState == null) { tryInitFileManager() } + checkWhatsNewDialog() checkIfRootAvailable() storeStateVariables() @@ -230,14 +230,14 @@ class MainActivity : SimpleActivity() { } private fun checkIfRootAvailable() { - Thread({ + Thread { config.isRootAvailable = RootTools.isRootAvailable() if (config.isRootAvailable && config.enableRootAccess) { RootHelpers().askRootIFNeeded(this) { config.enableRootAccess = it } } - }).start() + }.start() } fun pickedPath(path: String) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 1ac664d4..703bcddb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -187,7 +187,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList, destinationPath: String) { activity.toast(R.string.copying) - Thread({ + Thread { var fileCnt = files.count() files.forEach { if (RootTools.copyFile(it.absolutePath, destinationPath, false, true)) { @@ -205,7 +205,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList Unit) { private var currSorting = 0 private var config = activity.config - private var view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null) + private var view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null) init { view.sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt index c396c2f3..cf3bc86a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt @@ -37,25 +37,26 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.compress_as) - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { - val name = view.file_name.value - when { - name.isEmpty() -> activity.toast(R.string.empty_name) - name.isAValidFilename() -> { - val newFile = File(realPath, "$name.zip") - if (newFile.exists()) { - activity.toast(R.string.name_taken) - return@OnClickListener - } + activity.setupDialogStuff(view, this, R.string.compress_as) { + window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { + val name = view.file_name.value + when { + name.isEmpty() -> activity.toast(R.string.empty_name) + name.isAValidFilename() -> { + val newFile = File(realPath, "$name.zip") + if (newFile.exists()) { + activity.toast(R.string.name_taken) + return@OnClickListener + } - dismiss() - callback(newFile.absolutePath) + dismiss() + callback(newFile.absolutePath) + } + else -> activity.toast(R.string.invalid_name) } - else -> activity.toast(R.string.invalid_name) - } - }) + }) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt index a12aa9c0..37485f18 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt @@ -6,7 +6,6 @@ import android.view.WindowManager import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.filemanager.R -import com.simplemobiletools.filemanager.activities.SimpleActivity import kotlinx.android.synthetic.main.dialog_create_new.view.* import java.io.File import java.io.IOException @@ -19,32 +18,33 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { - activity.setupDialogStuff(view, this, R.string.create_new) - window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { - val name = view.item_name.value - if (name.isEmpty()) { - activity.toast(R.string.empty_name) - } else if (name.isAValidFilename()) { - val file = File(path, name) - if (file.exists()) { - activity.toast(R.string.name_taken) - return@OnClickListener - } + activity.setupDialogStuff(view, this, R.string.create_new) { + window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { + val name = view.item_name.value + if (name.isEmpty()) { + activity.toast(R.string.empty_name) + } else if (name.isAValidFilename()) { + val file = File(path, name) + if (file.exists()) { + activity.toast(R.string.name_taken) + return@OnClickListener + } - if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) { - createDirectory(file, this) { - callback(it) + if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) { + createDirectory(file, this) { + callback(it) + } + } else { + createFile(file, this) { + callback(it) + } } } else { - createFile(file, this) { - callback(it) - } + activity.toast(R.string.invalid_name) } - } else { - activity.toast(R.string.invalid_name) - } - }) + }) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt index 0c65722b..c90cc3c8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt @@ -1,14 +1,12 @@ package com.simplemobiletools.filemanager.dialogs import android.support.v7.app.AlertDialog -import android.view.LayoutInflater import android.view.WindowManager import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.filemanager.R -import com.simplemobiletools.filemanager.activities.SimpleActivity import kotlinx.android.synthetic.main.dialog_save_as.view.* import java.io.File @@ -20,7 +18,7 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb } var realPath = File(path).parent.trimEnd('/') - val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null).apply { + val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply { save_as_path.text = activity.humanizePath(realPath) val fullName = path.getFilenameFromPath() @@ -47,38 +45,39 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb .setNegativeButton(R.string.cancel, null) .create().apply { window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - activity.setupDialogStuff(view, this, R.string.save_as) - getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ - val filename = view.save_as_name.value - val extension = view.save_as_extension.value + activity.setupDialogStuff(view, this, R.string.save_as) { + getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { + val filename = view.save_as_name.value + val extension = view.save_as_extension.value - if (filename.isEmpty()) { - activity.toast(R.string.filename_cannot_be_empty) - return@setOnClickListener - } + if (filename.isEmpty()) { + activity.toast(R.string.filename_cannot_be_empty) + return@setOnClickListener + } - if (extension.isEmpty()) { - activity.toast(R.string.extension_cannot_be_empty) - return@setOnClickListener - } + if (extension.isEmpty()) { + activity.toast(R.string.extension_cannot_be_empty) + return@setOnClickListener + } - val newFile = File(realPath, "$filename.$extension") - if (!newFile.name.isAValidFilename()) { - activity.toast(R.string.filename_invalid_characters) - return@setOnClickListener - } + val newFile = File(realPath, "$filename.$extension") + if (!newFile.name.isAValidFilename()) { + activity.toast(R.string.filename_invalid_characters) + return@setOnClickListener + } - if (newFile.exists()) { - val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name) - ConfirmationDialog(activity, title) { + if (newFile.exists()) { + val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFile.name) + ConfirmationDialog(activity, title) { + callback(newFile.absolutePath) + dismiss() + } + } else { callback(newFile.absolutePath) dismiss() } - } else { - callback(newFile.absolutePath) - dismiss() } - }) + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index 657d53e5..46d6490c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -51,7 +51,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) mView.apply { - items_swipe_refresh.setOnRefreshListener({ refreshItems() }) + items_swipe_refresh.setOnRefreshListener { refreshItems() } items_fab.setOnClickListener { createNewItem() } breadcrumbs.listener = this@ItemsFragment } @@ -160,13 +160,13 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as LinearLayoutManager) private fun getItems(path: String, callback: (items: ArrayList) -> Unit) { - Thread({ + Thread { if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) { getRegularItemsOf(path, callback) } else { RootHelpers().getFiles(activity as SimpleActivity, path, callback) } - }).start() + }.start() } private fun getRegularItemsOf(path: String, callback: (items: ArrayList) -> Unit) { diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 46e5bce6..0be50415 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,5 @@ - +