[fenix] Fixes history visual bugs

pull/600/head
Jeff Boek 6 years ago
parent eda5d413f1
commit e222b24c7a

@ -10,6 +10,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer import io.reactivex.Observer
import kotlinx.coroutines.Job
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.library.history.viewholders.HistoryDeleteButtonViewHolder import org.mozilla.fenix.library.history.viewholders.HistoryDeleteButtonViewHolder
import org.mozilla.fenix.library.history.viewholders.HistoryHeaderViewHolder import org.mozilla.fenix.library.history.viewholders.HistoryHeaderViewHolder
@ -96,6 +97,7 @@ class HistoryAdapter(
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var historyList: HistoryList = HistoryList(emptyList()) private var historyList: HistoryList = HistoryList(emptyList())
private var mode: HistoryState.Mode = HistoryState.Mode.Normal private var mode: HistoryState.Mode = HistoryState.Mode.Normal
private lateinit var job: Job
fun updateData(items: List<HistoryItem>, mode: HistoryState.Mode) { fun updateData(items: List<HistoryItem>, mode: HistoryState.Mode) {
this.historyList = HistoryList(items) this.historyList = HistoryList(items)
@ -119,12 +121,11 @@ class HistoryAdapter(
return when (viewType) { return when (viewType) {
HistoryDeleteButtonViewHolder.LAYOUT_ID -> HistoryDeleteButtonViewHolder(view, actionEmitter) HistoryDeleteButtonViewHolder.LAYOUT_ID -> HistoryDeleteButtonViewHolder(view, actionEmitter)
HistoryHeaderViewHolder.LAYOUT_ID -> HistoryHeaderViewHolder(view) HistoryHeaderViewHolder.LAYOUT_ID -> HistoryHeaderViewHolder(view)
HistoryListItemViewHolder.LAYOUT_ID -> HistoryListItemViewHolder(view, actionEmitter) HistoryListItemViewHolder.LAYOUT_ID -> HistoryListItemViewHolder(view, actionEmitter, job)
else -> throw IllegalStateException() else -> throw IllegalStateException()
} }
} }
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) { when (holder) {
is HistoryDeleteButtonViewHolder -> holder.bind(mode) is HistoryDeleteButtonViewHolder -> holder.bind(mode)
@ -136,6 +137,16 @@ class HistoryAdapter(
is HistoryListItemViewHolder -> (historyList.items[position] as AdapterItem.Item).also { is HistoryListItemViewHolder -> (historyList.items[position] as AdapterItem.Item).also {
holder.bind(it.item, mode) holder.bind(it.item, mode)
} }
} }
}
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
job = Job()
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
job.cancel()
} }
} }

