fix: use context instead of requireContext() for backward compatibility

It fixes crash when opening certain screens like Contribution Details, Bookmark, etc. on lower Android versions
This commit is contained in:
Rohit Verma 2025-08-17 18:21:03 +05:30
parent 5bdfbf5f6f
commit 87142a79ac
4 changed files with 17 additions and 17 deletions

View file

@ -36,7 +36,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
requireDb(), projection, selection,
selectionArgs, null, null, sortOrder
).apply {
setNotificationUri(requireContext().contentResolver, uri)
setNotificationUri(context?.contentResolver, uri)
}
}
@ -66,7 +66,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
)
}
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rowsUpdated
}
@ -75,7 +75,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
*/
override fun insert(uri: Uri, contentValues: ContentValues?): Uri? {
val id = requireDb().insert(TABLE_NAME, null, contentValues)
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return "$BASE_URI/$id".toUri()
}
@ -89,7 +89,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
"$COLUMN_ID = ?",
arrayOf(uri.lastPathSegment)
)
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rows
}

View file

@ -36,7 +36,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
requireDb(), projection, selection,
selectionArgs, null, null, sortOrder
)
cursor.setNotificationUri(requireContext().contentResolver, uri)
cursor.setNotificationUri(context?.contentResolver, uri)
return cursor
}
@ -66,7 +66,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
"Parameter `selection` should be empty when updating an ID"
)
}
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rowsUpdated
}
@ -75,7 +75,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
*/
override fun insert(uri: Uri, contentValues: ContentValues?): Uri {
val id = requireDb().insert(TABLE_NAME, null, contentValues)
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return "$BASE_URI/$id".toUri()
}
@ -85,7 +85,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
"media_name = ?",
arrayOf(uri.lastPathSegment)
)
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rows
}

View file

@ -50,7 +50,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
else -> throw IllegalArgumentException("Unknown URI$uri")
}
cursor.setNotificationUri(requireContext().contentResolver, uri)
cursor.setNotificationUri(context?.contentResolver, uri)
return cursor
}
@ -67,7 +67,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
else -> throw IllegalArgumentException("Unknown URI: $uri")
}
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return "$BASE_URI/$id".toUri()
}
@ -88,7 +88,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
else -> throw IllegalArgumentException("Unknown URI - $uri")
}
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rows
}
@ -108,7 +108,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
}
sqlDB.setTransactionSuccessful()
sqlDB.endTransaction()
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return values.size
}
@ -147,7 +147,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
else -> throw IllegalArgumentException("Unknown URI: $uri with type $uriType")
}
requireContext().contentResolver.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rowsUpdated
}

View file

@ -59,7 +59,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
null,
sortOrder
)
cursor.setNotificationUri(requireContext().contentResolver, uri)
cursor.setNotificationUri(context?.contentResolver, uri)
return cursor
}
@ -90,7 +90,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
throw IllegalArgumentException("Parameter `selection` should be empty when updating an ID")
}
requireContext().contentResolver?.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rowsUpdated
}
@ -105,7 +105,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
null,
contentValues
)
requireContext().contentResolver?.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return "$BASE_URI/$id".toUri()
}
@ -119,7 +119,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
"language_code = ?",
arrayOf(uri.lastPathSegment)
)
requireContext().contentResolver?.notifyChange(uri, null)
context?.contentResolver?.notifyChange(uri, null)
return rows
}
}