/* 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 import android.content.res.Resources import android.graphics.drawable.BitmapDrawable import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.navigation.Navigation import kotlinx.android.synthetic.main.fragment_home.* import kotlinx.android.synthetic.main.fragment_home.view.* import org.mozilla.fenix.R import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.home.sessions.SessionsComponent import org.mozilla.fenix.home.sessions.layoutComponents import org.mozilla.fenix.mvi.ActionBusFactory import kotlin.math.roundToInt class HomeFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.fragment_home, container, false) SessionsComponent(view.homeLayout, ActionBusFactory.get(this)) ActionBusFactory.get(this).logMergedObservables() return view } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) layoutComponents(view.homeLayout) val searchIcon = requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext()).let { BitmapDrawable(resources, it.icon) } // Temporary so we can easily test settings menuButton.setOnClickListener { Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_settingsActivity, null, null) } toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null) val roundToInt = (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt() toolbar.compoundDrawablePadding = roundToInt toolbar.setOnClickListener { it -> Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_searchFragment, null, null) } } companion object { const val toolbarPaddingDp = 12f } }