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/225 -Adds checkbox listener to data items
This commit is contained in:
parent
66af144c4f
commit
cce2ebb754
@ -10,12 +10,66 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.android.synthetic.main.fragment_delete_browsing_data.view.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class DeleteBrowsingDataFragment : Fragment(), CoroutineScope {
|
||||
private lateinit var sessionObserver: SessionManager.Observer
|
||||
|
||||
class DeleteBrowsingDataFragment : Fragment() {
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_delete_browsing_data, container, false)
|
||||
private lateinit var job: Job
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.Main + job
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
|
||||
inflater.inflate(R.layout.fragment_delete_browsing_data, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
job = Job()
|
||||
|
||||
sessionObserver = object : SessionManager.Observer {
|
||||
override fun onSessionAdded(session: Session) {
|
||||
super.onSessionAdded(session)
|
||||
updateTabCount()
|
||||
}
|
||||
|
||||
override fun onSessionRemoved(session: Session) {
|
||||
super.onSessionRemoved(session)
|
||||
updateTabCount()
|
||||
}
|
||||
|
||||
override fun onSessionSelected(session: Session) {
|
||||
super.onSessionSelected(session)
|
||||
updateTabCount()
|
||||
}
|
||||
|
||||
override fun onSessionsRestored() {
|
||||
super.onSessionsRestored()
|
||||
updateTabCount()
|
||||
}
|
||||
|
||||
override fun onAllSessionsRemoved() {
|
||||
super.onAllSessionsRemoved()
|
||||
updateTabCount()
|
||||
}
|
||||
}
|
||||
|
||||
requireComponents.core.sessionManager.register(sessionObserver, owner = this)
|
||||
|
||||
view?.open_tabs_item?.onCheckListener = { _ -> updateDeleteButton() }
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@ -24,5 +78,54 @@ class DeleteBrowsingDataFragment : Fragment() {
|
||||
title = getString(R.string.preferences_delete_browsing_data)
|
||||
supportActionBar?.show()
|
||||
}
|
||||
|
||||
updateTabCount()
|
||||
updateHistoryCount()
|
||||
updateCollectionsCount()
|
||||
}
|
||||
|
||||
private fun updateDeleteButton() {
|
||||
|
||||
}
|
||||
|
||||
private fun updateTabCount() {
|
||||
view?.open_tabs_item?.apply {
|
||||
val openTabs = requireComponents.core.sessionManager.size
|
||||
subtitleView.text = resources.getString(R.string.preferences_delete_browsing_data_tabs_subtitle, openTabs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateHistoryCount() {
|
||||
view?.browsing_data_item?.subtitleView?.text = ""
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
val historyCount = requireComponents.core.historyStorage.getVisited().size
|
||||
launch(Dispatchers.Main) {
|
||||
view?.browsing_data_item?.apply {
|
||||
subtitleView.text =
|
||||
resources.getString(
|
||||
R.string.preferences_delete_browsing_data_browsing_data_subtitle,
|
||||
historyCount
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCollectionsCount() {
|
||||
view?.browsing_data_item?.subtitleView?.text = ""
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
val collectionsCount = requireComponents.core.tabCollectionStorage.getTabCollectionsCount()
|
||||
launch(Dispatchers.Main) {
|
||||
view?.collections_item?.apply {
|
||||
subtitleView.text =
|
||||
resources.getString(
|
||||
R.string.preferences_delete_browsing_data_collections_subtitle,
|
||||
collectionsCount
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package org.mozilla.fenix.settings
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import kotlinx.android.synthetic.main.delete_browsing_data_item.view.*
|
||||
import org.mozilla.fenix.R
|
||||
@ -16,6 +17,18 @@ class DeleteBrowsingDataItem @JvmOverloads constructor(
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
val titleView: TextView
|
||||
get() = title
|
||||
|
||||
val subtitleView: TextView
|
||||
get() = subtitle
|
||||
|
||||
val isChecked: Boolean
|
||||
get() = checkbox.isChecked
|
||||
|
||||
var onCheckListener: ((Boolean) -> Unit)? = null
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.delete_browsing_data_item, this, true)
|
||||
|
||||
@ -23,6 +36,10 @@ class DeleteBrowsingDataItem @JvmOverloads constructor(
|
||||
checkbox.isChecked = !checkbox.isChecked
|
||||
}
|
||||
|
||||
checkbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
onCheckListener?.invoke(isChecked)
|
||||
}
|
||||
|
||||
attrs.let {
|
||||
context.theme.obtainStyledAttributes(
|
||||
it,
|
||||
|
@ -13,7 +13,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<org.mozilla.fenix.settings.DeleteBrowsingDataItem
|
||||
android:id="@+id/openTabsItem"
|
||||
android:id="@+id/open_tabs_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
@ -24,7 +24,7 @@
|
||||
app:deleteBrowsingDataItemTitle="@string/preferences_delete_browsing_data_tabs_title"
|
||||
app:deleteBrowsingDataItemSubtitle="@string/preferences_delete_browsing_data_tabs_subtitle" />
|
||||
<org.mozilla.fenix.settings.DeleteBrowsingDataItem
|
||||
android:id="@+id/browsingDataItem"
|
||||
android:id="@+id/browsing_data_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
@ -35,7 +35,7 @@
|
||||
app:deleteBrowsingDataItemTitle="@string/preferences_delete_browsing_data_browsing_data_title"
|
||||
app:deleteBrowsingDataItemSubtitle="@string/preferences_delete_browsing_data_browsing_data_subtitle" />
|
||||
<org.mozilla.fenix.settings.DeleteBrowsingDataItem
|
||||
android:id="@+id/collectionsItem"
|
||||
android:id="@+id/collections_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
|
@ -568,15 +568,15 @@
|
||||
<!-- Title for the tabs item in Delete browsing data -->
|
||||
<string name="preferences_delete_browsing_data_tabs_title">Open Tabs</string>
|
||||
<!-- Subtitle for the tabs item in Delete browsing data, parameter will be replaced with the number of open tabs -->
|
||||
<string name="preferences_delete_browsing_data_tabs_subtitle">%s tabs</string>
|
||||
<string name="preferences_delete_browsing_data_tabs_subtitle">%d tabs</string>
|
||||
<!-- Title for the data and history items in Delete browsing data -->
|
||||
<string name="preferences_delete_browsing_data_browsing_data_title">Browsing history and site data</string>
|
||||
<!-- Subtitle for the data and history items item in Delete browsing data, parameter will be replaced with the
|
||||
number of history items the user has -->
|
||||
<string name="preferences_delete_browsing_data_browsing_data_subtitle">%s addresses</string>
|
||||
<string name="preferences_delete_browsing_data_browsing_data_subtitle">%d addresses</string>
|
||||
<!-- Title for the collections item in Delete browsing data -->
|
||||
<string name="preferences_delete_browsing_data_collections_title">Collections</string>
|
||||
<!-- Subtitle for the collections item in Delete browsing data, parameter will be replaced with the
|
||||
number of collections that will be deleted -->
|
||||
<string name="preferences_delete_browsing_data_collections_subtitle">%s collections</string>
|
||||
<string name="preferences_delete_browsing_data_collections_subtitle">%d collections</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user