diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/YamlHttpSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/YamlHttpSource.kt index 2d907a53b..e73681d23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/YamlHttpSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/YamlHttpSource.kt @@ -176,8 +176,7 @@ class YamlHttpSource(mappings: Map<*, *>) : HttpSource() { val pages = mutableListOf() - // TODO lazy initialization in Kotlin 1.1 - val document = Jsoup.parse(body, url) + val document by lazy { Jsoup.parse(body, url) } with(map.pages) { // Capture a list of values where page urls will be resolved. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/FragmentMixin.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/FragmentMixin.kt index 1f43336c6..24c766182 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/FragmentMixin.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/fragment/FragmentMixin.kt @@ -1,6 +1,6 @@ package eu.kanade.tachiyomi.ui.base.fragment -import android.support.v7.app.AppCompatActivity +import android.support.v4.app.FragmentActivity import eu.kanade.tachiyomi.ui.base.activity.ActivityMixin interface FragmentMixin { @@ -13,7 +13,7 @@ interface FragmentMixin { (getActivity() as ActivityMixin).setToolbarTitle(getString(resourceId)) } - fun getActivity(): AppCompatActivity + fun getActivity(): FragmentActivity fun getString(resource: Int): String } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt index 15af1ad94..8c9639098 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt @@ -4,6 +4,7 @@ import android.content.res.Configuration import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.widget.DrawerLayout +import android.support.v7.app.AppCompatActivity import android.support.v7.widget.* import android.view.* import android.widget.ArrayAdapter @@ -155,7 +156,7 @@ open class CatalogueFragment : BaseRxFragment(), setupRecycler() // Create toolbar spinner - val themedContext = activity.supportActionBar?.themedContext ?: activity + val themedContext = (activity as AppCompatActivity).supportActionBar?.themedContext ?: activity val spinnerAdapter = ArrayAdapter(themedContext, android.R.layout.simple_spinner_item, presenter.sources) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index c0663516b..916022439 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -9,6 +9,7 @@ import android.support.design.widget.TabLayout import android.support.v4.graphics.drawable.DrawableCompat import android.support.v4.view.ViewPager import android.support.v4.widget.DrawerLayout +import android.support.v7.app.AppCompatActivity import android.support.v7.view.ActionMode import android.support.v7.widget.SearchView import android.view.* @@ -356,7 +357,7 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback */ fun createActionModeIfNeeded() { if (actionMode == null) { - actionMode = activity.startSupportActionMode(this) + actionMode = (activity as AppCompatActivity).startSupportActionMode(this) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index b1990ef80..8be382b6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -177,12 +177,9 @@ class LibraryPresenter : BasePresenter() { private fun applySort(map: Map>): Map> { val sortingMode = preferences.librarySortingMode().getOrDefault() - // TODO lazy initialization in kotlin 1.1 - var lastReadManga: Map? = null - if (sortingMode == LibrarySort.LAST_READ) { + val lastReadManga by lazy { var counter = 0 - lastReadManga = db.getLastReadManga().executeAsBlocking() - .associate { it.id!! to counter++ } + db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ } } val sortFn: (Manga, Manga) -> Int = { manga1, manga2 -> @@ -190,8 +187,8 @@ class LibraryPresenter : BasePresenter() { LibrarySort.ALPHA -> manga1.title.compareTo(manga2.title) LibrarySort.LAST_READ -> { // Get index of manga, set equal to list if size unknown. - val manga1LastRead = lastReadManga!![manga1.id!!] ?: lastReadManga!!.size - val manga2LastRead = lastReadManga!![manga2.id!!] ?: lastReadManga!!.size + val manga1LastRead = lastReadManga[manga1.id!!] ?: lastReadManga.size + val manga2LastRead = lastReadManga[manga2.id!!] ?: lastReadManga.size manga1LastRead.compareTo(manga2LastRead) } LibrarySort.LAST_UPDATED -> manga2.last_update.compareTo(manga1.last_update) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt index 7997bfb9c..359706dee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.app.DialogFragment +import android.support.v7.app.AppCompatActivity import android.support.v7.view.ActionMode import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager @@ -420,7 +421,7 @@ class ChaptersFragment : BaseRxFragment(), ActionMode.Callbac override fun onListItemLongClick(position: Int) { if (actionMode == null) - actionMode = activity.startSupportActionMode(this) + actionMode = (activity as AppCompatActivity).startSupportActionMode(this) toggleSelection(position) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt index 607f732b9..338f28d51 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersFragment.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.recent_updates import android.os.Bundle import android.support.v4.app.DialogFragment +import android.support.v7.app.AppCompatActivity import android.support.v7.view.ActionMode import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager @@ -142,7 +143,7 @@ class RecentChaptersFragment: */ override fun onItemLongClick(position: Int) { if (actionMode == null) - actionMode = activity.startSupportActionMode(this) + actionMode = (activity as AppCompatActivity).startSupportActionMode(this) toggleSelection(position) }