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

It fixes crash when opening certain screens like Contribution Details, Bookmark, etc. on lower Android versions

Co-authored-by: Ritika Pahwa <83745993+RitikaPahwa4444@users.noreply.github.com>
This commit is contained in:
Rohit Verma 2025-08-23 12:33:30 +05:30 committed by GitHub
parent 718c466505
commit 4f3f7b97fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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
}
}