@@ -90,6 +90,7 @@ private Megaphones() {}
9090 .map (Map .Entry ::getKey )
9191 .map (records ::get )
9292 .map (record -> Megaphones .forRecord (context , record ))
93+ .filterNot (Objects ::isNull )
9394 .toList ();
9495
9596 if (megaphones .size () > 0 ) {
@@ -137,7 +138,7 @@ private static boolean shouldShowLinkedDeviceInactiveMegaphone() {
137138 return expiringIn < TimeUnit .DAYS .toMillis (7 ) && expiringIn > 0 ;
138139 }
139140
140- private static @ NonNull Megaphone forRecord (@ NonNull Context context , @ NonNull MegaphoneRecord record ) {
141+ private static @ Nullable Megaphone forRecord (@ NonNull Context context , @ NonNull MegaphoneRecord record ) {
141142 switch (record .getEvent ()) {
142143 case PINS_FOR_ALL :
143144 return buildPinsForAllMegaphone (record );
@@ -308,42 +309,43 @@ public void onReminderCompleted(@NonNull String pin, boolean includedFailure) {
308309 .build ();
309310 }
310311
311- private static @ NonNull Megaphone buildRemoteMegaphone (@ NonNull Context context ) {
312+ private static @ Nullable Megaphone buildRemoteMegaphone (@ NonNull Context context ) {
312313 RemoteMegaphoneRecord record = RemoteMegaphoneRepository .getRemoteMegaphoneToShow (System .currentTimeMillis ());
313314
314- if (record != null ) {
315- Megaphone .Builder builder = new Megaphone .Builder (Event .REMOTE_MEGAPHONE , Megaphone .Style .BASIC )
316- .setTitle (record .getTitle ())
317- .setBody (record .getBody ());
318-
319- if (record .getImageUri () != null ) {
320- builder .setImageRequestBuilder (Glide .with (context ).asDrawable ().load (record .getImageUri ()));
321- }
315+ if (record == null ) {
316+ Log .w (TAG , "No remote megaphone record when told to show one!" );
317+ return null ;
318+ }
322319
323- if (record .hasPrimaryAction ()) {
324- //noinspection ConstantConditions
325- builder .setActionButton (record .getPrimaryActionText (), (megaphone , controller ) -> {
326- RemoteMegaphoneRepository .getAction (Objects .requireNonNull (record .getPrimaryActionId ()))
327- .run (context , controller , record );
328- });
329- }
320+ Megaphone .Builder builder = new Megaphone .Builder (Event .REMOTE_MEGAPHONE , Megaphone .Style .BASIC )
321+ .setTitle (record .getTitle ())
322+ .setBody (record .getBody ());
330323
331- if (record .hasSecondaryAction ()) {
332- //noinspection ConstantConditions
333- builder .setSecondaryButton (record .getSecondaryActionText (), (megaphone , controller ) -> {
334- RemoteMegaphoneRepository .getAction (Objects .requireNonNull (record .getSecondaryActionId ()))
335- .run (context , controller , record );
336- });
337- }
324+ if (record .getImageUri () != null ) {
325+ builder .setImageRequestBuilder (Glide .with (context ).asDrawable ().load (record .getImageUri ()));
326+ }
338327
339- builder .setOnVisibleListener ((megaphone , controller ) -> {
340- RemoteMegaphoneRepository .markShown (record .getUuid ());
328+ if (record .hasPrimaryAction ()) {
329+ //noinspection ConstantConditions
330+ builder .setActionButton (record .getPrimaryActionText (), (megaphone , controller ) -> {
331+ RemoteMegaphoneRepository .getAction (Objects .requireNonNull (record .getPrimaryActionId ()))
332+ .run (context , controller , record );
341333 });
334+ }
342335
343- return builder .build ();
344- } else {
345- throw new IllegalStateException ("No record to show" );
336+ if (record .hasSecondaryAction ()) {
337+ //noinspection ConstantConditions
338+ builder .setSecondaryButton (record .getSecondaryActionText (), (megaphone , controller ) -> {
339+ RemoteMegaphoneRepository .getAction (Objects .requireNonNull (record .getSecondaryActionId ()))
340+ .run (context , controller , record );
341+ });
346342 }
343+
344+ builder .setOnVisibleListener ((megaphone , controller ) -> {
345+ RemoteMegaphoneRepository .markShown (record .getUuid ());
346+ });
347+
348+ return builder .build ();
347349 }
348350
349351 @ SuppressLint ("InlinedApi" )
0 commit comments