2019-02-05 22:52:04 +01:00
|
|
|
/* 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.library
|
|
|
|
|
2019-05-11 03:24:56 +02:00
|
|
|
import android.graphics.PorterDuff
|
|
|
|
import android.graphics.PorterDuffColorFilter
|
2019-02-05 22:52:04 +01:00
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
2019-02-08 00:37:52 +01:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuInflater
|
|
|
|
import android.view.MenuItem
|
2019-02-05 22:52:04 +01:00
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
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-08 00:37:52 +01:00
|
|
|
import androidx.navigation.Navigation
|
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-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-04-23 16:23:27 +02:00
|
|
|
import org.mozilla.fenix.ext.getColorFromAttr
|
2019-05-15 23:26:21 +02:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2019-02-05 22:52:04 +01:00
|
|
|
|
|
|
|
class LibraryFragment : Fragment() {
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
|
|
|
return inflater.inflate(R.layout.fragment_library, container, false)
|
|
|
|
}
|
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-04-23 16:23:27 +02:00
|
|
|
|
|
|
|
setToolbarColor()
|
2019-04-10 00:36:21 +02:00
|
|
|
(activity as AppCompatActivity).title = getString(R.string.library_title)
|
2019-02-08 00:37:52 +01:00
|
|
|
(activity as AppCompatActivity).supportActionBar?.show()
|
|
|
|
}
|
|
|
|
|
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)))
|
|
|
|
Navigation.findNavController(view)
|
|
|
|
.navigate(LibraryFragmentDirections.actionLibraryFragmentToHistoryFragment())
|
|
|
|
}
|
|
|
|
|
|
|
|
libraryBookmarks.setOnClickListener {
|
|
|
|
requireComponents.analytics.metrics
|
|
|
|
.track(Event.LibrarySelectedItem(view.context.getString(R.string.library_bookmarks)))
|
|
|
|
Navigation.findNavController(view)
|
|
|
|
.navigate(LibraryFragmentDirections.actionLibraryFragmentToBookmarksFragment(BookmarkRoot.Mobile.id))
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
return when (item.itemId) {
|
|
|
|
R.id.libraryClose -> {
|
2019-02-13 01:04:01 +01:00
|
|
|
Navigation.findNavController(requireActivity(), R.id.container).navigateUp()
|
2019-02-08 00:37:52 +01:00
|
|
|
true
|
|
|
|
}
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 16:23:27 +02:00
|
|
|
|
2019-05-15 23:26:21 +02:00
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
requireComponents.analytics.metrics.track(Event.LibraryClosed)
|
|
|
|
}
|
|
|
|
|
2019-04-23 16:23:27 +02:00
|
|
|
private fun setToolbarColor() {
|
|
|
|
val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar)
|
2019-05-11 03:24:56 +02:00
|
|
|
|
|
|
|
val backgroundColor = R.attr.foundation.getColorFromAttr(context!!)
|
|
|
|
val foregroundColor = R.attr.primaryText.getColorFromAttr(context!!)
|
|
|
|
|
|
|
|
toolbar.setBackgroundColor(backgroundColor)
|
|
|
|
toolbar.setTitleTextColor(foregroundColor)
|
|
|
|
toolbar.navigationIcon?.colorFilter =
|
|
|
|
PorterDuffColorFilter(foregroundColor, PorterDuff.Mode.SRC_IN)
|
2019-04-23 16:23:27 +02:00
|
|
|
}
|
2019-02-05 22:52:04 +01:00
|
|
|
}
|