Skip to content

Commit

Permalink
Consistent naming of task classes (#2140)
Browse files Browse the repository at this point in the history
* s/PolygonDrawing/DrawArea/

* s/DropAPin/DropPinTask/

* s/CaptureLocationMap/CaptureLocationTaskMap/

* Fix nav id
  • Loading branch information
gino-m authored Dec 27, 2023
1 parent 260e797 commit f5c0259
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal object SubmissionConverter {
Task.Type.NUMBER -> putNumberResponse(taskId, obj, data)
Task.Type.DATE -> putDateResponse(taskId, obj, data)
Task.Type.TIME -> putTimeResponse(taskId, obj, data)
Task.Type.DROP_PIN -> putDropAPinResponse(taskId, obj, data)
Task.Type.DROP_PIN -> putDropPinResponse(taskId, obj, data)
Task.Type.DRAW_AREA -> putGeometryTaskResponse(taskId, obj, data)
Task.Type.CAPTURE_LOCATION -> putCaptureLocationResult(taskId, obj, data)
else -> throw DataStoreException("Unknown type " + task.type)
Expand All @@ -117,7 +117,7 @@ internal object SubmissionConverter {
TimeResponse.fromDate(value.toDate())?.let { r: Value -> data[taskId] = r }
}

private fun putDropAPinResponse(taskId: String, obj: Any, data: MutableMap<String, Value>) {
private fun putDropPinResponse(taskId: String, obj: Any, data: MutableMap<String, Value>) {
val map = obj as HashMap<String, *>
check(map["type"] == "Point")
val result = GeometryConverter.fromFirestoreMap(map).getOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.google.android.ground.MainViewModel
import com.google.android.ground.ui.datacollection.tasks.date.DateTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.location.CaptureLocationMapViewModel
import com.google.android.ground.ui.datacollection.tasks.location.CaptureLocationTaskMapViewModel
import com.google.android.ground.ui.datacollection.tasks.location.CaptureLocationTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.multiplechoice.MultipleChoiceTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.number.NumberTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.photo.PhotoTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.point.DropAPinTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.polygon.PolygonDrawingViewModel
import com.google.android.ground.ui.datacollection.tasks.point.DropPinTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.polygon.DrawAreaTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.text.TextTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.time.TimeTaskViewModel
import com.google.android.ground.ui.home.HomeScreenViewModel
Expand All @@ -50,8 +50,8 @@ import dagger.multibindings.IntoMap
abstract class ViewModelModule {
@Binds
@IntoMap
@ViewModelKey(PolygonDrawingViewModel::class)
abstract fun bindPolygonDrawingViewModel(viewModel: PolygonDrawingViewModel): ViewModel
@ViewModelKey(DrawAreaTaskViewModel::class)
abstract fun bindDrawAreaTaskViewModel(viewModel: DrawAreaTaskViewModel): ViewModel

@Binds
@IntoMap
Expand Down Expand Up @@ -135,8 +135,8 @@ abstract class ViewModelModule {

@Binds
@IntoMap
@ViewModelKey(DropAPinTaskViewModel::class)
abstract fun bindDropAPinTaskViewModel(viewModel: DropAPinTaskViewModel): ViewModel
@ViewModelKey(DropPinTaskViewModel::class)
abstract fun bindDropPinTaskViewModel(viewModel: DropPinTaskViewModel): ViewModel

@Binds
@IntoMap
Expand All @@ -155,8 +155,10 @@ abstract class ViewModelModule {

@Binds
@IntoMap
@ViewModelKey(CaptureLocationMapViewModel::class)
abstract fun bindCaptureLocationMapViewModel(viewModel: CaptureLocationMapViewModel): ViewModel
@ViewModelKey(CaptureLocationTaskMapViewModel::class)
abstract fun bindCaptureLocationTaskMapViewModel(
viewModel: CaptureLocationTaskMapViewModel
): ViewModel

@Binds
@IntoMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import com.google.android.ground.ui.datacollection.tasks.location.CaptureLocatio
import com.google.android.ground.ui.datacollection.tasks.multiplechoice.MultipleChoiceTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.number.NumberTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.photo.PhotoTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.point.DropAPinTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.polygon.PolygonDrawingViewModel
import com.google.android.ground.ui.datacollection.tasks.point.DropPinTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.polygon.DrawAreaTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.text.TextTaskViewModel
import com.google.android.ground.ui.datacollection.tasks.time.TimeTaskViewModel
import com.google.android.ground.ui.home.HomeScreenFragmentDirections
Expand Down Expand Up @@ -218,8 +218,8 @@ internal constructor(
Task.Type.NUMBER -> NumberTaskViewModel::class.java
Task.Type.DATE -> DateTaskViewModel::class.java
Task.Type.TIME -> TimeTaskViewModel::class.java
Task.Type.DROP_PIN -> DropAPinTaskViewModel::class.java
Task.Type.DRAW_AREA -> PolygonDrawingViewModel::class.java
Task.Type.DROP_PIN -> DropPinTaskViewModel::class.java
Task.Type.DRAW_AREA -> DrawAreaTaskViewModel::class.java
Task.Type.CAPTURE_LOCATION -> CaptureLocationTaskViewModel::class.java
Task.Type.UNKNOWN -> throw IllegalArgumentException("Unsupported task type: $taskType")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import com.google.android.ground.ui.datacollection.tasks.location.CaptureLocatio
import com.google.android.ground.ui.datacollection.tasks.multiplechoice.MultipleChoiceTaskFragment
import com.google.android.ground.ui.datacollection.tasks.number.NumberTaskFragment
import com.google.android.ground.ui.datacollection.tasks.photo.PhotoTaskFragment
import com.google.android.ground.ui.datacollection.tasks.point.DropAPinTaskFragment
import com.google.android.ground.ui.datacollection.tasks.polygon.PolygonDrawingTaskFragment
import com.google.android.ground.ui.datacollection.tasks.point.DropPinTaskFragment
import com.google.android.ground.ui.datacollection.tasks.polygon.DrawAreaTaskFragment
import com.google.android.ground.ui.datacollection.tasks.text.TextTaskFragment
import com.google.android.ground.ui.datacollection.tasks.time.TimeTaskFragment
import dagger.assisted.Assisted
Expand All @@ -49,8 +49,8 @@ constructor(
Task.Type.TEXT -> TextTaskFragment()
Task.Type.MULTIPLE_CHOICE -> MultipleChoiceTaskFragment()
Task.Type.PHOTO -> PhotoTaskFragment()
Task.Type.DROP_PIN -> DropAPinTaskFragment()
Task.Type.DRAW_AREA -> PolygonDrawingTaskFragment()
Task.Type.DROP_PIN -> DropPinTaskFragment()
Task.Type.DRAW_AREA -> DrawAreaTaskFragment()
Task.Type.NUMBER -> NumberTaskFragment()
Task.Type.DATE -> DateTaskFragment()
Task.Type.TIME -> TimeTaskFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class CaptureLocationTaskFragment :
.beginTransaction()
.add(
rowLayout.id,
CaptureLocationMapFragment.newInstance(viewModel, map),
CaptureLocationMapFragment::class.java.simpleName
CaptureLocationTaskMapFragment.newInstance(viewModel, map),
CaptureLocationTaskMapFragment::class.java.simpleName
)
.commit()
return rowLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint(AbstractMapFragmentWithControls::class)
class CaptureLocationMapFragment(private val viewModel: CaptureLocationTaskViewModel) :
Hilt_CaptureLocationMapFragment() {
class CaptureLocationTaskMapFragment(private val viewModel: CaptureLocationTaskViewModel) :
Hilt_CaptureLocationTaskMapFragment() {

private lateinit var mapViewModel: CaptureLocationMapViewModel
private lateinit var mapViewModel: CaptureLocationTaskMapViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mapViewModel = getViewModel(CaptureLocationMapViewModel::class.java)
mapViewModel = getViewModel(CaptureLocationTaskMapViewModel::class.java)
}

override fun getMapViewModel(): BaseMapViewModel = mapViewModel
Expand All @@ -58,6 +58,6 @@ class CaptureLocationMapFragment(private val viewModel: CaptureLocationTaskViewM

companion object {
fun newInstance(viewModel: CaptureLocationTaskViewModel, map: MapFragment) =
CaptureLocationMapFragment(viewModel).apply { this.map = map }
CaptureLocationTaskMapFragment(viewModel).apply { this.map = map }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.google.android.ground.ui.common.BaseMapViewModel
import com.google.android.ground.ui.common.MapConfig
import javax.inject.Inject

class CaptureLocationMapViewModel
class CaptureLocationTaskMapViewModel
@Inject
internal constructor(
offlineAreaRepository: OfflineAreaRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint(AbstractTaskFragment::class)
class DropAPinTaskFragment : Hilt_DropAPinTaskFragment<DropAPinTaskViewModel>() {
class DropPinTaskFragment : Hilt_DropPinTaskFragment<DropPinTaskViewModel>() {

@Inject lateinit var markerIconFactory: IconFactory
@Inject lateinit var map: MapFragment
Expand All @@ -43,7 +43,7 @@ class DropAPinTaskFragment : Hilt_DropAPinTaskFragment<DropAPinTaskViewModel>()
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() }
parentFragmentManager
.beginTransaction()
.add(rowLayout.id, DropAPinMapFragment.newInstance(viewModel, map), "Drop a pin fragment")
.add(rowLayout.id, DropPinTaskMapFragment.newInstance(viewModel, map), "Drop a pin fragment")
.commit()
return rowLayout
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint(AbstractMapFragmentWithControls::class)
class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) :
Hilt_DropAPinMapFragment() {
class DropPinTaskMapFragment(private val viewModel: DropPinTaskViewModel) :
Hilt_DropPinTaskMapFragment() {

private lateinit var mapViewModel: BaseMapViewModel
private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel
Expand Down Expand Up @@ -74,7 +74,7 @@ class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) :
}

companion object {
fun newInstance(viewModel: DropAPinTaskViewModel, map: MapFragment) =
DropAPinMapFragment(viewModel).apply { this.map = map }
fun newInstance(viewModel: DropPinTaskViewModel, map: MapFragment) =
DropPinTaskMapFragment(viewModel).apply { this.map = map }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.google.android.ground.ui.map.Feature
import com.google.android.ground.ui.map.FeatureType
import javax.inject.Inject

class DropAPinTaskViewModel
class DropPinTaskViewModel
@Inject
constructor(resources: Resources, private val uuidGenerator: OfflineUuidGenerator) :
AbstractTaskViewModel(resources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import javax.inject.Inject
import kotlinx.coroutines.launch

@AndroidEntryPoint(AbstractTaskFragment::class)
class PolygonDrawingTaskFragment : Hilt_PolygonDrawingTaskFragment<PolygonDrawingViewModel>() {
class DrawAreaTaskFragment : Hilt_DrawAreaTaskFragment<DrawAreaTaskViewModel>() {

@Inject lateinit var markerIconFactory: IconFactory
@Inject lateinit var map: MapFragment
Expand All @@ -45,21 +45,17 @@ class PolygonDrawingTaskFragment : Hilt_PolygonDrawingTaskFragment<PolygonDrawin
private lateinit var nextButton: TaskButton
private lateinit var undoButton: TaskButton

private lateinit var polygonDrawingMapFragment: PolygonDrawingMapFragment
private lateinit var drawAreaTaskMapFragment: DrawAreaTaskMapFragment

override fun onCreateTaskView(inflater: LayoutInflater): TaskView =
TaskViewFactory.createWithCombinedHeader(inflater, R.drawable.outline_draw)

override fun onCreateTaskBody(inflater: LayoutInflater): View {
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() }
polygonDrawingMapFragment = PolygonDrawingMapFragment.newInstance(viewModel, map)
drawAreaTaskMapFragment = DrawAreaTaskMapFragment.newInstance(viewModel, map)
parentFragmentManager
.beginTransaction()
.add(
rowLayout.id,
polygonDrawingMapFragment,
PolygonDrawingMapFragment::class.java.simpleName
)
.add(rowLayout.id, drawAreaTaskMapFragment, DrawAreaTaskMapFragment::class.java.simpleName)
.commit()
return rowLayout
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint(AbstractMapFragmentWithControls::class)
class PolygonDrawingMapFragment(private val viewModel: PolygonDrawingViewModel) :
Hilt_PolygonDrawingMapFragment() {
class DrawAreaTaskMapFragment(private val viewModel: DrawAreaTaskViewModel) :
Hilt_DrawAreaTaskMapFragment() {

private lateinit var mapViewModel: BaseMapViewModel
private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel
Expand Down Expand Up @@ -65,7 +65,7 @@ class PolygonDrawingMapFragment(private val viewModel: PolygonDrawingViewModel)
}

companion object {
fun newInstance(viewModel: PolygonDrawingViewModel, map: MapFragment) =
PolygonDrawingMapFragment(viewModel).apply { this.map = map }
fun newInstance(viewModel: DrawAreaTaskViewModel, map: MapFragment) =
DrawAreaTaskMapFragment(viewModel).apply { this.map = map }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn

@SharedViewModel
class PolygonDrawingViewModel
class DrawAreaTaskViewModel
@Inject
internal constructor(private val uuidGenerator: OfflineUuidGenerator, resources: Resources) :
AbstractTaskViewModel(resources) {
Expand Down
6 changes: 3 additions & 3 deletions ground/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
</fragment>

<fragment
android:id="@+id/drop_a_pin_task_fragment"
android:name="com.google.android.ground.ui.datacollection.tasks.point.DropAPinTaskFragment"
android:id="@+id/drop_pin_task_fragment"
android:name="com.google.android.ground.ui.datacollection.tasks.point.DropPinTaskFragment"
android:label="@string/collect_data"
tools:layout="@layout/text_task_frag" />

Expand Down Expand Up @@ -134,7 +134,7 @@

<fragment
android:id="@+id/polygon_task_fragment"
android:name="com.google.android.ground.ui.datacollection.tasks.polygon.PolygonDrawingTaskFragment"
android:name="com.google.android.ground.ui.datacollection.tasks.polygon.DrawAreaTaskFragment"
android:label="@string/collect_data"
tools:layout="@layout/text_task_frag" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ import com.google.android.ground.ui.map.CameraPosition
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.hamcrest.core.IsNot.*
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.robolectric.RobolectricTestRunner

@OptIn(ExperimentalCoroutinesApi::class)
@HiltAndroidTest
@RunWith(RobolectricTestRunner::class)
class DropAPinTaskFragmentTest :
BaseTaskFragmentTest<DropAPinTaskFragment, DropAPinTaskViewModel>() {
class DropPinTaskFragmentTest : BaseTaskFragmentTest<DropPinTaskFragment, DropPinTaskViewModel>() {

@BindValue @Mock override lateinit var dataCollectionViewModel: DataCollectionViewModel
@Inject override lateinit var viewModelFactory: ViewModelFactory
Expand All @@ -62,15 +59,15 @@ class DropAPinTaskFragmentTest :

@Test
fun testHeader() {
setupTaskFragment<DropAPinTaskFragment>(job, task)
setupTaskFragment<DropPinTaskFragment>(job, task)

hasTaskViewWithoutHeader(task.label)
}

@Test
fun testDropPin() = runWithTestDispatcher {
val testPosition = CameraPosition(Coordinates(10.0, 20.0))
setupTaskFragment<DropAPinTaskFragment>(job, task)
setupTaskFragment<DropPinTaskFragment>(job, task)

viewModel.updateCameraPosition(testPosition)
onView(withText("Drop pin")).perform(click())
Expand All @@ -83,15 +80,15 @@ class DropAPinTaskFragmentTest :

@Test
fun testInfoCard_noValue() {
setupTaskFragment<DropAPinTaskFragment>(job, task)
setupTaskFragment<DropPinTaskFragment>(job, task)

infoCardHidden()
}

@Test
fun testUndo() = runWithTestDispatcher {
val testPosition = CameraPosition(Coordinates(10.0, 20.0))
setupTaskFragment<DropAPinTaskFragment>(job, task)
setupTaskFragment<DropPinTaskFragment>(job, task)

viewModel.updateCameraPosition(testPosition)
onView(withText("Drop pin")).perform(click())
Expand All @@ -104,7 +101,7 @@ class DropAPinTaskFragmentTest :

@Test
fun testActionButtons() {
setupTaskFragment<DropAPinTaskFragment>(job, task)
setupTaskFragment<DropPinTaskFragment>(job, task)

assertFragmentHasButtons(
ButtonAction.PREVIOUS,
Expand All @@ -117,7 +114,7 @@ class DropAPinTaskFragmentTest :

@Test
fun testActionButtons_whenTaskIsOptional() {
setupTaskFragment<DropAPinTaskFragment>(job, task.copy(isRequired = false))
setupTaskFragment<DropPinTaskFragment>(job, task.copy(isRequired = false))

buttonIsHidden("Next")
buttonIsEnabled("Skip")
Expand All @@ -127,7 +124,7 @@ class DropAPinTaskFragmentTest :

@Test
fun testActionButtons_whenTaskIsRequired() {
setupTaskFragment<DropAPinTaskFragment>(job, task.copy(isRequired = true))
setupTaskFragment<DropPinTaskFragment>(job, task.copy(isRequired = true))

buttonIsHidden("Next")
buttonIsHidden("Skip")
Expand All @@ -137,7 +134,7 @@ class DropAPinTaskFragmentTest :

@Test
fun `Hint icon is shown`() {
setupTaskFragment<DropAPinTaskFragment>(job, task)
setupTaskFragment<DropPinTaskFragment>(job, task)

onView(withId(R.id.hintIcon)).check(matches(isDisplayed()))
}
Expand Down
Loading

0 comments on commit f5c0259

Please sign in to comment.