Skip to content

Commit 9474266

Browse files
authored
tweak(SimListActivity): improve next upcoming subscription schedule summary readability (#81)
* tweak(SimListActivity): improve next upcoming subscription schedule summary readability This will force the date-time string in the next upcoming subscription schedule summary to be separated by new line when displayed in portrait orientation, otherwise by space. Signed-off-by: iusmac <iusico.maxim@libero.it> * Add screenshot tests * Update golden screenshots for Roborazzi tests --------- Signed-off-by: iusmac <iusico.maxim@libero.it>
1 parent 0419351 commit 9474266

File tree

19 files changed

+80
-6
lines changed

19 files changed

+80
-6
lines changed

src/com/github/iusmac/sevensim/ui/sim/SimListActivity.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.github.iusmac.sevensim.Logger;
1919
import com.github.iusmac.sevensim.R;
2020
import com.github.iusmac.sevensim.telephony.Subscriptions;
21+
import com.github.iusmac.sevensim.ui.UiUtils;
2122
import com.github.iusmac.sevensim.ui.components.CollapsingToolbarBaseActivity;
2223
import com.github.iusmac.sevensim.ui.preferences.PreferenceListActivity;
2324

@@ -118,8 +119,9 @@ public void onSubscriptionsChanged() {
118119
mSubscriptionsChangedListenerInitialized = true;
119120
}
120121

121-
sHandler.postDelayed(getViewModel()::refreshSimEntries, mSubscriptionsChangedToken,
122-
delayMillis);
122+
final boolean isLandscape = UiUtils.isLandscape(this);
123+
sHandler.postDelayed(() -> getViewModel().refreshSimEntries(isLandscape),
124+
mSubscriptionsChangedToken, delayMillis);
123125
}
124126

125127
@Override
@@ -152,9 +154,11 @@ public void onReceive(final Context context, final Intent intent) {
152154
mLogger.d("onReceive() : intent=" + intent);
153155

154156
switch (action) {
155-
case Intent.ACTION_TIMEZONE_CHANGED, Intent.ACTION_TIME_CHANGED ->
157+
case Intent.ACTION_TIMEZONE_CHANGED, Intent.ACTION_TIME_CHANGED -> {
156158
// Refresh SIM entries to regenerate time-sensitive data
157-
sHandler.post(getViewModel()::refreshSimEntries);
159+
final boolean isLandscape = UiUtils.isLandscape(context);
160+
sHandler.post(() -> getViewModel().refreshSimEntries(isLandscape));
161+
}
158162

159163
default -> {
160164
mLogger.e("onReceive() : Unhandled action: %s.", action);

src/com/github/iusmac/sevensim/ui/sim/SimListViewModel.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ LiveData<SparseArrayCompat<SimEntry>> getSimEntries() {
6565

6666
/**
6767
* Refresh the live SIM entry list.
68+
*
69+
* @param isLandscape Whether the app is currently displayed in landscape orientation or not.
70+
* Needed to improve readability of the next upcoming subscription schedule summary text.
6871
*/
6972
@WorkerThread
70-
void refreshSimEntries() {
73+
void refreshSimEntries(final boolean isLandscape) {
7174
final SparseArrayCompat<SimEntry> simEntries = new SparseArrayCompat<>();
7275
final LocalDateTime now = mSystemTimeProvider.now();
7376
for (Subscription sub : mSubscriptions) {
@@ -78,8 +81,9 @@ void refreshSimEntries() {
7881
final int id = sub.getSlotIndex() == INVALID_SIM_SLOT_INDEX ? sub.getId() :
7982
sub.getSlotIndex();
8083

84+
final String dateTimeSeparator = isLandscape ? null : "<br/>";
8185
final CharSequence nextUpcomingScheduleSummary = mSubscriptionSchedulerSummaryBuilder
82-
.buildNextUpcomingSubscriptionScheduleSummary(sub, now);
86+
.buildNextUpcomingSubscriptionScheduleSummary(sub, now, dateTimeSeparator);
8387

8488
simEntries.put(id, new SimEntry(sub, nextUpcomingScheduleSummary));
8589
}

tests/test/java/com/github/iusmac/sevensim/ui/sim/SimListActivityTest.kt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,72 @@ class SimListActivityTest {
417417
}
418418
}
419419

420+
@Test
421+
@Config(minSdk = Q, qualifiers = "+ru") // use the verbose Russian locale to get text wrapping
422+
fun `test should separate date-time in SIM entries by new line when in portrait`() {
423+
val subInfo = SubscriptionInfoBuilder.newBuilder().apply {
424+
setId(1)
425+
setDisplayName("SIM 1")
426+
setIconTint(Color.BLUE)
427+
}.buildSubscriptionInfo()
428+
shadowOf(mSubscriptionManager).setAvailableSubscriptionInfos(subInfo)
429+
430+
// Insert a schedule for the SIM card in database to be displayed in the summary
431+
runBlocking {
432+
val insertJob = async(Dispatchers.Default) {
433+
val schedule = SubscriptionScheduleEntity().apply {
434+
setSubscriptionId(subInfo.subscriptionId)
435+
setSubscriptionEnabled(false)
436+
setEnabled(true)
437+
setDaysOfWeek(mDaysOfWeekFactory.create(*arrayOf(TUESDAY)))
438+
setTime(LocalTime.of(18, 30))
439+
}
440+
mAppDatabaseDE.subscriptionSchedulerDao().insert(schedule)
441+
}
442+
withTimeout(5.seconds) { insertJob.await() }
443+
}
444+
445+
onActivity {
446+
// Ensure ViewModel finished updating UI before capturing the initial state
447+
waitActivityWorkerThreadUntilIdle()
448+
shadowOf(Looper.getMainLooper()).idle()
449+
onSimEntryAt(0).captureRoboImage(idleFor = SCROLL_BAR_FADE_DURATION)
450+
}
451+
}
452+
453+
@Test
454+
@Config(minSdk = Q, qualifiers = "+land +ru") // use the verbose Russian locale to get text wrapping
455+
fun `test should separate date-time in SIM entries by space when in landscape`() {
456+
val subInfo = SubscriptionInfoBuilder.newBuilder().apply {
457+
setId(1)
458+
setDisplayName("SIM 1")
459+
setIconTint(Color.BLUE)
460+
}.buildSubscriptionInfo()
461+
shadowOf(mSubscriptionManager).setAvailableSubscriptionInfos(subInfo)
462+
463+
// Insert a schedule for the SIM card in database to be displayed in the summary
464+
runBlocking {
465+
val insertJob = async(Dispatchers.Default) {
466+
val schedule = SubscriptionScheduleEntity().apply {
467+
setSubscriptionId(subInfo.subscriptionId)
468+
setSubscriptionEnabled(false)
469+
setEnabled(true)
470+
setDaysOfWeek(mDaysOfWeekFactory.create(*arrayOf(TUESDAY)))
471+
setTime(LocalTime.of(18, 30))
472+
}
473+
mAppDatabaseDE.subscriptionSchedulerDao().insert(schedule)
474+
}
475+
withTimeout(5.seconds) { insertJob.await() }
476+
}
477+
478+
onActivity {
479+
// Ensure ViewModel finished updating UI before capturing the initial state
480+
waitActivityWorkerThreadUntilIdle()
481+
shadowOf(Looper.getMainLooper()).idle()
482+
onSimEntryAt(0).captureRoboImage(idleFor = SCROLL_BAR_FADE_DURATION)
483+
}
484+
}
485+
420486
@Test
421487
@Config(minSdk = Q)
422488
fun `test should show No SIM cards inserted entry ONLY when appropriate`() = onActivity {
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)