mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/357 - Adds a button to delete history
This commit is contained in:
parent
ac6d3a3f71
commit
a2fee5b715
@ -14,6 +14,7 @@ import android.widget.TextView
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import io.reactivex.Observer
|
import io.reactivex.Observer
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
|
||||||
class HistoryAdapter(
|
class HistoryAdapter(
|
||||||
private val actionEmitter: Observer<HistoryAction>
|
private val actionEmitter: Observer<HistoryAction>
|
||||||
@ -111,6 +112,24 @@ class HistoryAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class HistoryDeleteViewHolder(
|
||||||
|
view: View
|
||||||
|
) : RecyclerView.ViewHolder(view) {
|
||||||
|
private val button = view.findViewById<View>(R.id.delete_history_button)
|
||||||
|
private val text = view.findViewById<TextView>(R.id.delete_history_button_text).apply {
|
||||||
|
val color = ContextCompat.getColor(context, R.color.photonRed60)
|
||||||
|
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_delete)
|
||||||
|
drawable?.setTint(color)
|
||||||
|
this.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind() { }
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val LAYOUT_ID = R.layout.history_delete
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var items: List<HistoryItem> = emptyList()
|
private var items: List<HistoryItem> = emptyList()
|
||||||
private var mode: HistoryState.Mode = HistoryState.Mode.Normal
|
private var mode: HistoryState.Mode = HistoryState.Mode.Normal
|
||||||
|
|
||||||
@ -124,6 +143,7 @@ class HistoryAdapter(
|
|||||||
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
||||||
|
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
|
HistoryDeleteViewHolder.LAYOUT_ID -> HistoryDeleteViewHolder(view)
|
||||||
HistoryHeaderViewHolder.LAYOUT_ID -> HistoryHeaderViewHolder(view)
|
HistoryHeaderViewHolder.LAYOUT_ID -> HistoryHeaderViewHolder(view)
|
||||||
HistoryListItemViewHolder.LAYOUT_ID -> HistoryListItemViewHolder(view, actionEmitter)
|
HistoryListItemViewHolder.LAYOUT_ID -> HistoryListItemViewHolder(view, actionEmitter)
|
||||||
else -> throw IllegalStateException("viewType $viewType does not match to a ViewHolder")
|
else -> throw IllegalStateException("viewType $viewType does not match to a ViewHolder")
|
||||||
@ -132,7 +152,8 @@ class HistoryAdapter(
|
|||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
return when (position) {
|
return when (position) {
|
||||||
0 -> HistoryHeaderViewHolder.LAYOUT_ID
|
0 -> HistoryDeleteViewHolder.LAYOUT_ID
|
||||||
|
1 -> HistoryHeaderViewHolder.LAYOUT_ID
|
||||||
else -> HistoryListItemViewHolder.LAYOUT_ID
|
else -> HistoryListItemViewHolder.LAYOUT_ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +168,6 @@ class HistoryAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val NUMBER_OF_SECTIONS = 1
|
private const val NUMBER_OF_SECTIONS = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ data class HistoryState(val items: List<HistoryItem>, val mode: Mode) : ViewStat
|
|||||||
sealed class HistoryAction : Action {
|
sealed class HistoryAction : Action {
|
||||||
data class Select(val item: HistoryItem) : HistoryAction()
|
data class Select(val item: HistoryItem) : HistoryAction()
|
||||||
data class EnterEditMode(val item: HistoryItem) : HistoryAction()
|
data class EnterEditMode(val item: HistoryItem) : HistoryAction()
|
||||||
object onBackPressed : HistoryAction()
|
object BackPressed : HistoryAction()
|
||||||
data class AddItemForRemoval(val item: HistoryItem) : HistoryAction()
|
data class AddItemForRemoval(val item: HistoryItem) : HistoryAction()
|
||||||
data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction()
|
data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction()
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class HistoryFragment : Fragment(), CoroutineScope, BackHandler {
|
|||||||
.onNext(HistoryChange.AddItemForRemoval(it.item))
|
.onNext(HistoryChange.AddItemForRemoval(it.item))
|
||||||
is HistoryAction.RemoveItemForRemoval -> getManagedEmitter<HistoryChange>()
|
is HistoryAction.RemoveItemForRemoval -> getManagedEmitter<HistoryChange>()
|
||||||
.onNext(HistoryChange.RemoveItemForRemoval(it.item))
|
.onNext(HistoryChange.RemoveItemForRemoval(it.item))
|
||||||
is HistoryAction.onBackPressed -> getManagedEmitter<HistoryChange>()
|
is HistoryAction.BackPressed -> getManagedEmitter<HistoryChange>()
|
||||||
.onNext(HistoryChange.ExitEditMode)
|
.onNext(HistoryChange.ExitEditMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ class HistoryFragment : Fragment(), CoroutineScope, BackHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
if((historyComponent.uiView as HistoryUIView).onBackPressed()) { return true }
|
if ((historyComponent.uiView as HistoryUIView).onBackPressed()) { return true }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class HistoryUIView(
|
|||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
if (mode is HistoryState.Mode.Editing) {
|
if (mode is HistoryState.Mode.Editing) {
|
||||||
actionEmitter.onNext(HistoryAction.onBackPressed)
|
actionEmitter.onNext(HistoryAction.BackPressed)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
app/src/main/res/drawable/delete_history_background.xml
Normal file
9
app/src/main/res/drawable/delete_history_background.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<corners android:radius="4dp"/>
|
||||||
|
<solid android:color="@color/history_delete_button_background" />
|
||||||
|
</shape>
|
23
app/src/main/res/layout/history_delete.xml
Normal file
23
app/src/main/res/layout/history_delete.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/delete_history_button"
|
||||||
|
android:background="@drawable/delete_history_background"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:padding="6dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/delete_history_button_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Delete History"
|
||||||
|
android:textColor="@color/photonRed60"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
</FrameLayout>
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/history_title"
|
android:id="@+id/history_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
<color name="color_primary_dark">#202340</color>
|
<color name="color_primary_dark">#202340</color>
|
||||||
<color name="color_accent">#D81B60</color>
|
<color name="color_accent">#D81B60</color>
|
||||||
|
|
||||||
|
<color name="history_delete_button_background">#F2F2F5</color>
|
||||||
|
|
||||||
<color name="awesome_bar_title_color">#212121</color>
|
<color name="awesome_bar_title_color">#212121</color>
|
||||||
<color name="awesome_bar_description_color">#6b6b6b</color>
|
<color name="awesome_bar_description_color">#6b6b6b</color>
|
||||||
<color name="search_dark_background">#F2F2F5</color>
|
<color name="search_dark_background">#F2F2F5</color>
|
||||||
|
Loading…
Reference in New Issue
Block a user