For #355 - Navigat back to brows when you tap a history item
parent
aac39f97f2
commit
b9171cd99a
|
@ -15,6 +15,7 @@ data class HistoryItem(val url: String) {
|
|||
val title: String
|
||||
get() = siteTitle()
|
||||
|
||||
@SuppressWarnings("TooGenericExceptionCaught")
|
||||
private fun siteTitle(): String {
|
||||
return try {
|
||||
URL(url).host
|
||||
|
@ -50,7 +51,7 @@ class HistoryComponent(
|
|||
data class HistoryState(val items: List<HistoryItem>) : ViewState
|
||||
|
||||
sealed class HistoryAction : Action {
|
||||
object Select : HistoryAction()
|
||||
data class Select(val item: HistoryItem) : HistoryAction()
|
||||
}
|
||||
|
||||
sealed class HistoryChange : Change {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package org.mozilla.fenix.library.history
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
|
@ -22,6 +23,7 @@ import kotlinx.coroutines.launch
|
|||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.getSafeManagedObservable
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class HistoryFragment : Fragment(), CoroutineScope {
|
||||
|
@ -41,12 +43,23 @@ class HistoryFragment : Fragment(), CoroutineScope {
|
|||
return view
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
job = Job()
|
||||
|
||||
setHasOptionsMenu(true)
|
||||
(activity as AppCompatActivity).supportActionBar?.show()
|
||||
|
||||
getSafeManagedObservable<HistoryAction>()
|
||||
.subscribe {
|
||||
if (it is HistoryAction.Select) {
|
||||
Navigation.findNavController(requireActivity(), R.id.container)
|
||||
.popBackStack(R.id.browserFragment, false)
|
||||
|
||||
requireComponents.useCases.sessionUseCases.loadUrl.invoke(it.item.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
|
@ -5,16 +5,10 @@
|
|||
|
||||
package org.mozilla.fenix.library.history
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.Observable
|
||||
|
@ -36,7 +30,7 @@ class HistoryUIView(
|
|||
|
||||
init {
|
||||
view.apply {
|
||||
adapter = HistoryAdapter(context)
|
||||
adapter = HistoryAdapter(actionEmitter)
|
||||
layoutManager = LinearLayoutManager(container.context)
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +40,29 @@ class HistoryUIView(
|
|||
}
|
||||
}
|
||||
|
||||
private class HistoryAdapter(val context: Context) : RecyclerView.Adapter<HistoryAdapter.HistoryListItemViewHolder>() {
|
||||
class HistoryListItemViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
private class HistoryAdapter(
|
||||
private val actionEmitter: Observer<HistoryAction>
|
||||
) : RecyclerView.Adapter<HistoryAdapter.HistoryListItemViewHolder>() {
|
||||
class HistoryListItemViewHolder(
|
||||
view: View,
|
||||
private val actionEmitter: Observer<HistoryAction>
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
private var title = view.findViewById<TextView>(R.id.history_title)
|
||||
private var url = view.findViewById<TextView>(R.id.history_url)
|
||||
private var item: HistoryItem? = null
|
||||
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
item?.apply {
|
||||
actionEmitter.onNext(HistoryAction.Select(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(item: HistoryItem) {
|
||||
this.item = item
|
||||
|
||||
title.text = item.title
|
||||
url.text = item.url
|
||||
}
|
||||
|
@ -71,7 +82,7 @@ private class HistoryAdapter(val context: Context) : RecyclerView.Adapter<Histor
|
|||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryListItemViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
||||
|
||||
return HistoryListItemViewHolder(view)
|
||||
return HistoryListItemViewHolder(view, actionEmitter)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:padding="4dp"
|
||||
android:paddingStart="20dp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<TextView
|
||||
|
|
Loading…
Reference in New Issue