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
|
|
|
|
|
|
|
|
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-04-23 16:23:27 +02:00
|
|
|
import org.mozilla.fenix.ext.getColorFromAttr
|
2019-03-21 20:41:41 +01:00
|
|
|
import org.mozilla.fenix.library.bookmarks.BookmarkFragmentArgs
|
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-03-22 01:08:03 +01:00
|
|
|
libraryHistory.setOnClickListener(
|
|
|
|
Navigation.createNavigateOnClickListener(
|
|
|
|
LibraryFragmentDirections.actionLibraryFragmentToHistoryFragment().actionId,
|
|
|
|
null
|
|
|
|
)
|
2019-02-12 18:47:51 +01:00
|
|
|
)
|
2019-03-21 20:41:41 +01:00
|
|
|
|
2019-04-29 23:54:48 +02:00
|
|
|
libraryBookmarks.setOnClickListener(
|
|
|
|
Navigation.createNavigateOnClickListener(
|
|
|
|
LibraryFragmentDirections.actionLibraryFragmentToBookmarksFragment(BookmarkRoot.Mobile.id).actionId,
|
|
|
|
BookmarkFragmentArgs(BookmarkRoot.Mobile.id).toBundle()
|
|
|
|
)
|
|
|
|
)
|
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
|
|
|
|
|
|
|
private fun setToolbarColor() {
|
|
|
|
val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar)
|
|
|
|
toolbar.setBackgroundColor(R.attr.foundation.getColorFromAttr(context!!))
|
|
|
|
toolbar.setTitleTextColor(R.attr.primaryText.getColorFromAttr(context!!))
|
|
|
|
}
|
2019-02-05 22:52:04 +01:00
|
|
|
}
|