Removed use of indeterminate progress bar

No longer supported in version 21 of the support library
This commit is contained in:
daniel oeh 2014-10-25 11:20:29 +02:00
parent 17feaa72ad
commit dcc7c9d25d
9 changed files with 70 additions and 41 deletions

View File

@ -269,14 +269,17 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override @Override
protected void postStatusMsg(int resId) { protected void postStatusMsg(int resId) {
setSupportProgressBarIndeterminateVisibility(resId == R.string.player_preparing_msg if (resId == R.string.player_preparing_msg
|| resId == R.string.player_seeking_msg || resId == R.string.player_seeking_msg
|| resId == R.string.player_buffering_msg); || resId == R.string.player_buffering_msg) {
// TODO Show progress bar here
}
} }
@Override @Override
protected void clearStatusMsg() { protected void clearStatusMsg() {
setSupportProgressBarIndeterminateVisibility(false); // TODO Hide progress bar here
} }
/** /**

View File

@ -75,7 +75,6 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme()); setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
StorageUtils.checkStorageAvailability(this); StorageUtils.checkStorageAvailability(this);
setContentView(R.layout.main); setContentView(R.layout.main);
setVolumeControlStream(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC);

View File

@ -167,9 +167,6 @@ public abstract class MediaplayerActivity extends ActionBarActivity
chooseTheme(); chooseTheme();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// subclasses might use this feature
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Log.d(TAG, "Creating Activity"); Log.d(TAG, "Creating Activity");
StorageUtils.checkStorageAvailability(this); StorageUtils.checkStorageAvailability(this);

View File

@ -349,10 +349,6 @@ public class ItemDescriptionFragment extends Fragment {
@Override @Override
protected void onCancelled() { protected void onCancelled() {
super.onCancelled(); super.onCancelled();
if (getActivity() != null) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
webViewLoader = null; webViewLoader = null;
} }
@ -364,10 +360,6 @@ public class ItemDescriptionFragment extends Fragment {
// /webvDescription.loadData(url, "text/html", "utf-8"); // /webvDescription.loadData(url, "text/html", "utf-8");
webvDescription.loadDataWithBaseURL(null, data, "text/html", webvDescription.loadDataWithBaseURL(null, data, "text/html",
"utf-8", "about:blank"); "utf-8", "about:blank");
if (getActivity() != null) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Log.d(TAG, "Webview loaded"); Log.d(TAG, "Webview loaded");
webViewLoader = null; webViewLoader = null;
@ -376,10 +368,6 @@ public class ItemDescriptionFragment extends Fragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
if (getActivity() != null) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
} }
@Override @Override

View File

@ -37,7 +37,6 @@ import de.danoeh.antennapod.core.asynctask.FeedRemover;
import de.danoeh.antennapod.core.asynctask.PicassoProvider; import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.dialog.FeedItemDialog;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
@ -48,6 +47,7 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.QueueAccess; import de.danoeh.antennapod.core.util.QueueAccess;
import de.danoeh.antennapod.dialog.FeedItemDialog;
import de.danoeh.antennapod.menuhandler.FeedMenuHandler; import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.menuhandler.NavDrawerActivity; import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
@ -82,6 +82,7 @@ public class ItemlistFragment extends ListFragment {
private FeedItemDialog feedItemDialog; private FeedItemDialog feedItemDialog;
private FeedItemDialog.FeedItemDialogSavedInstance feedItemDialogSavedInstance; private FeedItemDialog.FeedItemDialogSavedInstance feedItemDialogSavedInstance;
private boolean isUpdatingFeed;
/** /**
* Creates new ItemlistFragment which shows the Feeditems of a specific * Creates new ItemlistFragment which shows the Feeditems of a specific
@ -160,6 +161,17 @@ public class ItemlistFragment extends ListFragment {
feedItemDialog = null; feedItemDialog = null;
} }
private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = new MenuItemUtils.UpdateRefreshMenuItemChecker() {
@Override
public boolean isRefreshing() {
if (feed != null && DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFile(feed)) {
return true;
} else {
return false;
}
}
};
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
@ -185,6 +197,7 @@ public class ItemlistFragment extends ListFragment {
return false; return false;
} }
}); });
isUpdatingFeed = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker);
} }
} }
@ -277,15 +290,7 @@ public class ItemlistFragment extends ListFragment {
}; };
private void updateProgressBarVisibility() { private void updateProgressBarVisibility() {
if (feed != null) { if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {
if (DownloadService.isRunning
&& DownloadRequester.getInstance().isDownloadingFile(feed)) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(true);
} else {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
getActivity().supportInvalidateOptionsMenu(); getActivity().supportInvalidateOptionsMenu();
} }
} }

View File

@ -7,6 +7,7 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.view.*; import android.view.*;
@ -75,6 +76,8 @@ public class NewEpisodesFragment extends Fragment {
private FeedItemDialog feedItemDialog; private FeedItemDialog feedItemDialog;
private FeedItemDialog.FeedItemDialogSavedInstance feedItemDialogSavedInstance; private FeedItemDialog.FeedItemDialogSavedInstance feedItemDialogSavedInstance;
private boolean isUpdatingFeeds;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -136,6 +139,14 @@ public class NewEpisodesFragment extends Fragment {
feedItemDialog = null; feedItemDialog = null;
} }
private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = new MenuItemUtils.UpdateRefreshMenuItemChecker() {
@Override
public boolean isRefreshing() {
return DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds();
}
};
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
@ -158,6 +169,7 @@ public class NewEpisodesFragment extends Fragment {
return false; return false;
} }
}); });
isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker);
} }
} }
@ -252,7 +264,6 @@ public class NewEpisodesFragment extends Fragment {
} }
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
getActivity().supportInvalidateOptionsMenu(); getActivity().supportInvalidateOptionsMenu();
updateProgressBarVisibility();
updateShowOnlyEpisodesListViewState(); updateShowOnlyEpisodesListViewState();
} }
@ -319,21 +330,14 @@ public class NewEpisodesFragment extends Fragment {
}; };
private void updateProgressBarVisibility() {
if (!viewsCreated) {
return;
}
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(DownloadService.isRunning
&& DownloadRequester.getInstance().isDownloadingFeeds());
}
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
@Override @Override
public void update(EventDistributor eventDistributor, Integer arg) { public void update(EventDistributor eventDistributor, Integer arg) {
if ((arg & EVENTS) != 0) { if ((arg & EVENTS) != 0) {
startItemLoader(); startItemLoader();
updateProgressBarVisibility(); if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
getActivity().supportInvalidateOptionsMenu();
}
} }
} }
}; };

View File

@ -28,4 +28,29 @@ public class MenuItemUtils {
public static boolean isActivityDrawerOpen(NavDrawerActivity activity) { public static boolean isActivityDrawerOpen(NavDrawerActivity activity) {
return activity != null && activity.isDrawerOpen(); return activity != null && activity.isDrawerOpen();
} }
/**
* Changes the appearance of a MenuItem depending on whether the given UpdateRefreshMenuItemChecker
* is refreshing or not. If it returns true, the menu item will be replaced by an indeterminate progress
* bar, otherwise nothing will happen.
*
* @param menu The menu that the MenuItem belongs to
* @param resId The id of the MenuItem
* @param checker Is used for checking whether to show the progress indicator or not.
* @return The returned value of the UpdateRefreshMenuItemChecker's isRefreshing() method.
*/
public static boolean updateRefreshMenuItem(Menu menu, int resId, UpdateRefreshMenuItemChecker checker) {
// expand actionview if feeds are being downloaded, collapse otherwise
if (checker.isRefreshing()) {
MenuItem refreshItem = menu.findItem(resId);
MenuItemCompat.setActionView(refreshItem, de.danoeh.antennapod.R.layout.refresh_action_view);
return true;
} else {
return false;
}
}
public static interface UpdateRefreshMenuItemChecker {
public boolean isRefreshing();
}
} }

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:indeterminateOnly="true">
</ProgressBar>

View File

@ -7,7 +7,7 @@
android:id="@+id/refresh_item" android:id="@+id/refresh_item"
android:title="@string/refresh_label" android:title="@string/refresh_label"
android:menuCategory="container" android:menuCategory="container"
custom:showAsAction="ifRoom|collapseActionView" custom:showAsAction="ifRoom"
android:icon="?attr/navigation_refresh"/> android:icon="?attr/navigation_refresh"/>
<item <item