|
@@ -5,9 +5,13 @@
|
|
|
|
|
|
|
|
<data>
|
|
<data>
|
|
|
<import type="android.view.View"/>
|
|
<import type="android.view.View"/>
|
|
|
- <!-- Ссылка на наш Data Class внизу файла MainActivity.kt -->
|
|
|
|
|
|
|
+
|
|
|
<variable name="weather" type="com.example.weather.WeatherInfo" />
|
|
<variable name="weather" type="com.example.weather.WeatherInfo" />
|
|
|
<variable name="isLoading" type="Boolean" />
|
|
<variable name="isLoading" type="Boolean" />
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Переменные состояния -->
|
|
|
|
|
+ <variable name="isFahrenheit" type="Boolean" />
|
|
|
|
|
+ <variable name="showWind" type="Boolean" />
|
|
|
</data>
|
|
</data>
|
|
|
|
|
|
|
|
<androidx.constraintlayout.widget.ConstraintLayout
|
|
<androidx.constraintlayout.widget.ConstraintLayout
|
|
@@ -15,26 +19,59 @@
|
|
|
android:layout_height="match_parent"
|
|
android:layout_height="match_parent"
|
|
|
android:padding="16dp">
|
|
android:padding="16dp">
|
|
|
|
|
|
|
|
- <EditText
|
|
|
|
|
- android:id="@+id/etCity"
|
|
|
|
|
|
|
+ <Spinner
|
|
|
|
|
+ android:id="@+id/spinnerCity"
|
|
|
android:layout_width="0dp"
|
|
android:layout_width="0dp"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
- android:hint="City (e.g. Paris)"
|
|
|
|
|
- android:text="London"
|
|
|
|
|
- app:layout_constraintEnd_toStartOf="@+id/btnSearch"
|
|
|
|
|
|
|
+ android:entries="@array/cities_array"
|
|
|
|
|
+ android:minHeight="48dp"
|
|
|
|
|
+ app:layout_constraintEnd_toEndOf="parent"
|
|
|
app:layout_constraintStart_toStartOf="parent"
|
|
app:layout_constraintStart_toStartOf="parent"
|
|
|
app:layout_constraintTop_toTopOf="parent" />
|
|
app:layout_constraintTop_toTopOf="parent" />
|
|
|
|
|
|
|
|
- <Button
|
|
|
|
|
- android:id="@+id/btnSearch"
|
|
|
|
|
- android:layout_width="wrap_content"
|
|
|
|
|
|
|
+ <LinearLayout
|
|
|
|
|
+ android:id="@+id/settingsPanel"
|
|
|
|
|
+ android:layout_width="match_parent"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
- android:text="Search"
|
|
|
|
|
- android:onClick="onGetWeatherClick"
|
|
|
|
|
- app:layout_constraintEnd_toEndOf="parent"
|
|
|
|
|
- app:layout_constraintTop_toTopOf="parent" />
|
|
|
|
|
|
|
+ android:orientation="horizontal"
|
|
|
|
|
+ android:gravity="center_vertical"
|
|
|
|
|
+ android:layout_marginTop="10dp"
|
|
|
|
|
+ app:layout_constraintTop_toBottomOf="@+id/spinnerCity">
|
|
|
|
|
+
|
|
|
|
|
+ <RadioGroup
|
|
|
|
|
+ android:id="@+id/rgTemp"
|
|
|
|
|
+ android:layout_width="wrap_content"
|
|
|
|
|
+ android:layout_height="wrap_content"
|
|
|
|
|
+ android:orientation="horizontal">
|
|
|
|
|
+
|
|
|
|
|
+ <RadioButton
|
|
|
|
|
+ android:id="@+id/rbCelsius"
|
|
|
|
|
+ android:layout_width="wrap_content"
|
|
|
|
|
+ android:layout_height="wrap_content"
|
|
|
|
|
+ android:text="°C"
|
|
|
|
|
+ android:checked="true"/>
|
|
|
|
|
+
|
|
|
|
|
+ <RadioButton
|
|
|
|
|
+ android:id="@+id/rbFahrenheit"
|
|
|
|
|
+ android:layout_width="wrap_content"
|
|
|
|
|
+ android:layout_height="wrap_content"
|
|
|
|
|
+ android:text="°F"
|
|
|
|
|
+ android:layout_marginStart="8dp"/>
|
|
|
|
|
+ </RadioGroup>
|
|
|
|
|
+
|
|
|
|
|
+ <View
|
|
|
|
|
+ android:layout_width="0dp"
|
|
|
|
|
+ android:layout_height="0dp"
|
|
|
|
|
+ android:layout_weight="1"/>
|
|
|
|
|
+
|
|
|
|
|
+ <CheckBox
|
|
|
|
|
+ android:id="@+id/cbWind"
|
|
|
|
|
+ android:layout_width="wrap_content"
|
|
|
|
|
+ android:layout_height="wrap_content"
|
|
|
|
|
+ android:text="Wind Info"
|
|
|
|
|
+ android:checked="true"/>
|
|
|
|
|
+ </LinearLayout>
|
|
|
|
|
|
|
|
- <!-- Прогресс бар, виден если isLoading == true -->
|
|
|
|
|
<ProgressBar
|
|
<ProgressBar
|
|
|
android:layout_width="wrap_content"
|
|
android:layout_width="wrap_content"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
@@ -42,25 +79,26 @@
|
|
|
app:layout_constraintBottom_toBottomOf="parent"
|
|
app:layout_constraintBottom_toBottomOf="parent"
|
|
|
app:layout_constraintEnd_toEndOf="parent"
|
|
app:layout_constraintEnd_toEndOf="parent"
|
|
|
app:layout_constraintStart_toStartOf="parent"
|
|
app:layout_constraintStart_toStartOf="parent"
|
|
|
- app:layout_constraintTop_toBottomOf="@+id/etCity" />
|
|
|
|
|
|
|
+ app:layout_constraintTop_toBottomOf="@+id/settingsPanel" />
|
|
|
|
|
|
|
|
- <!-- Контейнер погоды, виден если данные есть и не грузимся -->
|
|
|
|
|
<LinearLayout
|
|
<LinearLayout
|
|
|
android:layout_width="match_parent"
|
|
android:layout_width="match_parent"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
android:orientation="vertical"
|
|
android:orientation="vertical"
|
|
|
android:gravity="center"
|
|
android:gravity="center"
|
|
|
android:visibility="@{!isLoading && weather != null ? View.VISIBLE : View.GONE}"
|
|
android:visibility="@{!isLoading && weather != null ? View.VISIBLE : View.GONE}"
|
|
|
- app:layout_constraintTop_toBottomOf="@+id/etCity"
|
|
|
|
|
|
|
+ app:layout_constraintTop_toBottomOf="@+id/settingsPanel"
|
|
|
app:layout_constraintBottom_toBottomOf="parent">
|
|
app:layout_constraintBottom_toBottomOf="parent">
|
|
|
|
|
|
|
|
|
|
+ <!-- ИСПРАВЛЕНИЕ ЗДЕСЬ: Вызов метода модели вместо сложной логики в XML -->
|
|
|
<TextView
|
|
<TextView
|
|
|
- android:text="@{weather.temperature}"
|
|
|
|
|
- android:textSize="60sp"
|
|
|
|
|
|
|
+ android:text="@{weather.getTempString(isFahrenheit)}"
|
|
|
|
|
+ android:textSize="80sp"
|
|
|
android:textStyle="bold"
|
|
android:textStyle="bold"
|
|
|
|
|
+ android:textColor="@android:color/holo_blue_dark"
|
|
|
android:layout_width="wrap_content"
|
|
android:layout_width="wrap_content"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
- tools:text="20°C"/>
|
|
|
|
|
|
|
+ tools:text="25°C"/>
|
|
|
|
|
|
|
|
<ImageView
|
|
<ImageView
|
|
|
android:layout_width="120dp"
|
|
android:layout_width="120dp"
|
|
@@ -71,33 +109,37 @@
|
|
|
<TextView
|
|
<TextView
|
|
|
android:text="@{weather.description}"
|
|
android:text="@{weather.description}"
|
|
|
android:textSize="24sp"
|
|
android:textSize="24sp"
|
|
|
|
|
+ android:textAllCaps="true"
|
|
|
android:layout_width="wrap_content"
|
|
android:layout_width="wrap_content"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
- tools:text="Sunny"/>
|
|
|
|
|
|
|
+ tools:text="Clear Sky"/>
|
|
|
|
|
|
|
|
<TextView
|
|
<TextView
|
|
|
android:text="@{weather.humidity}"
|
|
android:text="@{weather.humidity}"
|
|
|
- android:layout_marginTop="10dp"
|
|
|
|
|
|
|
+ android:layout_marginTop="8dp"
|
|
|
android:layout_width="wrap_content"
|
|
android:layout_width="wrap_content"
|
|
|
- android:layout_height="wrap_content"/>
|
|
|
|
|
|
|
+ android:layout_height="wrap_content"
|
|
|
|
|
+ tools:text="Humidity: 50%"/>
|
|
|
|
|
|
|
|
<LinearLayout
|
|
<LinearLayout
|
|
|
android:layout_width="wrap_content"
|
|
android:layout_width="wrap_content"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
android:orientation="horizontal"
|
|
android:orientation="horizontal"
|
|
|
android:gravity="center_vertical"
|
|
android:gravity="center_vertical"
|
|
|
- android:layout_marginTop="10dp">
|
|
|
|
|
|
|
+ android:layout_marginTop="16dp"
|
|
|
|
|
+ android:visibility="@{showWind ? View.VISIBLE : View.GONE}">
|
|
|
|
|
|
|
|
|
|
+ <!-- Простое объединение строк работает стабильнее -->
|
|
|
<TextView
|
|
<TextView
|
|
|
- android:text="@{weather.windInfo}"
|
|
|
|
|
|
|
+ android:text="@{`Wind: ` + weather.windSpeed + ` m/s`}"
|
|
|
android:layout_width="wrap_content"
|
|
android:layout_width="wrap_content"
|
|
|
android:layout_height="wrap_content"
|
|
android:layout_height="wrap_content"
|
|
|
|
|
+ android:textSize="16sp"
|
|
|
tools:text="Wind: 5 m/s"/>
|
|
tools:text="Wind: 5 m/s"/>
|
|
|
|
|
|
|
|
- <!-- Стрелка ветра -->
|
|
|
|
|
<ImageView
|
|
<ImageView
|
|
|
- android:layout_width="30dp"
|
|
|
|
|
- android:layout_height="30dp"
|
|
|
|
|
|
|
+ android:layout_width="24dp"
|
|
|
|
|
+ android:layout_height="24dp"
|
|
|
android:src="@android:drawable/arrow_up_float"
|
|
android:src="@android:drawable/arrow_up_float"
|
|
|
app:tint="#555"
|
|
app:tint="#555"
|
|
|
app:rotationAngle="@{weather.windRotation}"
|
|
app:rotationAngle="@{weather.windRotation}"
|
|
@@ -105,6 +147,5 @@
|
|
|
</LinearLayout>
|
|
</LinearLayout>
|
|
|
|
|
|
|
|
</LinearLayout>
|
|
</LinearLayout>
|
|
|
-
|
|
|
|
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
|
</layout>
|
|
</layout>
|