Search in sources :

Example 1 with EventBus

use of de.greenrobot.event.EventBus in project sharelock-android by auth0.

the class LinkFragment method onViewCreated.

@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final EventBus bus = this.bus;
    TextView secretText = (TextView) view.findViewById(R.id.link_secret_text);
    secretText.setText(secret.getSecret());
    ShareEditText shareEditText = (ShareEditText) view.findViewById(R.id.link_share_list);
    shareEditText.setFocusable(false);
    shareEditText.allowDuplicates(false);
    for (String viewer : secret.getAllowedViewers()) {
        shareEditText.addObject(viewer);
    }
    linkText = (TextView) view.findViewById(R.id.link_text);
    progressBar = (ProgressBar) view.findViewById(R.id.link_progress);
    retryButton = (Button) view.findViewById(R.id.link_retry_button);
    shareButton = (ImageButton) view.findViewById(R.id.link_share_button);
    newButton = (ImageButton) view.findViewById(R.id.link_new_button);
    buttons = (ViewGroup) view.findViewById(R.id.link_buttons);
    retryButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            bus.post(new RequestLinkEvent(secret));
        }
    });
    shareButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, link.toString());
            sendIntent.setType("text/plain");
            startActivity(Intent.createChooser(sendIntent, getString(R.string.share_link_chooser_title)));
        }
    });
    newButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.new_link_prompt_title).setMessage(R.string.new_link_prompt_message).setCancelable(true).setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bus.post(new RequestNewSecretEvent());
                }
            }).setNegativeButton(R.string.cancel_button, null).create();
            dialog.show();
        }
    });
    ImageView craftedBy = (ImageView) view.findViewById(R.id.crafted_by);
    craftedBy.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(getString(R.string.crafted_by_url)));
            startActivity(intent);
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) RequestNewSecretEvent(com.auth0.sharelock.event.RequestNewSecretEvent) Intent(android.content.Intent) EventBus(de.greenrobot.event.EventBus) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RequestLinkEvent(com.auth0.sharelock.event.RequestLinkEvent) ShareEditText(com.auth0.sharelock.widget.ShareEditText) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 2 with EventBus

use of de.greenrobot.event.EventBus in project sharelock-android by auth0.

the class ComposeActivity method onEvent.

public void onEvent(RequestLinkEvent event) {
    final Secret secret = event.getSecret();
    final EventBus bus = this.bus;
    SharedPreferences preferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
    client = new LinkAPIClient(preferences.getString(LinkAPIClient.SHARELOCK_ENDPOINT_KEY, LinkAPIClient.DEFAULT_URL));
    client.generateLinkForSecret(secret, this, new LinkAPIClient.LinkCallback() {

        @Override
        public void onSuccess(final Uri link) {
            Log.d(TAG, "Obtained link path " + link);
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    bus.postSticky(new NewLinkEvent(link));
                    final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    final ClipData clipData = ClipData.newRawUri("sharelocked-link", link);
                    clipboardManager.setPrimaryClip(clipData);
                    Snackbar snackbar = Snackbar.with(ComposeActivity.this).text(R.string.link_in_clipboard_message).duration(Snackbar.SnackbarDuration.LENGTH_SHORT);
                    SnackbarManager.show(snackbar);
                }
            }, DELAY_MILLIS);
        }

        @Override
        public void onError(Throwable reason) {
            Log.e(TAG, "Failed to generate link", reason);
            bus.post(new SharelockAPIErrorEvent());
            AlertDialog dialog = new AlertDialog.Builder(ComposeActivity.this).setTitle(R.string.link_generation_failed_title).setMessage(R.string.link_generation_failed).setCancelable(true).setPositiveButton(R.string.retry_button, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bus.post(new RequestLinkEvent(secret));
                }
            }).setNegativeButton(R.string.cancel_button, null).create();
            dialog.show();
        }
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) EventBus(de.greenrobot.event.EventBus) Uri(android.net.Uri) RequestLinkEvent(com.auth0.sharelock.event.RequestLinkEvent) NewLinkEvent(com.auth0.sharelock.event.NewLinkEvent) ClipData(android.content.ClipData) SharelockAPIErrorEvent(com.auth0.sharelock.event.SharelockAPIErrorEvent) Snackbar(com.nispok.snackbar.Snackbar)

Example 3 with EventBus

use of de.greenrobot.event.EventBus in project edx-app-android by edx.

the class NewVersionAvailableEventTest method postAndRemoveEvent.

