2019-01-09 23:22:58 +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.home
|
|
|
|
|
2019-01-29 00:26:37 +01:00
|
|
|
import android.content.res.Resources
|
|
|
|
import android.graphics.drawable.BitmapDrawable
|
2019-01-09 23:22:58 +01:00
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-01-15 02:42:58 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.navigation.Navigation
|
2019-01-10 01:07:33 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_home.*
|
2019-01-30 03:59:19 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_home.view.*
|
2019-01-09 23:22:58 +01:00
|
|
|
import org.mozilla.fenix.R
|
2019-01-30 03:59:19 +01:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2019-01-28 17:46:39 +01:00
|
|
|
import org.mozilla.fenix.home.sessions.SessionsComponent
|
|
|
|
import org.mozilla.fenix.home.sessions.layoutComponents
|
|
|
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
2019-01-29 00:26:37 +01:00
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
2019-01-09 23:22:58 +01:00
|
|
|
class HomeFragment : Fragment() {
|
|
|
|
override fun onCreateView(
|
2019-01-30 17:36:14 +01:00
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
2019-01-09 23:22:58 +01:00
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2019-01-30 03:59:19 +01:00
|
|
|
val view = inflater.inflate(R.layout.fragment_home, container, false)
|
2019-01-29 20:20:29 +01:00
|
|
|
SessionsComponent(view.homeLayout, ActionBusFactory.get(this))
|
|
|
|
ActionBusFactory.get(this).logMergedObservables()
|
2019-01-30 03:59:19 +01:00
|
|
|
return view
|
2019-01-09 23:22:58 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 01:07:33 +01:00
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
2019-01-11 18:44:22 +01:00
|
|
|
|
2019-01-29 20:20:29 +01:00
|
|
|
layoutComponents(view.homeLayout)
|
|
|
|
|
2019-01-29 00:26:37 +01:00
|
|
|
val searchIcon = requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext()).let {
|
|
|
|
BitmapDrawable(resources, it.icon)
|
|
|
|
}
|
2019-01-25 17:11:43 +01:00
|
|
|
|
2019-01-30 21:02:11 +01:00
|
|
|
// Temporary so we can easily test settings
|
|
|
|
menuButton.setOnClickListener {
|
|
|
|
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_settingsActivity, null, null)
|
|
|
|
}
|
|
|
|
|
2019-01-29 00:26:37 +01:00
|
|
|
toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null)
|
2019-01-30 17:36:14 +01:00
|
|
|
val roundToInt = (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
|
|
|
|
toolbar.compoundDrawablePadding = roundToInt
|
2019-01-15 02:42:58 +01:00
|
|
|
toolbar.setOnClickListener { it ->
|
2019-01-30 01:55:37 +01:00
|
|
|
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_searchFragment, null, null)
|
2019-01-10 01:19:54 +01:00
|
|
|
}
|
2019-01-10 01:07:33 +01:00
|
|
|
}
|
2019-01-30 17:36:14 +01:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val toolbarPaddingDp = 12f
|
|
|
|
}
|
2019-01-09 23:22:58 +01:00
|
|
|
}
|