Search in sources :

Example 66 with Subscribe

use of com.squareup.otto.Subscribe in project zype-android by zype.

the class VideoDetailViewModel method handleVideo.

/**
 * Handles API request for video
 *
 * @param event Response event
 */
@Subscribe
public void handleVideo(VideoEvent event) {
    Logger.d("handleVideo()");
    VideoData data = event.getEventData().getModelData().getVideoData();
    Video video = DbHelper.videoDataToVideoEntity(data);
    Video dbVideo = repo.getVideoSync(videoId);
    if (dbVideo == null) {
        dbVideo = video;
        onAir.setValue(video.onAir == 1);
    } else {
        if (dbVideo.onAir != video.onAir) {
            dbVideo.onAir = video.onAir;
            onAir.setValue(video.onAir == 1);
        }
    }
    repo.updateVideo(dbVideo);
    if (dbVideo != null)
        videoLiveData.setValue(dbVideo);
}
Also used : Video(com.zype.android.Db.Entity.Video) VideoData(com.zype.android.webapi.model.video.VideoData) Subscribe(com.squareup.otto.Subscribe)

Example 67 with Subscribe

use of com.squareup.otto.Subscribe in project zype-android by zype.

the class VideoDetailViewModel method handleDownloadVideo.

/**
 * Handles API request for player video download url
 *
 * @param event Response event
 */
@Subscribe
public void handleDownloadVideo(DownloadVideoEvent event) {
    Logger.d("handleDownloadVideo()");
    File file = ListUtils.getFileByType(event.getEventData().getModelData().getResponse().getBody().getFiles(), "mp4");
    String url;
    if (file != null) {
        url = file.getUrl();
        String videoId = event.mFileId;
        // Save download url in the local database if it was changed
        Video video = repo.getVideoSync(videoId);
        video.downloadVideoUrl = url;
        repo.updateVideo(video);
        if (!TextUtils.isEmpty(url)) {
            downloadsAvailableLiveData.setValue(true);
        }
    } else {
        Logger.e("handleDownloadVideo(): mp4 source not found");
    }
}
Also used : Video(com.zype.android.Db.Entity.Video) File(com.zype.android.webapi.model.player.File) Subscribe(com.squareup.otto.Subscribe)

Example 68 with Subscribe

use of com.squareup.otto.Subscribe in project zype-android by zype.

the class ZypeApp method handleConsumer.

@Subscribe
public void handleConsumer(ConsumerEvent event) {
    Logger.d("handleConsumer()");
    if (event.getRequest() == WebApiManager.Request.CONSUMER_FORGOT_PASSWORD) {
        return;
    }
    Consumer data = event.getEventData().getModelData();
    int subscriptionCount = data.getConsumerData().getSubscriptionCount();
    SettingsProvider.getInstance().saveSubscriptionCount(subscriptionCount);
    String consumerId = data.getConsumerData().getId();
    SettingsProvider.getInstance().saveConsumerId(consumerId);
    SettingsProvider.getInstance().setString(SettingsProvider.CONSUMER_EMAIL, data.getConsumerData().getEmail());
}
Also used : Consumer(com.zype.android.webapi.model.consumers.Consumer) Subscribe(com.squareup.otto.Subscribe)

Example 69 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class ActionCreatorTest method createTodoActionTest.

@Test
public void createTodoActionTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    actionBus.register(new Object() {

        @Subscribe
        public void addTodo(TodoAction action) {
            assertThat(action.getData().get(TodoAction.DataKeys.DESCRIPTION, "")).isEqualTo("Test");
            testDone.set(true);
        }
    });
    actionCreator.createNewTodoAction("Test");
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscribe(com.squareup.otto.Subscribe) Test(org.junit.Test)

Example 70 with Subscribe

use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.

the class ActionCreatorTest method createViewActiveTodosActionTest.

@Test
public void createViewActiveTodosActionTest() {
    final AtomicBoolean testDone = new AtomicBoolean(false);
    actionBus.register(new Object() {

        @Subscribe
        public void addTodo(ViewAction action) {
            assertThat(action.getType()).isEqualTo(ViewAction.ActionTypes.VIEW_ACTIVE);
            testDone.set(true);
        }
    });
    actionCreator.createViewActiveTodosAction();
    while (!testDone.get()) ;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscribe(com.squareup.otto.Subscribe) Test(org.junit.Test)

Aggregations

Subscribe (com.squareup.otto.Subscribe)86 Test (org.junit.Test)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)27 RawTodoList (com.armueller.fluxytodo.data.RawTodoList)13 ArrayList (java.util.ArrayList)12 TodoAction (com.armueller.fluxytodo.actions.TodoAction)9 VideoData (com.zype.android.webapi.model.video.VideoData)8 DataBundle (com.armueller.fluxytodo.actions.DataBundle)7 File (com.zype.android.webapi.model.player.File)7 Intent (android.content.Intent)6 FilteredTodoList (com.armueller.fluxytodo.data.FilteredTodoList)6 ConsumerFavoriteVideoData (com.zype.android.webapi.model.consumers.ConsumerFavoriteVideoData)6 Bundle (android.os.Bundle)5 Video (com.zype.android.Db.Entity.Video)5 Consumer (com.zype.android.webapi.model.consumers.Consumer)5 IOException (java.io.IOException)5 Context (android.content.Context)4 ConnectivityManager (android.net.ConnectivityManager)4 NetworkInfo (android.net.NetworkInfo)4 Dialog (android.app.Dialog)3