Skip to content

Commit 4cecb78

Browse files
committed
Add popup explaining notifications - make theme easier to read
1 parent 35cf3d9 commit 4cecb78

File tree

7 files changed

+136
-20
lines changed

7 files changed

+136
-20
lines changed

app/src/main/java/com/chdboy/MainActivity.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.android.material.card.MaterialCardView;
2323
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
2424
import com.google.android.material.bottomsheet.BottomSheetBehavior;
25+
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
2526
import android.widget.LinearLayout;
2627

2728
public class MainActivity extends AppCompatActivity {
@@ -95,7 +96,7 @@ public void onCreate(Bundle savedInstanceState) {
9596
// Request notification permission for Android 13+
9697
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
9798
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
98-
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.POST_NOTIFICATIONS}, 1);
99+
showNotificationPermissionDialog();
99100
}
100101
}
101102
}
@@ -174,6 +175,27 @@ private void hideBottomSheet() {
174175
}
175176
}
176177

178+
private void showNotificationPermissionDialog() {
179+
new MaterialAlertDialogBuilder(this)
180+
.setTitle("Enable Notifications")
181+
.setMessage("CHDBOY needs notification permission to keep you updated on compression progress.\n\n" +
182+
"Some conversions can take a while depending on file size. Notifications allow the app to:\n\n" +
183+
"• Run compressions in the background\n" +
184+
"• Show progress updates\n" +
185+
"• Notify you when conversions are complete")
186+
.setPositiveButton("Allow", (dialog, which) -> {
187+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
188+
ActivityCompat.requestPermissions(this,
189+
new String[]{android.Manifest.permission.POST_NOTIFICATIONS}, 1);
190+
}
191+
})
192+
.setNegativeButton("Not Now", (dialog, which) -> {
193+
dialog.dismiss();
194+
})
195+
.setCancelable(false)
196+
.show();
197+
}
198+
177199
@Override
178200
public boolean onOptionsItemSelected(MenuItem item) {
179201
if (item.getItemId() == R.id.action_settings) {

app/src/main/java/com/chdboy/services/ChdmanService.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Notification;
44
import android.app.NotificationChannel;
55
import android.app.NotificationManager;
6+
import android.app.PendingIntent;
67
import android.app.Service;
78
import android.content.Context;
89
import android.content.Intent;
@@ -13,6 +14,7 @@
1314
import androidx.core.app.ActivityCompat;
1415
import androidx.core.app.NotificationCompat;
1516
import androidx.core.app.NotificationManagerCompat;
17+
import com.chdboy.MainActivity;
1618
import com.chdboy.R;
1719

1820
public class ChdmanService extends Service {
@@ -32,24 +34,28 @@ public void onCreate() {
3234

3335
private void startForegroundNotification() {
3436
try {
37+
PendingIntent pendingIntent = createPendingIntent(this);
3538
Notification notif = new NotificationCompat.Builder(this, CHANNEL_ID)
3639
.setContentTitle("CHDBOY")
3740
.setContentText("Starting compression...")
3841
.setSmallIcon(R.drawable.ic_stat_name)
3942
.setOngoing(true)
4043
.setPriority(NotificationCompat.PRIORITY_LOW)
4144
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
45+
.setContentIntent(pendingIntent)
4246
.build();
4347
startForeground(NOTIF_ID, notif);
4448
android.util.Log.d("ChdmanService", "Started foreground notification");
4549
} catch (Exception e) {
4650
android.util.Log.e("ChdmanService", "Failed to start foreground: " + e.getMessage());
4751
// Try with minimal notification
4852
try {
53+
PendingIntent pendingIntent = createPendingIntent(this);
4954
Notification minimal = new NotificationCompat.Builder(this, CHANNEL_ID)
5055
.setContentTitle("CHDBOY")
5156
.setContentText("Working...")
5257
.setSmallIcon(R.drawable.ic_stat_name)
58+
.setContentIntent(pendingIntent)
5359
.build();
5460
startForeground(NOTIF_ID, minimal);
5561
} catch (Exception e2) {
@@ -96,12 +102,15 @@ private void ensureChannel() {
96102
public static void updateProgress(Context ctx, String message) {
97103
if (!hasNotificationPermission(ctx)) return;
98104

105+
PendingIntent pendingIntent = createPendingIntent(ctx);
99106
Notification notif = new NotificationCompat.Builder(ctx, CHANNEL_ID)
100-
.setContentTitle(ctx.getString(R.string.app_name))
107+
.setContentTitle("Compressing...")
101108
.setContentText(message)
102109
.setSmallIcon(R.drawable.ic_stat_name)
110+
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
103111
.setOngoing(true)
104112
.setOnlyAlertOnce(true)
113+
.setContentIntent(pendingIntent)
105114
.build();
106115
try {
107116
NotificationManagerCompat.from(ctx).notify(NOTIF_ID, notif);
@@ -112,13 +121,15 @@ public static void notifyDone(Context ctx, String message) {
112121
if (!hasNotificationPermission(ctx)) return;
113122

114123
// Show completion notification with static icon
124+
PendingIntent pendingIntent = createPendingIntent(ctx);
115125
Notification notif = new NotificationCompat.Builder(ctx, CHANNEL_ID)
116126
.setContentTitle(ctx.getString(R.string.app_name))
117127
.setContentText(message)
118128
.setSmallIcon(R.drawable.ic_stat_name)
119129
.setPriority(NotificationCompat.PRIORITY_HIGH)
120130
.setCategory(NotificationCompat.CATEGORY_STATUS)
121131
.setAutoCancel(true)
132+
.setContentIntent(pendingIntent)
122133
.build();
123134
try {
124135
NotificationManagerCompat.from(ctx).notify(NOTIF_ID + 1, notif);
@@ -129,12 +140,14 @@ public static void updateIdle(Context ctx, String message) {
129140
if (!hasNotificationPermission(ctx)) return;
130141

131142
// Show idle notification with static icon
143+
PendingIntent pendingIntent = createPendingIntent(ctx);
132144
Notification notif = new NotificationCompat.Builder(ctx, CHANNEL_ID)
133145
.setContentTitle(ctx.getString(R.string.app_name))
134146
.setContentText(message)
135147
.setSmallIcon(R.drawable.ic_stat_name)
136148
.setOngoing(true)
137149
.setOnlyAlertOnce(true)
150+
.setContentIntent(pendingIntent)
138151
.build();
139152
try {
140153
NotificationManagerCompat.from(ctx).notify(NOTIF_ID, notif);
@@ -152,4 +165,14 @@ private static boolean hasNotificationPermission(Context ctx) {
152165
}
153166
return true; // Pre-Android 13 doesn't require explicit permission
154167
}
168+
169+
private static PendingIntent createPendingIntent(Context ctx) {
170+
Intent intent = new Intent(ctx, MainActivity.class);
171+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
172+
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
173+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
174+
flags |= PendingIntent.FLAG_IMMUTABLE;
175+
}
176+
return PendingIntent.getActivity(ctx, 0, intent, flags);
177+
}
155178
}

app/src/main/java/com/chdboy/utils/Chdman.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.DialogInterface;
55

66
import android.content.SharedPreferences;
7+
import android.content.res.Configuration;
78
import android.os.Environment;
89
import androidx.preference.PreferenceManager;
910
import java.lang.reflect.Field;
@@ -25,6 +26,7 @@
2526
import android.widget.Spinner;
2627

2728
import androidx.appcompat.app.AlertDialog;
29+
import androidx.core.content.ContextCompat;
2830
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
2931
import java.io.BufferedInputStream;
3032
import java.io.BufferedReader;
@@ -112,12 +114,24 @@ private AlertDialog createProgressDialog(String title) {
112114
android.widget.LinearLayout layout = new android.widget.LinearLayout(mContext);
113115
layout.setOrientation(android.widget.LinearLayout.VERTICAL);
114116
layout.setPadding(60, 40, 60, 40);
117+
118+
// Adjust text contrast based on the active (light/dark) theme
119+
boolean isNightMode = (mContext.getResources().getConfiguration().uiMode
120+
& Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
121+
int primaryTextColor = ContextCompat.getColor(
122+
mContext,
123+
isNightMode ? R.color.md_theme_dark_onSurface : R.color.md_theme_light_onSurface
124+
);
125+
int secondaryTextColor = ContextCompat.getColor(
126+
mContext,
127+
isNightMode ? R.color.md_theme_dark_onSurfaceVariant : R.color.md_theme_light_onSurfaceVariant
128+
);
115129

116130
// Main status text
117131
android.widget.TextView statusText = new android.widget.TextView(mContext);
118132
statusText.setText("Starting Smart Compress...");
119133
statusText.setTextSize(16);
120-
statusText.setTextColor(0xFFFFFFFF); // White for visibility
134+
statusText.setTextColor(primaryTextColor);
121135
statusText.setId(android.R.id.message);
122136
android.widget.LinearLayout.LayoutParams statusParams = new android.widget.LinearLayout.LayoutParams(
123137
android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
@@ -178,7 +192,7 @@ private AlertDialog createProgressDialog(String title) {
178192
android.widget.TextView separator = new android.widget.TextView(mContext);
179193
separator.setText("•");
180194
separator.setTextSize(12);
181-
separator.setTextColor(0xFFFFFFFF); // White for visibility
195+
separator.setTextColor(secondaryTextColor);
182196
separator.setGravity(android.view.Gravity.CENTER);
183197
android.widget.LinearLayout.LayoutParams sepParams = new android.widget.LinearLayout.LayoutParams(
184198
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
@@ -192,7 +206,7 @@ private AlertDialog createProgressDialog(String title) {
192206
android.widget.TextView speedText = new android.widget.TextView(mContext);
193207
speedText.setText("Speed: --");
194208
speedText.setTextSize(12);
195-
speedText.setTextColor(0xFFFFFFFF); // White for visibility
209+
speedText.setTextColor(primaryTextColor);
196210
speedText.setId(android.R.id.summary); // Use summary for speed/time
197211
android.widget.LinearLayout.LayoutParams speedParams = new android.widget.LinearLayout.LayoutParams(
198212
0,
@@ -208,7 +222,7 @@ private AlertDialog createProgressDialog(String title) {
208222
android.widget.TextView noteText = new android.widget.TextView(mContext);
209223
noteText.setText("💡 You can exit the app - compression will continue in background and notify when complete");
210224
noteText.setTextSize(10);
211-
noteText.setTextColor(0xFFFFFFFF); // White for visibility
225+
noteText.setTextColor(secondaryTextColor);
212226
noteText.setGravity(android.view.Gravity.CENTER);
213227
noteText.setPadding(0, 16, 0, 0);
214228
noteText.setTypeface(null, android.graphics.Typeface.ITALIC);
@@ -879,4 +893,4 @@ public void run() {
879893
static {
880894
System.loadLibrary("chdman");
881895
}
882-
}
896+
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@
8888
android:textAppearance="?attr/textAppearanceTitleLarge"
8989
android:textColor="?attr/colorPrimary"
9090
android:textStyle="bold"
91-
android:textAlignment="center" />
91+
android:textAlignment="center"
92+
android:shadowColor="#000000"
93+
android:shadowDx="0"
94+
android:shadowDy="0"
95+
android:shadowRadius="8" />
9296

9397
<com.google.android.material.textview.MaterialTextView
9498
android:layout_width="match_parent"
@@ -206,7 +210,11 @@
206210
android:textAppearance="?attr/textAppearanceTitleLarge"
207211
android:textColor="#FFEF00"
208212
android:textStyle="bold"
209-
android:letterSpacing="0.1" />
213+
android:letterSpacing="0.1"
214+
android:shadowColor="#000000"
215+
android:shadowDx="0"
216+
android:shadowDy="0"
217+
android:shadowRadius="8" />
210218

211219
</com.google.android.material.appbar.MaterialToolbar>
212220

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949

5050
<!-- Floating Action Button styling -->
5151
<item name="floatingActionButtonStyle">@style/Widget.CHDBOY.FloatingActionButton</item>
52+
53+
<!-- MaterialAlertDialog styling for dark mode -->
54+
<item name="materialAlertDialogTheme">@style/ThemeOverlay.CHDBOY.MaterialAlertDialog</item>
5255
</style>
5356

5457
<!-- No ActionBar variant for dark mode -->
@@ -80,4 +83,13 @@
8083
<item name="android:navigationBarColor">@color/transparent</item>
8184
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
8285
</style>
86+
87+
<!-- MaterialAlertDialog theme overlay for dark mode -->
88+
<style name="ThemeOverlay.CHDBOY.MaterialAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
89+
<item name="colorSurface">#2B2930</item>
90+
<item name="colorOnSurface">#E6E3DD</item>
91+
<item name="colorOnSurfaceVariant">#C8C5D0</item>
92+
<item name="android:textColorPrimary">#E6E3DD</item>
93+
<item name="android:textColorSecondary">#C8C5D0</item>
94+
</style>
8395
</resources>

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
<color name="md_theme_light_onTertiaryContainer">#3E2723</color>
3232

3333
<!-- Surface colors -->
34-
<color name="md_theme_light_surface">#FFFBFE</color>
34+
<color name="md_theme_light_surface">#FF8C00</color>
3535
<color name="md_theme_light_onSurface">#1C1B1F</color>
36-
<color name="md_theme_light_surfaceVariant">#F4F0E7</color>
37-
<color name="md_theme_light_onSurfaceVariant">#47464F</color>
38-
<color name="md_theme_light_surfaceContainerLowest">#FFFFFF</color>
39-
<color name="md_theme_light_surfaceContainerLow">#F8F5F0</color>
40-
<color name="md_theme_light_surfaceContainer">#F2EFE9</color>
41-
<color name="md_theme_light_surfaceContainerHigh">#ECE9E3</color>
42-
<color name="md_theme_light_surfaceContainerHighest">#E6E3DD</color>
36+
<color name="md_theme_light_surfaceVariant">#FFA500</color>
37+
<color name="md_theme_light_onSurfaceVariant">#1C1B1F</color>
38+
<color name="md_theme_light_surfaceContainerLowest">#FF8C00</color>
39+
<color name="md_theme_light_surfaceContainerLow">#FF8C00</color>
40+
<color name="md_theme_light_surfaceContainer">#FF8C00</color>
41+
<color name="md_theme_light_surfaceContainerHigh">#FF8C00</color>
42+
<color name="md_theme_light_surfaceContainerHighest">#FF8C00</color>
4343

4444
<!-- Background -->
45-
<color name="md_theme_light_background">#FFFBFE</color>
45+
<color name="md_theme_light_background">#FF8C00</color>
4646
<color name="md_theme_light_onBackground">#1C1B1F</color>
4747

4848
<!-- Error -->
@@ -100,8 +100,8 @@
100100
<color name="md_theme_dark_outlineVariant">#47464F</color>
101101

102102
<!-- Hero card colors -->
103-
<color name="hero_card_background_light">@color/md_theme_light_primaryContainer</color>
104-
<color name="hero_card_text_light">@color/md_theme_light_onPrimaryContainer</color>
103+
<color name="hero_card_background_light">#FFFFFFFF</color>
104+
<color name="hero_card_text_light">#1C1B1F</color>
105105
<color name="hero_card_background_dark">#FF000000</color>
106106
<color name="hero_card_text_dark">#FFFFFFFF</color>
107107

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949

5050
<!-- Floating Action Button styling -->
5151
<item name="floatingActionButtonStyle">@style/Widget.CHDBOY.FloatingActionButton</item>
52+
53+
<!-- MaterialAlertDialog styling for better contrast -->
54+
<item name="materialAlertDialogTheme">@style/ThemeOverlay.CHDBOY.MaterialAlertDialog</item>
5255
</style>
5356

5457
<!-- No ActionBar variant -->
@@ -113,4 +116,38 @@
113116
<item name="android:activityCloseEnterAnimation">@anim/slide_in_left</item>
114117
<item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>
115118
</style>
119+
120+
<!-- MaterialAlertDialog theme overlay for light mode -->
121+
<style name="ThemeOverlay.CHDBOY.MaterialAlertDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog">
122+
<item name="colorSurface">#FF8C00</item>
123+
<item name="colorOnSurface">#000000</item>
124+
<item name="colorOnSurfaceVariant">#000000</item>
125+
<item name="colorPrimary">#000000</item>
126+
<item name="android:textColorPrimary">#000000</item>
127+
<item name="android:textColorSecondary">#000000</item>
128+
<item name="android:textColor">#000000</item>
129+
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.CHDBOY.Title.Text</item>
130+
<item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialog.CHDBOY.Body.Text</item>
131+
<item name="buttonBarPositiveButtonStyle">@style/Widget.CHDBOY.Button.TextButton.Dialog</item>
132+
<item name="buttonBarNegativeButtonStyle">@style/Widget.CHDBOY.Button.TextButton.Dialog</item>
133+
<item name="buttonBarNeutralButtonStyle">@style/Widget.CHDBOY.Button.TextButton.Dialog</item>
134+
</style>
135+
136+
<!-- Dialog title text style -->
137+
<style name="MaterialAlertDialog.CHDBOY.Title.Text" parent="MaterialAlertDialog.Material3.Title.Text">
138+
<item name="android:textColor">#000000</item>
139+
</style>
140+
141+
<!-- Dialog body text style -->
142+
<style name="MaterialAlertDialog.CHDBOY.Body.Text" parent="MaterialAlertDialog.Material3.Body.Text">
143+
<item name="android:textColor">#000000</item>
144+
<item name="android:textColorPrimary">#000000</item>
145+
<item name="android:textColorSecondary">#000000</item>
146+
</style>
147+
148+
<!-- Dialog button style -->
149+
<style name="Widget.CHDBOY.Button.TextButton.Dialog" parent="Widget.Material3.Button.TextButton.Dialog">
150+
<item name="android:textColor">#000000</item>
151+
<item name="iconTint">#000000</item>
152+
</style>
116153
</resources>

0 commit comments

Comments
 (0)