Skip to content

Commit b277559

Browse files
authored
Widget Updates (#49)
- Update Transparent Widget Theme
1 parent 2b1ebe0 commit b277559

File tree

4 files changed

+47
-39
lines changed

4 files changed

+47
-39
lines changed

app/src/main/java/com/djangofiles/djangofiles/WidgetProvider.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,16 @@ class WidgetProvider : AppWidgetProvider() {
127127
views.setTextViewText(R.id.files_count, filesCount)
128128

129129
Log.d("Widget[onUpdate]", "server.humanSize: ${server.humanSize}")
130-
val humanSize =
131-
if (server.humanSize.isNullOrEmpty()) "Unknown" else server.humanSize
132-
Log.d("Widget[onUpdate]", "humanSize: $humanSize")
133-
views.setTextViewText(R.id.files_size, humanSize)
130+
131+
val split =
132+
server.humanSize?.split(' ')?.filter { it.isNotEmpty() } ?: emptyList()
133+
Log.d("Widget[onUpdate]", "split: $split")
134+
views.setTextViewText(R.id.files_size, split.getOrElse(0) { "Unknown" })
135+
views.setTextViewText(R.id.files_unit, split.getOrElse(1) { "" })
134136
}
135137

136-
val time = java.time.LocalTime.now().format(java.time.format.DateTimeFormatter.ofPattern("HH:mm"))
138+
val time = java.time.LocalTime.now()
139+
.format(java.time.format.DateTimeFormatter.ofPattern("HH:mm"))
137140
Log.d("Widget[onUpdate]", "time: $time")
138141
views.setTextViewText(R.id.update_time, time)
139142

app/src/main/java/com/djangofiles/djangofiles/ui/home/HomeFragment.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.djangofiles.djangofiles.R
3333
import com.djangofiles.djangofiles.databinding.FragmentHomeBinding
3434
import com.djangofiles.djangofiles.db.ServerDao
3535
import com.djangofiles.djangofiles.db.ServerDatabase
36+
import com.djangofiles.djangofiles.getUserAgent
3637

3738
class HomeFragment : Fragment() {
3839

@@ -87,12 +88,8 @@ class HomeFragment : Fragment() {
8788
arguments?.remove("url")
8889
}
8990

90-
val versionName = requireContext()
91-
.packageManager
92-
.getPackageInfo(requireContext().packageName, 0).versionName
93-
Log.d("Home[onViewCreated]", "versionName: $versionName")
9491
val userAgent =
95-
"${binding.webView.settings.userAgentString} DjangoFiles Android/${versionName}"
92+
"${binding.webView.settings.userAgentString} ${requireContext().getUserAgent()}"
9693
Log.d("Home[onViewCreated]", "UA: $userAgent")
9794

9895
//Log.d("Home[onViewCreated]", "BEFORE - currentUrl: $currentUrl")

app/src/main/res/layout/widget_layout.xml

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414
android:layout_width="match_parent"
1515
android:layout_height="wrap_content"
1616
android:layout_gravity="center_vertical"
17-
android:layout_marginStart="8dp"
18-
android:layout_marginEnd="130dp"
17+
android:layout_marginEnd="128dp"
1918
android:columnCount="2">
2019

2120
<ImageView
2221
android:layout_width="18dp"
2322
android:layout_height="18dp"
2423
android:layout_marginTop="1dp"
25-
android:layout_marginEnd="4dp"
24+
android:layout_marginEnd="2dp"
2625
android:layout_gravity="center_vertical"
2726
android:contentDescription="Files Count"
2827
android:src="@drawable/md_description_24px" />
2928
<TextView
3029
android:id="@+id/files_count"
31-
android:layout_width="wrap_content"
30+
android:layout_width="match_parent"
3231
android:layout_height="wrap_content"
33-
android:layout_gravity="center_vertical"
3432
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
33+
android:textSize="20sp"
34+
android:maxLines="1"
3535
android:text="0"
36-
tools:text="4096" />
36+
tools:text="0123456789" />
3737

3838
<ImageView
3939
android:layout_width="18dp"
@@ -42,14 +42,28 @@
4242
android:layout_gravity="center_vertical"
4343
android:contentDescription="Files Size"
4444
android:src="@drawable/md_storage_24px" />
45-
<TextView
46-
android:id="@+id/files_size"
47-
android:layout_width="wrap_content"
48-
android:layout_height="wrap_content"
49-
android:layout_gravity="center_vertical"
50-
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
51-
android:text="0"
52-
tools:text="69.9 GB" />
45+
<LinearLayout
46+
android:layout_width="match_parent"
47+
android:layout_height="match_parent">
48+
<TextView
49+
android:id="@+id/files_size"
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
53+
android:textSize="20sp"
54+
android:maxLines="1"
55+
android:text="0"
56+
tools:text="9.99" />
57+
58+
<TextView
59+
android:id="@+id/files_unit"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
android:layout_marginStart="4dp"
63+
android:maxLines="1"
64+
android:text="MB"
65+
tools:text="GB" />
66+
</LinearLayout>
5367
</GridLayout>
5468

5569
<LinearLayout
@@ -61,38 +75,32 @@
6175
android:id="@+id/widget_refresh_button"
6276
android:layout_width="48dp"
6377
android:layout_height="match_parent"
64-
android:background="?android:selectableItemBackgroundBorderless"
65-
android:src="@drawable/md_refresh_24px"
66-
android:tint="@android:color/white"
6778
android:contentDescription="Refresh"
68-
tools:ignore="UseAppTint" />
79+
android:background="?android:selectableItemBackgroundBorderless"
80+
android:src="@drawable/md_refresh_24px" />
6981
<ImageButton
7082
android:id="@+id/widget_upload_button"
7183
android:layout_width="48dp"
7284
android:layout_height="match_parent"
73-
android:background="?android:selectableItemBackgroundBorderless"
74-
android:src="@drawable/md_outbox_24px"
75-
android:tint="@android:color/white"
7685
android:contentDescription="Upload"
77-
tools:ignore="UseAppTint" />
86+
android:background="?android:selectableItemBackgroundBorderless"
87+
android:src="@drawable/md_upload_24px" />
7888
<ImageButton
7989
android:id="@+id/file_list_button"
8090
android:layout_width="48dp"
8191
android:layout_height="match_parent"
82-
android:background="?android:selectableItemBackgroundBorderless"
83-
android:src="@drawable/md_list_alt_24px"
84-
android:tint="@android:color/white"
8592
android:contentDescription="File List"
86-
tools:ignore="UseAppTint" />
93+
android:background="?android:selectableItemBackgroundBorderless"
94+
android:src="@drawable/md_list_alt_24px" />
8795
</LinearLayout>
8896

8997
<TextView
9098
android:id="@+id/update_time"
9199
android:layout_width="wrap_content"
92100
android:layout_height="wrap_content"
101+
android:layout_marginStart="12dp"
93102
android:layout_gravity="center_horizontal|bottom"
94-
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
95-
android:textSize="12sp"
103+
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
96104
android:text="--:--"
97105
tools:text="23:59" />
98106

app/src/main/res/values/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
<style name="WidgetStyle" parent="Theme.MaterialComponents">
1717
<item name="android:textColor">@android:color/white</item>
18-
<item name="android:textSize">18sp</item>
18+
<item name="android:tint">@android:color/white</item>
1919
</style>
2020
</resources>

0 commit comments

Comments
 (0)