app/src/main/java/com/mizo0203/natureremoapisample/MainFragment.kt
/*
* Copyright 2019, Satoki Mizoguchi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mizo0203.natureremoapisample
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import com.mizo0203.natureremoapisample.databinding.FragmentMainBinding
import com.mizo0203.natureremoapisample.util.setupSnackbar
/**
* Display a grid of [Task]s. User can choose to view all, active or completed tasks.
*/
class MainFragment : Fragment() {
private lateinit var viewDataBinding: FragmentMainBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
viewDataBinding = FragmentMainBinding.inflate(inflater, container, false).apply {
viewmodel = (activity as MainActivity).obtainViewModel()
}
setHasOptionsMenu(true)
return viewDataBinding.root
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewDataBinding.viewmodel?.let {
view?.setupSnackbar(this, it.snackbarMessage, Snackbar.LENGTH_LONG)
}
viewDataBinding.lifecycleOwner = this.viewLifecycleOwner
}
companion object {
fun newInstance() = MainFragment()
@Suppress("unused")
private const val TAG = "MainFragment"
}
}