From f0b0898f714f02f3f1a81db257b1b7c4d31a8e25 Mon Sep 17 00:00:00 2001 From: David Development Date: Wed, 25 Jun 2014 21:43:11 +0200 Subject: [PATCH] Update podcast support --- .../ListView/PodcastArrayAdapter.java | 2 +- .../ListView/PodcastFeedArrayAdapter.java | 4 +- .../NewsDetailActivity.java | 20 +- .../NewsReaderListActivity.java | 34 +--- .../owncloudnewsreader/PodcastFragment.java | 185 ++++++++++++++---- .../{ => podcast}/AudioPodcastClicked.java | 2 +- .../{ => podcast}/OpenAudioPodcastEvent.java | 2 +- .../{ => podcast}/PodcastFeedClicked.java | 2 +- .../{ => podcast}/TogglePlayerStateEvent.java | 2 +- .../UpdatePodcastStatusEvent.java | 10 +- .../events/podcast/WindPodcast.java | 10 + .../services/AudioPodcastService.java | 54 ++++- .../view/PodcastNotification.java | 4 +- .../src/main/res/values/colors.xml | 2 + .../src/main/res/values/strings.xml | 16 +- .../src/main/res/xml/pref_headers.xml | 9 +- .../src/main/res/xml/pref_podcast.xml | 9 + 17 files changed, 266 insertions(+), 101 deletions(-) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/{ => podcast}/AudioPodcastClicked.java (66%) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/{ => podcast}/OpenAudioPodcastEvent.java (72%) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/{ => podcast}/PodcastFeedClicked.java (66%) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/{ => podcast}/TogglePlayerStateEvent.java (61%) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/{ => podcast}/UpdatePodcastStatusEvent.java (70%) create mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/WindPodcast.java create mode 100644 News-Android-App/src/main/res/xml/pref_podcast.xml diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastArrayAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastArrayAdapter.java index e8293a13..0e0c2fea 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastArrayAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastArrayAdapter.java @@ -11,7 +11,7 @@ import butterknife.ButterKnife; import butterknife.InjectView; import de.greenrobot.event.EventBus; import de.luhmer.owncloudnewsreader.R; -import de.luhmer.owncloudnewsreader.events.AudioPodcastClicked; +import de.luhmer.owncloudnewsreader.events.podcast.AudioPodcastClicked; import de.luhmer.owncloudnewsreader.model.AudioPodcastItem; /** diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastFeedArrayAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastFeedArrayAdapter.java index d66ee904..bc2a4360 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastFeedArrayAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/PodcastFeedArrayAdapter.java @@ -11,7 +11,7 @@ import butterknife.ButterKnife; import butterknife.InjectView; import de.greenrobot.event.EventBus; import de.luhmer.owncloudnewsreader.R; -import de.luhmer.owncloudnewsreader.events.PodcastFeedClicked; +import de.luhmer.owncloudnewsreader.events.podcast.PodcastFeedClicked; import de.luhmer.owncloudnewsreader.model.PodcastFeedItem; /** @@ -41,7 +41,7 @@ public class PodcastFeedArrayAdapter extends ArrayAdapter { final PodcastFeedItem feedItem = getItem(position); holder.tvTitle.setText(feedItem.title); - holder.tvBody.setText(feedItem.count + " Podcasts available."); + holder.tvBody.setText(feedItem.count + " Podcasts available"); view.setOnClickListener(new View.OnClickListener() { @Override diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index 4c548fb7..2bda52cd 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -75,6 +75,8 @@ public class NewsDetailActivity extends SherlockFragmentActivity { public ViewPager mViewPager; private int currentPosition; + PodcastFragment podcastFragment; + PostDelayHandler pDelayHandler; MenuItem menuItem_Starred; @@ -187,7 +189,7 @@ public class NewsDetailActivity extends SherlockFragmentActivity { public void UpdatePodcastView() { SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this); if(mPrefs.getBoolean(SettingsActivity.CB_ENABLE_PODCASTS_STRING, false)) { - PodcastFragment podcastFragment = PodcastFragment.newInstance(null, null); + podcastFragment = PodcastFragment.newInstance(null, null); getSupportFragmentManager().beginTransaction() .replace(R.id.podcast_frame, podcastFragment) .commit(); @@ -345,6 +347,15 @@ public class NewsDetailActivity extends SherlockFragmentActivity { return new BitmapDrawable(bitmapResized); } + @Override + public void onBackPressed() { + if(podcastFragment != null && sliding_layout.isExpanded()) { + if (!podcastFragment.onBackPressed()) + sliding_layout.collapsePane(); + } else + super.onBackPressed(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -372,7 +383,12 @@ public class NewsDetailActivity extends SherlockFragmentActivity { switch (item.getItemId()) { case android.R.id.home: - super.onBackPressed(); + if(podcastFragment != null && sliding_layout.isExpanded()) { + if (!podcastFragment.onBackPressed()) + sliding_layout.collapsePane(); + } else { + super.onBackPressed(); + } break; case R.id.action_starred: diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index f88733d2..a47edd84 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -41,7 +41,6 @@ import android.view.View; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; -import com.sothree.slidinguppanel.SlidingUpPanelLayout; import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter; import de.luhmer.owncloudnewsreader.LoginDialogFragment.LoginSuccessfullListener; @@ -84,7 +83,7 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im public static final String TITEL = "TITEL"; PodcastFragment podcastFragment; - boolean isSlideUpPanelExpanded = false; + //boolean isSlideUpPanelExpanded = false; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override @@ -138,29 +137,6 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im sliding_layout = (PodcastSlidingUpPanelLayout) findViewById(R.id.sliding_layout); UpdatePodcastView(); - sliding_layout.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() { - @Override - public void onPanelSlide(View view, float v) { - - } - - @Override - public void onPanelCollapsed(View view) { - isSlideUpPanelExpanded = false; - } - - @Override - public void onPanelExpanded(View view) { - isSlideUpPanelExpanded = true; - } - - @Override - public void onPanelAnchored(View view) { - - } - }); - - mSlidingLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane); @@ -505,7 +481,7 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im @Override public void onBackPressed() { - if(podcastFragment != null && isSlideUpPanelExpanded) { + if(podcastFragment != null && sliding_layout.isExpanded()) { if (!podcastFragment.onBackPressed()) sliding_layout.collapsePane(); } else if(mSlidingLayout.isOpen()) @@ -526,7 +502,11 @@ public class NewsReaderListActivity extends MenuUtilsSherlockFragmentActivity im switch (item.getItemId()) { case android.R.id.home: - if(!mSlidingLayout.isOpen()) + if(podcastFragment != null && sliding_layout.isExpanded()) { + if (!podcastFragment.onBackPressed()) + sliding_layout.collapsePane(); + } + else if(!mSlidingLayout.isOpen()) mSlidingLayout.openPane(); return true; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java index 1624f6c5..1d9b5275 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragment.java @@ -1,9 +1,12 @@ package de.luhmer.owncloudnewsreader; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.util.Log; +import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -13,10 +16,13 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.RelativeLayout; +import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; +import android.widget.ViewSwitcher; import com.actionbarsherlock.app.SherlockFragment; +import com.sothree.slidinguppanel.SlidingUpPanelLayout; import java.util.List; @@ -27,14 +33,16 @@ import de.greenrobot.event.EventBus; import de.luhmer.owncloudnewsreader.ListView.PodcastArrayAdapter; import de.luhmer.owncloudnewsreader.ListView.PodcastFeedArrayAdapter; import de.luhmer.owncloudnewsreader.database.DatabaseConnection; -import de.luhmer.owncloudnewsreader.events.AudioPodcastClicked; -import de.luhmer.owncloudnewsreader.events.OpenAudioPodcastEvent; -import de.luhmer.owncloudnewsreader.events.PodcastFeedClicked; -import de.luhmer.owncloudnewsreader.events.TogglePlayerStateEvent; -import de.luhmer.owncloudnewsreader.events.UpdatePodcastStatusEvent; +import de.luhmer.owncloudnewsreader.events.podcast.AudioPodcastClicked; +import de.luhmer.owncloudnewsreader.events.podcast.OpenAudioPodcastEvent; +import de.luhmer.owncloudnewsreader.events.podcast.PodcastFeedClicked; +import de.luhmer.owncloudnewsreader.events.podcast.TogglePlayerStateEvent; +import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent; +import de.luhmer.owncloudnewsreader.events.podcast.WindPodcast; import de.luhmer.owncloudnewsreader.model.AudioPodcastItem; import de.luhmer.owncloudnewsreader.model.PodcastFeedItem; import de.luhmer.owncloudnewsreader.services.AudioPodcastService; +import de.luhmer.owncloudnewsreader.view.PodcastSlidingUpPanelLayout; /** @@ -51,6 +59,7 @@ public class PodcastFragment extends SherlockFragment { // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM2 = "param2"; + private static final String TAG = "PodcastFragment"; // TODO: Rename and change types of parameters private String mParam1; @@ -108,6 +117,8 @@ public class PodcastFragment extends SherlockFragment { getActivity().startService(new Intent(getActivity(), AudioPodcastService.class)); } + + @Override public void onResume() { eventBus.register(this); @@ -122,7 +133,7 @@ public class PodcastFragment extends SherlockFragment { super.onPause(); } - public void onEvent(AudioPodcastClicked podcast) { + public void onEventMainThread(AudioPodcastClicked podcast) { final AudioPodcastItem audioPodcast = audioPodcasts.get(podcast.position); tvTitle.setText(audioPodcast.title); @@ -132,7 +143,7 @@ public class PodcastFragment extends SherlockFragment { Toast.makeText(getActivity(), "Starting podcast.. please wait", Toast.LENGTH_SHORT).show(); } - public void onEvent(PodcastFeedClicked podcast) { + public void onEventMainThread(PodcastFeedClicked podcast) { DatabaseConnection dbConn = new DatabaseConnection(getActivity()); audioPodcasts = dbConn.getListOfAudioPodcastsForFeed(feedsWithAudioPodcasts.get(podcast.position).itemId); @@ -148,15 +159,17 @@ public class PodcastFragment extends SherlockFragment { int lastDrawableId; - public void onEvent(UpdatePodcastStatusEvent podcast) { + public void onEventMainThread(UpdatePodcastStatusEvent podcast) { hasTitleInCache = true; int drawableId = podcast.isPlaying() ? android.R.drawable.ic_media_pause : android.R.drawable.ic_media_play; + int drawableIdDarkDesign = podcast.isPlaying() ? R.drawable.av_pause : R.drawable.av_play; if(lastDrawableId != drawableId) { lastDrawableId = drawableId; btnPlayPausePodcast.setBackgroundResource(drawableId); + btnPlayPausePodcastSlider.setBackgroundResource(drawableIdDarkDesign); } int hours = (int)( podcast.getCurrent() / (1000*60*60)); @@ -164,34 +177,65 @@ public class PodcastFragment extends SherlockFragment { int seconds = (int) ((podcast.getCurrent() % (1000*60*60)) % (1000*60) / 1000); minutes += hours * 60; tvFrom.setText(String.format("%02d:%02d", minutes, seconds)); + tvFromSlider.setText(String.format("%02d:%02d", minutes, seconds)); hours = (int)( podcast.getMax() / (1000*60*60)); minutes = (int)(podcast.getMax() % (1000*60*60)) / (1000*60); seconds = (int) ((podcast.getMax() % (1000*60*60)) % (1000*60) / 1000); minutes += hours * 60; tvTo.setText(String.format("%02d:%02d", minutes, seconds)); + tvToSlider.setText(String.format("%02d:%02d", minutes, seconds)); tvTitle.setText(podcast.getTitle()); + tvTitleSlider.setText(podcast.getTitle()); - double progress = ((double)podcast.getCurrent() / (double)podcast.getMax()) * 100d; - pbProgress.setProgress((int) progress); + if(podcast.isPreparingFile()) { + if(!blockSeekbarUpdate) + sb_progress.setIndeterminate(true); + + pb_progress.setIndeterminate(true); + } else { + double progress = ((double) podcast.getCurrent() / (double) podcast.getMax()) * 100d; + + if(!blockSeekbarUpdate) { + sb_progress.setIndeterminate(false); + sb_progress.setProgress((int) progress); + } + + pb_progress.setIndeterminate(false); + pb_progress.setProgress((int) progress); + } } List audioPodcasts; List feedsWithAudioPodcasts; @InjectView(R.id.btn_playPausePodcast) ImageButton btnPlayPausePodcast; + @InjectView(R.id.btn_playPausePodcastSlider) ImageButton btnPlayPausePodcastSlider; + @InjectView(R.id.btn_nextPodcastSlider) ImageButton btnNextPodcastSlider; + @InjectView(R.id.btn_previousPodcastSlider) ImageButton btnPreviousPodcastSlider; + + @InjectView(R.id.tv_title) TextView tvTitle; + @InjectView(R.id.tv_titleSlider) TextView tvTitleSlider; + + @InjectView(R.id.tv_from) TextView tvFrom; @InjectView(R.id.tv_to) TextView tvTo; - @InjectView(R.id.pb_progress) ProgressBar pbProgress; + @InjectView(R.id.tv_fromSlider) TextView tvFromSlider; + @InjectView(R.id.tv_ToSlider) TextView tvToSlider; + + @InjectView(R.id.sb_progress) SeekBar sb_progress; + @InjectView(R.id.pb_progress) ProgressBar pb_progress; + @InjectView(R.id.podcastFeedList) ListView /* CardGridView CardListView*/ podcastFeedList; @InjectView(R.id.rlPodcast) RelativeLayout rlPodcast; @InjectView(R.id.ll_podcast_header) LinearLayout rlPodcastHeader; @InjectView(R.id.fl_playPausePodcastWrapper) FrameLayout playPausePodcastWrapper; - @InjectView(R.id.podcastTitleGrid) ListView /*CardGridView*/ podcastTitleGrid; + @InjectView(R.id.viewSwitcherProgress) ViewSwitcher /*CardGridView*/ viewSwitcherProgress; + boolean hasTitleInCache = false; @OnClick(R.id.fl_playPausePodcastWrapper) void playPause() { @@ -201,21 +245,51 @@ public class PodcastFragment extends SherlockFragment { eventBus.post(new TogglePlayerStateEvent()); } + @OnClick(R.id.btn_playPausePodcastSlider) void playPauseSlider() { + playPause(); + } + + @OnClick(R.id.btn_nextPodcastSlider) void nextChapter() { + Toast.makeText(getActivity(), "This feature is not supported yet :(", Toast.LENGTH_SHORT).show(); + } + + @OnClick(R.id.btn_previousPodcastSlider) void previousChapter() { + Toast.makeText(getActivity(), "This feature is not supported yet :(", Toast.LENGTH_SHORT).show(); + } + + PodcastSlidingUpPanelLayout sliding_layout; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_podcast, container, false); + + + // create ContextThemeWrapper from the original Activity Context with the custom theme + Context context = new ContextThemeWrapper(getActivity(), R.style.Theme_Sherlock_Light_DarkActionBar); + // clone the inflater using the ContextThemeWrapper + LayoutInflater localInflater = inflater.cloneInContext(context); + // inflate using the cloned inflater, not the passed in default + View view = localInflater.inflate(R.layout.fragment_podcast, container, false); + + + //View view = inflater.inflate(R.layout.fragment_podcast, container, false); ButterKnife.inject(this, view); + if(getActivity() instanceof NewsReaderListActivity) { - ((NewsReaderListActivity) getActivity()).sliding_layout.setSlideableView(rlPodcast); - ((NewsReaderListActivity) getActivity()).sliding_layout.setDragView(rlPodcastHeader); - //((NewsReaderListActivity) getActivity()).sliding_layout.setEnableDragViewTouchEvents(true); + sliding_layout = ((NewsReaderListActivity) getActivity()).sliding_layout; } else if(getActivity() instanceof NewsDetailActivity) { - ((NewsDetailActivity) getActivity()).sliding_layout.setSlideableView(rlPodcast); - ((NewsDetailActivity) getActivity()).sliding_layout.setDragView(rlPodcastHeader); - //((NewsReaderListActivity) getActivity()).sliding_layout.setEnableDragViewTouchEvents(true); + sliding_layout = ((NewsDetailActivity) getActivity()).sliding_layout; } + if(sliding_layout != null) { + sliding_layout.setSlideableView(rlPodcast); + sliding_layout.setDragView(rlPodcastHeader); + + sliding_layout.setPanelSlideListener(onPanelSlideListener); + } + + + + DatabaseConnection dbConn = new DatabaseConnection(getActivity()); feedsWithAudioPodcasts = dbConn.getListOfFeedsWithAudioPodcasts(); PodcastFeedArrayAdapter mArrayAdapter = new PodcastFeedArrayAdapter(getActivity(), feedsWithAudioPodcasts.toArray(new PodcastFeedItem[feedsWithAudioPodcasts.size()])); @@ -227,32 +301,11 @@ public class PodcastFragment extends SherlockFragment { view.findViewById(R.id.tv_no_podcasts_available).setVisibility(View.GONE); } - /* - ArrayList cards = new ArrayList(); - - - for(String key : feedsWithAudioPodcasts.keySet()) { - Card card = new CardPodcastFeed(getActivity(), feedsWithAudioPodcasts.get(key), "4 Podcasts verfügbar!"); - //card.setTitle(feedsWithAudioPodcasts.get(key)); - card.setId(key); - - //Set Background resource - //card.setBackgroundResourceId(R.drawable.card_feed_podcast_background); - - card.setOnClickListener(onFeedCardClickListener); - - cards.add(card); - } - - CardGridArrayAdapter mCardArrayAdapter = new CardGridArrayAdapter(getActivity(), cards); - //CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(getActivity(),cards); - if (podcastFeedList != null) { - podcastFeedList.setAdapter(mCardArrayAdapter); - }*/ - podcastTitleGrid.setVisibility(View.GONE); podcastFeedList.setVisibility(View.VISIBLE); + sb_progress.setOnSeekBarChangeListener(onSeekBarChangeListener); + return view; } @@ -300,4 +353,52 @@ public class PodcastFragment extends SherlockFragment { public void onFragmentInteraction(Uri uri); } + + private SlidingUpPanelLayout.PanelSlideListener onPanelSlideListener = new SlidingUpPanelLayout.PanelSlideListener() { + @Override + public void onPanelSlide(View view, float v) { + + } + + @Override + public void onPanelCollapsed(View view) { + if(sliding_layout != null) + sliding_layout.setDragView(rlPodcastHeader); + viewSwitcherProgress.setDisplayedChild(0); + } + + @Override + public void onPanelExpanded(View view) { + if(sliding_layout != null) + sliding_layout.setDragView(viewSwitcherProgress); + viewSwitcherProgress.setDisplayedChild(1); + } + + @Override + public void onPanelAnchored(View view) { + + } + }; + + boolean blockSeekbarUpdate = false; + private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + Log.d(TAG, "onProgressChanged"); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + blockSeekbarUpdate = true; + Log.d(TAG, "onStartTrackingTouch"); + } + + @Override + public void onStopTrackingTouch(final SeekBar seekBar) { + eventBus.post(new WindPodcast() {{ toPositionInPercent = seekBar.getProgress(); }}); + blockSeekbarUpdate = false; + Log.d(TAG, "onStopTrackingTouch"); + } + }; + } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/AudioPodcastClicked.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/AudioPodcastClicked.java similarity index 66% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/AudioPodcastClicked.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/AudioPodcastClicked.java index 437461bb..dc34bdc4 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/AudioPodcastClicked.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/AudioPodcastClicked.java @@ -1,4 +1,4 @@ -package de.luhmer.owncloudnewsreader.events; +package de.luhmer.owncloudnewsreader.events.podcast; /** * Created by David on 21.06.2014. diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/OpenAudioPodcastEvent.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/OpenAudioPodcastEvent.java similarity index 72% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/OpenAudioPodcastEvent.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/OpenAudioPodcastEvent.java index 1e84e767..22f6e604 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/OpenAudioPodcastEvent.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/OpenAudioPodcastEvent.java @@ -1,4 +1,4 @@ -package de.luhmer.owncloudnewsreader.events; +package de.luhmer.owncloudnewsreader.events.podcast; /** * Created by David on 21.06.2014. diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/PodcastFeedClicked.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/PodcastFeedClicked.java similarity index 66% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/PodcastFeedClicked.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/PodcastFeedClicked.java index 9fd8a90f..8805a7d8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/PodcastFeedClicked.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/PodcastFeedClicked.java @@ -1,4 +1,4 @@ -package de.luhmer.owncloudnewsreader.events; +package de.luhmer.owncloudnewsreader.events.podcast; /** * Created by David on 21.06.2014. diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/TogglePlayerStateEvent.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/TogglePlayerStateEvent.java similarity index 61% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/TogglePlayerStateEvent.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/TogglePlayerStateEvent.java index 26dcc02c..10a39333 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/TogglePlayerStateEvent.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/TogglePlayerStateEvent.java @@ -1,4 +1,4 @@ -package de.luhmer.owncloudnewsreader.events; +package de.luhmer.owncloudnewsreader.events.podcast; /** * Created by David on 20.06.2014. diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/UpdatePodcastStatusEvent.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/UpdatePodcastStatusEvent.java similarity index 70% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/UpdatePodcastStatusEvent.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/UpdatePodcastStatusEvent.java index b9722b3d..f26bbf44 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/UpdatePodcastStatusEvent.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/UpdatePodcastStatusEvent.java @@ -1,4 +1,4 @@ -package de.luhmer.owncloudnewsreader.events; +package de.luhmer.owncloudnewsreader.events.podcast; /** * Created by David on 20.06.2014. @@ -9,6 +9,7 @@ public class UpdatePodcastStatusEvent { private long max; private String title; private boolean playing; + private boolean preparingFile; public String getTitle() { return title; @@ -26,11 +27,16 @@ public class UpdatePodcastStatusEvent { return max; } - public UpdatePodcastStatusEvent(long current, long max, boolean playing, String title) { + public boolean isPreparingFile() { + return preparingFile; + } + + public UpdatePodcastStatusEvent(long current, long max, boolean playing, String title, boolean preparingFile) { this.current = current; this.max = max; this.playing = playing; this.title = title; + this.preparingFile = preparingFile; } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/WindPodcast.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/WindPodcast.java new file mode 100644 index 00000000..220b430a --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/WindPodcast.java @@ -0,0 +1,10 @@ +package de.luhmer.owncloudnewsreader.events.podcast; + +/** + * Created by David on 25.06.2014. + */ +public class WindPodcast { + + public double toPositionInPercent; + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/AudioPodcastService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/AudioPodcastService.java index 42d78127..9fe56b8a 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/AudioPodcastService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/AudioPodcastService.java @@ -9,9 +9,10 @@ import android.os.IBinder; import java.io.IOException; import de.greenrobot.event.EventBus; -import de.luhmer.owncloudnewsreader.events.OpenAudioPodcastEvent; -import de.luhmer.owncloudnewsreader.events.TogglePlayerStateEvent; -import de.luhmer.owncloudnewsreader.events.UpdatePodcastStatusEvent; +import de.luhmer.owncloudnewsreader.events.podcast.OpenAudioPodcastEvent; +import de.luhmer.owncloudnewsreader.events.podcast.TogglePlayerStateEvent; +import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent; +import de.luhmer.owncloudnewsreader.events.podcast.WindPodcast; import de.luhmer.owncloudnewsreader.view.PodcastNotification; public class AudioPodcastService extends Service { @@ -57,17 +58,40 @@ public class AudioPodcastService extends Service { public static final int delay = 500; //In milliseconds + private boolean isPreparing = false; + public void openFile(String pathToFile, String mediaTitle) { try { this.mediaTitle = mediaTitle; + if(mediaPlayer.isPlaying()) + pause(); + + isPreparing = true; + mHandler.postDelayed(mUpdateTimeTask, 0); + mediaPlayer.reset(); mediaPlayer.setDataSource(pathToFile); - mediaPlayer.prepare(); + mediaPlayer.prepareAsync(); + + mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { + @Override + public void onPrepared(MediaPlayer mediaPlayer) { + play(); + isPreparing = false; + } + }); + + mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mediaPlayer) { + pause();//Send the over signal + } + }); - play(); } catch (IOException e) { e.printStackTrace(); + isPreparing = false; } } @@ -90,6 +114,14 @@ public class AudioPodcastService extends Service { } } + public void onEvent(WindPodcast event) { + if(mediaPlayer != null) { + double totalDuration = mediaPlayer.getDuration(); + int position = (int)((totalDuration / 100d) * event.toPositionInPercent); + mediaPlayer.seekTo(position); + } + } + public void onEventBackgroundThread(OpenAudioPodcastEvent event) { openFile(event.pathToFile, event.mediaTitle); } @@ -99,6 +131,8 @@ public class AudioPodcastService extends Service { public void play() { mediaPlayer.start(); + + mHandler.removeCallbacks(mUpdateTimeTask); mHandler.postDelayed(mUpdateTimeTask, 0); } @@ -110,8 +144,12 @@ public class AudioPodcastService extends Service { } public void sendMediaStatus() { - long totalDuration = mediaPlayer.getDuration(); - long currentDuration = mediaPlayer.getCurrentPosition(); + long totalDuration = 0; + long currentDuration = 0; + if(!isPreparing) { + totalDuration = mediaPlayer.getDuration(); + currentDuration = mediaPlayer.getCurrentPosition(); + } /* // Displaying Total Duration time @@ -125,7 +163,7 @@ public class AudioPodcastService extends Service { songProgressBar.setProgress(progress); */ - UpdatePodcastStatusEvent audioPodcastEvent = new UpdatePodcastStatusEvent(currentDuration, totalDuration, mediaPlayer.isPlaying(), mediaTitle); + UpdatePodcastStatusEvent audioPodcastEvent = new UpdatePodcastStatusEvent(currentDuration, totalDuration, mediaPlayer.isPlaying(), mediaTitle, isPreparing); eventBus.post(audioPodcastEvent); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java index 81585ada..116db3d8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/view/PodcastNotification.java @@ -9,7 +9,7 @@ import android.support.v4.app.NotificationCompat; import de.greenrobot.event.EventBus; import de.luhmer.owncloudnewsreader.NewsReaderListActivity; import de.luhmer.owncloudnewsreader.R; -import de.luhmer.owncloudnewsreader.events.UpdatePodcastStatusEvent; +import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent; /** * Created by David on 22.06.2014. @@ -101,7 +101,7 @@ public class PodcastNotification { notificationBuilder .setContentTitle(podcast.getTitle()) .setContentText(fromText + " - " + toText) - .setProgress(100, progress, false) + .setProgress(100, progress, podcast.isPreparingFile()) .build(); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); diff --git a/News-Android-App/src/main/res/values/colors.xml b/News-Android-App/src/main/res/values/colors.xml index 96c7ed75..564c333a 100644 --- a/News-Android-App/src/main/res/values/colors.xml +++ b/News-Android-App/src/main/res/values/colors.xml @@ -14,5 +14,7 @@ #ffaaaaaa #ff393939 + #ff343434 + #ffdcdcdc diff --git a/News-Android-App/src/main/res/values/strings.xml b/News-Android-App/src/main/res/values/strings.xml index 29a23cc9..1a9b6cac 100644 --- a/News-Android-App/src/main/res/values/strings.xml +++ b/News-Android-App/src/main/res/values/strings.xml @@ -20,7 +20,6 @@ Reload All unread items Starred items - Add new feed @@ -30,11 +29,9 @@ Download images Download more items - Import Account - Sourcecode of item - Bugreport Send EMail @@ -50,7 +47,6 @@ Settings Sync Settings Add new feed - You have X new unread items X new unread items available @@ -124,6 +120,12 @@ Abort Certificate Verification + + + Podcast + Enable Podcast support + + Display App theme (requires restart to apply) @@ -209,8 +211,6 @@ 5000 10000 - - 5 Minutes 15 Minutes @@ -258,7 +258,7 @@ --> - + Notifications + Hello blank fragment + \ No newline at end of file diff --git a/News-Android-App/src/main/res/xml/pref_headers.xml b/News-Android-App/src/main/res/xml/pref_headers.xml index 30976b20..45279355 100644 --- a/News-Android-App/src/main/res/xml/pref_headers.xml +++ b/News-Android-App/src/main/res/xml/pref_headers.xml @@ -17,12 +17,13 @@
- - -