Search in sources :

Example 46 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project krypton-android by kryptco.

the class MemberQR method onCreateClient.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onCreateClient(TeamService.GenerateClientResult r) {
    if (r.c.error != null) {
        Error.shortToast(getContext(), r.c.error);
        Transitions.beginFade(this).remove(this).commitAllowingStateLoss();
        return;
    }
    Sigchain.Identity identity = r.c.success;
    Sigchain.MemberQRPayload memberQRPayload = new Sigchain.MemberQRPayload(identity.email, identity.publicKey);
    Sigchain.QRPayload qrPayload = new Sigchain.QRPayload(memberQRPayload);
    try {
        BitMatrix qrData = new QRCodeWriter().encode(JSON.toJson(qrPayload), BarcodeFormat.DATA_MATRIX.QR_CODE, 500, 500);
        qr.setImageBitmap(new BarcodeEncoder().createBitmap(qrData));
        qrPayloads.set(new QRPayloads(memberQRPayload, MemberScan.lastScannedPayload.get()));
        loadQRProgress.setAlpha(0);
        joinProgress.animate().setDuration(1000).alpha(1).start();
        new JoinTeamProgress(getContext()).updateTeamData((s, d) -> {
            d.identity = identity;
            d.teamName = qrPayloads.get().admin.teamName;
            return s;
        });
    } catch (WriterException e) {
        e.printStackTrace();
        Error.shortToast(getContext(), "Error creating QRCode");
        Transitions.beginFade(this).remove(this).commitAllowingStateLoss();
        return;
    }
    EventBus.getDefault().post(new PollRead());
}
Also used : Sigchain(co.krypt.krypton.team.Sigchain) BarcodeEncoder(com.journeyapps.barcodescanner.BarcodeEncoder) JoinTeamProgress(co.krypt.krypton.team.onboarding.join.JoinTeamProgress) BitMatrix(com.google.zxing.common.BitMatrix) QRCodeWriter(com.google.zxing.qrcode.QRCodeWriter) WriterException(com.google.zxing.WriterException) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 47 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project osm-contributor by jawg.

the class MapActivity method onPleaseInitializeDrawer.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseInitializeDrawer(PleaseInitializeDrawer event) {
    Timber.d("initializing drawer with poiType");
    if (filtersItemList == null) {
        filtersItemList = new ArrayList<>();
    }
    List<PoiType> poiTypes = event.getPoiTypes();
    poiTypesHidden = event.getPoiTypeHidden();
    filters.clear();
    for (PoiType poiType : poiTypes) {
        Long id = poiType.getId();
        filters.add(new PoiTypeFilter(poiType.getName(), id, poiType.getIcon(), !poiTypesHidden.contains(id)));
    }
    Collections.sort(filters);
    Menu menu = filterView.getMenu();
    int order = 1;
    for (PoiTypeFilter poiTypeFilter : filters) {
        PoiTypeFilter nextPoiTypeFilter = null;
        if (order < filters.size()) {
            nextPoiTypeFilter = filters.get(order);
        }
        // Add only menu if not present
        if (menu.findItem(poiTypeFilter.getPoiTypeId().intValue()) == null) {
            filtersItemList.add(menu.add(Menu.NONE, poiTypeFilter.getPoiTypeId().intValue(), (nextPoiTypeFilter != null ? (poiTypeFilter.compareTo(nextPoiTypeFilter) > 0 ? order - 1 : order) : order), poiTypeFilter.getPoiTypeName()).setChecked(poiTypeFilter.isActive()).setIcon(bitmapHandler.getDrawable(poiTypeFilter.getPoiTypeIconName())));
        }
        order++;
    }
    // Remove only filter removed by user
    if (filters.size() < filtersItemList.size()) {
        List<MenuItem> temp = new ArrayList<>(filters.size());
        for (MenuItem menuItem : filtersItemList) {
            PoiTypeFilter poiTypeFilter = new PoiTypeFilter("", (long) menuItem.getItemId(), "", true);
            if (!filters.contains(poiTypeFilter)) {
                menu.removeItem(poiTypeFilter.getPoiTypeId().intValue());
            } else {
                temp.add(menuItem);
            }
        }
        filtersItemList.clear();
        filtersItemList.addAll(temp);
        temp.clear();
    }
    selectAllMenuItem.setChecked(poiTypesHidden.isEmpty());
}
Also used : PoiTypeFilter(io.jawg.osmcontributor.ui.utils.PoiTypeFilter) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) Menu(android.view.Menu) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 48 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project osm-contributor by jawg.

