Database access threading (#2781)
This commit is contained in:
parent
3d61002d88
commit
1d265a9c3a
|
@ -1,23 +1,50 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.ProgressBar;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import rx.Completable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Creator: vbarad
|
||||
* Date: 2016-12-03
|
||||
* Project: AntennaPod
|
||||
* Shows the AntennaPod logo while waiting for the main activity to start
|
||||
*/
|
||||
|
||||
public class SplashActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.splash);
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
ProgressBar progressBar = findViewById(R.id.progressBar);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable());
|
||||
DrawableCompat.setTint(wrapDrawable, 0xffffffff);
|
||||
progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
|
||||
} else {
|
||||
progressBar.getIndeterminateDrawable().setColorFilter(0xffffffff, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
Completable.create(subscriber -> {
|
||||
// Trigger schema updates
|
||||
PodDBAdapter.getInstance().open();
|
||||
PodDBAdapter.getInstance().close();
|
||||
subscriber.onCompleted();
|
||||
})
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(() -> {
|
||||
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
|||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
import rx.Single;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Fragment which is supposed to be displayed outside of the MediaplayerActivity
|
||||
|
@ -127,8 +130,9 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
controller.init();
|
||||
onPositionObserverUpdate();
|
||||
|
||||
controller.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -173,7 +177,14 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
Playable media = controller.getMedia();
|
||||
Single.create(subscriber -> subscriber.onSuccess(controller.getMedia()))
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> updateUi((Playable) media));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateUi(Playable media) {
|
||||
if (media != null) {
|
||||
txtvTitle.setText(media.getEpisodeTitle());
|
||||
mFeedName.setText(media.getFeedTitle());
|
||||
|
@ -194,10 +205,8 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
} else {
|
||||
butPlay.setVisibility(View.VISIBLE);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
Log.w(TAG, "loadMediaInfo was called while the media object of playbackService was null!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ProgressBar
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="36dp"
|
||||
android:id="@+id/progressBar"/>
|
||||
</RelativeLayout>
|
|
@ -263,6 +263,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
Log.d(TAG, "Service created.");
|
||||
isRunning = true;
|
||||
|
||||
NotificationCompat.Builder notificationBuilder = createBasicNotification();
|
||||
startForeground(NOTIFICATION_ID, notificationBuilder.build());
|
||||
|
||||
registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS"));
|
||||
registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
|
||||
registerReceiver(shutdownReceiver, new IntentFilter(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
|
@ -311,11 +314,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
|
||||
flavorHelper.initializeMediaPlayer(PlaybackService.this);
|
||||
|
||||
mediaSession.setActive(true);
|
||||
|
||||
NotificationCompat.Builder notificationBuilder = createBasicNotification();
|
||||
startForeground(NOTIFICATION_ID, notificationBuilder.build());
|
||||
EventBus.getDefault().post(new ServiceEvent(ServiceEvent.Action.SERVICE_STARTED));
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,12 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
|||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils;
|
||||
import rx.Completable;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
import rx.Subscription;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.observers.Subscribers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
|
@ -780,18 +783,24 @@ public abstract class PlaybackController {
|
|||
}
|
||||
|
||||
private void initServiceNotRunning() {
|
||||
if (getMedia() == null) {
|
||||
return;
|
||||
}
|
||||
if (getMedia().getMediaType() == MediaType.AUDIO) {
|
||||
TypedArray res = activity.obtainStyledAttributes(new int[]{
|
||||
de.danoeh.antennapod.core.R.attr.av_play_big});
|
||||
getPlayButton().setImageResource(
|
||||
res.getResourceId(0, de.danoeh.antennapod.core.R.drawable.ic_play_arrow_grey600_36dp));
|
||||
res.recycle();
|
||||
} else {
|
||||
getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp);
|
||||
}
|
||||
Single.create(subscriber -> subscriber.onSuccess(getMedia()))
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe((Object media) -> {
|
||||
if (media == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((Playable) media).getMediaType() == MediaType.AUDIO) {
|
||||
TypedArray res = activity.obtainStyledAttributes(new int[]{
|
||||
de.danoeh.antennapod.core.R.attr.av_play_big});
|
||||
getPlayButton().setImageResource(
|
||||
res.getResourceId(0, de.danoeh.antennapod.core.R.drawable.ic_play_arrow_grey600_36dp));
|
||||
res.recycle();
|
||||
} else {
|
||||
getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue