Skip to content

Commit

Permalink
Merge branch 'main' into update-contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 authored Jan 20, 2025
2 parents 0febf67 + c7dc471 commit 0eb3f5f
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ class FieldGuideRepo private constructor(private val context: Context) {
BuiltInFieldGuide.getFieldGuide(context) + saved
}

suspend fun getPage(id: Long): FieldGuidePage? {
return if (id < 0) {
suspend fun getPage(id: Long): FieldGuidePage? = onIO {
if (id < 0) {
BuiltInFieldGuide.getFieldGuidePage(context, id)
} else {
dao.getPage(id)?.toFieldGuidePage()
}
}

suspend fun delete(page: FieldGuidePage) {
suspend fun delete(page: FieldGuidePage) = onIO {
if (page.isReadOnly) {
return
return@onIO
}
page.images.forEach { files.delete(it) }
dao.delete(FieldGuidePageEntity.fromFieldGuidePage(page))
}

suspend fun add(page: FieldGuidePage): Long {
suspend fun add(page: FieldGuidePage): Long = onIO {
if (page.isReadOnly) {
return -1
return@onIO -1
}
val entity = FieldGuidePageEntity.fromFieldGuidePage(page)
return dao.upsert(entity)
dao.upsert(entity)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.kylecorry.trail_sense.tools.field_guide.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.kylecorry.andromeda.fragments.BoundFragment
import com.kylecorry.andromeda.fragments.inBackground
import com.kylecorry.trail_sense.databinding.FragmentCreateFieldGuidePageBinding
import com.kylecorry.trail_sense.shared.CustomUiUtils
import com.kylecorry.trail_sense.shared.withId
import com.kylecorry.trail_sense.tools.field_guide.domain.FieldGuidePage
import com.kylecorry.trail_sense.tools.field_guide.domain.FieldGuidePageTag
import com.kylecorry.trail_sense.tools.field_guide.infrastructure.FieldGuideRepo

class CreateFieldGuidePageFragment : BoundFragment<FragmentCreateFieldGuidePageBinding>() {

private var existingPage by state<FieldGuidePage?>(null)
private var tags by state<List<FieldGuidePageTag>>(emptyList())
private val repo by lazy { FieldGuideRepo.getInstance(requireContext()) }

override fun generateBinding(
layoutInflater: LayoutInflater,
container: ViewGroup?
): FragmentCreateFieldGuidePageBinding {
return FragmentCreateFieldGuidePageBinding.inflate(layoutInflater, container, false)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
val pageId = it.getLong(ARG_PAGE_ID, 0L)
if (pageId != 0L) {
inBackground {
existingPage = repo.getPage(pageId)
}
}

val tag = it.getLong(ARG_CLASSIFICATION_ID, 0L)
.takeIf { id -> id != 0L }
?.let { id -> FieldGuidePageTag.entries.withId(id) }

if (tag != null) {
tags += listOf(tag)
}
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
CustomUiUtils.setButtonState(binding.createFieldGuidePageTitle.rightButton, true)
}

companion object {
private const val ARG_PAGE_ID = "page_id"
private const val ARG_CLASSIFICATION_ID = "classification_id"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.os.bundleOf
import androidx.navigation.fragment.findNavController
import com.kylecorry.andromeda.alerts.dialog
import com.kylecorry.andromeda.core.coroutines.BackgroundMinimumState
import com.kylecorry.andromeda.core.coroutines.onIO
import com.kylecorry.andromeda.core.system.Resources
Expand All @@ -23,7 +22,6 @@ import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.databinding.FragmentFieldGuideBinding
import com.kylecorry.trail_sense.shared.io.DeleteTempFilesCommand
import com.kylecorry.trail_sense.shared.io.FileSubsystem
import com.kylecorry.trail_sense.shared.views.Views
import com.kylecorry.trail_sense.tools.field_guide.domain.FieldGuidePage
import com.kylecorry.trail_sense.tools.field_guide.domain.FieldGuidePageTag
import com.kylecorry.trail_sense.tools.field_guide.infrastructure.FieldGuideRepo
Expand Down Expand Up @@ -64,6 +62,14 @@ class FieldGuideFragment : BoundFragment<FragmentFieldGuideBinding>() {
}
}
}

binding.addBtn.setOnClickListener {
findNavController().navigate(
R.id.createFieldGuidePageFragment, bundleOf(
"classification_id" to (tagFilter?.id ?: 0L)
)
)
}
}

override fun onUpdate() {
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/fragment_create_field_guide_page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.kylecorry.andromeda.views.toolbar.Toolbar
android:id="@+id/create_field_guide_page_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:rightButtonIcon="@drawable/ic_add"
app:showSubtitle="false"
tools:title="Test Name" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

</LinearLayout>
28 changes: 22 additions & 6 deletions app/src/main/res/layout/fragment_field_guide.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">

<com.kylecorry.trail_sense.shared.views.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" />
android:padding="16dp"
app:layout_constraintTop_toTopOf="parent" />

<com.kylecorry.andromeda.views.list.AndromedaListView
android:id="@+id/list"
style="@style/AppTheme.ListViewWithFab"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/search" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="@dimen/default_bottom_margin"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@
android:defaultValue="0L"
app:argType="long" />
</fragment>

<fragment
android:id="@+id/createFieldGuidePageFragment"
android:name="com.kylecorry.trail_sense.tools.field_guide.ui.CreateFieldGuidePageFragment"
android:label="CreateFieldGuidePageFragment">

<argument
android:name="page_id"
android:defaultValue="0L"
app:argType="long" />

<argument
android:name="classification_id"
android:defaultValue="0L"
app:argType="long" />
</fragment>
<fragment
android:id="@+id/beacon_list"
android:name="com.kylecorry.trail_sense.tools.beacons.ui.list.BeaconListFragment"
Expand Down

0 comments on commit 0eb3f5f

Please sign in to comment.