Skip to content

Commit a661458

Browse files
authored
fix: inflate crash and media provider bug (#2987)
* IconicsContextWrapper is crashing * fix `GROUP BY` query hack * workaround fix for Android 10 Glide failed to load image * see bumptech/glide#3896
1 parent e1d57e7 commit a661458

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
android:name=".MyApplication"
4343
android:allowBackup="true"
4444
android:icon="@mipmap/ic_launcher"
45+
android:requestLegacyExternalStorage="true"
4546
android:label="@string/app_name"
4647
android:largeHeap="true"
4748
android:supportsRtl="true"

app/src/main/java/org/fossasia/phimpme/base/ThemedActivity.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import androidx.core.content.ContextCompat;
1919
import androidx.core.graphics.drawable.DrawableCompat;
2020
import com.mikepenz.iconics.IconicsDrawable;
21-
import com.mikepenz.iconics.context.IconicsContextWrapper;
2221
import com.mikepenz.iconics.typeface.IIcon;
2322
import java.util.ArrayList;
2423
import org.fossasia.phimpme.R;
@@ -62,12 +61,6 @@ public void updateTheme() {
6261
}
6362
}
6463

65-
@Override
66-
protected void attachBaseContext(Context newBase) {
67-
// NOTE: icons stuff
68-
super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
69-
}
70-
7164
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
7265
public void setNavBarColor() {
7366
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

app/src/main/java/org/fossasia/phimpme/gallery/data/providers/MediaStoreProvider.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,10 @@ public static ArrayList<Album> getAlbums(Context context) {
8585
MediaStore.Files.FileColumns.PARENT, MediaStore.Images.Media.BUCKET_DISPLAY_NAME
8686
};
8787

88-
String selection, selectionArgs[];
89-
90-
selection =
91-
MediaStore.Files.FileColumns.MEDIA_TYPE
92-
+ "=? ) GROUP BY ( "
93-
+ MediaStore.Files.FileColumns.PARENT
94-
+ " ";
95-
selectionArgs = new String[] {String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE)};
88+
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ";
89+
String[] selectionArgs =
90+
new String[] {String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE)};
91+
String sortOrder = MediaStore.Files.FileColumns.PARENT;
9692

9793
Cursor cur =
9894
context
@@ -102,23 +98,26 @@ public static ArrayList<Album> getAlbums(Context context) {
10298
projection,
10399
selection,
104100
selectionArgs,
105-
null);
101+
sortOrder);
106102

107103
if (cur != null) {
108104
if (cur.moveToFirst()) {
109105
int idColumn = cur.getColumnIndex(MediaStore.Files.FileColumns.PARENT);
110106
int nameColumn = cur.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
107+
HashSet<Long> idSet = new HashSet<>();
111108
do {
112109
Media media = getLastMedia(context, cur.getLong(idColumn));
113110
if (media != null && media.getPath() != null) {
114111
String path = StringUtils.getBucketPathByImagePath(media.getPath());
115112
boolean excluded = isExcluded(path, context);
116-
if (!excluded) {
113+
long curIdColumn = cur.getLong(idColumn);
114+
if (!excluded && !idSet.contains(curIdColumn)) {
115+
idSet.add(curIdColumn);
117116
Album album =
118117
new Album(
119118
context,
120119
path,
121-
cur.getLong(idColumn),
120+
curIdColumn,
122121
cur.getString(nameColumn),
123122
getAlbumCount(context, cur.getLong(idColumn)));
124123
if (album.addMedia(getLastMedia(context, album.getId()))) list.add(album);

0 commit comments

Comments
 (0)