Skip to content

Commit

Permalink
fix: inflate crash and media provider bug (#2987)
Browse files Browse the repository at this point in the history
* IconicsContextWrapper is crashing

* fix `GROUP BY` query hack

* workaround fix for Android 10 Glide failed to load image

* see bumptech/glide#3896
  • Loading branch information
TBog authored Apr 10, 2020
1 parent e1d57e7 commit a661458
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.context.IconicsContextWrapper;
import com.mikepenz.iconics.typeface.IIcon;
import java.util.ArrayList;
import org.fossasia.phimpme.R;
Expand Down Expand Up @@ -62,12 +61,6 @@ public void updateTheme() {
}
}

@Override
protected void attachBaseContext(Context newBase) {
// NOTE: icons stuff
super.attachBaseContext(IconicsContextWrapper.wrap(newBase));
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setNavBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ public static ArrayList<Album> getAlbums(Context context) {
MediaStore.Files.FileColumns.PARENT, MediaStore.Images.Media.BUCKET_DISPLAY_NAME
};

String selection, selectionArgs[];

selection =
MediaStore.Files.FileColumns.MEDIA_TYPE
+ "=? ) GROUP BY ( "
+ MediaStore.Files.FileColumns.PARENT
+ " ";
selectionArgs = new String[] {String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE)};
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ";
String[] selectionArgs =
new String[] {String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE)};
String sortOrder = MediaStore.Files.FileColumns.PARENT;

Cursor cur =
context
Expand All @@ -102,23 +98,26 @@ public static ArrayList<Album> getAlbums(Context context) {
projection,
selection,
selectionArgs,
null);
sortOrder);

if (cur != null) {
if (cur.moveToFirst()) {
int idColumn = cur.getColumnIndex(MediaStore.Files.FileColumns.PARENT);
int nameColumn = cur.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
HashSet<Long> idSet = new HashSet<>();
do {
Media media = getLastMedia(context, cur.getLong(idColumn));
if (media != null && media.getPath() != null) {
String path = StringUtils.getBucketPathByImagePath(media.getPath());
boolean excluded = isExcluded(path, context);
if (!excluded) {
long curIdColumn = cur.getLong(idColumn);
if (!excluded && !idSet.contains(curIdColumn)) {
idSet.add(curIdColumn);
Album album =
new Album(
context,
path,
cur.getLong(idColumn),
curIdColumn,
cur.getString(nameColumn),
getAlbumCount(context, cur.getLong(idColumn)));
if (album.addMedia(getLastMedia(context, album.getId()))) list.add(album);
Expand Down

0 comments on commit a661458

Please sign in to comment.