activity_main.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools">
  5. <data>
  6. <import type="android.view.View"/>
  7. <!-- Ссылка на наш Data Class внизу файла MainActivity.kt -->
  8. <variable name="weather" type="com.example.weather.WeatherInfo" />
  9. <variable name="isLoading" type="Boolean" />
  10. </data>
  11. <androidx.constraintlayout.widget.ConstraintLayout
  12. android:layout_width="match_parent"
  13. android:layout_height="match_parent"
  14. android:padding="16dp">
  15. <EditText
  16. android:id="@+id/etCity"
  17. android:layout_width="0dp"
  18. android:layout_height="wrap_content"
  19. android:hint="City (e.g. Paris)"
  20. android:text="London"
  21. app:layout_constraintEnd_toStartOf="@+id/btnSearch"
  22. app:layout_constraintStart_toStartOf="parent"
  23. app:layout_constraintTop_toTopOf="parent" />
  24. <Button
  25. android:id="@+id/btnSearch"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. android:text="Search"
  29. android:onClick="onGetWeatherClick"
  30. app:layout_constraintEnd_toEndOf="parent"
  31. app:layout_constraintTop_toTopOf="parent" />
  32. <!-- Прогресс бар, виден если isLoading == true -->
  33. <ProgressBar
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:visibility="@{isLoading ? View.VISIBLE : View.GONE}"
  37. app:layout_constraintBottom_toBottomOf="parent"
  38. app:layout_constraintEnd_toEndOf="parent"
  39. app:layout_constraintStart_toStartOf="parent"
  40. app:layout_constraintTop_toBottomOf="@+id/etCity" />
  41. <!-- Контейнер погоды, виден если данные есть и не грузимся -->
  42. <LinearLayout
  43. android:layout_width="match_parent"
  44. android:layout_height="wrap_content"
  45. android:orientation="vertical"
  46. android:gravity="center"
  47. android:visibility="@{!isLoading &amp;&amp; weather != null ? View.VISIBLE : View.GONE}"
  48. app:layout_constraintTop_toBottomOf="@+id/etCity"
  49. app:layout_constraintBottom_toBottomOf="parent">
  50. <TextView
  51. android:text="@{weather.temperature}"
  52. android:textSize="60sp"
  53. android:textStyle="bold"
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content"
  56. tools:text="20°C"/>
  57. <ImageView
  58. android:layout_width="120dp"
  59. android:layout_height="120dp"
  60. app:imageUrl="@{weather.iconUrl}"
  61. tools:src="@android:drawable/ic_menu_camera"/>
  62. <TextView
  63. android:text="@{weather.description}"
  64. android:textSize="24sp"
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. tools:text="Sunny"/>
  68. <TextView
  69. android:text="@{weather.humidity}"
  70. android:layout_marginTop="10dp"
  71. android:layout_width="wrap_content"
  72. android:layout_height="wrap_content"/>
  73. <LinearLayout
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content"
  76. android:orientation="horizontal"
  77. android:gravity="center_vertical"
  78. android:layout_marginTop="10dp">
  79. <TextView
  80. android:text="@{weather.windInfo}"
  81. android:layout_width="wrap_content"
  82. android:layout_height="wrap_content"
  83. tools:text="Wind: 5 m/s"/>
  84. <!-- Стрелка ветра -->
  85. <ImageView
  86. android:layout_width="30dp"
  87. android:layout_height="30dp"
  88. android:src="@android:drawable/arrow_up_float"
  89. app:tint="#555"
  90. app:rotationAngle="@{weather.windRotation}"
  91. android:layout_marginStart="8dp"/>
  92. </LinearLayout>
  93. </LinearLayout>
  94. </androidx.constraintlayout.widget.ConstraintLayout>
  95. </layout>