mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-04-25 15:38:52 +02:00
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 firstLoad;
|
||||||
private boolean flag_loading;
|
private boolean flag_loading;
|
||||||
private PeertubeAdapter peertubeAdapter;
|
private PeertubeAdapter peertubeAdapter;
|
||||||
|
private PlaylistsVM viewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -100,7 +101,7 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
setTitle(playlist.getDisplayName());
|
setTitle(playlist.getDisplayName());
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(PlaylistsActivity.this).get(PlaylistsVM.class);
|
||||||
lv_playlist.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
lv_playlist.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||||
@ -110,7 +111,6 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||||
if (!flag_loading) {
|
if (!flag_loading) {
|
||||||
flag_loading = true;
|
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));
|
viewModel.manage(GET_LIST_VIDEOS, playlist, null, max_id).observe(PlaylistsActivity.this, apiResponse -> manageVIewPlaylists(PlaylistsVM.action.GET_LIST_VIDEOS, apiResponse));
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
nextElementLoader.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@ -127,11 +127,9 @@ public class PlaylistsActivity extends AppCompatActivity {
|
|||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
flag_loading = true;
|
flag_loading = true;
|
||||||
swiped = 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));
|
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));
|
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) {
|
public static Peertube parsePeertube(JSONObject resobj) {
|
||||||
Peertube peertube = new Peertube();
|
Peertube peertube = new Peertube();
|
||||||
if (resobj.has("video")) {
|
if (resobj.has("video") && !resobj.isNull("video")) {
|
||||||
try {
|
try {
|
||||||
resobj = resobj.getJSONObject("video");
|
resobj = resobj.getJSONObject("video");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
peertube.setId(resobj.getString("id"));
|
peertube.setId(resobj.getString("id"));
|
||||||
@ -271,7 +273,11 @@ public class PeertubeAPI {
|
|||||||
LinkedHashMap<Integer, String> license = new LinkedHashMap<>();
|
LinkedHashMap<Integer, String> license = new LinkedHashMap<>();
|
||||||
LinkedHashMap<Integer, String> privacy = new LinkedHashMap<>();
|
LinkedHashMap<Integer, String> privacy = new LinkedHashMap<>();
|
||||||
category.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
|
category.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
|
||||||
license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").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"));
|
privacy.put(resobj.getJSONObject("privacy").getInt("id"), resobj.getJSONObject("privacy").getString("label"));
|
||||||
langue.put(resobj.getJSONObject("language").getString("id"), resobj.getJSONObject("language").getString("label"));
|
langue.put(resobj.getJSONObject("language").getString("id"), resobj.getJSONObject("language").getString("label"));
|
||||||
peertube.setCategory(category);
|
peertube.setCategory(category);
|
||||||
@ -1989,7 +1995,7 @@ public class PeertubeAPI {
|
|||||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||||
Peertube peertube = parsePeertube(resobj);
|
Peertube peertube = parsePeertube(resobj);
|
||||||
i++;
|
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);
|
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);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, "");
|
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) {
|
if (peertube.getChannel() == null) {
|
||||||
holder.peertube_account_name.setText(account.getAcct());
|
holder.peertube_account_name.setText(account.getAcct());
|
||||||
|
@ -130,7 +130,9 @@ public class PeertubeFavoritesDAO {
|
|||||||
//Restore cached status
|
//Restore cached status
|
||||||
try {
|
try {
|
||||||
Peertube peertube = PeertubeAPI.parsePeertube(new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
|
Peertube peertube = PeertubeAPI.parsePeertube(new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE))));
|
||||||
peertubes.add(peertube);
|
if (peertube != null) {
|
||||||
|
peertubes.add(peertube);
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user