Skip to content

Commit 8f8b98b

Browse files
committed
ui: color balance in schedule
1 parent dd256fa commit 8f8b98b

File tree

4 files changed

+71
-19
lines changed

4 files changed

+71
-19
lines changed

app/src/main/java/com/example/partymaker/ui/features/groups/creation/CreateGroupActivity.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class CreateGroupActivity extends BaseActivity implements OnMapReadyCallb
105105
private GoogleMap map;
106106
private LatLng chosenLatLng;
107107
private FusedLocationProviderClient locationClient;
108+
private boolean isDatePickerShowing = false;
108109

109110
@Override
110111
protected void onCreate(Bundle savedInstanceState) {
@@ -223,6 +224,11 @@ private void initializeViews() {
223224
etPartyName = findViewById(R.id.etPartyName);
224225
groupTypeCheckBox = findViewById(R.id.cbGroupType);
225226
timePicker = findViewById(R.id.timePicker);
227+
228+
// Apply custom theme to TimePicker programmatically for better visibility
229+
if (timePicker != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
230+
timePicker.setHour(timePicker.getHour()); // Refresh to apply theme
231+
}
226232

227233
// Floating action button
228234
chatFab = findViewById(R.id.fabChat);
@@ -502,6 +508,7 @@ private void transitionToDateTimeStep() {
502508
showViews(tvPartyDate, tvHours, tvSelectedDate, timePicker, btnAddGroup, btnBack2);
503509

504510
hideMapAndLocationSearch();
511+
// Automatically show date picker for better UX
505512
showDatePicker();
506513
}
507514

@@ -934,31 +941,21 @@ public boolean onCreateOptionsMenu(Menu menu) {
934941
}
935942

936943
private void showDatePicker() {
944+
// Prevent showing multiple date pickers
945+
if (isDatePickerShowing) {
946+
return;
947+
}
948+
949+
isDatePickerShowing = true;
950+
937951
DatePickerDialog datePickerDialog =
938952
new DatePickerDialog(
939953
this,
954+
android.R.style.Theme_Material_Light_Dialog_Alert,
940955
(view, year, month, dayOfMonth) -> {
941-
Calendar pickedDate = Calendar.getInstance();
942-
pickedDate.set(year, month, dayOfMonth);
943-
944-
// Check if picked date is in the past
945-
Calendar today = Calendar.getInstance();
946-
today.set(Calendar.HOUR_OF_DAY, 0);
947-
today.set(Calendar.MINUTE, 0);
948-
today.set(Calendar.SECOND, 0);
949-
today.set(Calendar.MILLISECOND, 0);
950-
951-
if (pickedDate.before(today)) {
952-
Toast.makeText(
953-
this,
954-
"Cannot select a date in the past. Please choose today or a future date.",
955-
Toast.LENGTH_LONG)
956-
.show();
957-
return;
958-
}
959-
960956
selectedDate.set(year, month, dayOfMonth);
961957
updateSelectedDate();
958+
isDatePickerShowing = false;
962959
},
963960
selectedDate.get(Calendar.YEAR),
964961
selectedDate.get(Calendar.MONTH),
@@ -967,6 +964,22 @@ private void showDatePicker() {
967964
// Set minimum date to today to prevent past date selection
968965
Calendar today = Calendar.getInstance();
969966
datePickerDialog.getDatePicker().setMinDate(today.getTimeInMillis());
967+
968+
// Fix button text color to be visible
969+
datePickerDialog.setOnShowListener(dialog -> {
970+
Button positiveButton = datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE);
971+
Button negativeButton = datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE);
972+
if (positiveButton != null) {
973+
positiveButton.setTextColor(ContextCompat.getColor(this, R.color.primaryBlue));
974+
}
975+
if (negativeButton != null) {
976+
negativeButton.setTextColor(ContextCompat.getColor(this, R.color.primaryBlue));
977+
}
978+
});
979+
980+
// Handle dialog cancel/dismiss
981+
datePickerDialog.setOnCancelListener(dialog -> isDatePickerShowing = false);
982+
datePickerDialog.setOnDismissListener(dialog -> isDatePickerShowing = false);
970983

971984
datePickerDialog.show();
972985
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@
149149

150150
<TimePicker
151151
android:id="@+id/timePicker"
152+
style="@style/TimePickerStyle"
152153
android:layout_width="wrap_content"
153154
android:layout_height="wrap_content"
154155
android:layout_marginBottom="16dp"
155156
android:timePickerMode="clock"
157+
android:theme="@style/CustomTimePickerTheme"
156158
android:visibility="invisible" />
157159

158160
</LinearLayout>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,13 @@
6767
<!-- Bottom Navigation Style -->
6868
<!-- Dialog Styles -->
6969
<!-- Navigation styles removed due to compatibility issues -->
70+
71+
<!-- Custom TimePicker Style with better visibility -->
72+
<style name="TimePickerStyle" parent="@android:style/Widget.Material.Light.TimePicker">
73+
<item name="android:headerBackground">@color/primaryBlue</item>
74+
<item name="android:numbersTextColor">@color/white</item>
75+
<item name="android:numbersSelectorColor">@color/modern_accent_teal</item>
76+
<item name="android:numbersBackgroundColor">@android:color/transparent</item>
77+
<item name="android:amPmTextColor">@color/white</item>
78+
</style>
7079
</resources>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,34 @@
161161
<item name="android:windowBackground">@null</item>
162162
</style>
163163

164+
<!-- Custom DatePicker theme -->
165+
<style name="CustomDatePickerTheme" parent="Theme.AppCompat.Light.Dialog">
166+
<item name="colorAccent">@color/primaryBlue</item>
167+
<item name="android:datePickerStyle">@style/CustomDatePickerStyle</item>
168+
<item name="android:textColorPrimary">@color/primaryBlue</item>
169+
<item name="android:colorControlNormal">@color/primaryBlue</item>
170+
</style>
171+
172+
<style name="CustomDatePickerStyle" parent="@android:style/Widget.Material.DatePicker">
173+
<item name="android:headerBackground">@color/primaryBlue</item>
174+
<item name="android:dateTextAppearance">@style/DatePickerTextAppearance</item>
175+
</style>
176+
177+
<style name="DatePickerTextAppearance" parent="TextAppearance.AppCompat.Body1">
178+
<item name="android:textColor">@color/primaryBlue</item>
179+
</style>
180+
181+
<!-- Custom TimePicker theme -->
182+
<style name="CustomTimePickerTheme">
183+
<item name="android:numbersTextColor">@color/white</item>
184+
<item name="android:numbersBackgroundColor">@android:color/transparent</item>
185+
<item name="android:numbersSelectorColor">@color/modern_accent_teal</item>
186+
<item name="android:amPmTextColor">@color/white</item>
187+
<item name="android:textColorPrimary">@color/white</item>
188+
<item name="android:textColorSecondary">@color/modern_accent_teal</item>
189+
<item name="colorAccent">@color/modern_accent_teal</item>
190+
</style>
191+
164192
<!-- Material3 themes without window background -->
165193
<style name="Theme.Material3.Login.NoWindowBackground" parent="Theme.Material3.Login">
166194
<item name="android:windowBackground">@null</item>

0 commit comments

Comments
 (0)