Skip to content

Commit

Permalink
Smooth livestream's list displaying (#407)
Browse files Browse the repository at this point in the history
* Show livestream's list with progress bar while loading content

* Don't show livestreams on categories content list
  • Loading branch information
kekkyojin authored Nov 14, 2022
1 parent bd5c41e commit e4a467e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ private void fetchClaimSearchContent(boolean reset) {
Activity a = getActivity();

if (a != null) {
scheduledLivestreamsLayout.findViewById(R.id.livestreams_progressbar).setVisibility(View.VISIBLE);
scheduledLivestreamsLayout.setVisibility(View.VISIBLE);

Collection<Callable<Page>> callables = new ArrayList<>(2);
callables.add(() -> new Page(findActiveStream(), true /* ignored */));
callables.add(() -> Lbry.claimSearch(claimSearchOptions, Lbry.API_CONNECTION_STRING));
Expand Down Expand Up @@ -350,6 +353,8 @@ public void onClaimClicked(Claim claim, int position) {
scheduledClaimsListAdapter.addItems(finalScheduledClaims);
}

scheduledLivestreamsLayout.findViewById(R.id.livestreams_progressbar).setVisibility(View.GONE);

if (scheduledStreamsList != null && scheduledStreamsList.getAdapter() == null) {
scheduledStreamsList.setAdapter(scheduledClaimsListAdapter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ private Map<String, Object> buildContentOptions() {
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
}

List<String> channelIdsForCategory = null;
List<String> channelIdsForCategory;
List<String> excludedChannelIdsForCategory = Arrays.asList(dynamicCategories.get(currentCategoryId).getExcludedChannelIds());

if (currentChannelIdList != null) {
Expand Down Expand Up @@ -526,6 +526,8 @@ public void fetchClaimSearchContent(boolean reset) {
contentClaimSearchLoading = true;
Helper.setViewVisibility(noContentView, View.GONE);
Map<String, Object> claimSearchOptions = buildContentOptions();
claimSearchOptions.put("has_source", true);
// TODO Use a Search callable instead of this AsyncTask
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
Expand Down Expand Up @@ -587,6 +589,8 @@ private void fetchActiveLivestreams() {
activeClaimsListAdapter.clearItems();
}

activeLivestreamsLayout.findViewById(R.id.livestreams_progressbar).setVisibility(View.VISIBLE);

Thread t = new Thread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -626,6 +630,8 @@ public void onClaimClicked(Claim claim, int position) {

livestreamingClaimsFetched = true;

activeLivestreamsLayout.findViewById(R.id.livestreams_progressbar).setVisibility(View.GONE);

if (livestreamsList != null && livestreamsList.getAdapter() == null) {
livestreamsList.setAdapter(activeClaimsListAdapter);
}
Expand All @@ -650,6 +656,13 @@ private List<Claim> findActiveLivestreams() {
List<Claim> subscribedActiveClaims = new ArrayList<>();
if (a != null) {
try {
a.runOnUiThread(new Runnable() {
@Override
public void run() {
Helper.setViewVisibility(activeLivestreamsLayout, View.VISIBLE);
}
});

Map<String, JSONObject> activeJsonData;
Callable<Map<String, JSONObject>> callable;
Future<Map<String, JSONObject>> futureActive;
Expand All @@ -658,12 +671,12 @@ private List<Claim> findActiveLivestreams() {
List<String> channelIds = Arrays.asList(currentChannelIdList);

callable = new ChannelLiveStatus(channelIds, false, true);
futureActive = ((OdyseeApp) a.getApplication()).getExecutor().submit(callable);
} else {
callable = new GetAllLivestreams();
futureActive = ((OdyseeApp) a.getApplication()).getExecutor().submit(callable);
}

futureActive = ((OdyseeApp) a.getApplication()).getExecutor().submit(callable);

activeJsonData = futureActive.get();

if (activeJsonData != null && activeJsonData.size() > 0) {
Expand Down Expand Up @@ -709,6 +722,13 @@ private List<Claim> findActiveLivestreams() {
throw new RuntimeException(e);
}
}
} else {
a.runOnUiThread(new Runnable() {
@Override
public void run() {
Helper.setViewVisibility(activeLivestreamsLayout, View.GONE);
}
});
}
} catch (InterruptedException | ExecutionException e) {
Throwable cause = e.getCause();
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/fragment_all_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="12dp"
android:orientation="vertical"
tools:visibility="visible"
android:visibility="gone">
Expand Down Expand Up @@ -73,6 +74,16 @@
android:background="?attr/selectableItemBackground"
android:src="@drawable/ic_expand"/>

<ProgressBar
android:id="@+id/livestreams_progressbar"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintTop_toBottomOf="@id/active_livestreams_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/active_livestreams_recyclerview"
android:layout_width="match_parent"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_channel_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
android:background="?attr/selectableItemBackground"
android:src="@drawable/ic_expand"/>

<ProgressBar
android:id="@+id/livestreams_progressbar"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintTop_toBottomOf="@id/upcoming_livestreams_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/scheduled_livestreams_recyclerview"
android:layout_width="match_parent"
Expand Down

0 comments on commit e4a467e

Please sign in to comment.