Made sure that all fragments have a progress bar

This commit is contained in:
ByteHamster 2020-03-21 19:25:54 +01:00
parent 1cdc8fc33e
commit b6bbcf5afb
10 changed files with 56 additions and 19 deletions

View File

@ -8,6 +8,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
@ -55,7 +56,9 @@ public class CompletedDownloadsFragment extends Fragment {
private List<FeedItem> items = new ArrayList<>();
private CompletedDownloadsListAdapter adapter;
private RecyclerView recyclerView;
private ProgressBar progressBar;
private Disposable disposable;
private EmptyViewHandler emptyView;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@ -72,6 +75,7 @@ public class CompletedDownloadsFragment extends Fragment {
recyclerView.setVisibility(View.GONE);
adapter = new CompletedDownloadsListAdapter((MainActivity) getActivity());
recyclerView.setAdapter(adapter);
progressBar = root.findViewById(R.id.progLoading);
addEmptyView();
EventBus.getDefault().register(this);
@ -127,7 +131,7 @@ public class CompletedDownloadsFragment extends Fragment {
}
private void addEmptyView() {
EmptyViewHandler emptyView = new EmptyViewHandler(getActivity());
emptyView = new EmptyViewHandler(getActivity());
emptyView.setIcon(R.attr.av_download);
emptyView.setTitle(R.string.no_comp_downloads_head_label);
emptyView.setMessage(R.string.no_comp_downloads_label);
@ -191,6 +195,8 @@ public class CompletedDownloadsFragment extends Fragment {
if (disposable != null) {
disposable.dispose();
}
progressBar.setVisibility(View.VISIBLE);
emptyView.hide();
disposable = Observable.fromCallable(DBReader::getDownloadedItems)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -198,6 +204,7 @@ public class CompletedDownloadsFragment extends Fragment {
items = result;
adapter.updateItems(result);
requireActivity().invalidateOptionsMenu();
progressBar.setVisibility(View.GONE);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}

View File

@ -364,7 +364,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update;
if (event.hasChangedFeedUpdateStatus(isUpdatingFeed)) {
updateProgressBarVisibility();
updateSyncProgressBarVisibility();
}
if (adapter != null && update.mediaIds.length > 0) {
for (long mediaId : update.mediaIds) {
@ -391,7 +391,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
private void updateUi() {
loadItems();
updateProgressBarVisibility();
updateSyncProgressBarVisibility();
}
@Subscribe(threadMode = ThreadMode.MAIN)
@ -411,7 +411,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
}
}
private void updateProgressBarVisibility() {
private void updateSyncProgressBarVisibility() {
if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {
getActivity().supportInvalidateOptionsMenu();
}
@ -436,7 +436,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
adapter.updateItems(feed.getItems());
getActivity().supportInvalidateOptionsMenu();
updateProgressBarVisibility();
updateSyncProgressBarVisibility();
}
private void refreshHeaderView() {
@ -478,8 +478,10 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
// https://github.com/bumptech/glide/issues/529
imgvBackground.setColorFilter(new LightingColorFilter(0xff666666, 0x000000));
butShowInfo.setVisibility(View.VISIBLE);
butShowInfo.setOnClickListener(v -> showFeedInfo());
imgvCover.setOnClickListener(v -> showFeedInfo());
butShowSettings.setVisibility(View.VISIBLE);
butShowSettings.setOnClickListener(v -> {
if (feed != null) {
FeedSettingsFragment fragment = FeedSettingsFragment.newInstance(feed);
@ -522,6 +524,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
if (disposable != null) {
disposable.dispose();
}
progressBar.setVisibility(View.VISIBLE);
disposable = Observable.fromCallable(this::loadData)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())

View File

@ -97,6 +97,7 @@ public class FeedSettingsFragment extends Fragment {
public static class FeedSettingsPreferenceFragment extends PreferenceFragmentCompat {
private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter";
private static final CharSequence PREF_SCREEN = "feedSettingsScreen";
private static final String PREF_FEED_PLAYBACK_SPEED = "feedPlaybackSpeed";
private static final DecimalFormat SPEED_FORMAT =
new DecimalFormat("0.00", DecimalFormatSymbols.getInstance(Locale.US));
@ -116,7 +117,7 @@ public class FeedSettingsFragment extends Fragment {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.feed_settings);
findPreference(PREF_SCREEN).setEnabled(false);
setupAutoDownloadGlobalPreference(); // To prevent transition animation because of summary update
long feedId = getArguments().getLong(EXTRA_FEED_ID);
@ -146,6 +147,7 @@ public class FeedSettingsFragment extends Fragment {
updateVolumeReductionValue();
updateAutoDownloadEnabled();
updatePlaybackSpeedPreference();
findPreference(PREF_SCREEN).setEnabled(true);
}, error -> Log.d(TAG, Log.getStackTraceString(error)), () -> { });
}

View File

@ -9,6 +9,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@ -51,6 +52,8 @@ public class PlaybackHistoryFragment extends Fragment {
private PlaybackHistoryListAdapter adapter;
private Disposable disposable;
private RecyclerView recyclerView;
private EmptyViewHandler emptyView;
private ProgressBar progressBar;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -75,8 +78,9 @@ public class PlaybackHistoryFragment extends Fragment {
recyclerView.setVisibility(View.GONE);
adapter = new PlaybackHistoryListAdapter((MainActivity) getActivity());
recyclerView.setAdapter(adapter);
progressBar = root.findViewById(R.id.progLoading);
EmptyViewHandler emptyView = new EmptyViewHandler(getActivity());
emptyView = new EmptyViewHandler(getActivity());
emptyView.setIcon(R.attr.ic_history);
emptyView.setTitle(R.string.no_history_head_label);
emptyView.setMessage(R.string.no_history_label);
@ -215,15 +219,16 @@ public class PlaybackHistoryFragment extends Fragment {
if (disposable != null) {
disposable.dispose();
}
progressBar.setVisibility(View.VISIBLE);
emptyView.hide();
disposable = Observable.fromCallable(this::loadData)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
if (result != null) {
playbackHistory = result;
adapter.updateItems(playbackHistory);
onFragmentLoaded();
}
progressBar.setVisibility(View.GONE);
playbackHistory = result;
adapter.updateItems(playbackHistory);
onFragmentLoaded();
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.ProgressBar;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
@ -65,6 +66,7 @@ public class SubscriptionFragment extends Fragment {
private DBReader.NavDrawerData navDrawerData;
private SubscriptionsAdapter subscriptionAdapter;
private FloatingActionButton subscriptionAddButton;
private ProgressBar progressBar;
private EmptyViewHandler emptyView;
private int mPosition = -1;
@ -91,6 +93,7 @@ public class SubscriptionFragment extends Fragment {
subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3));
registerForContextMenu(subscriptionGridLayout);
subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
progressBar = root.findViewById(R.id.progLoading);
return root;
}
@ -175,16 +178,17 @@ public class SubscriptionFragment extends Fragment {
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
if(disposable != null) {
if (disposable != null) {
disposable.dispose();
}
}
private void loadSubscriptions() {
if(disposable != null) {
if (disposable != null) {
disposable.dispose();
}
emptyView.hide();
progressBar.setVisibility(View.VISIBLE);
disposable = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -192,6 +196,7 @@ public class SubscriptionFragment extends Fragment {
navDrawerData = result;
subscriptionAdapter.notifyDataSetChanged();
emptyView.updateVisibility();
progressBar.setVisibility(View.GONE);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
@ -207,7 +212,7 @@ public class SubscriptionFragment extends Fragment {
return;
}
Feed feed = (Feed)selectedObject;
Feed feed = (Feed) selectedObject;
MenuInflater inflater = requireActivity().getMenuInflater();
inflater.inflate(R.menu.nav_feed_context, menu);
@ -221,7 +226,7 @@ public class SubscriptionFragment extends Fragment {
public boolean onContextItemSelected(MenuItem item) {
final int position = mPosition;
mPosition = -1; // reset
if(position < 0) {
if (position < 0) {
return false;
}
@ -231,8 +236,8 @@ public class SubscriptionFragment extends Fragment {
return false;
}
Feed feed = (Feed)selectedObject;
switch(item.getItemId()) {
Feed feed = (Feed) selectedObject;
switch (item.getItemId()) {
case R.id.remove_all_new_flags_item:
displayConfirmationDialog(
R.string.remove_all_new_flags_label,

View File

@ -20,6 +20,7 @@
<ImageView
android:id="@+id/imgvBackground"
style="@style/BigBlurryBackground"
android:background="@color/image_readability_tint"
android:layout_width="match_parent"
android:layout_height="256dp"
app:layout_collapseMode="parallax"

View File

@ -20,6 +20,7 @@
<ImageView
android:id="@+id/imgvBackground"
style="@style/BigBlurryBackground"
android:background="@color/image_readability_tint"
android:layout_width="match_parent"
android:layout_height="256dp"
app:layout_collapseMode="parallax"

View File

@ -71,6 +71,8 @@
android:layout_marginLeft="-8dp"
android:layout_marginStart="-8dp"
android:scaleType="fitXY"
android:visibility="invisible"
tools:visibility="visible"
android:padding="8dp"/>
<ImageButton
@ -82,6 +84,8 @@
app:srcCompat="@drawable/ic_settings_white"
tools:background="@android:color/holo_green_dark"
android:scaleType="fitXY"
android:visibility="invisible"
tools:visibility="visible"
android:padding="8dp"/>
</LinearLayout>

View File

@ -26,6 +26,14 @@
android:paddingBottom="88dp"
android:clipToPadding="false"/>
<ProgressBar
android:id="@+id/progLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateOnly="true"
android:visibility="visible"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/subscriptions_add"
android:layout_width="56dp"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="feedSettingsScreen">
<SwitchPreference
android:key="keepUpdated"