adapter_profile.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layout xmlns:android="http://schemas.android.com/apk/res/android">
  3. <data>
  4. <variable
  5. name="profile"
  6. type="com.github.kr328.clash.service.model.Profile" />
  7. <variable
  8. name="currentTime"
  9. type="com.github.kr328.clash.design.ui.ObservableCurrentTime" />
  10. <variable
  11. name="clicked"
  12. type="android.view.View.OnClickListener" />
  13. <variable
  14. name="menu"
  15. type="android.view.View.OnClickListener" />
  16. <import type="android.view.View" />
  17. <import type="com.github.kr328.clash.design.util.I18nKt" />
  18. <import type="com.github.kr328.clash.design.util.IntervalKt" />
  19. </data>
  20. <RelativeLayout
  21. android:elevation="5dp"
  22. android:id="@+id/root_view"
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. android:layout_margin="5dp"
  26. android:background="@drawable/bg_b"
  27. android:clickable="true"
  28. android:focusable="true"
  29. android:minHeight="@dimen/item_min_height"
  30. android:nextFocusRight="@id/menu_view"
  31. android:onClick="@{clicked}">
  32. <RadioButton
  33. android:id="@+id/icon_view"
  34. android:layout_width="@dimen/item_header_component_size"
  35. android:layout_height="@dimen/item_header_component_size"
  36. android:layout_centerVertical="true"
  37. android:layout_marginHorizontal="@dimen/item_header_margin"
  38. android:checked="@{profile.active}"
  39. android:clickable="false"
  40. android:focusable="false"
  41. android:gravity="center" />
  42. <LinearLayout
  43. android:layout_width="wrap_content"
  44. android:layout_height="wrap_content"
  45. android:layout_centerVertical="true"
  46. android:layout_toStartOf="@id/elapsed_view"
  47. android:layout_toEndOf="@id/icon_view"
  48. android:orientation="vertical"
  49. android:paddingVertical="@dimen/item_padding_vertical">
  50. <TextView
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:text="@{profile.name}"
  54. android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
  55. <TextView
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:layout_marginTop="@dimen/item_text_margin"
  59. android:text="@{profile.pending ? @string/format_type_unsaved(I18nKt.toString(profile.type, context)) : I18nKt.toString(profile.type, context)}"
  60. android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" />
  61. <LinearLayout
  62. android:layout_width="match_parent"
  63. android:layout_height="match_parent"
  64. android:orientation="horizontal"
  65. >
  66. <TextView
  67. android:textSize="12sp"
  68. android:layout_width="wrap_content"
  69. android:layout_height="wrap_content"
  70. android:visibility="@{profile.download ==0 ? View.GONE : View.VISIBLE}"
  71. android:text='@{profile.download >0 ?I18nKt.toBytesString(profile.download+profile.upload)+"/" :""}'
  72. android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
  73. <TextView
  74. android:textSize="12sp"
  75. android:layout_width="wrap_content"
  76. android:layout_height="wrap_content"
  77. android:visibility="@{profile.download ==0 ? View.GONE : View.VISIBLE}"
  78. android:text='@{profile.download >0 ?I18nKt.toBytesString(profile.total) : ""}'
  79. android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
  80. </LinearLayout>
  81. <TextView
  82. android:textSize="12sp"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:visibility="@{profile.expire==0 ? View.GONE : View.VISIBLE}"
  86. android:text='@{profile.expire>0 ? I18nKt.toDateStr(profile.expire):""}'
  87. android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" />
  88. <ProgressBar
  89. style="?android:attr/progressBarStyleHorizontal"
  90. android:layout_width="match_parent"
  91. android:layout_height="wrap_content"
  92. android:max="1000"
  93. android:visibility="@{profile.download==0 ? View.GONE : View.VISIBLE}"
  94. android:progress="@{profile.download>0 ?I18nKt.toProgress ((profile.download+profile.upload)/(profile.total/1000)) :0}"
  95. />
  96. </LinearLayout>
  97. <TextView
  98. android:id="@+id/elapsed_view"
  99. android:layout_width="wrap_content"
  100. android:layout_height="wrap_content"
  101. android:layout_centerVertical="true"
  102. android:layout_marginEnd="@dimen/item_midden_margin"
  103. android:layout_toStartOf="@id/menu_view"
  104. android:text="@{IntervalKt.elapsedIntervalString(currentTime.value - profile.updatedAt, context)}"
  105. android:textAppearance="@style/TextAppearance.MaterialComponents.Tooltip" />
  106. <View
  107. android:layout_width="2dp"
  108. android:layout_height="match_parent"
  109. android:layout_toStartOf="@id/menu_view"
  110. android:background="@color/color_clash_dark" />
  111. <FrameLayout
  112. android:id="@+id/menu_view"
  113. android:layout_width="wrap_content"
  114. android:layout_height="wrap_content"
  115. android:layout_alignParentEnd="true"
  116. android:layout_centerVertical="true"
  117. android:background="?attr/selectableItemBackground"
  118. android:clickable="true"
  119. android:focusable="true"
  120. android:nextFocusLeft="@id/root_view"
  121. android:onClick="@{menu}">
  122. <View
  123. android:layout_width="@dimen/item_tailing_component_size"
  124. android:layout_height="@dimen/item_tailing_component_size"
  125. android:layout_margin="@dimen/item_tailing_margin"
  126. android:background="@drawable/ic_baseline_more_vert" />
  127. </FrameLayout>
  128. </RelativeLayout>
  129. </layout>