Skip to content

Commit 4f3f7b9

Browse files
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 <[email protected]>
1 parent 718c466 commit 4f3f7b9

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

app/src/main/java/fr/free/nrw/commons/bookmarks/items/BookmarkItemsContentProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
3636
requireDb(), projection, selection,
3737
selectionArgs, null, null, sortOrder
3838
).apply {
39-
setNotificationUri(requireContext().contentResolver, uri)
39+
setNotificationUri(context?.contentResolver, uri)
4040
}
4141
}
4242

@@ -66,7 +66,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
6666
)
6767
}
6868

69-
requireContext().contentResolver.notifyChange(uri, null)
69+
context?.contentResolver?.notifyChange(uri, null)
7070
return rowsUpdated
7171
}
7272

@@ -75,7 +75,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
7575
*/
7676
override fun insert(uri: Uri, contentValues: ContentValues?): Uri? {
7777
val id = requireDb().insert(TABLE_NAME, null, contentValues)
78-
requireContext().contentResolver.notifyChange(uri, null)
78+
context?.contentResolver?.notifyChange(uri, null)
7979
return "$BASE_URI/$id".toUri()
8080
}
8181

@@ -89,7 +89,7 @@ class BookmarkItemsContentProvider : CommonsDaggerContentProvider() {
8989
"$COLUMN_ID = ?",
9090
arrayOf(uri.lastPathSegment)
9191
)
92-
requireContext().contentResolver.notifyChange(uri, null)
92+
context?.contentResolver?.notifyChange(uri, null)
9393
return rows
9494
}
9595

app/src/main/java/fr/free/nrw/commons/bookmarks/pictures/BookmarkPicturesContentProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
3636
requireDb(), projection, selection,
3737
selectionArgs, null, null, sortOrder
3838
)
39-
cursor.setNotificationUri(requireContext().contentResolver, uri)
39+
cursor.setNotificationUri(context?.contentResolver, uri)
4040

4141
return cursor
4242
}
@@ -66,7 +66,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
6666
"Parameter `selection` should be empty when updating an ID"
6767
)
6868
}
69-
requireContext().contentResolver.notifyChange(uri, null)
69+
context?.contentResolver?.notifyChange(uri, null)
7070
return rowsUpdated
7171
}
7272

@@ -75,7 +75,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
7575
*/
7676
override fun insert(uri: Uri, contentValues: ContentValues?): Uri {
7777
val id = requireDb().insert(TABLE_NAME, null, contentValues)
78-
requireContext().contentResolver.notifyChange(uri, null)
78+
context?.contentResolver?.notifyChange(uri, null)
7979
return "$BASE_URI/$id".toUri()
8080
}
8181

@@ -85,7 +85,7 @@ class BookmarkPicturesContentProvider : CommonsDaggerContentProvider() {
8585
"media_name = ?",
8686
arrayOf(uri.lastPathSegment)
8787
)
88-
requireContext().contentResolver.notifyChange(uri, null)
88+
context?.contentResolver?.notifyChange(uri, null)
8989
return rows
9090
}
9191

app/src/main/java/fr/free/nrw/commons/explore/recentsearches/RecentSearchesContentProvider.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
5050
else -> throw IllegalArgumentException("Unknown URI$uri")
5151
}
5252

53-
cursor.setNotificationUri(requireContext().contentResolver, uri)
53+
cursor.setNotificationUri(context?.contentResolver, uri)
5454

5555
return cursor
5656
}
@@ -67,7 +67,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
6767

6868
else -> throw IllegalArgumentException("Unknown URI: $uri")
6969
}
70-
requireContext().contentResolver.notifyChange(uri, null)
70+
context?.contentResolver?.notifyChange(uri, null)
7171
return "$BASE_URI/$id".toUri()
7272
}
7373

@@ -88,7 +88,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
8888

8989
else -> throw IllegalArgumentException("Unknown URI - $uri")
9090
}
91-
requireContext().contentResolver.notifyChange(uri, null)
91+
context?.contentResolver?.notifyChange(uri, null)
9292
return rows
9393
}
9494

@@ -108,7 +108,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
108108
}
109109
sqlDB.setTransactionSuccessful()
110110
sqlDB.endTransaction()
111-
requireContext().contentResolver.notifyChange(uri, null)
111+
context?.contentResolver?.notifyChange(uri, null)
112112
return values.size
113113
}
114114

@@ -147,7 +147,7 @@ class RecentSearchesContentProvider : CommonsDaggerContentProvider() {
147147

148148
else -> throw IllegalArgumentException("Unknown URI: $uri with type $uriType")
149149
}
150-
requireContext().contentResolver.notifyChange(uri, null)
150+
context?.contentResolver?.notifyChange(uri, null)
151151
return rowsUpdated
152152
}
153153

app/src/main/java/fr/free/nrw/commons/recentlanguages/RecentLanguagesContentProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
5959
null,
6060
sortOrder
6161
)
62-
cursor.setNotificationUri(requireContext().contentResolver, uri)
62+
cursor.setNotificationUri(context?.contentResolver, uri)
6363
return cursor
6464
}
6565

@@ -90,7 +90,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
9090
throw IllegalArgumentException("Parameter `selection` should be empty when updating an ID")
9191
}
9292

93-
requireContext().contentResolver?.notifyChange(uri, null)
93+
context?.contentResolver?.notifyChange(uri, null)
9494
return rowsUpdated
9595
}
9696

@@ -105,7 +105,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
105105
null,
106106
contentValues
107107
)
108-
requireContext().contentResolver?.notifyChange(uri, null)
108+
context?.contentResolver?.notifyChange(uri, null)
109109
return "$BASE_URI/$id".toUri()
110110
}
111111

@@ -119,7 +119,7 @@ class RecentLanguagesContentProvider : CommonsDaggerContentProvider() {
119119
"language_code = ?",
120120
arrayOf(uri.lastPathSegment)
121121
)
122-
requireContext().contentResolver?.notifyChange(uri, null)
122+
context?.contentResolver?.notifyChange(uri, null)
123123
return rows
124124
}
125125
}

0 commit comments

Comments
 (0)