Update podcast support
This commit is contained in:
parent
7c9f5798e9
commit
f0b0898f71
17 changed files with 266 additions and 101 deletions
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<PodcastFeedItem> {
|
|||
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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<AudioPodcastItem> audioPodcasts;
|
||||
List<PodcastFeedItem> 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<Card> cards = new ArrayList<Card>();
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package de.luhmer.owncloudnewsreader.events;
|
||||
package de.luhmer.owncloudnewsreader.events.podcast;
|
||||
|
||||
/**
|
||||
* Created by David on 21.06.2014.
|
|
@ -1,4 +1,4 @@
|
|||
package de.luhmer.owncloudnewsreader.events;
|
||||
package de.luhmer.owncloudnewsreader.events.podcast;
|
||||
|
||||
/**
|
||||
* Created by David on 21.06.2014.
|
|
@ -1,4 +1,4 @@
|
|||
package de.luhmer.owncloudnewsreader.events;
|
||||
package de.luhmer.owncloudnewsreader.events.podcast;
|
||||
|
||||
/**
|
||||
* Created by David on 21.06.2014.
|
|
@ -1,4 +1,4 @@
|
|||
package de.luhmer.owncloudnewsreader.events;
|
||||
package de.luhmer.owncloudnewsreader.events.podcast;
|
||||
|
||||
/**
|
||||
* Created by David on 20.06.2014.
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package de.luhmer.owncloudnewsreader.events.podcast;
|
||||
|
||||
/**
|
||||
* Created by David on 25.06.2014.
|
||||
*/
|
||||
public class WindPodcast {
|
||||
|
||||
public double toPositionInPercent;
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -14,5 +14,7 @@
|
|||
<color name="extended_listview_item_body_text_color_dark_theme">#ffaaaaaa</color>
|
||||
<color name="extended_listview_item_body_text_color_light_theme">#ff393939</color>
|
||||
|
||||
<color name="slide_up_panel_header_background_color">#ff343434</color>
|
||||
<color name="slide_up_panel_slider_background_color">#ffdcdcdc</color>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
<string name="message_bar_reload">Reload</string>
|
||||
<string name="allUnreadFeeds">All unread items</string>
|
||||
<string name="starredFeeds">Starred items</string>
|
||||
|
||||
<string name="title_activity_new_feed">Add new feed</string>
|
||||
<!-- <string name="non_sorted_articles">Nicht zugeordnete Artikel</string> -->
|
||||
|
||||
|
@ -30,11 +29,9 @@
|
|||
<string name="menu_StartImageCaching">Download images</string>
|
||||
<string name="menu_downloadMoreItems">Download more items</string>
|
||||
|
||||
|
||||
<!-- Import Accounts -->
|
||||
<string name="import_account_dialog_title">Import Account</string>
|
||||
|
||||
|
||||
<!-- EMAIL -->
|
||||
<string name="email_sourceCode">Sourcecode of item - Bugreport</string>
|
||||
<string name="email_sendMail">Send EMail</string>
|
||||
|
@ -50,7 +47,6 @@
|
|||
<string name="action_settings">Settings</string>
|
||||
<string name="action_sync_settings">Sync Settings</string>
|
||||
<string name="action_add_new_feed">Add new feed</string>
|
||||
|
||||
<string name="notification_new_items_ticker">You have X new unread items</string>
|
||||
<string name="notification_new_items_text">X new unread items available</string>
|
||||
|
||||
|
@ -124,6 +120,12 @@
|
|||
<string name="mtm_decision_abort">Abort</string>
|
||||
<string name="mtm_notification">Certificate Verification</string>
|
||||
|
||||
|
||||
<!-- Podcast -->
|
||||
<string name="pref_header_podcast">Podcast</string>
|
||||
<string name="pref_enable_podcasts">Enable Podcast support</string>
|
||||
|
||||
|
||||
<!-- Settings for Display -->
|
||||
<string name="pref_header_display">Display</string>
|
||||
<string name="pref_title_app_theme">App theme (requires restart to apply)</string>
|
||||
|
@ -209,8 +211,6 @@
|
|||
<item>5000</item>
|
||||
<item>10000</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
<string-array name="array_sync_interval">
|
||||
<item>5 Minutes</item>
|
||||
<item>15 Minutes</item>
|
||||
|
@ -258,7 +258,7 @@
|
|||
-->
|
||||
|
||||
|
||||
<!-- <string name="pref_title_system_sync_settings">System sync settings</string> -->
|
||||
<!-- <string name="pref_title_system_sync_settings">System sync settings</string> -->
|
||||
|
||||
<string name="pref_header_notifications">Notifications</string>
|
||||
<!--
|
||||
|
@ -268,4 +268,6 @@
|
|||
<string name="pref_title_vibrate">Vibrate</string>
|
||||
-->
|
||||
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
|
||||
</resources>
|
|
@ -17,12 +17,13 @@
|
|||
<header
|
||||
android:fragment="de.luhmer.owncloudnewsreader.SettingsActivity$DataSyncPreferenceFragment"
|
||||
android:title="@string/pref_header_data_sync" />
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
|
||||
<header
|
||||
android:fragment="de.luhmer.owncloudnewsreader.SettingsActivity$NotificationPreferenceFragment"
|
||||
android:fragment="de.luhmer.owncloudnewsreader.SettingsActivity$PodcastPreferenceFragment"
|
||||
android:title="@string/pref_header_notifications" />
|
||||
|
||||
<!--
|
||||
<header
|
||||
android:fragment="de.luhmer.owncloudnewsreader.SettingsActivity$DataSyncPreferenceFragment"
|
||||
android:title="@string/pref_header_data_sync" />
|
||||
|
|
9
News-Android-App/src/main/res/xml/pref_podcast.xml
Normal file
9
News-Android-App/src/main/res/xml/pref_podcast.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="cb_enablePodcasts"
|
||||
android:title="@string/pref_enable_podcasts" />
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue