Fix some crashes
This commit is contained in:
parent
c714e6a625
commit
2f909d5ffa
|
@ -53,6 +53,7 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
private boolean firstLoad;
|
||||
private boolean flag_loading;
|
||||
private PeertubeAdapter peertubeAdapter;
|
||||
private PlaylistsVM viewModel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -100,7 +101,7 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
|
||||
setTitle(playlist.getDisplayName());
|
||||
|
||||
|
||||
viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
lv_playlist.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
|
@ -110,7 +111,6 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
PlaylistsVM viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, max_id).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -127,11 +127,9 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
swiped = true;
|
||||
PlaylistsVM viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
});
|
||||
|
||||
PlaylistsVM viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||
viewModel.manage(GET_LIST_VIDEOS, playlist, null, null).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||
}
|
||||
|
||||
|
|
|
@ -228,12 +228,14 @@ public class PeertubeAPI {
|
|||
*/
|
||||
public static Peertube parsePeertube(JSONObject resobj) {
|
||||
Peertube peertube = new Peertube();
|
||||
if (resobj.has("video")) {
|
||||
if (resobj.has("video") && !resobj.isNull("video")) {
|
||||
try {
|
||||
resobj = resobj.getJSONObject("video");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
peertube.setId(resobj.getString("id"));
|
||||
|
@ -271,7 +273,11 @@ public class PeertubeAPI {
|
|||
LinkedHashMap<Integer, String> license = new LinkedHashMap<>();
|
||||
LinkedHashMap<Integer, String> privacy = new LinkedHashMap<>();
|
||||
category.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
|
||||
if (!resobj.getJSONObject("licence").isNull("id")) {
|
||||
license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").getString("label"));
|
||||
} else {
|
||||
license.put(1, "Unknown");
|
||||
}
|
||||
privacy.put(resobj.getJSONObject("privacy").getInt("id"), resobj.getJSONObject("privacy").getString("label"));
|
||||
langue.put(resobj.getJSONObject("language").getString("id"), resobj.getJSONObject("language").getString("label"));
|
||||
peertube.setCategory(category);
|
||||
|
@ -1989,7 +1995,7 @@ public class PeertubeAPI {
|
|||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Peertube peertube = parsePeertube(resobj);
|
||||
i++;
|
||||
if (peertube.getName() == null || !peertube.getName().toLowerCase().contains("youtube video downloader")) {
|
||||
if (peertube != null && (peertube.getName() == null || !peertube.getName().toLowerCase().contains("youtube video downloader"))) {
|
||||
peertubes.add(peertube);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
|
||||
|
||||
boolean ownVideos = peertube.getAccount().getInstance().compareTo(Helper.getLiveInstance(context)) == 0 && userId != null && peertube.getAccount().getId() != null && peertube.getAccount().getId().compareTo(userId) == 0;
|
||||
boolean ownVideos = peertube.getAccount().getHost().compareTo(Helper.getLiveInstance(context)) == 0 && userId != null && peertube.getAccount().getId() != null && peertube.getAccount().getId().compareTo(userId) == 0;
|
||||
|
||||
if (peertube.getChannel() == null) {
|
||||
holder.peertube_account_name.setText(account.getAcct());
|
||||
|
|
|
@ -130,7 +130,9 @@ public class PeertubeFavoritesDAO {
|
|||
//Restore cached status
|
||||
try {
|
||||
Peertube peertube = PeertubeAPI.parsePeertube(new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
|
||||
if (peertube != null) {
|
||||
peertubes.add(peertube);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue