Skip to content

Commit

Permalink
Add create menu for packing lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Jul 10, 2024
1 parent 934d174 commit db4f166
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -62,10 +64,7 @@ class PackListFragment : BoundFragment<FragmentPackListBinding>() {

binding.addBtn.setOnClickListener { createPack() }

// TODO: Temporary
binding.packListTitle.rightButton.setOnClickListener {
ImportPackingListCommand(this).execute()
}
bindCreateMenu()
}

private fun renamePack(pack: Pack) {
Expand Down Expand Up @@ -157,4 +156,58 @@ class PackListFragment : BoundFragment<FragmentPackListBinding>() {
}
}

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
}

}
25 changes: 24 additions & 1 deletion app/src/main/res/layout/fragment_pack_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand All @@ -27,6 +26,30 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pack_list_title" />

<ImageView
android:id="@+id/overlay_mask"
android:layout_width="0dp"
android:layout_height="0dp"
android:alpha="0.86"
android:background="?android:colorBackground"
android:clickable="true"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.kylecorry.trail_sense.shared.views.FloatingActionButtonMenu
android:id="@+id/create_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/add_btn"
app:layout_constraintEnd_toEndOf="@id/add_btn"
app:menu="@menu/add_pack_menu"
tools:visibility="visible" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_btn"
android:layout_width="wrap_content"
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/menu/add_pack_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_import_packing_list"
android:icon="@drawable/ic_file"
android:title="@string/import_packing_list" />
<item
android:id="@+id/action_create_packing_list"
android:icon="@drawable/ic_tool_pack"
android:title="@string/new_packing_list" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1439,4 +1439,5 @@
<string name="pref_weather_forecast_source" translatable="false">pref_weather_forecast_source</string>
<string name="forecast_algorithm">Forecast algorithm</string>
<string name="no_items_found">No items found</string>
<string name="import_packing_list">Import packing list</string>
</resources>

0 comments on commit db4f166

Please sign in to comment.