Migrate rxjava to version 2

This commit is contained in:
Martin Fietz 2018-09-30 19:58:53 +02:00
parent c105a63165
commit 3de661d953
36 changed files with 447 additions and 436 deletions

View File

@ -161,10 +161,9 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion" implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion"
implementation "com.squareup.okio:okio:$okioVersion" implementation "com.squareup.okio:okio:$okioVersion"
implementation "de.greenrobot:eventbus:$eventbusVersion" implementation "de.greenrobot:eventbus:$eventbusVersion"
implementation "io.reactivex:rxandroid:$rxAndroidVersion" implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
implementation "io.reactivex:rxjava:$rxJavaVersion" implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
// And ProGuard rules for RxJava!
implementation "com.artemzin.rxjava:proguard-rules:$rxJavaRulesVersion"
implementation "com.joanzapata.iconify:android-iconify-fontawesome:$iconifyVersion" implementation "com.joanzapata.iconify:android-iconify-fontawesome:$iconifyVersion"
implementation "com.joanzapata.iconify:android-iconify-material:$iconifyVersion" implementation "com.joanzapata.iconify:android-iconify-material:$iconifyVersion"
implementation("com.afollestad.material-dialogs:commons:$materialDialogsVersion") { implementation("com.afollestad.material-dialogs:commons:$materialDialogsVersion") {
@ -179,7 +178,7 @@ dependencies {
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion" implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion"
implementation 'com.github.mfietz:fyydlin:v0.3' implementation 'com.github.mfietz:fyydlin:v0.4'
implementation 'com.github.ByteHamster:SearchPreference:v1.0.8' implementation 'com.github.ByteHamster:SearchPreference:v1.0.8'
androidTestImplementation "com.jayway.android.robotium:robotium-solo:$robotiumSoloVersion" androidTestImplementation "com.jayway.android.robotium:robotium-solo:$robotiumSoloVersion"

View File

@ -21,10 +21,10 @@ import java.nio.charset.Charset;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import rx.Single; import io.reactivex.Single;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Displays the 'about' screen * Displays the 'about' screen
@ -35,7 +35,7 @@ public class AboutActivity extends AppCompatActivity {
private WebView webView; private WebView webView;
private LinearLayout webViewContainer; private LinearLayout webViewContainer;
private Subscription subscription; private Disposable disposable;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -69,7 +69,7 @@ public class AboutActivity extends AppCompatActivity {
} }
private void loadAsset(String filename) { private void loadAsset(String filename) {
subscription = Single.create(subscriber -> { disposable = Single.create(subscriber -> {
InputStream input = null; InputStream input = null;
try { try {
TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes(
@ -115,7 +115,7 @@ public class AboutActivity extends AppCompatActivity {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
webViewData -> webViewData ->
@ -146,8 +146,8 @@ public class AboutActivity extends AppCompatActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if (webViewContainer != null && webView != null) { if (webViewContainer != null && webView != null) {
webViewContainer.removeAllViews(); webViewContainer.removeAllViews();

View File

@ -16,8 +16,14 @@ import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.Feed;
@ -30,13 +36,11 @@ import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.LangUtils; import de.danoeh.antennapod.core.util.LangUtils;
import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText;
import de.danoeh.antennapod.menuhandler.FeedMenuHandler; import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import org.apache.commons.lang3.StringUtils; import io.reactivex.Maybe;
import org.jsoup.Jsoup; import io.reactivex.MaybeOnSubscribe;
import org.jsoup.nodes.Document; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.Observable; import io.reactivex.disposables.Disposable;
import rx.Subscription; import io.reactivex.schedulers.Schedulers;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/** /**
* Displays information about a feed. * Displays information about a feed.
@ -56,7 +60,7 @@ public class FeedInfoActivity extends AppCompatActivity {
private TextView txtvAuthor; private TextView txtvAuthor;
private TextView txtvUrl; private TextView txtvUrl;
private Subscription subscription; private Disposable disposable;
private final View.OnClickListener copyUrlToClipboard = new View.OnClickListener() { private final View.OnClickListener copyUrlToClipboard = new View.OnClickListener() {
@ -101,14 +105,17 @@ public class FeedInfoActivity extends AppCompatActivity {
txtvUrl.setOnClickListener(copyUrlToClipboard); txtvUrl.setOnClickListener(copyUrlToClipboard);
subscription = Observable.fromCallable(()-> DBReader.getFeed(feedId)) disposable = Maybe.create((MaybeOnSubscribe<Feed>) emitter -> {
.subscribeOn(Schedulers.newThread()) Feed feed = DBReader.getFeed(feedId);
if(feed != null) {
emitter.onSuccess(feed);
} else {
emitter.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result == null) {
Log.e(TAG, "Activity was started with invalid arguments");
finish();
}
feed = result; feed = result;
Log.d(TAG, "Language is " + feed.getLanguage()); Log.d(TAG, "Language is " + feed.getLanguage());
Log.d(TAG, "Author is " + feed.getAuthor()); Log.d(TAG, "Author is " + feed.getAuthor());
@ -164,14 +171,17 @@ public class FeedInfoActivity extends AppCompatActivity {
}, error -> { }, error -> {
Log.d(TAG, Log.getStackTraceString(error)); Log.d(TAG, Log.getStackTraceString(error));
finish(); finish();
}, () -> {
Log.e(TAG, "Activity was started with invalid arguments");
finish();
}); });
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }

View File

@ -1,6 +1,5 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import android.content.ClipData;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -24,8 +23,9 @@ import android.widget.ImageView;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
@ -40,10 +40,11 @@ import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.menuhandler.FeedMenuHandler; import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import rx.Observable; import io.reactivex.Maybe;
import rx.Subscription; import io.reactivex.MaybeOnSubscribe;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/** /**
* Displays information about a feed. * Displays information about a feed.
@ -67,23 +68,7 @@ public class FeedSettingsActivity extends AppCompatActivity {
private Spinner spnAutoDelete; private Spinner spnAutoDelete;
private boolean filterInclude = true; private boolean filterInclude = true;
private Subscription subscription; private Disposable disposable;
private final View.OnClickListener copyUrlToClipboard = new View.OnClickListener() {
@Override
public void onClick(View v) {
if(feed != null && feed.getDownload_url() != null) {
String url = feed.getDownload_url();
ClipData clipData = ClipData.newPlainText(url, url);
android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedSettingsActivity.this
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
Toast t = Toast.makeText(FeedSettingsActivity.this, R.string.copied_url_msg, Toast.LENGTH_SHORT);
t.show();
}
}
};
private boolean authInfoChanged = false; private boolean authInfoChanged = false;
@ -153,14 +138,17 @@ public class FeedSettingsActivity extends AppCompatActivity {
filterTextChanged = true; filterTextChanged = true;
}); });
subscription = Observable.fromCallable(()-> DBReader.getFeed(feedId)) disposable = Maybe.create((MaybeOnSubscribe<Feed>) emitter -> {
.subscribeOn(Schedulers.newThread()) Feed feed = DBReader.getFeed(feedId);
if(feed != null) {
emitter.onSuccess(feed);
} else {
emitter.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result == null) {
Log.e(TAG, "Activity was started with invalid arguments");
finish();
}
feed = result; feed = result;
FeedPreferences prefs = feed.getPreferences(); FeedPreferences prefs = feed.getPreferences();
Glide.with(FeedSettingsActivity.this) Glide.with(FeedSettingsActivity.this)
@ -259,6 +247,9 @@ public class FeedSettingsActivity extends AppCompatActivity {
}, error -> { }, error -> {
Log.d(TAG, Log.getStackTraceString(error)); Log.d(TAG, Log.getStackTraceString(error));
finish(); finish();
}, () -> {
Log.e(TAG, "Activity was started with invalid arguments");
finish();
}); });
} }
@ -296,8 +287,8 @@ public class FeedSettingsActivity extends AppCompatActivity {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }

View File

@ -30,9 +30,6 @@ import android.widget.ListView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -45,6 +42,7 @@ import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.event.MessageEvent;
import de.danoeh.antennapod.core.event.ProgressEvent; import de.danoeh.antennapod.core.event.ProgressEvent;
import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.event.QueueEvent;
import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
@ -55,7 +53,9 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.Flavors; import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
import de.danoeh.antennapod.dialog.RatingDialog; import de.danoeh.antennapod.dialog.RatingDialog;
import de.danoeh.antennapod.dialog.RenameFeedDialog; import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.fragment.AddFeedFragment; import de.danoeh.antennapod.fragment.AddFeedFragment;
@ -68,10 +68,10 @@ import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment;
import de.danoeh.antennapod.menuhandler.NavDrawerActivity; import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* The activity that is shown when the user launches the app. * The activity that is shown when the user launches the app.
@ -121,7 +121,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
private ProgressDialog pd; private ProgressDialog pd;
private Subscription subscription; private Disposable disposable;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -488,8 +488,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
super.onStop(); super.onStop();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if(pd != null) { if(pd != null) {
pd.dismiss(); pd.dismiss();
@ -717,8 +717,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
}; };
private void loadData() { private void loadData() {
subscription = Observable.fromCallable(DBReader::getNavDrawerData) disposable = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
boolean handleIntent = (navDrawerData == null); boolean handleIntent = (navDrawerData == null);

View File

@ -47,9 +47,11 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.Consumer;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.Flavors; import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.Function;
import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.StorageUtils;
@ -62,11 +64,10 @@ import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
import de.danoeh.antennapod.dialog.SleepTimerDialog; import de.danoeh.antennapod.dialog.SleepTimerDialog;
import de.danoeh.antennapod.dialog.VariableSpeedDialog; import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import rx.Observable; import io.reactivex.Observable;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.functions.Action1; import io.reactivex.disposables.Disposable;
import rx.functions.Func1; import io.reactivex.schedulers.Schedulers;
import rx.schedulers.Schedulers;
/** /**
@ -95,6 +96,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
private boolean isFavorite = false; private boolean isFavorite = false;
private Disposable disposable;
private PlaybackController newPlaybackController() { private PlaybackController newPlaybackController() {
return new PlaybackController(this, false) { return new PlaybackController(this, false) {
@ -293,6 +296,9 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
controller.release(); controller.release();
controller = null; // prevent leak controller = null; // prevent leak
} }
if(disposable != null) {
disposable.dispose();
}
super.onStop(); super.onStop();
} }
@ -644,7 +650,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
if (controller != null) { if (controller != null) {
controller.init(); controller.init();
} }
} }
} }
@ -730,8 +735,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
R.string.pref_rewind); R.string.pref_rewind);
private final Supplier<Integer> getPrefSecsFn; private final Supplier<Integer> getPrefSecsFn;
private final Func1<MediaplayerActivity, TextView> getTextViewFn; private final Function<MediaplayerActivity, TextView> getTextViewFn;
private final Action1<Integer> setPrefSecsFn; private final Consumer<Integer> setPrefSecsFn;
private final int titleResourceID; private final int titleResourceID;
/** /**
@ -743,7 +748,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
* @param setPrefSecsFn Handle to function that sets the preference (setting) for the skip delta value (and optionally updates the button label with the current values) * @param setPrefSecsFn Handle to function that sets the preference (setting) for the skip delta value (and optionally updates the button label with the current values)
* @param titleResourceID ID of the resource string with the title for a view * @param titleResourceID ID of the resource string with the title for a view
*/ */
SkipDirection(Supplier<Integer> getPrefSecsFn, Func1<MediaplayerActivity, TextView> getTextViewFn, Action1<Integer> setPrefSecsFn, int titleResourceID) { SkipDirection(Supplier<Integer> getPrefSecsFn, Function<MediaplayerActivity, TextView> getTextViewFn, Consumer<Integer> setPrefSecsFn, int titleResourceID) {
this.getPrefSecsFn = getPrefSecsFn; this.getPrefSecsFn = getPrefSecsFn;
this.getTextViewFn = getTextViewFn; this.getTextViewFn = getTextViewFn;
this.setPrefSecsFn = setPrefSecsFn; this.setPrefSecsFn = setPrefSecsFn;
@ -762,10 +767,10 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
* @param activity MediaplyerActivity that contains textview to update the display of the skip delta setting (or null if nothing to update) * @param activity MediaplyerActivity that contains textview to update the display of the skip delta setting (or null if nothing to update)
*/ */
public void setPrefSkipSeconds(int seconds, @Nullable Activity activity) { public void setPrefSkipSeconds(int seconds, @Nullable Activity activity) {
setPrefSecsFn.call(seconds); setPrefSecsFn.accept(seconds);
if (activity != null && activity instanceof MediaplayerActivity) { if (activity != null && activity instanceof MediaplayerActivity) {
TextView tv = getTextViewFn.call((MediaplayerActivity)activity); TextView tv = getTextViewFn.apply((MediaplayerActivity)activity);
if (tv != null) tv.setText(String.valueOf(seconds)); if (tv != null) tv.setText(String.valueOf(seconds));
} }
} }
@ -946,22 +951,27 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
private void checkFavorite() { private void checkFavorite() {
Playable playable = controller.getMedia(); Playable playable = controller.getMedia();
if (playable != null && playable instanceof FeedMedia) { if (!(playable instanceof FeedMedia)) {
FeedItem feedItem = ((FeedMedia) playable).getItem(); return;
if (feedItem != null) {
Observable.fromCallable(() -> DBReader.getFeedItem(feedItem.getId()))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
item -> {
boolean isFav = item.isTagged(FeedItem.TAG_FAVORITE);
if (isFavorite != isFav) {
isFavorite = isFav;
invalidateOptionsMenu();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
} }
FeedItem feedItem = ((FeedMedia) playable).getItem();
if (feedItem == null) {
return;
}
if(disposable != null) {
disposable.dispose();
}
disposable = Observable.fromCallable(() -> DBReader.getFeedItem(feedItem.getId()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
item -> {
boolean isFav = item.isTagged(FeedItem.TAG_FAVORITE);
if (isFavorite != isFav) {
isFavorite = isFav;
invalidateOptionsMenu();
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
} }
void playExternalMedia(Intent intent, MediaType type) { void playExternalMedia(Intent intent, MediaType type) {

View File

@ -63,10 +63,10 @@ import de.danoeh.antennapod.fragment.QueueFragment;
import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment;
import de.danoeh.antennapod.menuhandler.NavDrawerActivity; import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Activity for playing files that do not require a video surface. * Activity for playing files that do not require a video surface.
@ -106,7 +106,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
private ViewPager pager; private ViewPager pager;
private MediaplayerInfoPagerAdapter pagerAdapter; private MediaplayerInfoPagerAdapter pagerAdapter;
private Subscription subscription; private Disposable disposable;
@Override @Override
protected void onPause() { protected void onPause() {
@ -127,8 +127,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
if(pagerAdapter != null) { if(pagerAdapter != null) {
pagerAdapter.setController(null); pagerAdapter.setController(null);
} }
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
saveCurrentFragment(); saveCurrentFragment();
@ -472,8 +472,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
private DBReader.NavDrawerData navDrawerData; private DBReader.NavDrawerData navDrawerData;
private void loadData() { private void loadData() {
subscription = Observable.fromCallable(DBReader::getNavDrawerData) disposable = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
navDrawerData = result; navDrawerData = result;

View File

@ -65,10 +65,10 @@ import de.danoeh.antennapod.core.util.syndication.FeedDiscoverer;
import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText;
import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Downloads a feed from a feed URL and parses it. Subclasses can display the * Downloads a feed from a feed URL and parses it. Subclasses can display the
@ -97,15 +97,15 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
private Button subscribeButton; private Button subscribeButton;
private Subscription download; private Disposable download;
private Subscription parser; private Disposable parser;
private Subscription updater; private Disposable updater;
private final EventDistributor.EventListener listener = new EventDistributor.EventListener() { private final EventDistributor.EventListener listener = new EventDistributor.EventListener() {
@Override @Override
public void update(EventDistributor eventDistributor, Integer arg) { public void update(EventDistributor eventDistributor, Integer arg) {
if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) { if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) {
updater = Observable.fromCallable(DBReader::getFeedList) updater = Observable.fromCallable(DBReader::getFeedList)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
feeds -> { feeds -> {
@ -212,13 +212,13 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if(updater != null) { if(updater != null) {
updater.unsubscribe(); updater.dispose();
} }
if(download != null) { if(download != null) {
download.unsubscribe(); download.dispose();
} }
if(parser != null) { if(parser != null) {
parser.unsubscribe(); parser.dispose();
} }
} }
@ -273,7 +273,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
downloader.call(); downloader.call();
return downloader.getResult(); return downloader.getResult();
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::checkDownloadResult, .subscribe(this::checkDownloadResult,
error -> Log.e(TAG, Log.getStackTraceString(error))); error -> Log.e(TAG, Log.getStackTraceString(error)));
@ -331,7 +331,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
Log.d(TAG, "Deleted feed source file. Result: " + rc); Log.d(TAG, "Deleted feed source file. Result: " + rc);
} }
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if(result != null) { if(result != null) {

View File

@ -9,11 +9,12 @@ import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.storage.PodDBAdapter;
import rx.Completable; import io.reactivex.Completable;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Shows the AntennaPod logo while waiting for the main activity to start * Shows the AntennaPod logo while waiting for the main activity to start
@ -37,14 +38,14 @@ public class SplashActivity extends AppCompatActivity {
// Trigger schema updates // Trigger schema updates
PodDBAdapter.getInstance().open(); PodDBAdapter.getInstance().open();
PodDBAdapter.getInstance().close(); PodDBAdapter.getInstance().close();
subscriber.onCompleted(); subscriber.onComplete();
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> { .subscribe(() -> {
Intent intent = new Intent(SplashActivity.this, MainActivity.class); Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish(); finish();
startActivity(intent);
}); });
} }
} }

View File

@ -20,10 +20,10 @@ import de.danoeh.antennapod.adapter.StatisticsListAdapter;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Displays the 'statistics' screen * Displays the 'statistics' screen
@ -35,7 +35,7 @@ public class StatisticsActivity extends AppCompatActivity
private static final String PREF_NAME = "StatisticsActivityPrefs"; private static final String PREF_NAME = "StatisticsActivityPrefs";
private static final String PREF_COUNT_ALL = "countAll"; private static final String PREF_COUNT_ALL = "countAll";
private Subscription subscription; private Disposable disposable;
private TextView totalTimeTextView; private TextView totalTimeTextView;
private ListView feedStatisticsList; private ListView feedStatisticsList;
private ProgressBar progressBar; private ProgressBar progressBar;
@ -119,21 +119,19 @@ public class StatisticsActivity extends AppCompatActivity
} }
private void loadStatistics() { private void loadStatistics() {
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
subscription = Observable.fromCallable(() -> DBReader.getStatistics(countAll)) disposable = Observable.fromCallable(() -> DBReader.getStatistics(countAll))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result != null) { totalTimeTextView.setText(Converter
totalTimeTextView.setText(Converter .shortLocalizedDuration(this, countAll ? result.totalTimeCountAll : result.totalTime));
.shortLocalizedDuration(this, countAll ? result.totalTimeCountAll : result.totalTime)); listAdapter.update(result.feedTime);
listAdapter.update(result.feedTime); progressBar.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE); totalTimeTextView.setVisibility(View.VISIBLE);
totalTimeTextView.setVisibility(View.VISIBLE); feedStatisticsList.setVisibility(View.VISIBLE);
feedStatisticsList.setVisibility(View.VISIBLE);
}
}, error -> Log.e(TAG, Log.getStackTraceString(error))); }, error -> Log.e(TAG, Log.getStackTraceString(error)));
} }

View File

@ -12,7 +12,7 @@ import de.danoeh.antennapod.core.export.ExportWriter;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.LangUtils; import de.danoeh.antennapod.core.util.LangUtils;
import rx.Observable; import io.reactivex.Observable;
/** /**
* Writes an OPML file into the export directory in the background. * Writes an OPML file into the export directory in the background.
@ -57,7 +57,7 @@ public class ExportWorker {
subscriber.onError(e); subscriber.onError(e);
} }
} }
subscriber.onCompleted(); subscriber.onComplete();
} }
}); });
} }

View File

@ -29,15 +29,15 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.service.download.ProxyConfig; import de.danoeh.antennapod.core.service.download.ProxyConfig;
import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Credentials; import okhttp3.Credentials;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class ProxyDialog { public class ProxyDialog {
@ -55,7 +55,7 @@ public class ProxyDialog {
private boolean testSuccessful = false; private boolean testSuccessful = false;
private TextView txtvMessage; private TextView txtvMessage;
private Subscription subscription; private Disposable disposable;
public ProxyDialog(Context context) { public ProxyDialog(Context context) {
this.context = context; this.context = context;
@ -229,8 +229,8 @@ public class ProxyDialog {
} }
private void test() { private void test() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if(!checkValidity()) { if(!checkValidity()) {
setTestRequired(true); setTestRequired(true);
@ -243,7 +243,7 @@ public class ProxyDialog {
txtvMessage.setTextColor(textColorPrimary); txtvMessage.setTextColor(textColorPrimary);
txtvMessage.setText("{fa-circle-o-notch spin} " + checking); txtvMessage.setText("{fa-circle-o-notch spin} " + checking);
txtvMessage.setVisibility(View.VISIBLE); txtvMessage.setVisibility(View.VISIBLE);
subscription = Observable.create((Observable.OnSubscribe<Response>) subscriber -> { disposable = Single.create((SingleOnSubscribe<Response>) emitter -> {
String type = (String) spType.getSelectedItem(); String type = (String) spType.getSelectedItem();
String host = etHost.getText().toString(); String host = etHost.getText().toString();
String port = etPort.getText().toString(); String port = etPort.getText().toString();
@ -275,13 +275,12 @@ public class ProxyDialog {
.build(); .build();
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
subscriber.onNext(response); emitter.onSuccess(response);
} catch(IOException e) { } catch(IOException e) {
subscriber.onError(e); emitter.onError(e);
} }
subscriber.onCompleted();
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
response -> { response -> {

View File

@ -50,10 +50,10 @@ import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Shows unread or recently published episodes * Shows unread or recently published episodes
@ -84,7 +84,7 @@ public class AllEpisodesFragment extends Fragment {
private boolean isUpdatingFeeds; private boolean isUpdatingFeeds;
boolean isMenuInvalidationAllowed = false; boolean isMenuInvalidationAllowed = false;
Subscription subscription; Disposable disposable;
private LinearLayoutManager layoutManager; private LinearLayoutManager layoutManager;
boolean showOnlyNewEpisodes() { return false; } boolean showOnlyNewEpisodes() { return false; }
@ -125,8 +125,8 @@ public class AllEpisodesFragment extends Fragment {
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -466,15 +466,15 @@ public class AllEpisodesFragment extends Fragment {
} }
void loadItems() { void loadItems() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if (viewsCreated && !itemsLoaded) { if (viewsCreated && !itemsLoaded) {
recyclerView.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE);
progLoading.setVisibility(View.VISIBLE); progLoading.setVisibility(View.VISIBLE);
} }
subscription = Observable.fromCallable(this::loadData) disposable = Observable.fromCallable(this::loadData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(data -> { .subscribe(data -> {
recyclerView.setVisibility(View.VISIBLE); recyclerView.setVisibility(View.VISIBLE);
@ -499,8 +499,8 @@ public class AllEpisodesFragment extends Fragment {
} }
Log.d(TAG, "markItemAsSeenWithUndo(" + item.getId() + ")"); Log.d(TAG, "markItemAsSeenWithUndo(" + item.getId() + ")");
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
// we're marking it as unplayed since the user didn't actually play it // we're marking it as unplayed since the user didn't actually play it
// but they don't want it considered 'NEW' anymore // but they don't want it considered 'NEW' anymore

View File

@ -1,8 +1,6 @@
package de.danoeh.antennapod.fragment; package de.danoeh.antennapod.fragment;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.util.Log; import android.util.Log;
@ -12,9 +10,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
@ -22,15 +17,14 @@ import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter; import de.danoeh.antennapod.adapter.DownloadedEpisodesListAdapter;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Displays all running downloads and provides a button to delete them * Displays all running downloads and provides a button to delete them
@ -48,7 +42,7 @@ public class CompletedDownloadsFragment extends ListFragment {
private boolean viewCreated = false; private boolean viewCreated = false;
private Subscription subscription; private Disposable disposable;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -67,16 +61,16 @@ public class CompletedDownloadsFragment extends ListFragment {
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@Override @Override
public void onDetach() { public void onDetach() {
super.onDetach(); super.onDetach();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -85,8 +79,8 @@ public class CompletedDownloadsFragment extends ListFragment {
super.onDestroyView(); super.onDestroyView();
listAdapter = null; listAdapter = null;
viewCreated = false; viewCreated = false;
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -188,21 +182,19 @@ public class CompletedDownloadsFragment extends ListFragment {
}; };
private void loadItems() { private void loadItems() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if (items == null && viewCreated) { if (items == null && viewCreated) {
setListShown(false); setListShown(false);
} }
subscription = Observable.fromCallable(DBReader::getDownloadedItems) disposable = Observable.fromCallable(DBReader::getDownloadedItems)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result != null) { items = result;
items = result; if (viewCreated && getActivity() != null) {
if (viewCreated && getActivity() != null) { onFragmentLoaded();
onFragmentLoaded();
}
} }
}, error -> Log.e(TAG, Log.getStackTraceString(error))); }, error -> Log.e(TAG, Log.getStackTraceString(error)));
} }

View File

@ -12,10 +12,10 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import java.util.List; import java.util.List;
import android.widget.TextView;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.DownloadLogAdapter; import de.danoeh.antennapod.adapter.DownloadLogAdapter;
import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.EventDistributor;
@ -23,10 +23,10 @@ import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.service.download.DownloadStatus;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Shows the download log * Shows the download log
@ -41,7 +41,7 @@ public class DownloadLogFragment extends ListFragment {
private boolean viewsCreated = false; private boolean viewsCreated = false;
private boolean itemsLoaded = false; private boolean itemsLoaded = false;
private Subscription subscription; private Disposable disposable;
@Override @Override
public void onStart() { public void onStart() {
@ -55,8 +55,8 @@ public class DownloadLogFragment extends ListFragment {
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -178,11 +178,11 @@ public class DownloadLogFragment extends ListFragment {
} }
private void loadItems() { private void loadItems() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
subscription = Observable.fromCallable(DBReader::getDownloadLog) disposable = Observable.fromCallable(DBReader::getDownloadLog)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result != null) { if (result != null) {

View File

@ -23,9 +23,10 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.core.util.playback.PlaybackController;
import rx.Single; import io.reactivex.Maybe;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/** /**
* Fragment which is supposed to be displayed outside of the MediaplayerActivity * Fragment which is supposed to be displayed outside of the MediaplayerActivity
@ -41,6 +42,7 @@ public class ExternalPlayerFragment extends Fragment {
private TextView mFeedName; private TextView mFeedName;
private ProgressBar mProgressBar; private ProgressBar mProgressBar;
private PlaybackController controller; private PlaybackController controller;
private Disposable disposable;
public ExternalPlayerFragment() { public ExternalPlayerFragment() {
super(); super();
@ -177,10 +179,18 @@ public class ExternalPlayerFragment extends Fragment {
return false; return false;
} }
Single.create(subscriber -> subscriber.onSuccess(controller.getMedia())) disposable = Maybe.create(emitter -> {
.subscribeOn(Schedulers.newThread()) Playable media = controller.getMedia();
if(media != null) {
emitter.onSuccess(media);
} else {
emitter.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(media -> updateUi((Playable) media)); .subscribe(media -> updateUi((Playable) media),
error -> Log.e(TAG, Log.getStackTraceString(error)));
return true; return true;
} }

View File

@ -62,8 +62,8 @@ public class FavoriteEpisodesFragment extends AllEpisodesFragment {
AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder)viewHolder; AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder)viewHolder;
Log.d(TAG, "remove(" + holder.getItemId() + ")"); Log.d(TAG, "remove(" + holder.getItemId() + ")");
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
FeedItem item = holder.getFeedItem(); FeedItem item = holder.getFeedItem();
if (item != null) { if (item != null) {

View File

@ -28,9 +28,9 @@ import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.mfietz.fyydlin.FyydClient; import de.mfietz.fyydlin.FyydClient;
import de.mfietz.fyydlin.FyydResponse; import de.mfietz.fyydlin.FyydResponse;
import de.mfietz.fyydlin.SearchHit; import de.mfietz.fyydlin.SearchHit;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import static de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast; import static de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
@ -55,7 +55,7 @@ public class FyydSearchFragment extends Fragment {
* List of podcasts retreived from the search * List of podcasts retreived from the search
*/ */
private List<Podcast> searchResults; private List<Podcast> searchResults;
private Subscription subscription; private Disposable disposable;
/** /**
* Constructor * Constructor
@ -98,8 +98,8 @@ public class FyydSearchFragment extends Fragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
adapter = null; adapter = null;
} }
@ -141,12 +141,12 @@ public class FyydSearchFragment extends Fragment {
} }
private void search(String query) { private void search(String query) {
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
showOnlyProgressBar(); showOnlyProgressBar();
subscription = client.searchPodcasts(query) disposable = client.searchPodcasts(query, 10)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
@ -174,7 +174,7 @@ public class FyydSearchFragment extends Fragment {
if (!response.getData().isEmpty()) { if (!response.getData().isEmpty()) {
adapter.clear(); adapter.clear();
searchResults = new ArrayList<>(); searchResults = new ArrayList<>();
for (SearchHit searchHit : response.getData().values()) { for (SearchHit searchHit : response.getData()) {
Podcast podcast = Podcast.fromSearch(searchHit); Podcast podcast = Podcast.fromSearch(searchHit);
searchResults.add(podcast); searchResults.add(podcast);
} }

View File

@ -39,10 +39,10 @@ import de.danoeh.antennapod.core.util.ShownotesProvider;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController; import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.core.util.playback.Timeline; import de.danoeh.antennapod.core.util.playback.Timeline;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Displays the description of a Playable object in a Webview. * Displays the description of a Playable object in a Webview.
@ -66,7 +66,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
private ShownotesProvider shownotesProvider; private ShownotesProvider shownotesProvider;
private Playable media; private Playable media;
private Subscription webViewLoader; private Disposable webViewLoader;
/** /**
* URL that was selected via long-press. * URL that was selected via long-press.
@ -167,7 +167,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
super.onDestroy(); super.onDestroy();
Log.d(TAG, "Fragment destroyed"); Log.d(TAG, "Fragment destroyed");
if (webViewLoader != null) { if (webViewLoader != null) {
webViewLoader.unsubscribe(); webViewLoader.dispose();
} }
if (webvDescription != null) { if (webvDescription != null) {
webvDescription.removeAllViews(); webvDescription.removeAllViews();
@ -198,7 +198,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
} else if (args.containsKey(ARG_FEEDITEM_ID)) { } else if (args.containsKey(ARG_FEEDITEM_ID)) {
long id = getArguments().getLong(ARG_FEEDITEM_ID); long id = getArguments().getLong(ARG_FEEDITEM_ID);
Observable.defer(() -> Observable.just(DBReader.getFeedItem(id))) Observable.defer(() -> Observable.just(DBReader.getFeedItem(id)))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(feedItem -> { .subscribe(feedItem -> {
shownotesProvider = feedItem; shownotesProvider = feedItem;
@ -298,13 +298,13 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
private void load() { private void load() {
Log.d(TAG, "load()"); Log.d(TAG, "load()");
if(webViewLoader != null) { if(webViewLoader != null) {
webViewLoader.unsubscribe(); webViewLoader.dispose();
} }
if(shownotesProvider == null) { if(shownotesProvider == null) {
return; return;
} }
webViewLoader = Observable.defer(() -> Observable.just(loadData())) webViewLoader = Observable.fromCallable(this::loadData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(data -> { .subscribe(data -> {
webvDescription.loadDataWithBaseURL(null, data, "text/html", webvDescription.loadDataWithBaseURL(null, data, "text/html",

View File

@ -34,8 +34,6 @@ import com.bumptech.glide.Glide;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.widget.IconButton; import com.joanzapata.iconify.widget.IconButton;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.NetworkUtils;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import java.util.List; import java.util.List;
@ -53,26 +51,27 @@ import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.service.download.Downloader;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.DateUtils;
import de.danoeh.antennapod.core.util.Flavors; import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.playback.Timeline; import de.danoeh.antennapod.core.util.playback.Timeline;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.view.OnSwipeGesture; import de.danoeh.antennapod.view.OnSwipeGesture;
import de.danoeh.antennapod.view.SwipeGestureDetector; import de.danoeh.antennapod.view.SwipeGestureDetector;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Displays information about a FeedItem and actions. * Displays information about a FeedItem and actions.
@ -135,7 +134,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
private IconButton butAction2; private IconButton butAction2;
private Menu popupMenu; private Menu popupMenu;
private Subscription subscription; private Disposable disposable;
/** /**
* URL that was selected via long-press. * URL that was selected via long-press.
@ -286,8 +285,8 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if (webvDescription != null && root != null) { if (webvDescription != null && root != null) {
root.removeView(webvDescription); root.removeView(webvDescription);
@ -572,12 +571,12 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
}; };
private void load() { private void load() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
progbarLoading.setVisibility(View.VISIBLE); progbarLoading.setVisibility(View.VISIBLE);
subscription = Observable.fromCallable(this::loadInBackground) disposable = Observable.fromCallable(this::loadInBackground)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
progbarLoading.setVisibility(View.GONE); progbarLoading.setVisibility(View.GONE);

View File

@ -4,8 +4,6 @@ import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.LightingColorFilter; import android.graphics.LightingColorFilter;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
@ -26,18 +24,16 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
import com.joanzapata.iconify.widget.IconTextView; import com.joanzapata.iconify.widget.IconTextView;
import de.danoeh.antennapod.activity.FeedSettingsActivity;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.FeedInfoActivity; import de.danoeh.antennapod.activity.FeedInfoActivity;
import de.danoeh.antennapod.activity.FeedSettingsActivity;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
import de.danoeh.antennapod.adapter.FeedItemlistAdapter; import de.danoeh.antennapod.adapter.FeedItemlistAdapter;
@ -55,7 +51,6 @@ import de.danoeh.antennapod.core.feed.FeedItemFilter;
import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.glide.FastBlurTransformation; import de.danoeh.antennapod.core.glide.FastBlurTransformation;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.service.download.Downloader;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
@ -71,10 +66,10 @@ import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.menuhandler.FeedMenuHandler; import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Displays a list of FeedItems. * Displays a list of FeedItems.
@ -114,7 +109,7 @@ public class ItemlistFragment extends ListFragment {
private TextView txtvInformation; private TextView txtvInformation;
private Subscription subscription; private Disposable disposable;
/** /**
* Creates new ItemlistFragment which shows the Feeditems of a specific * Creates new ItemlistFragment which shows the Feeditems of a specific
@ -165,8 +160,8 @@ public class ItemlistFragment extends ListFragment {
super.onPause(); super.onPause();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -618,11 +613,11 @@ public class ItemlistFragment extends ListFragment {
private void loadItems() { private void loadItems() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
subscription = Observable.fromCallable(this::loadData) disposable = Observable.fromCallable(this::loadData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result != null) { if (result != null) {

View File

@ -36,13 +36,14 @@ import de.danoeh.antennapod.adapter.itunes.ItunesAdapter;
import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import static de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast; import static de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast;
@ -69,7 +70,7 @@ public class ItunesSearchFragment extends Fragment {
*/ */
private List<Podcast> searchResults; private List<Podcast> searchResults;
private List<Podcast> topList; private List<Podcast> topList;
private Subscription subscription; private Disposable disposable;
/** /**
* Replace adapter data with provided search results from SearchTask. * Replace adapter data with provided search results from SearchTask.
@ -127,7 +128,7 @@ public class ItunesSearchFragment extends Fragment {
} else { } else {
gridView.setVisibility(View.GONE); gridView.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> { disposable = Single.create((SingleOnSubscribe<String>) emitter -> {
OkHttpClient client = AntennapodHttpClient.getHttpClient(); OkHttpClient client = AntennapodHttpClient.getHttpClient();
Request.Builder httpReq = new Request.Builder() Request.Builder httpReq = new Request.Builder()
.url(podcast.feedUrl) .url(podcast.feedUrl)
@ -139,17 +140,16 @@ public class ItunesSearchFragment extends Fragment {
JSONObject result = new JSONObject(resultString); JSONObject result = new JSONObject(resultString);
JSONObject results = result.getJSONArray("results").getJSONObject(0); JSONObject results = result.getJSONArray("results").getJSONObject(0);
String feedUrl = results.getString("feedUrl"); String feedUrl = results.getString("feedUrl");
subscriber.onNext(feedUrl); emitter.onSuccess(feedUrl);
} else { } else {
String prefix = getString(R.string.error_msg_prefix); String prefix = getString(R.string.error_msg_prefix);
subscriber.onError(new IOException(prefix + response)); emitter.onError(new IOException(prefix + response));
} }
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
subscriber.onError(e); emitter.onError(e);
} }
subscriber.onCompleted();
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(feedUrl -> { .subscribe(feedUrl -> {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
@ -183,8 +183,8 @@ public class ItunesSearchFragment extends Fragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
adapter = null; adapter = null;
} }
@ -228,15 +228,15 @@ public class ItunesSearchFragment extends Fragment {
} }
private void loadToplist() { private void loadToplist() {
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
gridView.setVisibility(View.GONE); gridView.setVisibility(View.GONE);
txtvError.setVisibility(View.GONE); txtvError.setVisibility(View.GONE);
butRetry.setVisibility(View.GONE); butRetry.setVisibility(View.GONE);
txtvEmpty.setVisibility(View.GONE); txtvEmpty.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
subscription = Observable.create((Observable.OnSubscribe<List<Podcast>>) subscriber -> { disposable = Single.create((SingleOnSubscribe<List<Podcast>>) emitter -> {
String lang = Locale.getDefault().getLanguage(); String lang = Locale.getDefault().getLanguage();
String url = "https://itunes.apple.com/" + lang + "/rss/toppodcasts/limit=25/explicit=true/json"; String url = "https://itunes.apple.com/" + lang + "/rss/toppodcasts/limit=25/explicit=true/json";
OkHttpClient client = AntennapodHttpClient.getHttpClient(); OkHttpClient client = AntennapodHttpClient.getHttpClient();
@ -268,15 +268,14 @@ public class ItunesSearchFragment extends Fragment {
} }
else { else {
String prefix = getString(R.string.error_msg_prefix); String prefix = getString(R.string.error_msg_prefix);
subscriber.onError(new IOException(prefix + response)); emitter.onError(new IOException(prefix + response));
} }
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
subscriber.onError(e); emitter.onError(e);
} }
subscriber.onNext(results); emitter.onSuccess(results);
subscriber.onCompleted();
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(podcasts -> { .subscribe(podcasts -> {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
@ -293,15 +292,15 @@ public class ItunesSearchFragment extends Fragment {
} }
private void search(String query) { private void search(String query) {
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
gridView.setVisibility(View.GONE); gridView.setVisibility(View.GONE);
txtvError.setVisibility(View.GONE); txtvError.setVisibility(View.GONE);
butRetry.setVisibility(View.GONE); butRetry.setVisibility(View.GONE);
txtvEmpty.setVisibility(View.GONE); txtvEmpty.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
subscription = rx.Observable.create((Observable.OnSubscribe<List<Podcast>>) subscriber -> { disposable = Single.create((SingleOnSubscribe<List<Podcast>>) subscriber -> {
String encodedQuery = null; String encodedQuery = null;
try { try {
encodedQuery = URLEncoder.encode(query, "UTF-8"); encodedQuery = URLEncoder.encode(query, "UTF-8");
@ -341,10 +340,9 @@ public class ItunesSearchFragment extends Fragment {
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
subscriber.onError(e); subscriber.onError(e);
} }
subscriber.onNext(podcasts); subscriber.onSuccess(podcasts);
subscriber.onCompleted();
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(podcasts -> { .subscribe(podcasts -> {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);

View File

@ -30,10 +30,10 @@ import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.LongList;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
public class PlaybackHistoryFragment extends ListFragment { public class PlaybackHistoryFragment extends ListFragment {
@ -50,7 +50,7 @@ public class PlaybackHistoryFragment extends ListFragment {
private List<Downloader> downloaderList; private List<Downloader> downloaderList;
private Subscription subscription; private Disposable disposable;
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
@ -107,16 +107,16 @@ public class PlaybackHistoryFragment extends ListFragment {
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@Override @Override
public void onDetach() { public void onDetach() {
super.onDetach(); super.onDetach();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -269,11 +269,11 @@ public class PlaybackHistoryFragment extends ListFragment {
}; };
private void loadItems() { private void loadItems() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
subscription = Observable.fromCallable(this::loadData) disposable = Observable.fromCallable(this::loadData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result != null) { if (result != null) {

View File

@ -21,7 +21,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
@ -46,7 +45,6 @@ import de.danoeh.antennapod.core.service.download.Downloader;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
@ -55,10 +53,10 @@ import de.danoeh.antennapod.core.util.QueueSorter;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils; import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Shows all items in the queue * Shows all items in the queue
@ -86,7 +84,7 @@ public class QueueFragment extends Fragment {
private static final String PREF_SCROLL_POSITION = "scroll_position"; private static final String PREF_SCROLL_POSITION = "scroll_position";
private static final String PREF_SCROLL_OFFSET = "scroll_offset"; private static final String PREF_SCROLL_OFFSET = "scroll_offset";
private Subscription subscription; private Disposable disposable;
private LinearLayoutManager layoutManager; private LinearLayoutManager layoutManager;
private ItemTouchHelper itemTouchHelper; private ItemTouchHelper itemTouchHelper;
@ -120,8 +118,8 @@ public class QueueFragment extends Fragment {
saveScrollPosition(); saveScrollPosition();
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -425,8 +423,8 @@ public class QueueFragment extends Fragment {
@Override @Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
final int position = viewHolder.getAdapterPosition(); final int position = viewHolder.getAdapterPosition();
Log.d(TAG, "remove(" + position + ")"); Log.d(TAG, "remove(" + position + ")");
@ -622,16 +620,16 @@ public class QueueFragment extends Fragment {
private void loadItems(final boolean restoreScrollPosition) { private void loadItems(final boolean restoreScrollPosition) {
Log.d(TAG, "loadItems()"); Log.d(TAG, "loadItems()");
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if (queue == null) { if (queue == null) {
recyclerView.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE);
txtvEmpty.setVisibility(View.GONE); txtvEmpty.setVisibility(View.GONE);
progLoading.setVisibility(View.VISIBLE); progLoading.setVisibility(View.VISIBLE);
} }
subscription = Observable.fromCallable(DBReader::getQueue) disposable = Observable.fromCallable(DBReader::getQueue)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(items -> { .subscribe(items -> {
if(items != null) { if(items != null) {

View File

@ -24,10 +24,10 @@ import de.danoeh.antennapod.core.feed.FeedComponent;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.SearchResult; import de.danoeh.antennapod.core.feed.SearchResult;
import de.danoeh.antennapod.core.storage.FeedSearcher; import de.danoeh.antennapod.core.storage.FeedSearcher;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Performs a search operation on all feeds or one specific feed and displays the search result. * Performs a search operation on all feeds or one specific feed and displays the search result.
@ -44,7 +44,7 @@ public class SearchFragment extends ListFragment {
private boolean viewCreated = false; private boolean viewCreated = false;
private boolean itemsLoaded = false; private boolean itemsLoaded = false;
private Subscription subscription; private Disposable disposable;
/** /**
* Create a new SearchFragment that searches all feeds. * Create a new SearchFragment that searches all feeds.
@ -85,8 +85,8 @@ public class SearchFragment extends ListFragment {
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
EventDistributor.getInstance().unregister(contentUpdate); EventDistributor.getInstance().unregister(contentUpdate);
} }
@ -94,8 +94,8 @@ public class SearchFragment extends ListFragment {
@Override @Override
public void onDetach() { public void onDetach() {
super.onDetach(); super.onDetach();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
@ -205,14 +205,14 @@ public class SearchFragment extends ListFragment {
private void search() { private void search() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
if (viewCreated && !itemsLoaded) { if (viewCreated && !itemsLoaded) {
setListShown(false); setListShown(false);
} }
subscription = Observable.fromCallable(this::performSearch) disposable = Observable.fromCallable(this::performSearch)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
if (result != null) { if (result != null) {

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod.fragment; package de.danoeh.antennapod.fragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log; import android.util.Log;
@ -16,7 +15,6 @@ import android.widget.GridView;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.MediaplayerInfoActivity;
import de.danoeh.antennapod.adapter.SubscriptionsAdapter; import de.danoeh.antennapod.adapter.SubscriptionsAdapter;
import de.danoeh.antennapod.core.asynctask.FeedRemover; import de.danoeh.antennapod.core.asynctask.FeedRemover;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
@ -29,10 +27,10 @@ import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.dialog.RenameFeedDialog; import de.danoeh.antennapod.dialog.RenameFeedDialog;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
/** /**
* Fragment for displaying feed subscriptions * Fragment for displaying feed subscriptions
@ -50,7 +48,7 @@ public class SubscriptionFragment extends Fragment {
private int mPosition = -1; private int mPosition = -1;
private Subscription subscription; private Disposable disposable;
public SubscriptionFragment() { public SubscriptionFragment() {
} }
@ -96,17 +94,17 @@ public class SubscriptionFragment extends Fragment {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }
private void loadSubscriptions() { private void loadSubscriptions() {
if(subscription != null) { if(disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
subscription = Observable.fromCallable(DBReader::getNavDrawerData) disposable = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
navDrawerData = result; navDrawerData = result;
@ -163,7 +161,7 @@ public class SubscriptionFragment extends Fragment {
dialog.dismiss(); dialog.dismiss();
Observable.fromCallable(() -> DBWriter.markFeedSeen(feed.getId())) Observable.fromCallable(() -> DBWriter.markFeedSeen(feed.getId()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> loadSubscriptions(), .subscribe(result -> loadSubscriptions(),
error -> Log.e(TAG, Log.getStackTraceString(error))); error -> Log.e(TAG, Log.getStackTraceString(error)));
@ -180,7 +178,7 @@ public class SubscriptionFragment extends Fragment {
public void onConfirmButtonPressed(DialogInterface dialog) { public void onConfirmButtonPressed(DialogInterface dialog) {
dialog.dismiss(); dialog.dismiss();
Observable.fromCallable(() -> DBWriter.markFeedRead(feed.getId())) Observable.fromCallable(() -> DBWriter.markFeedRead(feed.getId()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> loadSubscriptions(), .subscribe(result -> loadSubscriptions(),
error -> Log.e(TAG, Log.getStackTraceString(error))); error -> Log.e(TAG, Log.getStackTraceString(error)));

View File

@ -36,24 +36,9 @@ import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import com.bytehamster.lib.preferencesearch.SearchConfiguration; import com.bytehamster.lib.preferencesearch.SearchConfiguration;
import com.bytehamster.lib.preferencesearch.SearchPreference; import com.bytehamster.lib.preferencesearch.SearchPreference;
import de.danoeh.antennapod.activity.AboutActivity;
import de.danoeh.antennapod.activity.ImportExportActivity;
import de.danoeh.antennapod.activity.MediaplayerActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.StatisticsActivity;
import de.danoeh.antennapod.core.export.html.HtmlWriter;
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
import de.danoeh.antennapod.core.service.GpodnetSyncService;
import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog;
import de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog;
import de.danoeh.antennapod.dialog.ProxyDialog;
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import java.io.File; import java.io.File;
@ -67,18 +52,33 @@ import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.CrashReportWriter; import de.danoeh.antennapod.CrashReportWriter;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.AboutActivity;
import de.danoeh.antennapod.activity.DirectoryChooserActivity; import de.danoeh.antennapod.activity.DirectoryChooserActivity;
import de.danoeh.antennapod.activity.ImportExportActivity;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.MediaplayerActivity;
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.StatisticsActivity;
import de.danoeh.antennapod.asynctask.ExportWorker; import de.danoeh.antennapod.asynctask.ExportWorker;
import de.danoeh.antennapod.core.export.ExportWriter; import de.danoeh.antennapod.core.export.ExportWriter;
import de.danoeh.antennapod.core.export.html.HtmlWriter;
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
import de.danoeh.antennapod.core.preferences.GpodnetPreferences; import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.GpodnetSyncService;
import de.danoeh.antennapod.core.util.flattr.FlattrUtils; import de.danoeh.antennapod.core.util.flattr.FlattrUtils;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.dialog.AuthenticationDialog;
import de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog;
import de.danoeh.antennapod.dialog.ChooseDataFolderDialog; import de.danoeh.antennapod.dialog.ChooseDataFolderDialog;
import rx.Observable; import de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog;
import rx.Subscription; import de.danoeh.antennapod.dialog.ProxyDialog;
import rx.android.schedulers.AndroidSchedulers; import de.danoeh.antennapod.dialog.VariableSpeedDialog;
import rx.schedulers.Schedulers; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import static de.danoeh.antennapod.activity.PreferenceActivity.PARAM_RESOURCE; import static de.danoeh.antennapod.activity.PreferenceActivity.PARAM_RESOURCE;
@ -137,7 +137,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
} }
}; };
private CheckBoxPreference[] selectedNetworks; private CheckBoxPreference[] selectedNetworks;
private Subscription subscription; private Disposable disposable;
public PreferenceController(PreferenceUI ui) { public PreferenceController(PreferenceUI ui) {
this.ui = ui; this.ui = ui;
@ -624,7 +624,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
final AlertDialog.Builder alert = new AlertDialog.Builder(context) final AlertDialog.Builder alert = new AlertDialog.Builder(context)
.setNeutralButton(android.R.string.ok, (dialog, which) -> dialog.dismiss()); .setNeutralButton(android.R.string.ok, (dialog, which) -> dialog.dismiss());
Observable<File> observable = new ExportWorker(exportWriter).exportObservable(); Observable<File> observable = new ExportWorker(exportWriter).exportObservable();
subscription = observable.subscribeOn(Schedulers.newThread()) disposable = observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(output -> { .subscribe(output -> {
alert.setTitle(R.string.export_success_title); alert.setTitle(R.string.export_success_title);
@ -702,8 +702,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
} }
public void unsubscribeExportSubscription() { public void unsubscribeExportSubscription() {
if (subscription != null) { if (disposable != null) {
subscription.unsubscribe(); disposable.dispose();
} }
} }

View File

@ -41,10 +41,10 @@ import java.util.concurrent.ExecutionException;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.ApGlideSettings;
import rx.Observable; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
public class CustomMRControllerDialog extends MediaRouteControllerDialog { public class CustomMRControllerDialog extends MediaRouteControllerDialog {
public static final String TAG = "CustomMRContrDialog"; public static final String TAG = "CustomMRContrDialog";
@ -60,7 +60,7 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog {
private boolean viewsCreated = false; private boolean viewsCreated = false;
private Subscription fetchArtSubscription; private Disposable fetchArtSubscription;
private MediaControllerCompat mediaController; private MediaControllerCompat mediaController;
private MediaControllerCompat.Callback mediaControllerCallback; private MediaControllerCompat.Callback mediaControllerCallback;
@ -327,7 +327,7 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog {
@Override @Override
public void onDetachedFromWindow() { public void onDetachedFromWindow() {
if (fetchArtSubscription != null) { if (fetchArtSubscription != null) {
fetchArtSubscription.unsubscribe(); fetchArtSubscription.dispose();
fetchArtSubscription = null; fetchArtSubscription = null;
} }
super.onDetachedFromWindow(); super.onDetachedFromWindow();
@ -396,11 +396,11 @@ public class CustomMRControllerDialog extends MediaRouteControllerDialog {
} }
if (fetchArtSubscription != null) { if (fetchArtSubscription != null) {
fetchArtSubscription.unsubscribe(); fetchArtSubscription.dispose();
} }
fetchArtSubscription = Observable.fromCallable(() -> fetchArt(description)) fetchArtSubscription = Observable.fromCallable(() -> fetchArt(description))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {
fetchArtSubscription = null; fetchArtSubscription = null;

View File

@ -57,8 +57,8 @@ project.ext {
okioVersion = "1.14.0" okioVersion = "1.14.0"
recyclerviewFlexibledividerVersion = "1.4.0" recyclerviewFlexibledividerVersion = "1.4.0"
robotiumSoloVersion = "5.6.3" robotiumSoloVersion = "5.6.3"
rxAndroidVersion = "1.2.1" rxAndroidVersion = "2.1.0"
rxJavaVersion = "1.3.8" rxJavaVersion = "2.2.2"
rxJavaRulesVersion = "1.3.3.0" rxJavaRulesVersion = "1.3.3.0"
triangleLabelViewVersion = "1.1.2" triangleLabelViewVersion = "1.1.2"

View File

@ -65,7 +65,8 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion" implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion"
implementation "com.squareup.okio:okio:$okioVersion" implementation "com.squareup.okio:okio:$okioVersion"
implementation "de.greenrobot:eventbus:$eventbusVersion" implementation "de.greenrobot:eventbus:$eventbusVersion"
implementation "io.reactivex:rxandroid:$rxAndroidVersion" implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
implementation "com.google.android.exoplayer:exoplayer:$exoPlayerVersion" implementation "com.google.android.exoplayer:exoplayer:$exoPlayerVersion"
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion" implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion"

View File

@ -8,14 +8,7 @@ import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.service.download.ProxyConfig;
import de.danoeh.antennapod.core.storage.APCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -27,6 +20,15 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.service.download.ProxyConfig;
import de.danoeh.antennapod.core.storage.APCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
/** /**
* Provides access to preferences set by the user in the settings screen. A * Provides access to preferences set by the user in the settings screen. A
* private instance of this class must first be instantiated via * private instance of this class must first be instantiated via
@ -108,6 +110,7 @@ public class UserPreferences {
private static final String PREF_RIGHT_VOLUME = "prefRightVolume"; private static final String PREF_RIGHT_VOLUME = "prefRightVolume";
// Experimental // Experimental
public static final String PREF_SONIC = "prefSonic";
private static final String PREF_STEREO_TO_MONO = "PrefStereoToMono"; private static final String PREF_STEREO_TO_MONO = "PrefStereoToMono";
public static final String PREF_CAST_ENABLED = "prefCast"; //Used for enabling Chromecast support public static final String PREF_CAST_ENABLED = "prefCast"; //Used for enabling Chromecast support
public static final int EPISODE_CLEANUP_QUEUE = -1; public static final int EPISODE_CLEANUP_QUEUE = -1;

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.core.storage; package de.danoeh.antennapod.core.storage;
import android.database.Cursor; import android.database.Cursor;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap; import android.support.v4.util.ArrayMap;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -574,6 +575,7 @@ public final class DBReader {
} }
} }
@Nullable
static Feed getFeed(final long feedId, PodDBAdapter adapter) { static Feed getFeed(final long feedId, PodDBAdapter adapter) {
Feed feed = null; Feed feed = null;
Cursor cursor = null; Cursor cursor = null;

View File

@ -0,0 +1,5 @@
package de.danoeh.antennapod.core.util;
public interface Consumer<T> {
void accept(T t);
}

View File

@ -0,0 +1,7 @@
package de.danoeh.antennapod.core.util;
import io.reactivex.annotations.NonNull;
public interface Function<T, R> {
R apply(@NonNull T t);
}

View File

@ -18,13 +18,13 @@ import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
import io.reactivex.Single;
import io.reactivex.SingleOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class NetworkUtils { public class NetworkUtils {
@ -111,11 +111,10 @@ public class NetworkUtils {
return null; return null;
} }
public static Observable<Long> getFeedMediaSizeObservable(FeedMedia media) { public static Single<Long> getFeedMediaSizeObservable(FeedMedia media) {
return Observable.create((Observable.OnSubscribe<Long>) subscriber -> { return Single.create((SingleOnSubscribe<Long>) emitter -> {
if (!NetworkUtils.isDownloadAllowed()) { if (!NetworkUtils.isDownloadAllowed()) {
subscriber.onNext(0L); emitter.onSuccess(0L);
subscriber.onCompleted();
return; return;
} }
long size = Integer.MIN_VALUE; long size = Integer.MIN_VALUE;
@ -129,8 +128,7 @@ public class NetworkUtils {
String url = media.getDownload_url(); String url = media.getDownload_url();
if(TextUtils.isEmpty(url)) { if(TextUtils.isEmpty(url)) {
subscriber.onNext(0L); emitter.onSuccess(0L);
subscriber.onCompleted();
return; return;
} }
@ -150,8 +148,7 @@ public class NetworkUtils {
} }
} }
} catch (IOException e) { } catch (IOException e) {
subscriber.onNext(0L); emitter.onSuccess(0L);
subscriber.onCompleted();
Log.e(TAG, Log.getStackTraceString(e)); Log.e(TAG, Log.getStackTraceString(e));
return; // better luck next time return; // better luck next time
} }
@ -163,11 +160,10 @@ public class NetworkUtils {
} else { } else {
media.setSize(size); media.setSize(size);
} }
subscriber.onNext(size); emitter.onSuccess(size);
subscriber.onCompleted();
DBWriter.setFeedMedia(media); DBWriter.setFeedMedia(media);
}) })
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
} }

View File

@ -7,12 +7,10 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -24,10 +22,8 @@ import android.widget.ImageButton;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
@ -42,13 +38,12 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils; import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils;
import rx.Completable; import io.reactivex.Maybe;
import rx.Observable; import io.reactivex.MaybeOnSubscribe;
import rx.Single; import io.reactivex.Observable;
import rx.Subscription; import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable;
import rx.observers.Subscribers; import io.reactivex.schedulers.Schedulers;
import rx.schedulers.Schedulers;
/** /**
* Communicates with the playback service. GUI classes should use this class to * Communicates with the playback service. GUI classes should use this class to
@ -76,7 +71,8 @@ public abstract class PlaybackController {
private boolean released = false; private boolean released = false;
private boolean initialized = false; private boolean initialized = false;
private Subscription serviceBinder; private Disposable serviceBinder;
private Disposable mediaLoader;
/** /**
* True if controller should reinit playback service if 'pause' button is * True if controller should reinit playback service if 'pause' button is
@ -151,7 +147,7 @@ public abstract class PlaybackController {
} }
if(serviceBinder != null) { if(serviceBinder != null) {
serviceBinder.unsubscribe(); serviceBinder.dispose();
} }
try { try {
activity.unbindService(mConnection); activity.unbindService(mConnection);
@ -186,10 +182,10 @@ public abstract class PlaybackController {
private void bindToService() { private void bindToService() {
Log.d(TAG, "Trying to connect to service"); Log.d(TAG, "Trying to connect to service");
if (serviceBinder != null) { if (serviceBinder != null) {
serviceBinder.unsubscribe(); serviceBinder.dispose();
} }
serviceBinder = Observable.fromCallable(this::getPlayLastPlayedMediaIntent) serviceBinder = Observable.fromCallable(this::getPlayLastPlayedMediaIntent)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(intent -> { .subscribe(intent -> {
boolean bound = false; boolean bound = false;
@ -783,15 +779,18 @@ public abstract class PlaybackController {
} }
private void initServiceNotRunning() { private void initServiceNotRunning() {
Single.create(subscriber -> subscriber.onSuccess(getMedia())) mediaLoader = Maybe.create((MaybeOnSubscribe<Playable>) emitter -> {
.subscribeOn(Schedulers.newThread()) Playable media = getMedia();
if(media != null) {
emitter.onSuccess(media);
} else {
emitter.onComplete();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe((Object media) -> { .subscribe(media -> {
if (media == null) { if (media.getMediaType() == MediaType.AUDIO) {
return;
}
if (((Playable) media).getMediaType() == MediaType.AUDIO) {
TypedArray res = activity.obtainStyledAttributes(new int[]{ TypedArray res = activity.obtainStyledAttributes(new int[]{
de.danoeh.antennapod.core.R.attr.av_play_big}); de.danoeh.antennapod.core.R.attr.av_play_big});
getPlayButton().setImageResource( getPlayButton().setImageResource(
@ -800,7 +799,7 @@ public abstract class PlaybackController {
} else { } else {
getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp); getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp);
} }
}); }, error -> Log.e(TAG, Log.getStackTraceString(error)));
} }
/** /**
@ -808,7 +807,7 @@ public abstract class PlaybackController {
*/ */
public class MediaPositionObserver implements Runnable { public class MediaPositionObserver implements Runnable {
public static final int WAITING_INTERVALL = 1000; static final int WAITING_INTERVALL = 1000;
@Override @Override
public void run() { public void run() {