/**
 * Post the provided data via the {@link NewVersionAvailableEvent#post(Version, Date, boolean)}
 * method, then remove the sticky event from the event bus.
 *
 * @param newVersion The new version.
 * @param lastSupportedDate The last supported date.
 * @param isUnsupported Whether the current version is unsupported.
 * @return The event that was posted. This can be null if the data does not constitute a valid
 * event.
 */
@Nullable
private static NewVersionAvailableEvent postAndRemoveEvent(@Nullable final Version newVersion, @Nullable final Date lastSupportedDate, final boolean isUnsupported) {
    // This will throw an AssumptionViolatedException if the Android runtime
    // isn't loaded (i.e. through using the Robolectric test runner).
    final EventBus eventBus = getEventBus();
    eventBus.removeStickyEvent(NewVersionAvailableEvent.class);
    final NewVersionAvailableEvent event = postEvent(newVersion, lastSupportedDate, isUnsupported);
    if (event != null) {
        assertTrue(eventBus.removeStickyEvent(event));
    }
    return event;
}
Also used : EventBus(de.greenrobot.event.EventBus) Nullable(android.support.annotation.Nullable)

Example 4 with EventBus

use of de.greenrobot.event.EventBus in project edx-app-android by edx.

the class NewVersionAvailableEventTest method postAndRemoveEventFromInterceptor.

/**
 * Post the provided data by passing the appropriate headers and status code in a request chain
 * through an {@link NewVersionBroadcastInterceptor}, then remove the sticky event from the
 * event bus.
 *
 * @param newVersion The new version.
 * @param lastSupportedDate The last supported date.
 * @param isUnsupported Whether the current version is unsupported.
 * @return The event that was posted. This can be null if the data does not constitute a valid
 * event.
 */
@Nullable
private static NewVersionAvailableEvent postAndRemoveEventFromInterceptor(@Nullable final Version newVersion, @Nullable final Date lastSupportedDate, final boolean isUnsupported) throws IOException {
    // This will throw an AssumptionViolatedException if the Android runtime
    // isn't loaded (i.e. through using the Robolectric test runner).
    final EventBus eventBus = getEventBus();
    eventBus.removeStickyEvent(NewVersionAvailableEvent.class);
    final NewVersionAvailableEvent event = postEventFromInterceptor(new NewVersionBroadcastInterceptor(), newVersion, lastSupportedDate, isUnsupported);
    if (event != null) {
        assertTrue(eventBus.removeStickyEvent(event));
    }
    return event;
}
Also used : EventBus(de.greenrobot.event.EventBus) NewVersionBroadcastInterceptor(org.edx.mobile.http.interceptor.NewVersionBroadcastInterceptor) Nullable(android.support.annotation.Nullable)

Example 5 with EventBus

use of de.greenrobot.event.EventBus in project edx-app-android by edx.

the class NewVersionAvailableEventTest method postEvent.

/**
 * Post the provided data via the {@link NewVersionAvailableEvent#post(Version, Date, boolean)}
 * method.
 *
 * @param newVersion The new version.
 * @param lastSupportedDate The last supported date.
 * @param isUnsupported Whether the current version is unsupported.
 * @return The posted event. This can be null if the data does not constitute a valid event.
 */
@Nullable
private static NewVersionAvailableEvent postEvent(@Nullable final Version newVersion, @Nullable final Date lastSupportedDate, final boolean isUnsupported) {
    // This will throw an AssumptionViolatedException if the Android runtime
    // isn't loaded (i.e. through using the Robolectric test runner).
    final EventBus eventBus = getEventBus();
    NewVersionAvailableEvent.post(newVersion, lastSupportedDate, isUnsupported);
    return eventBus.getStickyEvent(NewVersionAvailableEvent.class);
}
Also used : EventBus(de.greenrobot.event.EventBus) Nullable(android.support.annotation.Nullable)

Aggregations

EventBus (de.greenrobot.event.EventBus)7 Nullable (android.support.annotation.Nullable)4 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 RequestLinkEvent (com.auth0.sharelock.event.RequestLinkEvent)2 NewVersionBroadcastInterceptor (org.edx.mobile.http.interceptor.NewVersionBroadcastInterceptor)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NewLinkEvent (com.auth0.sharelock.event.NewLinkEvent)1 RequestNewSecretEvent (com.auth0.sharelock.event.RequestNewSecretEvent)1 SharelockAPIErrorEvent (com.auth0.sharelock.event.SharelockAPIErrorEvent)1 ShareEditText (com.auth0.sharelock.widget.ShareEditText)1 Snackbar (com.nispok.snackbar.Snackbar)1 Interceptor (okhttp3.Interceptor)1