fixed playlist empty thumb crash

This commit is contained in:
gdlbo
2024-03-18 14:22:28 +03:00
parent b1fbe458f8
commit d52d9f594c
3 changed files with 26 additions and 6 deletions
@@ -33,6 +33,16 @@ public class PlaylistCacheDb extends SQLiteOpenHelper implements AutoCloseable {
}
private static Playlist fromCursor(Cursor cur) throws JSONException {
@SuppressLint("Range")
String photoString = cur.getString(cur.getColumnIndex(Constants.COLUMN_PHOTO));
JSONObject photo = null;
try {
photo = new JSONObject(photoString);
} catch (JSONException e) {
// ok and
}
@SuppressLint("Range")
JSONObject playlist = PlaylistHelper.generatePlaylist(
cur.getInt(cur.getColumnIndex(Constants.COLUMN_ID)),
@@ -40,7 +50,7 @@ public class PlaylistCacheDb extends SQLiteOpenHelper implements AutoCloseable {
Boolean.parseBoolean(cur.getString(cur.getColumnIndex(Constants.COLUMN_IS_EXPLICIT))),
cur.getString(cur.getColumnIndex(Constants.COLUMN_TITLE)),
cur.getString(cur.getColumnIndex(Constants.COLUMN_DESCRIPTION)),
new JSONObject(cur.getString(cur.getColumnIndex(Constants.COLUMN_PHOTO))),
photo,
0);
Log.d("Playlist", "generated " + Playlist.U.a(playlist).v1());
@@ -1,6 +1,7 @@
package ru.vtosters.lite.music.cache.delegate;
import android.content.Context;
import android.util.Log;
import com.vk.dto.music.MusicTrack;
import com.vk.dto.music.Playlist;
import org.json.JSONObject;
@@ -83,9 +84,11 @@ public class PlaylistCacheDbDelegate {
private static JSONObject getThumb(Playlist playlist) {
try {
Log.d("Playlist", "thumb is not null");
return playlist.F.J();
} catch (Exception e) {
return new JSONObject();
Log.d("Playlist", "thumb is null");
return null;
}
}
}
@@ -37,7 +37,7 @@ public class PlaylistHelper {
jsonArray.put(generatePlaylist(playlist.a, playlist.b, playlist.C, playlist.g, playlist.B, getThumb(playlist), playlist.O));
}
Log.d("PlaylistHelper", "Playlist cache added: " + playlist.a + " " + playlist.b + " " + playlist.C + " " + playlist.g + " " + playlist.B + " " + playlist.F.J());
Log.d("PlaylistHelper", "Playlist cache added: " + playlist.a + " " + playlist.b + " " + playlist.C + " " + playlist.g + " " + playlist.B);
}
} catch (JSONException e) {
e.fillInStackTrace();
@@ -46,7 +46,7 @@ public class PlaylistHelper {
}
public static JSONObject generatePlaylist(int id, int owner_id, boolean is_explicit, String title, String description, JSONObject photo, int count) throws JSONException {
return new JSONObject()
JSONObject playlist = new JSONObject()
.put("id", id)
.put("owner_id", owner_id)
.put("type", 0)
@@ -62,10 +62,15 @@ public class PlaylistHelper {
.put("create_time", 0)
.put("update_time", 0)
.put("subtitle", "")
.put("photo", photo)
.put("meta", new JSONObject()
.put("view", "compact"))
.put("count", count);
if (photo != null) {
playlist.put("photo", photo);
}
return playlist;
}
public static JSONObject getCachedSongsPlaylist() throws JSONException {
@@ -143,9 +148,11 @@ public class PlaylistHelper {
private static JSONObject getThumb(Playlist playlist) {
try {
Log.d("Playlist", "thumb is not null");
return playlist.F.J();
} catch (Exception e) {
return new JSONObject();
Log.d("Playlist", "thumb is null");
return null;
}
}
}