fixed app crashing when using links that have data missing

This commit is contained in:
Denis Çerri 2022-10-22 09:59:50 +02:00
parent 4a387ea0cf
commit 8f533ab67e
No known key found for this signature in database
GPG key ID: 3F50F14A8E7F7A13
5 changed files with 54 additions and 18 deletions

View file

@ -77,9 +77,15 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
ImageView thumbnail = card.findViewById(R.id.downloads_image_view);
String imageURL= video.getThumb();
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
if (!imageURL.isEmpty()){
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}else {
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(R.color.black).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}
// TITLE ----------------------------------
TextView videoTitle = card.findViewById(R.id.downloads_title);
@ -92,7 +98,11 @@ public class DownloadsRecyclerViewAdapter extends RecyclerView.Adapter<Downloads
// Bottom Info ----------------------------------
TextView bottomInfo = card.findViewById(R.id.downloads_info_bottom);
String info = video.getAuthor() + "" + video.getDuration();
String info = video.getAuthor();
if (!video.getDuration().isEmpty()){
if (!video.getAuthor().isEmpty()) info += "";
info += video.getDuration();
}
bottomInfo.setText(info);
// TIME DOWNLOADED ----------------------------------

View file

@ -67,10 +67,15 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
// THUMBNAIL ----------------------------------
ImageView thumbnail = card.findViewById(R.id.result_image_view);
String imageURL= video.getThumb();
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
if (!imageURL.isEmpty()){
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(imageURL).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}else {
Handler uiHandler = new Handler(Looper.getMainLooper());
uiHandler.post(() -> Picasso.get().load(R.color.black).into(thumbnail));
thumbnail.setColorFilter(Color.argb(70, 0, 0, 0));
}
// TITLE ----------------------------------
TextView videoTitle = card.findViewById(R.id.result_title);
@ -84,7 +89,11 @@ public class HomeRecyclerViewAdapter extends RecyclerView.Adapter<HomeRecyclerVi
// Bottom Info ----------------------------------
TextView bottomInfo = card.findViewById(R.id.result_info_bottom);
String info = video.getAuthor() + "" + video.getDuration();
String info = video.getAuthor();
if (!video.getDuration().isEmpty()){
if (!video.getAuthor().isEmpty()) info += "";
info += video.getDuration();
}
bottomInfo.setText(info);
// BUTTONS ----------------------------------

View file

@ -262,7 +262,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
try{
new Handler(Looper.getMainLooper()).post(() -> {
// DOWNLOAD ALL BUTTON
if (resultObjects.get(0).getIsPlaylistItem() == 1 || inputQueriesLength > 1) {
if ((resultObjects.size() > 1 && resultObjects.get(1).getIsPlaylistItem() == 1) || inputQueriesLength > 1) {
downloadAllFab.setVisibility(View.VISIBLE);
}
dbManager = new DBManager(context);
@ -385,7 +385,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
Thread thread = new Thread(() -> {
parseQuery(true);
// DOWNLOAD ALL BUTTON
if (resultObjects.get(0).getIsPlaylistItem() == 1) {
if (resultObjects.size() > 1 && resultObjects.get(1).getIsPlaylistItem() == 1) {
new Handler(Looper.getMainLooper()).post(() -> downloadAllFab.setVisibility(View.VISIBLE));
}
});

View file

@ -291,13 +291,30 @@ public class InfoUtil {
for (String result : results) {
JSONObject jsonObject = new JSONObject(result);
if (jsonObject.getString("title").equals("[Private video]")) continue;
String title = "";
if (jsonObject.has("title")){
if (jsonObject.getString("title").equals("[Private video]")) continue;
title = jsonObject.getString("title");
}else{
title = jsonObject.getString("webpage_url_basename");
}
String author = "";
if (jsonObject.has("uploader")){
author = jsonObject.getString("uploader");
}
String duration = "";
if (jsonObject.has("duration")){
duration = formatIntegerDuration(jsonObject.getInt("duration"));
}
String url = jsonObject.getString("webpage_url");
String thumb = "";
if (jsonObject.has("thumbnail")){
thumb = jsonObject.getString("thumbnail");
}else {
}else if (jsonObject.has("thumbnails")){
JSONArray thumbs = jsonObject.getJSONArray("thumbnails");
thumb = thumbs.getJSONObject(thumbs.length()-1).getString("url");
}
@ -312,9 +329,9 @@ public class InfoUtil {
videos.add(new Video(
jsonObject.getString("id"),
url,
jsonObject.getString("title"),
jsonObject.getString("uploader"),
formatIntegerDuration(jsonObject.getInt("duration")),
title,
author,
duration,
thumb,
dbManager.checkDownloaded(url, "audio"),
dbManager.checkDownloaded(url, "video"),

View file

@ -16,8 +16,8 @@ buildscript {
}
def versionMajor = 1
def versionMinor = 3
def versionPatch = 2
def versionMinor = 4
def versionPatch = 1
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
ext {