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
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_buffering_msg);
|| resId == R.string.player_buffering_msg) {
// TODO Show progress bar here
}
}
@Override
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) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
StorageUtils.checkStorageAvailability(this);
setContentView(R.layout.main);
setVolumeControlStream(AudioManager.STREAM_MUSIC);

View File

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

View File

@ -349,10 +349,6 @@ public class ItemDescriptionFragment extends Fragment {
@Override
protected void onCancelled() {
super.onCancelled();
if (getActivity() != null) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
webViewLoader = null;
}
@ -364,10 +360,6 @@ public class ItemDescriptionFragment extends Fragment {
// /webvDescription.loadData(url, "text/html", "utf-8");
webvDescription.loadDataWithBaseURL(null, data, "text/html",
"utf-8", "about:blank");
if (getActivity() != null) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
if (BuildConfig.DEBUG)
Log.d(TAG, "Webview loaded");
webViewLoader = null;
@ -376,10 +368,6 @@ public class ItemDescriptionFragment extends Fragment {
@Override
protected void onPreExecute() {
super.onPreExecute();
if (getActivity() != null) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
}
@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.dialog.ConfirmationDialog;
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.Feed;
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.DownloadRequester;
import de.danoeh.antennapod.core.util.QueueAccess;
import de.danoeh.antennapod.dialog.FeedItemDialog;
import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
@ -82,6 +82,7 @@ public class ItemlistFragment extends ListFragment {
private FeedItemDialog feedItemDialog;
private FeedItemDialog.FeedItemDialogSavedInstance feedItemDialogSavedInstance;
private boolean isUpdatingFeed;
/**
* Creates new ItemlistFragment which shows the Feeditems of a specific
@ -160,6 +161,17 @@ public class ItemlistFragment extends ListFragment {
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
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
@ -185,6 +197,7 @@ public class ItemlistFragment extends ListFragment {
return false;
}
});
isUpdatingFeed = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker);
}
}
@ -277,15 +290,7 @@ public class ItemlistFragment extends ListFragment {
};
private void updateProgressBarVisibility() {
if (feed != null) {
if (DownloadService.isRunning
&& DownloadRequester.getInstance().isDownloadingFile(feed)) {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(true);
} else {
((ActionBarActivity) getActivity())
.setSupportProgressBarIndeterminateVisibility(false);
}
if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {
getActivity().supportInvalidateOptionsMenu();
}
}

View File

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

View File

@ -28,4 +28,29 @@ public class MenuItemUtils {
public static boolean isActivityDrawerOpen(NavDrawerActivity activity) {
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:title="@string/refresh_label"
android:menuCategory="container"
custom:showAsAction="ifRoom|collapseActionView"
custom:showAsAction="ifRoom"
android:icon="?attr/navigation_refresh"/>
<item