Remove unused classes and arrays resources

This commit is contained in:
inorichi 2017-05-16 14:11:23 +02:00
parent 062788f222
commit 5914346ace
6 changed files with 70 additions and 284 deletions

View File

@ -229,10 +229,15 @@ class SettingsBackupController : SettingsController() {
class CreateBackupDialog : DialogController() {
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog.Builder(activity!!)
val activity = activity!!
val options = arrayOf(R.string.manga, R.string.categories, R.string.chapters,
R.string.track, R.string.history)
.map { activity.getString(it) }
return MaterialDialog.Builder(activity)
.title(R.string.pref_create_backup)
.content(R.string.backup_choice)
.items(R.array.backup_options)
.items(options)
.itemsDisabledIndices(0)
.itemsCallbackMultiChoice(arrayOf(0, 1, 2, 3, 4), { _, positions, _ ->
var flags = 0

View File

@ -1,9 +1,11 @@
package eu.kanade.tachiyomi.ui.setting
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.support.v4.content.ContextCompat
import android.support.v7.preference.PreferenceScreen
@ -12,9 +14,13 @@ import com.hippo.unifile.UniFile
import com.nononsenseapps.filepicker.FilePickerActivity
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.DiskUtil
import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.io.File
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
@ -30,7 +36,9 @@ class SettingsDownloadController : SettingsController() {
key = Keys.downloadsDirectory
titleRes = R.string.pref_download_directory
onClick {
showDownloadDirectoriesDialog()
val ctrl = DownloadDirectoriesDialog()
ctrl.targetController = this@SettingsDownloadController
ctrl.showDialog(router)
}
preferences.downloadsDirectory().asObservable()
@ -115,49 +123,6 @@ class SettingsDownloadController : SettingsController() {
}
}
private fun showDownloadDirectoriesDialog() {
val activity = activity ?: return
val currentDir = preferences.downloadsDirectory().getOrDefault()
val externalDirs = getExternalFilesDirs() + File(activity.getString(R.string.custom_dir))
val selectedIndex = externalDirs.map(File::toString).indexOfFirst { it in currentDir }
MaterialDialog.Builder(activity)
.items(externalDirs)
.itemsCallbackSingleChoice(selectedIndex, { _, _, which, text ->
if (which == externalDirs.lastIndex) {
if (Build.VERSION.SDK_INT < 21) {
// Custom dir selected, open directory selector
val i = Intent(activity, CustomLayoutPickerActivity::class.java)
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR)
i.putExtra(FilePickerActivity.EXTRA_START_PATH, currentDir)
startActivityForResult(i, DOWNLOAD_DIR_PRE_L)
} else {
val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
startActivityForResult(i, DOWNLOAD_DIR_L)
}
} else {
// One of the predefined folders was selected
val path = Uri.fromFile(File(text.toString()))
preferences.downloadsDirectory().set(path.toString())
}
true
})
.show()
}
private fun getExternalFilesDirs(): List<File> {
val defaultDir = Environment.getExternalStorageDirectory().absolutePath +
File.separator + resources?.getString(R.string.app_name) +
File.separator + "downloads"
return mutableListOf(File(defaultDir)) +
ContextCompat.getExternalFilesDirs(activity, "").filterNotNull()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
DOWNLOAD_DIR_PRE_L -> if (data != null && resultCode == Activity.RESULT_OK) {
@ -179,6 +144,60 @@ class SettingsDownloadController : SettingsController() {
}
}
fun predefinedDirectorySelected(selectedDir: String) {
val path = Uri.fromFile(File(selectedDir))
preferences.downloadsDirectory().set(path.toString())
}
fun customDirectorySelected(currentDir: String) {
if (Build.VERSION.SDK_INT < 21) {
val i = Intent(activity, CustomLayoutPickerActivity::class.java)
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR)
i.putExtra(FilePickerActivity.EXTRA_START_PATH, currentDir)
startActivityForResult(i, DOWNLOAD_DIR_PRE_L)
} else {
val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
startActivityForResult(i, DOWNLOAD_DIR_L)
}
}
class DownloadDirectoriesDialog : DialogController() {
private val preferences: PreferencesHelper = Injekt.get()
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val activity = activity!!
val currentDir = preferences.downloadsDirectory().getOrDefault()
val externalDirs = getExternalDirs() + File(activity.getString(R.string.custom_dir))
val selectedIndex = externalDirs.map(File::toString).indexOfFirst { it in currentDir }
return MaterialDialog.Builder(activity)
.items(externalDirs)
.itemsCallbackSingleChoice(selectedIndex, { _, _, which, text ->
val target = targetController as? SettingsDownloadController
if (which == externalDirs.lastIndex) {
target?.customDirectorySelected(currentDir)
} else {
target?.predefinedDirectorySelected(text.toString())
}
true
})
.build()
}
private fun getExternalDirs(): List<File> {
val defaultDir = Environment.getExternalStorageDirectory().absolutePath +
File.separator + resources?.getString(R.string.app_name) +
File.separator + "downloads"
return mutableListOf(File(defaultDir)) +
ContextCompat.getExternalFilesDirs(activity, "").filterNotNull()
}
}
private companion object {
const val DOWNLOAD_DIR_PRE_L = 103
const val DOWNLOAD_DIR_L = 104

View File

@ -1,22 +0,0 @@
package eu.kanade.tachiyomi.widget
import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R
class DeletingChaptersDialog : DialogFragment() {
companion object {
const val TAG = "deleting_dialog"
}
override fun onCreateDialog(savedState: Bundle?): Dialog {
return MaterialDialog.Builder(activity)
.progress(true, 0)
.content(R.string.deleting)
.build()
}
}

View File

@ -1,55 +0,0 @@
package eu.kanade.tachiyomi.widget.preference
import android.os.Bundle
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceDialogFragmentCompat
import android.view.View
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import kotlinx.android.synthetic.main.pref_library_columns.view.*
import uy.kohesive.injekt.injectLazy
class LibraryColumnsDialog : PreferenceDialogFragmentCompat() {
companion object {
fun newInstance(preference: Preference): LibraryColumnsDialog {
val fragment = LibraryColumnsDialog()
val bundle = Bundle(1)
bundle.putString("key", preference.key)
fragment.arguments = bundle
return fragment
}
}
var portrait: Int = 0
var landscape: Int = 0
val preferences: PreferencesHelper by injectLazy()
override fun onBindDialogView(view: View) {
super.onBindDialogView(view)
portrait = preferences.portraitColumns().getOrDefault()
landscape = preferences.landscapeColumns().getOrDefault()
view.portrait_columns.value = portrait
view.landscape_columns.value = landscape
view.portrait_columns.setOnValueChangedListener { picker, oldValue, newValue ->
portrait = newValue
}
view.landscape_columns.setOnValueChangedListener { picker, oldValue, newValue ->
landscape = newValue
}
}
override fun onDialogClosed(positiveResult: Boolean) {
if (positiveResult) {
preferences.portraitColumns().set(portrait)
preferences.landscapeColumns().set(landscape)
}
}
}

View File

@ -1,11 +0,0 @@
package eu.kanade.tachiyomi.widget.preference
import android.content.Context
import android.support.v7.preference.DialogPreference
import android.support.v7.preference.R.attr
import android.util.AttributeSet
open class SimpleDialogPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = attr.dialogPreferenceStyle, defStyleRes: Int = 0) :
DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
}

View File

@ -22,18 +22,6 @@
<item>@string/webtoon_viewer</item>
</string-array>
<string-array name="themes_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="themes">
<item>@string/light_theme</item>
<item>@string/dark_theme</item>
<item>@string/amoled_theme</item>
</string-array>
<string-array name="reader_themes">
<item>@string/white_background</item>
<item>@string/black_background</item>
@ -44,38 +32,6 @@
<item>1</item>
</string-array>
<string-array name="download_slots">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="backup_slots">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>
<string-array name="remove_after_read_slots">
<item>@string/disabled</item>
<item>@string/last_read_chapter</item>
<item>@string/second_to_last</item>
<item>@string/third_to_last</item>
<item>@string/fourth_to_last</item>
<item>@string/fifth_to_last</item>
</string-array>
<string-array name="remove_after_read_slots_values">
<item>-1</item>
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<string-array name="image_decoders">
<item>Image</item>
<item>Rapid</item>
@ -134,76 +90,6 @@
<item>4</item>
</string-array>
<string-array name="library_update_interval">
<item>@string/update_never</item>
<item>@string/update_1hour</item>
<item>@string/update_2hour</item>
<item>@string/update_3hour</item>
<item>@string/update_6hour</item>
<item>@string/update_12hour</item>
<item>@string/update_24hour</item>
<item>@string/update_48hour</item>
</string-array>
<string-array name="library_update_interval_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>6</item>
<item>12</item>
<item>24</item>
<item>48</item>
</string-array>
<string-array name="backup_update_interval">
<item>@string/update_never</item>
<item>@string/update_6hour</item>
<item>@string/update_12hour</item>
<item>@string/update_24hour</item>
<item>@string/update_48hour</item>
<item>@string/update_weekly</item>
</string-array>
<string-array name="backup_update_interval_values">
<item>0</item>
<item>6</item>
<item>12</item>
<item>24</item>
<item>48</item>
<item>168</item>
</string-array>
<string-array name="library_update_restrictions">
<item>@string/wifi</item>
<item>@string/charging</item>
</string-array>
<string-array name="library_update_restrictions_values">
<item>wifi</item>
<item>ac</item>
</string-array>
<string-array name="remove_recently_read">
<item>@string/scale_type_fit_screen</item>
</string-array>
<string-array name="remove_recently_read_values">
<item>remove</item>
</string-array>
<string-array name="start_screen_selection">
<item>@string/label_library</item>
<item>@string/label_recent_manga</item>
<item>@string/label_recent_updates</item>
</string-array>
<string-array name="start_screen_selection_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="reader_image_options">
<item>@string/set_as_cover</item>
<item>@string/action_share</item>
@ -216,40 +102,4 @@
<item>2</item>
</string-array>
<string-array name="backup_options">
<item>@string/manga</item>
<item>@string/categories</item>
<item>@string/chapters</item>
<item>@string/track</item>
<item>@string/history</item>
</string-array>
<string-array name="backup_options_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<string-array name="languages_values">
<item/> <!-- system language -->
<item>bg</item>
<item>en</item>
<item>es</item>
<item>fr</item>
<item>it</item>
<item>pt</item>
<item>ru</item>
<item>vi</item>
</string-array>
<string-array name="default_category_entry">
<item>@string/default_category_summary</item>
</string-array>
<string-array name="default_category_entry_value">
<item>-1</item>
</string-array>
</resources>