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
|
2019-01-15 02:42:58 +01:00
|
|
|
import android.transition.TransitionInflater
|
2019-01-09 23:22:58 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-01-15 02:42:58 +01:00
|
|
|
import androidx.core.view.ViewCompat
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.navigation.Navigation
|
|
|
|
import androidx.navigation.fragment.FragmentNavigator
|
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(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
2019-01-30 03:59:19 +01:00
|
|
|
val view = inflater.inflate(R.layout.fragment_home, container, false)
|
|
|
|
SessionsComponent(view.homeLayout, ActionBusFactory.get(this)).setup()
|
|
|
|
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 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-29 00:26:37 +01:00
|
|
|
toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null)
|
|
|
|
toolbar.compoundDrawablePadding = (12f * Resources.getSystem().displayMetrics.density).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-28 17:46:39 +01:00
|
|
|
layoutComponents(homeLayout)
|
2019-01-10 01:07:33 +01:00
|
|
|
}
|
2019-01-09 23:22:58 +01:00
|
|
|
}
|