[fenix] For https://github.com/mozilla-mobile/fenix/issues/673 - Modifies Session Bottom Sheet to work for current and archived sessions
parent
55b8b21e5c
commit
3cd141bffd
@ -1,51 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
package org.mozilla.fenix.home.sessions
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.current_session_bottom_sheet.view.*
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
|
||||
class CurrentSessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer {
|
||||
|
||||
override val containerView: View?
|
||||
get() = view
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CurrentSessionBottomSheetDialogTheme)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.current_session_bottom_sheet, container, false)
|
||||
val sessions = requireComponents.core.sessionManager.sessions.filter {
|
||||
(activity as HomeActivity).browsingModeManager.isPrivate == it.private
|
||||
}
|
||||
|
||||
view.current_session_card_tab_list.text = sessions.joinToString(", ") {
|
||||
if (it.title.length > maxTitleLength) it.title.substring(0, maxTitleLength) + "..." else it.title
|
||||
}
|
||||
|
||||
view.delete_session_button.setOnClickListener {
|
||||
sessions.forEach {
|
||||
requireComponents.core.sessionManager.remove(it)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val maxTitleLength = 20
|
||||
const val overflowFragmentTag = "sessionOverflow"
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/* 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/. */
|
||||
|
||||
package org.mozilla.fenix.home.sessions
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.session_bottom_sheet.view.*
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer {
|
||||
var archivedSession: ArchivedSession? = null
|
||||
var isCurrentSession: Boolean = false
|
||||
private lateinit var tabTitles: String
|
||||
var onDelete: ((ArchivedSession) -> Boolean)? = null
|
||||
var onArchive: (() -> Unit)? = null
|
||||
|
||||
override val containerView: View?
|
||||
get() = view
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CurrentSessionBottomSheetDialogTheme)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.session_bottom_sheet, container, false)
|
||||
val snapshot = archivedSession?.bundle?.restoreSnapshot(requireComponents.core.engine)
|
||||
?: throw IllegalStateException()
|
||||
|
||||
tabTitles = snapshot.sessions
|
||||
.map { it.session.title }
|
||||
.joinToString(", ") {
|
||||
if (it.length > maxTitleLength) it.substring(0, maxTitleLength) + "..." else it
|
||||
}
|
||||
|
||||
if (!isCurrentSession) {
|
||||
view.current_session_card_title.text = archivedSession?.formattedSavedAt
|
||||
}
|
||||
|
||||
view.current_session_card_tab_list.text = tabTitles
|
||||
|
||||
view.archive_session_button.apply {
|
||||
visibility = if (isCurrentSession) View.VISIBLE else View.GONE
|
||||
setOnClickListener {
|
||||
onArchive?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
view.delete_session_button.setOnClickListener {
|
||||
if (onDelete?.invoke(archivedSession!!) == true) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val maxTitleLength = 20
|
||||
const val overflowFragmentTag = "sessionOverflow"
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
app:layout_behavior="@string/bottom_sheet_behavior"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<!-- 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/. -->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
app:layout_behavior="@string/bottom_sheet_behavior"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/current_session_card"
|
Loading…
Reference in New Issue