diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/packs/ui/PackListFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/packs/ui/PackListFragment.kt index ff1587563..e24a0e8f5 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/packs/ui/PackListFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/packs/ui/PackListFragment.kt @@ -5,6 +5,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.os.bundleOf +import androidx.core.view.isVisible import androidx.lifecycle.LiveData import androidx.navigation.fragment.findNavController import com.kylecorry.andromeda.alerts.Alerts @@ -15,6 +16,7 @@ import com.kylecorry.andromeda.fragments.observe import com.kylecorry.andromeda.pickers.Pickers import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.databinding.FragmentPackListBinding +import com.kylecorry.trail_sense.shared.extensions.onBackPressed import com.kylecorry.trail_sense.tools.packs.domain.Pack import com.kylecorry.trail_sense.tools.packs.infrastructure.PackRepo import com.kylecorry.trail_sense.tools.packs.ui.commands.ExportPackingListCommand @@ -62,10 +64,7 @@ class PackListFragment : BoundFragment() { binding.addBtn.setOnClickListener { createPack() } - // TODO: Temporary - binding.packListTitle.rightButton.setOnClickListener { - ImportPackingListCommand(this).execute() - } + bindCreateMenu() } private fun renamePack(pack: Pack) { @@ -157,4 +156,58 @@ class PackListFragment : BoundFragment() { } } + private fun bindCreateMenu() { + binding.createMenu.setOverlay(binding.overlayMask) + binding.createMenu.setOnMenuItemClickListener { + when (it.itemId) { + R.id.action_import_packing_list -> { + setCreateMenuVisibility(false) + ImportPackingListCommand(this).execute() + } + + R.id.action_create_packing_list -> { + setCreateMenuVisibility(false) + createPack() + } + } + true + } + binding.createMenu.setOnHideListener { + binding.addBtn.setImageResource(R.drawable.ic_add) + } + + binding.createMenu.setOnShowListener { + binding.addBtn.setImageResource(R.drawable.ic_cancel) + } + + binding.addBtn.setOnClickListener { + setCreateMenuVisibility(!isCreateMenuOpen()) + } + + onBackPressed { + when { + isCreateMenuOpen() -> { + setCreateMenuVisibility(false) + } + + else -> { + remove() + findNavController().navigateUp() + } + } + } + } + + private fun setCreateMenuVisibility(isShowing: Boolean) { + if (isShowing) { + binding.createMenu.show() + } else { + binding.createMenu.hide() + } + } + + private fun isCreateMenuOpen(): Boolean { + return binding.createMenu.isVisible + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_pack_list.xml b/app/src/main/res/layout/fragment_pack_list.xml index 0a9dab5af..d89a6844b 100644 --- a/app/src/main/res/layout/fragment_pack_list.xml +++ b/app/src/main/res/layout/fragment_pack_list.xml @@ -12,7 +12,6 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:rightButtonIcon="@drawable/ic_import_export" app:showSubtitle="false" app:title="@string/packing_lists" /> @@ -27,6 +26,30 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/pack_list_title" /> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1bed65632..37dc2ec32 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1439,4 +1439,5 @@ pref_weather_forecast_source Forecast algorithm No items found + Import packing list \ No newline at end of file