Layout animations
This commit is contained in:
parent
5026415e45
commit
387ea890de
@ -4,6 +4,7 @@ import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import it.danieleverducci.subitobeers.entities.Beer
|
||||
import it.danieleverducci.subitobeers.ui.BeerDetailFragment
|
||||
|
||||
@ -17,6 +18,7 @@ class MainActivity : AppCompatActivity(), BeerNavigation {
|
||||
override fun showBeerDetail(beer: Beer) {
|
||||
val detailFragment = BeerDetailFragment(beer)
|
||||
supportFragmentManager.beginTransaction()
|
||||
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
|
||||
.replace(R.id.fragment_container, detailFragment)
|
||||
.addToBackStack(null)
|
||||
.commit()
|
||||
|
@ -24,9 +24,15 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
|
||||
enum class FILTERTYPE {SINCE, TO, CLEAR}
|
||||
|
||||
companion object {
|
||||
val INSTANCESTATE_FILTER_OPEN = "filter_open"
|
||||
val INSTANCESTATE_FILTER_SINCE = "filter_since"
|
||||
val INSTANCESTATE_FILTER_TO = "filter_to"
|
||||
}
|
||||
|
||||
private val rvAdapter = BeerRecyclerAdapter()
|
||||
private val repo = BeersRepository()
|
||||
lateinit var binding: FragmentBeersListBinding
|
||||
private var binding: FragmentBeersListBinding? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
@ -34,6 +40,7 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
): View? {
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
if (binding == null) {
|
||||
// Inflate layout
|
||||
binding = FragmentBeersListBinding.inflate(
|
||||
LayoutInflater.from(container!!.context),
|
||||
@ -42,12 +49,12 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
)
|
||||
|
||||
// Register filter buttons listeners
|
||||
binding.listFilterSinceBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.SINCE) }
|
||||
binding.listFilterToBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.TO) }
|
||||
binding.listFilterClear.setOnClickListener { onFilterButtonClicked(FILTERTYPE.CLEAR) }
|
||||
binding!!.listFilterSinceBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.SINCE) }
|
||||
binding!!.listFilterToBt.setOnClickListener { onFilterButtonClicked(FILTERTYPE.TO) }
|
||||
binding!!.listFilterClear.setOnClickListener { onFilterButtonClicked(FILTERTYPE.CLEAR) }
|
||||
|
||||
// Set the adapter
|
||||
with(binding.list) {
|
||||
with(binding!!.list) {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
adapter = rvAdapter
|
||||
}
|
||||
@ -58,12 +65,27 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
// Register for network completed events
|
||||
repo.listener = this
|
||||
|
||||
// Restore state
|
||||
repo.filter.brewedBefore = savedInstanceState?.getString(INSTANCESTATE_FILTER_TO)
|
||||
repo.filter.brewedAfter = savedInstanceState?.getString(INSTANCESTATE_FILTER_SINCE)
|
||||
binding!!.listFilterDropdown.visibility =
|
||||
if (savedInstanceState?.getBoolean(INSTANCESTATE_FILTER_OPEN) == true) View.VISIBLE else View.GONE
|
||||
|
||||
// Load first page
|
||||
loadBeers(true)
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
return binding!!.root
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
outState.putBoolean(INSTANCESTATE_FILTER_OPEN, binding!!.listFilterDropdown.visibility == View.VISIBLE)
|
||||
outState.putString(INSTANCESTATE_FILTER_SINCE, repo.filter.brewedAfter)
|
||||
outState.putString(INSTANCESTATE_FILTER_TO, repo.filter.brewedBefore)
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
requireActivity().menuInflater.inflate(R.menu.list_menu, menu)
|
||||
@ -101,8 +123,8 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
if (type == FILTERTYPE.CLEAR) {
|
||||
repo.filter.clear()
|
||||
loadBeers(true)
|
||||
binding.listFilterSinceBt.setText(R.string.list_filter_brewed_after)
|
||||
binding.listFilterToBt.setText(R.string.list_filter_brewed_before)
|
||||
binding!!.listFilterSinceBt.setText(R.string.list_filter_brewed_after)
|
||||
binding!!.listFilterToBt.setText(R.string.list_filter_brewed_before)
|
||||
return
|
||||
}
|
||||
|
||||
@ -111,10 +133,10 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
|
||||
if (type == FILTERTYPE.SINCE) {
|
||||
repo.filter.setBrewedAfter(selMonth, selYear)
|
||||
binding.listFilterSinceBt.setText(repo.filter.brewedAfter)
|
||||
binding!!.listFilterSinceBt.setText(repo.filter.brewedAfter)
|
||||
} else {
|
||||
repo.filter.setBrewedBefore(selMonth, selYear)
|
||||
binding.listFilterToBt.setText(repo.filter.brewedBefore)
|
||||
binding!!.listFilterToBt.setText(repo.filter.brewedBefore)
|
||||
}
|
||||
|
||||
// Update list
|
||||
@ -146,8 +168,8 @@ class BeersFragment : Fragment(), BeersRepository.Listener, BeerRecyclerAdapter.
|
||||
* Toggles beer filter visibility
|
||||
*/
|
||||
private fun toggleFilter() {
|
||||
binding.listFilterDropdown.visibility =
|
||||
if (binding.listFilterDropdown.visibility == View.VISIBLE) View.GONE else View.VISIBLE
|
||||
binding!!.listFilterDropdown.visibility =
|
||||
if (binding!!.listFilterDropdown.visibility == View.VISIBLE) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
|
26
app/src/main/res/anim/slide_in_right.xml
Normal file
26
app/src/main/res/anim/slide_in_right.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/* //device/apps/common/res/anim/slide_in_right.xml
|
||||
**
|
||||
** Copyright 2007, The Android Open Source Project
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="50%p" android:toXDelta="0"
|
||||
android:duration="@android:integer/config_mediumAnimTime"/>
|
||||
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
26
app/src/main/res/anim/slide_out_left.xml
Normal file
26
app/src/main/res/anim/slide_out_left.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/* //device/apps/common/res/anim/slide_out_left.xml
|
||||
**
|
||||
** Copyright 2007, The Android Open Source Project
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="0" android:toXDelta="-50%p"
|
||||
android:duration="@android:integer/config_mediumAnimTime"/>
|
||||
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
|
||||
android:duration="@android:integer/config_mediumAnimTime" />
|
||||
</set>
|
@ -4,7 +4,8 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/list_filter_dropdown"
|
||||
|
Loading…
Reference in New Issue
Block a user