mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Remove unused classes and arrays resources
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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() | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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) { | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user