use of com.squareup.otto.Subscribe in project zype-android by zype.
the class FavoritesFragment method handleRetrieveVideo.
@Subscribe
public void handleRetrieveVideo(RetrieveVideoEvent event) {
Logger.d("handleRetrieveVideo(): size=" + event.getEventData().getModelData().getVideoData().size());
Video data = event.getEventData().getModelData();
if (data.getVideoData().size() > 0) {
for (VideoData item : data.getVideoData()) {
if (!TextUtils.isEmpty(DataHelper.getFavoriteId(getActivity().getContentResolver(), item.getId()))) {
List<VideoData> videos = new ArrayList<>();
videos.add(item);
DataHelper.insertVideos(getActivity().getContentResolver(), videos);
DataHelper.setFavoriteVideo(getActivity().getContentResolver(), item.getId(), true);
}
}
}
}
use of com.squareup.otto.Subscribe in project zype-android by zype.
the class PlaylistActivity method handleRetrievePlaylist.
@Subscribe
public void handleRetrievePlaylist(PlaylistEvent event) {
Logger.d("Activity handlePlaylistEvent size=" + event.getEventData().getModelData().getResponse().size());
Playlist data = event.getEventData().getModelData();
if (data.getResponse().size() > 0) {
if (mPlaylistList == null) {
mPlaylistList = new ArrayList<>();
}
mPlaylistList.addAll(data.getResponse());
// with platform in case some palylists were deleted
if (event.getEventData().getModelData().getPagination().getCurrent() == 1) {
DataHelper.deletePlaylistsByParentId(this.getContentResolver(), parentId);
}
int i = DataHelper.insertPlaylists(this.getContentResolver(), data.getResponse());
Logger.d("added " + i + " playlists");
} else {
mTvEmpty.setText(R.string.videos_empty);
}
}
use of com.squareup.otto.Subscribe in project developmentDependencyLibrary by MatchlessBrother.
the class FileExplorerActivity method onClickFile.
@Subscribe
public void onClickFile(FileExplorerEvents.OnClickFile event) {
File f = event.mFile;
try {
f = f.getAbsoluteFile();
f = f.getCanonicalFile();
if (TextUtils.isEmpty(f.toString()))
f = new File("/");
} catch (IOException e) {
e.printStackTrace();
}
if (f.isDirectory()) {
String path = f.toString();
mSettings.setLastDirectory(path);
doOpenDirectory(path, true);
} else if (f.exists()) {
VideoActivity.intentTo(this, f.getPath(), f.getName());
}
}
use of com.squareup.otto.Subscribe in project open-event-android by fossasia.
the class MainActivity method handleJsonEvent.
@Subscribe
public void handleJsonEvent(final JsonReadEvent jsonReadEvent) {
final String name = jsonReadEvent.getName();
final String json = jsonReadEvent.getJson();
disposable.add(Completable.fromAction(() -> {
ObjectMapper objectMapper = APIClient.getObjectMapper();
// Need separate instance for background thread
Realm realm = Realm.getDefaultInstance();
RealmDataRepository realmDataRepository = RealmDataRepository.getInstance(realm);
switch(name) {
case ConstantStrings.EVENT:
{
Event event = objectMapper.readValue(json, Event.class);
saveEventDates(event);
realmDataRepository.saveEvent(event).subscribe();
realmDataRepository.saveEvent(event).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new EventDownloadEvent(true));
break;
}
case ConstantStrings.TRACKS:
{
List<Track> tracks = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Track.class));
realmDataRepository.saveTracks(tracks).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new TracksDownloadEvent(true));
break;
}
case ConstantStrings.SESSIONS:
{
List<Session> sessions = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Session.class));
for (Session current : sessions) {
current.setStartDate(current.getStartsAt().split("T")[0]);
}
realmDataRepository.saveSessions(sessions).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SessionDownloadEvent(true));
break;
}
case ConstantStrings.SPEAKERS:
{
List<Speaker> speakers = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Speaker.class));
realmRepo.saveSpeakers(speakers).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SpeakerDownloadEvent(true));
break;
}
case ConstantStrings.SPONSORS:
{
List<Sponsor> sponsors = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Sponsor.class));
realmRepo.saveSponsors(sponsors).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SponsorDownloadEvent(true));
break;
}
case ConstantStrings.MICROLOCATIONS:
{
List<Microlocation> microlocations = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Microlocation.class));
realmRepo.saveLocations(microlocations).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new MicrolocationDownloadEvent(true));
break;
}
case ConstantStrings.SESSION_TYPES:
{
List<SessionType> sessionTypes = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, SessionType.class));
realmRepo.saveSessionTypes(sessionTypes).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SessionTypesDownloadEvent(true));
break;
}
default:
}
realm.close();
}).observeOn(Schedulers.computation()).subscribe(() -> Timber.d("Saved event from JSON"), throwable -> {
throwable.printStackTrace();
Timber.e(throwable);
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new RetrofitError(throwable));
}));
}
use of com.squareup.otto.Subscribe in project FluxyAndroidTodo by armueller.
the class TodoListManagerTest method completeTodoTest.
@Test(timeout = 100)
public void completeTodoTest() throws InterruptedException {
final AtomicBoolean testDone = new AtomicBoolean(false);
final ArrayList<TodoItem> todoItems = new ArrayList<TodoItem>();
createTodos(2);
dataBus.register(new Object() {
@Subscribe
public void onListUpdated(RawTodoList rawTodoList) {
todoItems.clear();
todoItems.addAll(rawTodoList.list);
if (!todoItems.get(1).isComplete()) {
DataBundle<TodoAction.DataKeys> bundle = new DataBundle<>();
bundle.put(TodoAction.DataKeys.ID, todoItems.get(1).getId());
actionBus.post(new TodoAction(TodoAction.ActionTypes.TOGGLE, bundle));
} else {
assertThat(todoItems.get(0).isComplete()).isFalse();
assertThat(todoItems.get(1).isComplete()).isTrue();
testDone.set(true);
}
}
});
// Wait for test to finish or timeout
while (!testDone.get()) ;
}
Aggregations