Fix Nitter refresh

This commit is contained in:
tom79 2020-02-01 10:40:41 +01:00
parent 5de21f628c
commit 0fb2390f0f
2 changed files with 43 additions and 13 deletions

View File

@ -3502,6 +3502,7 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -3633,13 +3634,7 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
apiResponse.setStatuses(statuses); apiResponse.setStatuses(statuses);

View File

@ -382,7 +382,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}); });
if (instanceType == null || !instanceType.equals("PEERTUBE")) if (instanceType == null || (!instanceType.equals("PEERTUBE") && !instanceType.equals("NITTER"))) {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
@ -400,7 +400,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
} }
}); });
else { }else if(instanceType.equals("PEERTUBE")){
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
@ -419,6 +419,23 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
} }
} }
}); });
}else {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (statuses.size() > 0) {
int size = statuses.size();
isSwipped = true;
statuses.clear();
statuses = new ArrayList<>();
max_id = null;
statusListAdapter.notifyItemRangeRemoved(0, size);
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).execute();
}
}
});
} }
if (context != null) { if (context != null) {
//Load data depending of the value //Load data depending of the value
@ -517,7 +534,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//hide loaders //hide loaders
mainLoader.setVisibility(View.GONE); mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//handle other API error but discards 404 - error which can often happen due to toots which have been deleted //handle other API error but discards 404 - error which can often happen due to toots which have been deleted
if (this.peertubes == null || this.statuses == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) { if (this.peertubes == null || this.statuses == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) {
if (apiResponse == null) if (apiResponse == null)
@ -533,7 +549,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
flag_loading = false; flag_loading = false;
return; return;
} }
//For remote Peertube remote instances //For remote Peertube remote instances
if (instanceType.equals("PEERTUBE")) { if (instanceType.equals("PEERTUBE")) {
int previousPosition = this.peertubes.size(); int previousPosition = this.peertubes.size();
@ -554,12 +569,33 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size()); peertubeAdapater.notifyItemRangeInserted(previousPosition, apiResponse.getPeertubes().size());
//remove handlers //remove handlers
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
textviewNoAction.setVisibility(View.GONE);
if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) { if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) {
textviewNoActionText.setText(R.string.no_video_to_display); textviewNoActionText.setText(R.string.no_video_to_display);
textviewNoAction.setVisibility(View.VISIBLE); textviewNoAction.setVisibility(View.VISIBLE);
} }
flag_loading = false; flag_loading = false;
firstLoad = false; firstLoad = false;
}else if (instanceType.equals("NITTER")) {
int previousPosition = this.statuses.size();
//max_id needs to work like an offset
this.statuses.addAll(apiResponse.getStatuses());
//If no item were inserted previously the adapter is created
if (previousPosition == 0) {
boolean isOnWifi = Helper.isOnWIFI(context);
statusListAdapter = new StatusListAdapter(instanceType, type, targetedId, isOnWifi, this.statuses);
lv_status.setAdapter(statusListAdapter);
} else {
statusListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getStatuses().size());
}
textviewNoAction.setVisibility(View.GONE);
//remove handlers
swipeRefreshLayout.setRefreshing(false);
if (firstLoad && (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().size() == 0)) {
textviewNoAction.setVisibility(View.VISIBLE);
}
flag_loading = false;
firstLoad = false;
} else { } else {
//When Mastodon statuses have been fetched. //When Mastodon statuses have been fetched.
@ -626,7 +662,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
} }
//Let's deal with statuses //Let's deal with statuses
if (statuses != null && statuses.size() > 0) { if (statuses != null && statuses.size() > 0) {
if (statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("NITTER") || instanceType.equals("MISSKEY") || instanceType.equals("GNU"))) { if (statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") || instanceType.equals("GNU"))) {
this.statuses.addAll(statuses); this.statuses.addAll(statuses);
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
} else if (artListAdapter != null && instanceType.equals("ART")) { } else if (artListAdapter != null && instanceType.equals("ART")) {
@ -651,7 +687,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
} }
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
firstLoad = false; firstLoad = false;
} }
} }