the class EditPoiFragment method onPoiForEditionLoadedEvent.

/*=========================================*/
/*------------------EVENTS-----------------*/
/*=========================================*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPoiForEditionLoadedEvent(PoiForEditionLoadedEvent event) {
    poi = event.getPoi();
    // Set the poitype name in the action bar
    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (actionBar != null) {
        actionBar.setSubtitle(poi.getType().getName());
    }
    Log.i(TAG, "onPoiForEditionLoadedEvent: " + poi);
    tagsAdapter = new TagsAdapter(poi, tagItemList, getActivity(), event.getValuesMap(), sharedPreferences.getBoolean(getString(R.string.shared_prefs_expert_mode), false));
    recyclerView.setAdapter(tagsAdapter);
}
Also used : TagsAdapter(io.jawg.osmcontributor.ui.adapters.TagsAdapter) AppCompatActivity(android.support.v7.app.AppCompatActivity) ActionBar(android.support.v7.app.ActionBar) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 49 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project osm-contributor by jawg.

the class MyPreferenceFragment method onGoogleAuthenticatedEvent.

@Subscribe
public void onGoogleAuthenticatedEvent(GoogleAuthenticatedEvent event) {
    if (event.isSuccessful()) {
        Snackbar.make(getView(), R.string.valid_login, Snackbar.LENGTH_SHORT).show();
        bus.post(new UpdateGoogleCredentialsEvent(event.getToken(), event.getTokenSecret(), event.getConsumer(), event.getConsumerSecret()));
    } else {
        Snackbar.make(getView(), R.string.error_login, Snackbar.LENGTH_SHORT).show();
    }
}
Also used : UpdateGoogleCredentialsEvent(io.jawg.osmcontributor.ui.events.login.UpdateGoogleCredentialsEvent) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 50 with Subscribe

use of org.greenrobot.eventbus.Subscribe in project osm-contributor by jawg.

the class EditPoiManager method onPleaseCreatePoiEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseCreatePoiEvent(PleaseCreatePoiEvent event) {
    Timber.d("Please create poi");
    Poi poi = event.getPoi();
    poi.setUpdated(true);
    poi.applyChanges(event.getPoiChanges().getTagsMap());
    poi.applyChanges(applyConstraints(poi));
    poiManager.savePoi(poi);
    poiManager.updatePoiTypeLastUse(poi.getType().getId());
    eventBus.post(new PoiChangesApplyEvent());
}
Also used : PoiChangesApplyEvent(io.jawg.osmcontributor.ui.events.edition.PoiChangesApplyEvent) Poi(io.jawg.osmcontributor.model.entities.Poi) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

Subscribe (org.greenrobot.eventbus.Subscribe)164 Intent (android.content.Intent)20 Bundle (android.os.Bundle)11 EventBus (org.greenrobot.eventbus.EventBus)10 ThreadMode (org.greenrobot.eventbus.ThreadMode)10 View (android.view.View)9 Poi (io.jawg.osmcontributor.model.entities.Poi)9 PoiType (io.jawg.osmcontributor.model.entities.PoiType)9 ArrayList (java.util.ArrayList)9 Context (android.content.Context)8 Handler (android.os.Handler)8 ViewGroup (android.view.ViewGroup)8 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)8 SuppressLint (android.annotation.SuppressLint)6 LayoutInflater (android.view.LayoutInflater)6 MenuItem (android.view.MenuItem)6 DownloaderUpdate (de.danoeh.antennapod.core.event.DownloaderUpdate)6 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)6 Disposable (io.reactivex.disposables.Disposable)6 Schedulers (io.reactivex.schedulers.Schedulers)6