0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

Changed assert to assertThat in the test file and other refactoring.

This commit is contained in:
Anoop 2024-08-26 20:20:36 +05:30 committed by Arthur Milchior
parent d5e1f21d43
commit a03d3c1d3b
7 changed files with 34 additions and 37 deletions

View File

@ -84,7 +84,7 @@ private fun getPendingIntent(
}
/**
* Ensure a recurring alarm is set to update the widget every 10 minutes.
* Ensure a recurring alarm is set to update the widget every 1 minute.
*
* If the alarm is already set for the widget, this method does nothing.
* This ensures that multiple alarms are not created for the same widget,
@ -109,18 +109,15 @@ fun setRecurringAlarm(
Timber.v("Creating a new recurring alarm PendingIntent for widget ID: $appWidgetId")
val alarmManager = alarmManager(context)
val newPendingIntent = getPendingIntent(context, appWidgetId, widgetClass, create = true)
val newPendingIntent = getPendingIntent(context, appWidgetId, widgetClass, create = true) ?: return
// Set alarm to trigger every 10 minutes
val TEN_MINUTES_MILLIS = 10.minutes.inWholeMilliseconds
if (newPendingIntent != null) {
alarmManager.setRepeating(
AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + TEN_MINUTES_MILLIS,
TEN_MINUTES_MILLIS,
newPendingIntent
)
}
val ONE_MINUTE_MILLIS = 1.minutes.inWholeMilliseconds
alarmManager.setRepeating(
AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + ONE_MINUTE_MILLIS,
ONE_MINUTE_MILLIS,
newPendingIntent
)
}
/**

View File

@ -92,9 +92,6 @@ class DeckPickerWidget : AnalyticsWidgetProvider() {
* Each ID corresponds to a specific deck, and the view will
* contain exactly the decks whose IDs are in this list.
*
* TODO: If the deck is completely empty (no cards at all), display a Snackbar or Toast message
* saying "The deck is empty" instead of opening any activity.
*
*/
fun updateWidget(
context: Context,
@ -264,7 +261,7 @@ class DeckPickerWidget : AnalyticsWidgetProvider() {
override fun onDeleted(context: Context?, appWidgetIds: IntArray?) {
if (context == null) {
Timber.e("Context is null in onDeleted")
Timber.w("Context is null in onDeleted")
return
}

View File

@ -145,6 +145,7 @@ class DeckPickerWidgetConfig : AnkiActivity(), DeckSelectionListener, BaseSnackb
setupDoneButton()
// TODO: Implement multi-select functionality so that user can select desired decks in once.
// TODO: Implement a functionality to hide already selected deck.
findViewById<FloatingActionButton>(R.id.fabWidgetDeckPicker).setOnClickListener {
showDeckSelectionDialog()
}

View File

@ -21,8 +21,7 @@
android:id="@+id/action_button_remove_deck"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="?attr/selectableItemBackgroundBorderless"
android:paddingEnd="10dp"
android:src="@drawable/ic_delete_white" />
</LinearLayout>

View File

@ -38,12 +38,12 @@
</plurals>
<string name="widget_add_note_button">Add new AnkiDroid note</string>
<string name="deck_picker_widget_description">Deck Picker Widget</string>
<string name="deck_picker_widget_description">Deck Picker</string>
<!-- Strings to explain usage in Deck Picker Widget Configuration screen -->
<string name="select_deck_title" comment="Title for Deck Selection Dialog">Select decks</string>
<string name="no_selected_deck_placeholder_title" comment="Placeholder title when no decks are selected">Select decks to display in the widget. Select decks with the + icon.</string>
<string name="deck_removed_from_widget" comment="Snackbar when deck is removed from widget">Deck Removed</string>
<string name="deck_removed_from_widget" comment="Snackbar when deck is removed from widget">Deck removed</string>
<string name="deck_already_selected_message" comment="Snackbar when user try to select the same deck again">This deck is already selected</string>
<plurals name="deck_limit_reached">
<item quantity="one">You can select up to %d deck.</item>

View File

@ -1,13 +1,14 @@
<!--JPG type of file used in previewImage property because the SVG format is not supported on all devices.
<!-- JPG type of file used in previewImage property because the SVG format is not supported on all devices.
The widths and heights parameters are determined as follows:
The default is 3 cells in width and 2 in height.
The height is between 1 and 5 cells.
The width is between 3 and 4 cells.
Following https://developer.android.com/develop/ui/views/appwidgets/layouts#anatomy_determining_size
we used the portrait mode cell size for the width and the landscape mode cell size for the height. Leading to:
* height between 50 and 315
* width 203 and 276 -->
The widths and heights parameters are determined as follow.
The default is 3 cells in width and 2 in height
The height is between 1 and 5 cells.
The width is between 3 and 4 cells.
Following https://developer.android.com/develop/ui/views/appwidgets/layouts#anatomy_determining_size
we used the portrait mode cell size for the width and the landscape mode cell size for the height. Leading to:
* height between 50 and 315
* width 203 and 276-->
<!-- TODO: Use updatePeriodMillis instead of the 10-minute alarm for simpler widget updates.-->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/widget_deck_picker_large"

View File

@ -29,6 +29,8 @@ import com.ichi2.anki.RobolectricTest
import com.ichi2.anki.dialogs.DeckSelectionDialog
import com.ichi2.widget.WidgetPreferences
import com.ichi2.widget.deckpicker.DeckPickerWidgetConfig
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@ -85,8 +87,8 @@ class DeckPickerWidgetConfigTest : RobolectricTest() {
activity.saveSelectedDecksToPreferencesDeckPickerWidget()
// Verify saved decks
val selectedDeckIds = widgetPreferences.getSelectedDeckIdsFromPreferencesDeckPickerWidget(1)
assert(selectedDeckIds.contains(deck1.deckId))
val selectedDeckIds = widgetPreferences.getSelectedDeckIdsFromPreferencesDeckPickerWidget(1).toList()
assertThat(selectedDeckIds.contains(deck1.deckId), equalTo(true))
}
/**
@ -112,7 +114,7 @@ class DeckPickerWidgetConfigTest : RobolectricTest() {
val adapter = recyclerView.adapter
// Verify the adapter has the correct item count
assert(adapter != null && adapter.itemCount == deckIds.size)
assertThat(adapter?.itemCount, equalTo(deckIds.size))
}
/**
@ -128,16 +130,16 @@ class DeckPickerWidgetConfigTest : RobolectricTest() {
// Initially, no decks should be selected
activity.updateViewVisibility()
assert(noDecksPlaceholder.visibility == View.VISIBLE)
assert(widgetConfigContainer.visibility == View.GONE)
assertThat(noDecksPlaceholder.visibility, equalTo(View.VISIBLE))
assertThat(widgetConfigContainer.visibility, equalTo(View.GONE))
// Add a deck and update view visibility
val deck = DeckSelectionDialog.SelectableDeck(1, "Deck 1")
activity.deckAdapter.addDeck(deck)
activity.updateViewVisibility()
assert(noDecksPlaceholder.visibility == View.GONE)
assert(widgetConfigContainer.visibility == View.VISIBLE)
assertThat(noDecksPlaceholder.visibility, equalTo(View.GONE))
assertThat(widgetConfigContainer.visibility, equalTo(View.VISIBLE))
}
/**
@ -153,6 +155,6 @@ class DeckPickerWidgetConfigTest : RobolectricTest() {
// Verify deck is added to adapter
val recyclerView = activity.findViewById<RecyclerView>(R.id.recyclerViewSelectedDecks)
assert(recyclerView.adapter?.itemCount == 1)
assertThat(recyclerView.adapter?.itemCount, equalTo(1))
}
}