mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 21:45:14 -04:00
Delete duplicate dialog, format and clean up PagerAdapter, languageViewHolder, BooksAdapter, LibraryFragment
This commit is contained in:
parent
d819352d60
commit
f318da929c
@ -17,10 +17,6 @@ sealed class KiwixDialog(
|
||||
title: Int,
|
||||
message: Int
|
||||
) : KiwixDialog(title, message, R.string.yes, R.string.no) {
|
||||
object NoWifi : YesNoDialog(
|
||||
R.string.wifi_only_title, R.string.wifi_only_msg
|
||||
)
|
||||
|
||||
object StopDownload : YesNoDialog(
|
||||
R.string.confirm_stop_download_title, R.string.confirm_stop_download_msg
|
||||
)
|
||||
|
@ -34,23 +34,21 @@ class LanguageSelectDialog constructor(
|
||||
context: Context
|
||||
) : AlertDialog(context) {
|
||||
|
||||
class Builder : AlertDialog.Builder,LayoutContainer {
|
||||
class Builder : AlertDialog.Builder, LayoutContainer {
|
||||
lateinit var dialogView: View
|
||||
override val containerView: View? by lazy { dialogView }
|
||||
lateinit var onOkClicked: (List<Language>) -> Unit
|
||||
var languages: List<Language> = listOf()
|
||||
|
||||
constructor(context: Context) : super(context) {}
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
themeResId: Int
|
||||
) : super(context, themeResId) {
|
||||
}
|
||||
) : super(context, themeResId)
|
||||
|
||||
override fun create(): AlertDialog {
|
||||
dialogView = View.inflate(context, R.layout.language_selection, null)
|
||||
|
||||
val languageArrayAdapter = LanguageAdapter(languages.toMutableList())
|
||||
language_check_view.run {
|
||||
adapter = languageArrayAdapter
|
||||
@ -61,9 +59,7 @@ class LanguageSelectDialog constructor(
|
||||
setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
onOkClicked.invoke(languageArrayAdapter.listItems)
|
||||
}
|
||||
|
||||
return super.create()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import kotlinx.android.synthetic.main.language_check_item.language_entries_count
|
||||
import kotlinx.android.synthetic.main.language_check_item.language_name
|
||||
import kotlinx.android.synthetic.main.language_check_item.language_name_localized
|
||||
import kotlinx.android.synthetic.main.language_check_item.language_row
|
||||
import org.kiwix.kiwixmobile.R.string
|
||||
import org.kiwix.kiwixmobile.R
|
||||
import org.kiwix.kiwixmobile.utils.LanguageUtils
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.adapter.Language
|
||||
|
||||
@ -25,7 +25,7 @@ class LanguageViewHolder(
|
||||
val context = containerView.context
|
||||
language_name.text = language.language
|
||||
language_name_localized.text = context.getString(
|
||||
string.language_localized,
|
||||
R.string.language_localized,
|
||||
language.languageLocalized
|
||||
)
|
||||
language_name_localized.typeface = Typeface.createFromAsset(
|
||||
@ -33,7 +33,7 @@ class LanguageViewHolder(
|
||||
LanguageUtils.getTypeface(language.languageCode)
|
||||
)
|
||||
language_entries_count.text =
|
||||
context.getString(string.language_count, language.occurencesOfLanguage)
|
||||
context.getString(R.string.language_count, language.occurencesOfLanguage)
|
||||
language_checkbox.setOnCheckedChangeListener(null)
|
||||
language_checkbox.isChecked = language.active
|
||||
language_checkbox.setOnCheckedChangeListener { _, _ ->
|
||||
|
@ -30,14 +30,10 @@ class SectionsPagerAdapter(
|
||||
fm: FragmentManager
|
||||
) : FragmentPagerAdapter(fm) {
|
||||
|
||||
private val zimFileSelectFragment = ZimFileSelectFragment()
|
||||
private val libraryFragment = LibraryFragment()
|
||||
private val downloadFragment = DownloadFragment()
|
||||
|
||||
override fun getItem(position: Int) = when (position) {
|
||||
0 -> zimFileSelectFragment
|
||||
1 -> libraryFragment
|
||||
2 -> downloadFragment
|
||||
0 -> ZimFileSelectFragment()
|
||||
1 -> LibraryFragment()
|
||||
2 -> DownloadFragment()
|
||||
else -> throw RuntimeException("No matching fragment for position: $position")
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import org.kiwix.kiwixmobile.extensions.inflate
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.utils.BookUtils
|
||||
|
||||
// The Adapter for the ListView for when the ListView is populated with the rescanned files
|
||||
class BooksAdapter(
|
||||
private val bookUtils: BookUtils,
|
||||
private val onItemClick: (Book) -> Unit,
|
||||
|
@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.zim_manager.library_view
|
||||
import android.arch.lifecycle.Observer
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
@ -87,7 +86,7 @@ class LibraryFragment : BaseFragment() {
|
||||
private val noWifiWithWifiOnlyPreferenceSet
|
||||
get() = sharedPreferenceUtil.prefWifiOnly && !NetworkUtils.isWiFi(context!!)
|
||||
|
||||
private val isNotConnected get() = conMan.activeNetworkInfo?.isConnected?.not() ?: true
|
||||
private val isNotConnected get() = conMan.activeNetworkInfo?.isConnected == false
|
||||
|
||||
override fun inject(activityComponent: ActivityComponent) {
|
||||
activityComponent.inject(this)
|
||||
@ -210,19 +209,20 @@ class LibraryFragment : BaseFragment() {
|
||||
spaceAvailable < item.book.size.toLong() * 1024f
|
||||
|
||||
private fun showStorageSelectDialog() {
|
||||
val dialogFragment = StorageSelectDialog()
|
||||
dialogFragment.arguments = Bundle().apply {
|
||||
putString(
|
||||
StorageSelectDialog.STORAGE_DIALOG_INTERNAL,
|
||||
getString(string.internal_storage)
|
||||
)
|
||||
putString(
|
||||
StorageSelectDialog.STORAGE_DIALOG_EXTERNAL,
|
||||
getString(string.external_storage)
|
||||
)
|
||||
putInt(StorageSelectDialog.STORAGE_DIALOG_THEME, StyleUtils.dialogStyle())
|
||||
StorageSelectDialog().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(
|
||||
StorageSelectDialog.STORAGE_DIALOG_INTERNAL,
|
||||
getString(string.internal_storage)
|
||||
)
|
||||
putString(
|
||||
StorageSelectDialog.STORAGE_DIALOG_EXTERNAL,
|
||||
getString(string.external_storage)
|
||||
)
|
||||
putInt(StorageSelectDialog.STORAGE_DIALOG_THEME, StyleUtils.dialogStyle())
|
||||
}
|
||||
setOnSelectListener(this@LibraryFragment::storeDeviceInPreferences)
|
||||
}
|
||||
dialogFragment.setOnSelectListener(this::storeDeviceInPreferences)
|
||||
dialogFragment.show(fragmentManager, getString(string.pref_storage))
|
||||
.show(fragmentManager, getString(string.pref_storage))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user