Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define DrawAreaTaskFragment in XML instead of creating programmatically #2877

Merged
merged 10 commits into from
Dec 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.ComposeView
Expand Down Expand Up @@ -58,16 +57,21 @@ class DrawAreaTaskFragment @Inject constructor() : AbstractTaskFragment<DrawArea
override fun onCreateTaskBody(inflater: LayoutInflater): View {
// NOTE(#2493): Multiplying by a random prime to allow for some mathematical "uniqueness".
// Otherwise, the sequentially generated ID might conflict with an ID produced by Google Maps.
val rowLayout = LinearLayout(requireContext()).apply { id = View.generateViewId() * 11411 }
val rootView = inflater.inflate(R.layout.fragment_draw_area_task, null)
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved

drawAreaTaskMapFragment = drawAreaTaskMapFragmentProvider.get()
val args = Bundle()
args.putString(TASK_ID_FRAGMENT_ARG_KEY, taskId)
drawAreaTaskMapFragment.arguments = args
parentFragmentManager
.beginTransaction()
.add(rowLayout.id, drawAreaTaskMapFragment, DrawAreaTaskMapFragment::class.java.simpleName)
.add(
R.id.container_draw_area_task_map,
drawAreaTaskMapFragment,
DrawAreaTaskMapFragment::class.java.simpleName,
)
.commit()
return rowLayout
return rootView
}

override fun onCreateActionButtons() {
Expand Down
22 changes: 22 additions & 0 deletions ground/src/main/res/layout/fragment_draw_area_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright 2022 Google LLC
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
~
~ 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
~
~ https://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.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_draw_area_task_map"
android:layout_width="match_parent"
android:layout_height="wrap_content" />