diff options
Diffstat (limited to 'src/de/danoeh')
5 files changed, 392 insertions, 180 deletions
diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java index de989fa46..0c18bdd97 100644 --- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -4,11 +4,16 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.TypedArray; +import android.os.AsyncTask; import android.os.Bundle; +import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v4.app.ListFragment; +import android.support.v4.widget.DrawerLayout; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; @@ -18,18 +23,20 @@ import android.widget.ImageView.ScaleType; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.ChapterListAdapter; +import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.asynctask.ImageLoader; import de.danoeh.antennapod.dialog.VariableSpeedDialog; -import de.danoeh.antennapod.feed.Chapter; -import de.danoeh.antennapod.feed.MediaType; -import de.danoeh.antennapod.feed.SimpleChapter; +import de.danoeh.antennapod.feed.*; import de.danoeh.antennapod.fragment.CoverFragment; import de.danoeh.antennapod.fragment.ItemDescriptionFragment; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.service.playback.PlaybackService; +import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.util.playback.ExternalMedia; import de.danoeh.antennapod.util.playback.Playable; +import java.util.List; + /** * Activity for playing audio files. */ @@ -44,6 +51,11 @@ public class AudioplayerActivity extends MediaplayerActivity { private static final String PREF_KEY_SELECTED_FRAGMENT_POSITION = "selectedFragmentPosition"; private static final String PREF_PLAYABLE_ID = "playableId"; + private DrawerLayout drawerLayout; + private NavListAdapter navAdapter; + private ListView navList; + private ActionBarDrawerToggle drawerToggle; + private Fragment[] detachedFragments; private CoverFragment coverFragment; @@ -108,6 +120,8 @@ public class AudioplayerActivity extends MediaplayerActivity { super.onStop(); if (BuildConfig.DEBUG) Log.d(TAG, "onStop"); + cancelLoadTask(); + EventDistributor.getInstance().unregister(contentUpdate); } @@ -142,6 +156,7 @@ public class AudioplayerActivity extends MediaplayerActivity { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); + drawerToggle.onConfigurationChanged(newConfig); } @Override @@ -149,6 +164,7 @@ public class AudioplayerActivity extends MediaplayerActivity { // super.onSaveInstanceState(outState); would cause crash if (BuildConfig.DEBUG) Log.d(TAG, "onSaveInstanceState"); + } @Override @@ -223,6 +239,8 @@ public class AudioplayerActivity extends MediaplayerActivity { switchToFragment(savedPosition); } + EventDistributor.getInstance().register(contentUpdate); + loadData(); } @Override @@ -382,12 +400,53 @@ public class AudioplayerActivity extends MediaplayerActivity { protected void setupGUI() { super.setupGUI(); resetFragmentView(); + drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + navList = (ListView) findViewById(R.id.nav_list); txtvTitle = (TextView) findViewById(R.id.txtvTitle); txtvFeed = (TextView) findViewById(R.id.txtvFeed); butNavLeft = (ImageButton) findViewById(R.id.butNavLeft); butNavRight = (ImageButton) findViewById(R.id.butNavRight); butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed); + TypedArray typedArray = obtainStyledAttributes(new int[]{R.attr.nav_drawer_toggle}); + drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, typedArray.getResourceId(0,0), R.string.drawer_open, R.string.drawer_close) { + String currentTitle = getSupportActionBar().getTitle().toString(); + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + currentTitle = getSupportActionBar().getTitle().toString(); + getSupportActionBar().setTitle(R.string.app_name); + supportInvalidateOptionsMenu(); + } + + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + getSupportActionBar().setTitle(currentTitle); + supportInvalidateOptionsMenu(); + } + }; + typedArray.recycle(); + drawerToggle.setDrawerIndicatorEnabled(false); + + navAdapter = new NavListAdapter(itemAccess, this); + navList.setAdapter(navAdapter); + navList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + int viewType = parent.getAdapter().getItemViewType(position); + if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER) { + int relPos = (viewType == NavListAdapter.VIEW_TYPE_NAV) ? position : position - NavListAdapter.SUBSCRIPTION_OFFSET; + Intent intent = new Intent(AudioplayerActivity.this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, viewType); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, relPos); + startActivity(intent); + } + drawerLayout.closeDrawer(navList); + } + }); + drawerToggle.syncState(); + butNavLeft.setOnClickListener(new OnClickListener() { @Override @@ -551,4 +610,78 @@ public class AudioplayerActivity extends MediaplayerActivity { return R.layout.audioplayer_activity; } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (drawerToggle.onOptionsItemSelected(item)) { + return true; + } else { + return super.onOptionsItemSelected(item); + } + } + + private List<Feed> feeds; + private AsyncTask<Void, Void, List<Feed>> loadTask; + + private void loadData() { + loadTask = new AsyncTask<Void, Void, List<Feed>>() { + @Override + protected List<Feed> doInBackground(Void... params) { + return DBReader.getFeedList(AudioplayerActivity.this); + } + + @Override + protected void onPostExecute(List<Feed> result) { + super.onPostExecute(result); + feeds = result; + if (navAdapter != null) { + navAdapter.notifyDataSetChanged(); + } + } + }; + loadTask.execute(); + } + + private void cancelLoadTask() { + if (loadTask != null) { + loadTask.cancel(true); + } + } + + private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + + @Override + public void update(EventDistributor eventDistributor, Integer arg) { + if ((EventDistributor.FEED_LIST_UPDATE & arg) != 0) { + if (BuildConfig.DEBUG) + Log.d(TAG, "Received contentUpdate Intent."); + loadData(); + } + } + }; + + private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { + @Override + public int getCount() { + if (feeds != null) { + return feeds.size(); + } else { + return 0; + } + } + + @Override + public Feed getItem(int position) { + if (feeds != null && position < feeds.size()) { + return feeds.get(position); + } else { + return null; + } + } + + @Override + public int getSelectedItemIndex() { + return -1; + } + }; } diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index 46e5ffe41..395d289cb 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -1,10 +1,8 @@ package de.danoeh.antennapod.activity; -import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.content.res.TypedArray; -import android.graphics.Typeface; import android.media.AudioManager; import android.os.AsyncTask; import android.os.Bundle; @@ -17,10 +15,11 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.*; -import android.widget.*; +import android.widget.AdapterView; +import android.widget.ListView; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.fragment.*; @@ -41,6 +40,10 @@ public class MainActivity extends ActionBarActivity { | EventDistributor.FEED_LIST_UPDATE | EventDistributor.UNREAD_ITEMS_UPDATE; + public static final String EXTRA_NAV_INDEX = "nav_index"; + public static final String EXTRA_NAV_TYPE = "nav_type"; + public static final String EXTRA_FRAGMENT_ARGS = "fragment_args"; + public static final int POS_NEW = 0, POS_QUEUE = 1, POS_DOWNLOADS = 2, @@ -157,11 +160,13 @@ public class MainActivity extends ActionBarActivity { } currentTitle = getString(NavListAdapter.NAV_TITLES[relPos]); + selectedNavListIndex = relPos; } else if (viewType == NavListAdapter.VIEW_TYPE_SUBSCRIPTION) { Feed feed = itemAccess.getItem(relPos); currentTitle = ""; fragment = ItemlistFragment.newInstance(feed.getId()); + selectedNavListIndex = NavListAdapter.SUBSCRIPTION_OFFSET + relPos; } if (fragment != null) { @@ -172,6 +177,10 @@ public class MainActivity extends ActionBarActivity { fragmentManager.popBackStack(); } fT.commit(); + getSupportActionBar().setTitle(currentTitle); + if (navAdapter != null) { + navAdapter.notifyDataSetChanged(); + } } public void loadNavFragment(int position, Bundle args) { @@ -260,6 +269,8 @@ public class MainActivity extends ActionBarActivity { selectedNavListIndex = POS_ADD; navAdapter.notifyDataSetChanged(); } + } else if (feeds != null && intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) { + handleNavIntent(); } } @@ -303,7 +314,7 @@ public class MainActivity extends ActionBarActivity { private AsyncTask<Void, Void, List<Feed>> loadTask; private int selectedNavListIndex = 0; - private ItemAccess itemAccess = new ItemAccess() { + private NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { @Override public int getCount() { if (feeds != null) { @@ -340,8 +351,14 @@ public class MainActivity extends ActionBarActivity { @Override protected void onPostExecute(List<Feed> result) { super.onPostExecute(result); + boolean handleIntent = (feeds == null); + feeds = result; navAdapter.notifyDataSetChanged(); + + if (handleIntent) { + handleNavIntent(); + } } }; loadTask.execute(); @@ -365,173 +382,20 @@ public class MainActivity extends ActionBarActivity { } }; - private static class NavListAdapter extends BaseAdapter { - - static final int VIEW_TYPE_COUNT = 3; - static final int VIEW_TYPE_NAV = 0; - static final int VIEW_TYPE_SECTION_DIVIDER = 1; - static final int VIEW_TYPE_SUBSCRIPTION = 2; - - static final int[] NAV_TITLES = {R.string.new_episodes_label, R.string.queue_label, R.string.downloads_label, R.string.playback_history_label, R.string.add_feed_label}; - - - static final int SUBSCRIPTION_OFFSET = 1 + NAV_TITLES.length; - - private ItemAccess itemAccess; - private Context context; - - private NavListAdapter(ItemAccess itemAccess, Context context) { - this.itemAccess = itemAccess; - this.context = context; - } - - @Override - public int getCount() { - return NAV_TITLES.length + 1 + itemAccess.getCount(); - } - - @Override - public Object getItem(int position) { - int viewType = getItemViewType(position); - if (viewType == VIEW_TYPE_NAV) { - return context.getString(NAV_TITLES[position]); - } else if (viewType == VIEW_TYPE_SECTION_DIVIDER) { - return context.getString(R.string.podcasts_label); - } else { - return itemAccess.getItem(position); - } - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - public int getItemViewType(int position) { - if (0 <= position && position < NAV_TITLES.length) { - return VIEW_TYPE_NAV; - } else if (position < NAV_TITLES.length + 1) { - return VIEW_TYPE_SECTION_DIVIDER; - } else { - return VIEW_TYPE_SUBSCRIPTION; - } - } - - @Override - public int getViewTypeCount() { - return VIEW_TYPE_COUNT; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - int viewType = getItemViewType(position); - View v = null; - if (viewType == VIEW_TYPE_NAV) { - v = getNavView((String) getItem(position), position, convertView, parent); - } else if (viewType == VIEW_TYPE_SECTION_DIVIDER) { - v = getSectionDividerView((String) getItem(position), position, convertView, parent); - } else { - v = getFeedView(position - SUBSCRIPTION_OFFSET, convertView, parent); - } - if (v != null) { - TextView txtvTitle = (TextView) v.findViewById(R.id.txtvTitle); - if (position == itemAccess.getSelectedItemIndex()) { - txtvTitle.setTypeface(null, Typeface.BOLD); - } else { - txtvTitle.setTypeface(null, Typeface.NORMAL); - } - } - return v; - } - - private View getNavView(String title, int position, View convertView, ViewGroup parent) { - NavHolder holder; - if (convertView == null) { - holder = new NavHolder(); - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - convertView = inflater.inflate(R.layout.nav_listitem, null); - - holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); - convertView.setTag(holder); - } else { - holder = (NavHolder) convertView.getTag(); - } - - holder.title.setText(title); - - return convertView; - } - - private View getSectionDividerView(String title, int position, View convertView, ViewGroup parent) { - SectionHolder holder; - if (convertView == null) { - holder = new SectionHolder(); - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - convertView = inflater.inflate(R.layout.nav_section_item, null); - - holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); - convertView.setTag(holder); - } else { - holder = (SectionHolder) convertView.getTag(); - } - - holder.title.setText(title); - - convertView.setEnabled(false); - convertView.setOnClickListener(null); - - return convertView; - } - - private View getFeedView(int feedPos, View convertView, ViewGroup parent) { - FeedHolder holder; - Feed feed = itemAccess.getItem(feedPos); - - if (convertView == null) { - holder = new FeedHolder(); - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - convertView = inflater.inflate(R.layout.nav_feedlistitem, null); - - holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); - holder.image = (ImageView) convertView.findViewById(R.id.imgvCover); - convertView.setTag(holder); - } else { - holder = (FeedHolder) convertView.getTag(); - } - - holder.title.setText(feed.getTitle()); - ImageLoader.getInstance().loadThumbnailBitmap(feed.getImage(), holder.image, (int) context.getResources().getDimension(R.dimen.thumbnail_length_navlist)); - - return convertView; - } - - static class NavHolder { - TextView title; - } - - static class SectionHolder { - TextView title; - } - - static class FeedHolder { - TextView title; - ImageView image; + private void handleNavIntent() { + Intent intent = getIntent(); + if (intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) { + int index = intent.getIntExtra(EXTRA_NAV_INDEX, 0); + int type = intent.getIntExtra(EXTRA_NAV_TYPE, NavListAdapter.VIEW_TYPE_NAV); + Bundle args = intent.getBundleExtra(EXTRA_FRAGMENT_ARGS); + loadFragment(type, index, args); } + setIntent(new Intent(MainActivity.this, MainActivity.class)); // to avoid handling the intent twice when the configuration changes } - public interface ItemAccess { - int getCount(); - - Feed getItem(int position); - - int getSelectedItemIndex(); - + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + setIntent(intent); } } diff --git a/src/de/danoeh/antennapod/adapter/NavListAdapter.java b/src/de/danoeh/antennapod/adapter/NavListAdapter.java new file mode 100644 index 000000000..084f3609f --- /dev/null +++ b/src/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -0,0 +1,186 @@ +package de.danoeh.antennapod.adapter; + +import android.content.Context; +import android.graphics.Typeface; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.feed.Feed; + +/** + * BaseAdapter for the navigation drawer + */ +public class NavListAdapter extends BaseAdapter { + public static final int VIEW_TYPE_COUNT = 3; + public static final int VIEW_TYPE_NAV = 0; + public static final int VIEW_TYPE_SECTION_DIVIDER = 1; + public static final int VIEW_TYPE_SUBSCRIPTION = 2; + + public static final int[] NAV_TITLES = {R.string.new_episodes_label, R.string.queue_label, R.string.downloads_label, R.string.playback_history_label, R.string.add_feed_label}; + + + public static final int SUBSCRIPTION_OFFSET = 1 + NAV_TITLES.length; + + private ItemAccess itemAccess; + private Context context; + + public NavListAdapter(ItemAccess itemAccess, Context context) { + this.itemAccess = itemAccess; + this.context = context; + } + + @Override + public int getCount() { + return NAV_TITLES.length + 1 + itemAccess.getCount(); + } + + @Override + public Object getItem(int position) { + int viewType = getItemViewType(position); + if (viewType == VIEW_TYPE_NAV) { + return context.getString(NAV_TITLES[position]); + } else if (viewType == VIEW_TYPE_SECTION_DIVIDER) { + return context.getString(R.string.podcasts_label); + } else { + return itemAccess.getItem(position); + } + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public int getItemViewType(int position) { + if (0 <= position && position < NAV_TITLES.length) { + return VIEW_TYPE_NAV; + } else if (position < NAV_TITLES.length + 1) { + return VIEW_TYPE_SECTION_DIVIDER; + } else { + return VIEW_TYPE_SUBSCRIPTION; + } + } + + @Override + public int getViewTypeCount() { + return VIEW_TYPE_COUNT; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + int viewType = getItemViewType(position); + View v = null; + if (viewType == VIEW_TYPE_NAV) { + v = getNavView((String) getItem(position), position, convertView, parent); + } else if (viewType == VIEW_TYPE_SECTION_DIVIDER) { + v = getSectionDividerView((String) getItem(position), position, convertView, parent); + } else { + v = getFeedView(position - SUBSCRIPTION_OFFSET, convertView, parent); + } + if (v != null) { + TextView txtvTitle = (TextView) v.findViewById(R.id.txtvTitle); + if (position == itemAccess.getSelectedItemIndex()) { + txtvTitle.setTypeface(null, Typeface.BOLD); + } else { + txtvTitle.setTypeface(null, Typeface.NORMAL); + } + } + return v; + } + + private View getNavView(String title, int position, View convertView, ViewGroup parent) { + NavHolder holder; + if (convertView == null) { + holder = new NavHolder(); + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + convertView = inflater.inflate(R.layout.nav_listitem, null); + + holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); + convertView.setTag(holder); + } else { + holder = (NavHolder) convertView.getTag(); + } + + holder.title.setText(title); + + return convertView; + } + + private View getSectionDividerView(String title, int position, View convertView, ViewGroup parent) { + SectionHolder holder; + if (convertView == null) { + holder = new SectionHolder(); + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + convertView = inflater.inflate(R.layout.nav_section_item, null); + + holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); + convertView.setTag(holder); + } else { + holder = (SectionHolder) convertView.getTag(); + } + + holder.title.setText(title); + + convertView.setEnabled(false); + convertView.setOnClickListener(null); + + return convertView; + } + + private View getFeedView(int feedPos, View convertView, ViewGroup parent) { + FeedHolder holder; + Feed feed = itemAccess.getItem(feedPos); + + if (convertView == null) { + holder = new FeedHolder(); + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + convertView = inflater.inflate(R.layout.nav_feedlistitem, null); + + holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); + holder.image = (ImageView) convertView.findViewById(R.id.imgvCover); + convertView.setTag(holder); + } else { + holder = (FeedHolder) convertView.getTag(); + } + + holder.title.setText(feed.getTitle()); + ImageLoader.getInstance().loadThumbnailBitmap(feed.getImage(), holder.image, (int) context.getResources().getDimension(R.dimen.thumbnail_length_navlist)); + + return convertView; + } + + static class NavHolder { + TextView title; + } + + static class SectionHolder { + TextView title; + } + + static class FeedHolder { + TextView title; + ImageView image; + } + + + public interface ItemAccess { + public int getCount(); + + public Feed getItem(int position); + + public int getSelectedItemIndex(); + } + +} diff --git a/src/de/danoeh/antennapod/fragment/DownloadsFragment.java b/src/de/danoeh/antennapod/fragment/DownloadsFragment.java index 9cf9ea1bf..5a71cb36b 100644 --- a/src/de/danoeh/antennapod/fragment/DownloadsFragment.java +++ b/src/de/danoeh/antennapod/fragment/DownloadsFragment.java @@ -20,6 +20,11 @@ import de.danoeh.antennapod.activity.MainActivity; */ public class DownloadsFragment extends Fragment { + public static final String ARG_SELECTED_TAB = "selected_tab"; + + public static final int POS_RUNNING = 0; + public static final int POS_COMPLETED = 1; + public static final int POS_LOG = 2; private ViewPager pager; private MainActivity activity; @@ -71,6 +76,15 @@ public class DownloadsFragment extends Fragment { } @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + if (getArguments() != null) { + int tab = getArguments().getInt(ARG_SELECTED_TAB); + pager.setCurrentItem(tab, false); + } + } + + @Override public void onAttach(Activity activity) { super.onAttach(activity); this.activity = (MainActivity) activity; @@ -85,9 +99,7 @@ public class DownloadsFragment extends Fragment { public class DownloadsPagerAdapter extends FragmentPagerAdapter { - private final int POS_RUNNING = 0; - private final int POS_COMPLETED = 1; - private final int POS_LOG = 2; + Resources resources; diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index f5883babc..c7f3b8573 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -13,6 +13,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.MediaMetadataRetriever; import android.os.Binder; +import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.support.v4.app.NotificationCompat; @@ -23,7 +24,10 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.DownloadActivity; import de.danoeh.antennapod.activity.DownloadAuthenticationActivity; import de.danoeh.antennapod.activity.DownloadLogActivity; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.feed.*; +import de.danoeh.antennapod.fragment.DownloadsFragment; import de.danoeh.antennapod.storage.*; import de.danoeh.antennapod.syndication.handler.FeedHandler; import de.danoeh.antennapod.syndication.handler.UnsupportedFeedtypeException; @@ -274,11 +278,18 @@ public class DownloadService extends Service { @SuppressLint("NewApi") private void setupNotificationBuilders() { - PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent( - this, DownloadActivity.class), + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, NavListAdapter.VIEW_TYPE_NAV); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, MainActivity.POS_DOWNLOADS); + Bundle args = new Bundle(); + args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_RUNNING); + intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args); + + PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT ); + Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.stat_notify_sync); @@ -490,6 +501,13 @@ public class DownloadService extends Service { if (createReport) { if (BuildConfig.DEBUG) Log.d(TAG, "Creating report"); + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, NavListAdapter.VIEW_TYPE_NAV); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, MainActivity.POS_DOWNLOADS); + Bundle args = new Bundle(); + args.putInt(DownloadsFragment.ARG_SELECTED_TAB, DownloadsFragment.POS_LOG); + intent.putExtra(MainActivity.EXTRA_FRAGMENT_ARGS, args); + // create notification object Notification notification = new NotificationCompat.Builder(this) .setTicker( @@ -507,8 +525,7 @@ public class DownloadService extends Service { R.drawable.stat_notify_sync) ) .setContentIntent( - PendingIntent.getActivity(this, 0, new Intent(this, - DownloadLogActivity.class), 0) + PendingIntent.getActivity(this, 0, intent, 0) ) .setAutoCancel(true).getNotification(); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |