Improve UI
This commit is contained in:
@@ -9,7 +9,7 @@ data class Manga(
|
||||
val title: String,
|
||||
val localizedTitle: String? = null,
|
||||
val url: String,
|
||||
val rating: Float = -1f, //normalized value [0..1] or -1
|
||||
val rating: Float = NO_RATING, //normalized value [0..1] or -1
|
||||
val coverUrl: String,
|
||||
val largeCoverUrl: String? = null,
|
||||
val summary: String,
|
||||
@@ -18,4 +18,10 @@ data class Manga(
|
||||
val state: MangaState? = null,
|
||||
val chapters: List<MangaChapter>? = null,
|
||||
val source: MangaSource
|
||||
) : Parcelable
|
||||
) : Parcelable {
|
||||
|
||||
companion object {
|
||||
|
||||
const val NO_RATING = -1f
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class ReadmangaRepository(loaderContext: MangaLoaderContext) : MangaRepository(l
|
||||
?.substringBefore(' ')
|
||||
?.toFloatOrNull()
|
||||
?.div(10f)
|
||||
} ?: -1f,
|
||||
} ?: Manga.NO_RATING,
|
||||
tags = safe {
|
||||
descDiv.selectFirst("div.tile-info")
|
||||
?.select("a.element-link")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.ui.common
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Parcelable
|
||||
import androidx.annotation.IdRes
|
||||
@@ -21,4 +22,13 @@ abstract class BaseFragment(@LayoutRes contentLayoutId: Int) :
|
||||
fun <T : Parcelable> arg(name: String) = ParcelableArgumentDelegate<T>(name)
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) = Unit
|
||||
|
||||
open fun getTitle(): CharSequence? = null
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
getTitle()?.let {
|
||||
activity?.title = it
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,15 @@ import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
import org.koitharu.kotatsu.ui.main.list.MangaListFragment
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private lateinit var drawerToggle: ActionBarDrawerToggle
|
||||
|
||||
@@ -18,21 +20,23 @@ class MainActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
drawerToggle = ActionBarDrawerToggle(this, drawer, toolbar, R.string.open_menu, R.string.close_menu)
|
||||
drawerToggle =
|
||||
ActionBarDrawerToggle(this, drawer, toolbar, R.string.open_menu, R.string.close_menu)
|
||||
drawer.addDrawerListener(drawerToggle)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setHomeButtonEnabled(true)
|
||||
|
||||
navigationView.setNavigationItemSelectedListener(this)
|
||||
|
||||
if (!supportFragmentManager.isStateSaved) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, MangaListFragment.newInstance(MangaSource.READMANGA_RU))
|
||||
.commit()
|
||||
setPrimaryFragment(MangaListFragment.newInstance(MangaSource.READMANGA_RU))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
drawerToggle.syncState()
|
||||
initSideMenu(MangaSource.values().asList())
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
@@ -43,4 +47,33 @@ class MainActivity : BaseActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onNavigationItemSelected(item: MenuItem): Boolean {
|
||||
if (item.groupId == R.id.group_remote_sources) {
|
||||
val source = MangaSource.values().getOrNull(item.itemId) ?: return false
|
||||
setPrimaryFragment(MangaListFragment.newInstance(source))
|
||||
} else when (item.itemId) {
|
||||
R.id.nav_history -> Unit
|
||||
R.id.nav_favourites -> Unit
|
||||
R.id.nav_local_storage -> Unit
|
||||
else -> return false
|
||||
}
|
||||
drawer.closeDrawers()
|
||||
return true
|
||||
}
|
||||
|
||||
private fun initSideMenu(remoteSources: List<MangaSource>) {
|
||||
val submenu = navigationView.menu.findItem(R.id.nav_remote_sources).subMenu
|
||||
submenu.removeGroup(R.id.group_remote_sources)
|
||||
remoteSources.forEachIndexed { index, source ->
|
||||
submenu.add(R.id.group_remote_sources, source.ordinal, index, source.title)
|
||||
}
|
||||
submenu.setGroupCheckable(R.id.group_remote_sources, true, true)
|
||||
}
|
||||
|
||||
private fun setPrimaryFragment(fragment: Fragment) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, fragment)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import org.koitharu.kotatsu.ui.common.BaseFragment
|
||||
|
||||
class ChaptersFragment : BaseFragment(R.layout.fragment_chapters), MangaDetailsView {
|
||||
|
||||
@Suppress("unused")
|
||||
private val presenter by moxyPresenter { (activity as MangaDetailsActivity).presenter }
|
||||
|
||||
private lateinit var adapter: ChaptersAdapter
|
||||
|
||||
@@ -10,20 +10,24 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.ui.common.BaseFragment
|
||||
import org.koitharu.kotatsu.utils.ext.setChips
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class MangaDetailsFragment : BaseFragment(R.layout.fragment_details), MangaDetailsView {
|
||||
|
||||
@Suppress("unused")
|
||||
private val presenter by moxyPresenter { (activity as MangaDetailsActivity).presenter }
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onMangaUpdated(manga: Manga) {
|
||||
imageView_cover.load(manga.largeCoverUrl ?: manga.coverUrl)
|
||||
textView_title.text = manga.title
|
||||
textView_subtitle.text = manga.localizedTitle
|
||||
textView_description.text = manga.description
|
||||
if (manga.rating == Manga.NO_RATING) {
|
||||
ratingBar.isVisible = false
|
||||
} else {
|
||||
ratingBar.progress = (ratingBar.max * manga.rating).roundToInt()
|
||||
ratingBar.isVisible = true
|
||||
}
|
||||
chips_tags.setChips(manga.tags) {
|
||||
create(
|
||||
text = it.title,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.koitharu.kotatsu.ui.main.list
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import coil.api.load
|
||||
import coil.request.RequestDisposable
|
||||
import kotlinx.android.synthetic.main.item_manga_list_details.*
|
||||
@@ -8,11 +10,13 @@ import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.Manga
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class MangaListDetailsHolder(parent: ViewGroup) : BaseViewHolder<Manga>(parent, R.layout.item_manga_list_details) {
|
||||
|
||||
private var coverRequest: RequestDisposable? = null
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBind(data: Manga) {
|
||||
coverRequest?.dispose()
|
||||
textView_title.text = data.title
|
||||
@@ -20,5 +24,14 @@ class MangaListDetailsHolder(parent: ViewGroup) : BaseViewHolder<Manga>(parent,
|
||||
coverRequest = imageView_cover.load(data.coverUrl) {
|
||||
crossfade(true)
|
||||
}
|
||||
if(data.rating == Manga.NO_RATING) {
|
||||
textView_rating.isVisible = false
|
||||
} else {
|
||||
textView_rating.text = "${(data.rating * 10).roundToInt()}/10"
|
||||
textView_rating.isVisible = true
|
||||
}
|
||||
textView_tags.text = data.tags.joinToString(", ") {
|
||||
it.title
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,10 @@ class MangaListFragment : BaseFragment(R.layout.fragment_list), MangaListView,
|
||||
swipeRefreshLayout.isEnabled = !progressBar.isVisible
|
||||
}
|
||||
|
||||
override fun getTitle(): CharSequence? {
|
||||
return source.title
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
||||
when(key) {
|
||||
getString(R.string.key_list_mode) -> initListMode(settings.listMode)
|
||||
@@ -119,8 +123,8 @@ class MangaListFragment : BaseFragment(R.layout.fragment_list), MangaListView,
|
||||
}
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.addItemDecoration(when(mode) {
|
||||
ListMode.DETAILED_LIST,
|
||||
ListMode.LIST -> DividerItemDecoration(ctx, RecyclerView.VERTICAL)
|
||||
ListMode.DETAILED_LIST,
|
||||
ListMode.GRID -> SpacingItemDecoration(resources.getDimensionPixelOffset(R.dimen.grid_spacing))
|
||||
})
|
||||
adapter.notifyDataSetChanged()
|
||||
|
||||
Reference in New Issue
Block a user