@ -17,11 +17,11 @@ class HistoryDeleteButtonViewHolder(
private val actionEmitter: Observer<HistoryAction> private val actionEmitter: Observer<HistoryAction>
) : RecyclerView.ViewHolder(view) { ) : RecyclerView.ViewHolder(view) {
private var mode: HistoryState.Mode? = null private var mode: HistoryState.Mode? = null
val delete_history_button_text = view.delete_history_button_text private val textView = view.delete_history_button_text
val delete_history_button = view.delete_history_button private val buttonView = view.delete_history_button
init { init {
delete_history_button.setOnClickListener { buttonView.setOnClickListener {
mode?.also { mode?.also {
val action = when (it) { val action = when (it) {
is HistoryState.Mode.Normal -> HistoryAction.Delete.All is HistoryState.Mode.Normal -> HistoryAction.Delete.All
@ -36,19 +36,19 @@ class HistoryDeleteButtonViewHolder(
val mode = mode val mode = mode
val text = if (mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) { val text = if (mode is HistoryState.Mode.Editing && mode.selectedItems.isNotEmpty()) {
delete_history_button_text.context.resources.getString( textView.context.resources.getString(
R.string.history_delete_some, R.string.history_delete_some,
mode.selectedItems.size mode.selectedItems.size
) )
} else { } else {
delete_history_button_text.context.resources.getString(R.string.history_delete_all) textView.context.resources.getString(R.string.history_delete_all)
} }
delete_history_button.contentDescription = text buttonView.contentDescription = text
delete_history_button_text.text = text textView.text = text
} }
companion object { companion object {
const val LAYOUT_ID = R.layout.delete_history_button const val LAYOUT_ID = R.layout.delete_history_button
} }
} }

@ -21,4 +21,4 @@ class HistoryHeaderViewHolder(
companion object { companion object {
const val LAYOUT_ID = R.layout.history_header const val LAYOUT_ID = R.layout.history_header
} }
} }

@ -9,17 +9,28 @@ import android.widget.CompoundButton
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer import io.reactivex.Observer
import kotlinx.android.synthetic.main.history_list_item.view.* import kotlinx.android.synthetic.main.history_list_item.view.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import mozilla.components.browser.icons.IconRequest
import mozilla.components.browser.menu.BrowserMenu import mozilla.components.browser.menu.BrowserMenu
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.library.history.HistoryAction import org.mozilla.fenix.library.history.HistoryAction
import org.mozilla.fenix.library.history.HistoryItem import org.mozilla.fenix.library.history.HistoryItem
import org.mozilla.fenix.library.history.HistoryItemMenu import org.mozilla.fenix.library.history.HistoryItemMenu
import org.mozilla.fenix.library.history.HistoryState import org.mozilla.fenix.library.history.HistoryState
import kotlin.coroutines.CoroutineContext
class HistoryListItemViewHolder( class HistoryListItemViewHolder(
view: View, view: View,
private val actionEmitter: Observer<HistoryAction> private val actionEmitter: Observer<HistoryAction>,
) : RecyclerView.ViewHolder(view) { val job: Job
) : RecyclerView.ViewHolder(view), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
private val checkbox = view.should_remove_checkbox private val checkbox = view.should_remove_checkbox
private val favicon = view.history_favicon private val favicon = view.history_favicon
@ -99,6 +110,8 @@ class HistoryListItemViewHolder(
} }
checkbox.setOnCheckedChangeListener(checkListener) checkbox.setOnCheckedChangeListener(checkListener)
} }
updateFavIcon(item.url)
} }
private fun setupMenu() { private fun setupMenu() {
@ -111,7 +124,17 @@ class HistoryListItemViewHolder(
} }
} }
private fun updateFavIcon(url: String) {
launch(Dispatchers.IO) {
val bitmap = favicon.context.components.utils.icons
.loadIcon(IconRequest(url)).await().bitmap
launch(Dispatchers.Main) {
favicon.setImageBitmap(bitmap)
}
}
}
companion object { companion object {
const val LAYOUT_ID = R.layout.history_list_item const val LAYOUT_ID = R.layout.history_list_item
} }
} }

@ -52,7 +52,7 @@
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textColor="?attr/historyURLColor" android:textColor="?attr/historyURLColor"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="4dp"
app:layout_constraintEnd_toStartOf="@id/history_item_overflow" app:layout_constraintEnd_toStartOf="@id/history_item_overflow"
app:layout_constraintStart_toEndOf="@id/history_favicon" app:layout_constraintStart_toEndOf="@id/history_favicon"
app:layout_constraintTop_toBottomOf="@id/history_title" /> app:layout_constraintTop_toBottomOf="@id/history_title" />
@ -62,6 +62,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textAlignment="viewStart" android:textAlignment="viewStart"
@ -69,5 +70,5 @@
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintEnd_toStartOf="@id/history_item_overflow" app:layout_constraintEnd_toStartOf="@id/history_item_overflow"
app:layout_constraintStart_toEndOf="@id/history_favicon" app:layout_constraintStart_toEndOf="@id/history_favicon"
app:layout_constraintTop_toTopOf="@id/history_item_overflow" /> app:layout_constraintTop_toTopOf="@id/history_favicon" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save