2019-02-05 22:52:04 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* 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/. */
|
2019-02-05 22:52:04 +01:00
|
|
|
|
|
|
|
package org.mozilla.fenix.library
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2019-02-08 00:37:52 +01:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuInflater
|
2019-02-05 22:52:04 +01:00
|
|
|
import android.view.View
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-04-23 16:23:27 +02:00
|
|
|
import androidx.appcompat.widget.Toolbar
|
2019-02-05 22:52:04 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2019-02-09 00:33:50 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_library.*
|
2019-03-21 20:41:41 +01:00
|
|
|
import mozilla.appservices.places.BookmarkRoot
|
2019-10-05 07:20:58 +02:00
|
|
|
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
2019-02-05 22:52:04 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-05-15 23:26:21 +02:00
|
|
|
import org.mozilla.fenix.components.metrics.Event
|
2019-06-06 21:40:10 +02:00
|
|
|
import org.mozilla.fenix.ext.nav
|
2019-05-15 23:26:21 +02:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2019-10-26 06:41:48 +02:00
|
|
|
import org.mozilla.fenix.ext.setToolbarColors
|
2019-11-25 21:36:47 +01:00
|
|
|
import org.mozilla.fenix.ext.showToolbar
|
2019-02-05 22:52:04 +01:00
|
|
|
|
2019-10-06 19:57:41 +02:00
|
|
|
/**
|
|
|
|
* Displays buttons to navigate to library sections, such as bookmarks and history.
|
|
|
|
*/
|
|
|
|
class LibraryFragment : Fragment(R.layout.fragment_library) {
|
2019-02-08 00:37:52 +01:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setHasOptionsMenu(true)
|
2019-02-25 20:37:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2019-10-26 06:41:48 +02:00
|
|
|
initToolbar()
|
2019-02-08 00:37:52 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 00:33:50 +01:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
2019-05-15 23:26:21 +02:00
|
|
|
libraryHistory.setOnClickListener {
|
|
|
|
requireComponents.analytics.metrics
|
|
|
|
.track(Event.LibrarySelectedItem(view.context.getString(R.string.library_history)))
|
2019-10-26 06:41:48 +02:00
|
|
|
nav(
|
|
|
|
R.id.libraryFragment,
|
|
|
|
LibraryFragmentDirections.actionLibraryFragmentToHistoryFragment()
|
|
|
|
)
|
2019-05-15 23:26:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
libraryBookmarks.setOnClickListener {
|
|
|
|
requireComponents.analytics.metrics
|
|
|
|
.track(Event.LibrarySelectedItem(view.context.getString(R.string.library_bookmarks)))
|
2019-06-06 21:40:10 +02:00
|
|
|
nav(
|
|
|
|
R.id.libraryFragment,
|
|
|
|
LibraryFragmentDirections.actionLibraryFragmentToBookmarksFragment(BookmarkRoot.Mobile.id)
|
|
|
|
)
|
2019-05-15 23:26:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
requireComponents.analytics.metrics.track(Event.LibraryOpened)
|
2019-02-09 00:33:50 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 00:37:52 +01:00
|
|
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
|
|
|
inflater.inflate(R.menu.library_menu, menu)
|
|
|
|
}
|
|
|
|
|
2019-05-15 23:26:21 +02:00
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
requireComponents.analytics.metrics.track(Event.LibraryClosed)
|
|
|
|
}
|
|
|
|
|
2019-10-26 06:41:48 +02:00
|
|
|
private fun initToolbar() {
|
2019-11-25 21:36:47 +01:00
|
|
|
(activity as? AppCompatActivity)?.let { activity ->
|
|
|
|
val toolbar = activity.findViewById<Toolbar>(R.id.navigationToolbar)
|
2019-10-26 06:41:48 +02:00
|
|
|
toolbar?.setToolbarColors(
|
2019-11-25 21:36:47 +01:00
|
|
|
foreground = activity.getColorFromAttr(R.attr.primaryText),
|
|
|
|
background = activity.getColorFromAttr(R.attr.foundation)
|
2019-10-26 06:41:48 +02:00
|
|
|
)
|
2019-11-25 21:36:47 +01:00
|
|
|
showToolbar(getString(R.string.library_title))
|
2019-10-26 06:41:48 +02:00
|
|
|
}
|
2019-04-23 16:23:27 +02:00
|
|
|
}
|
2019-02-05 22:52:04 +01:00
|
|
|
}
|