Search in sources :

Example 1 with ShowNetworkDialogEvent

use of org.fossasia.openevent.common.events.ShowNetworkDialogEvent in project open-event-android by fossasia.

the class MainActivity method errorHandlerEvent.

@Subscribe
public void errorHandlerEvent(RetrofitError error) {
    String errorType;
    String errorDesc;
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netinfo = connMgr != null ? connMgr.getActiveNetworkInfo() : null;
    if (!(netinfo != null && netinfo.isConnected())) {
        StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new ShowNetworkDialogEvent());
    } else {
        if (error.getThrowable() instanceof IOException) {
            errorType = "Timeout";
            errorDesc = String.valueOf(error.getThrowable().getCause());
        } else if (error.getThrowable() instanceof IllegalStateException) {
            errorType = "ConversionError";
            errorDesc = String.valueOf(error.getThrowable().getCause());
        } else {
            errorType = "Other Error";
            errorDesc = String.valueOf(error.getThrowable().getLocalizedMessage());
        }
        Timber.tag(errorType).e(errorDesc);
        showErrorSnackbar(errorType, errorDesc);
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) ShowNetworkDialogEvent(org.fossasia.openevent.common.events.ShowNetworkDialogEvent) IOException(java.io.IOException) Subscribe(com.squareup.otto.Subscribe)

Example 2 with ShowNetworkDialogEvent

use of org.fossasia.openevent.common.events.ShowNetworkDialogEvent in project open-event-android by fossasia.

the class MainActivity method showNetworkDialog.

@Subscribe
public void showNetworkDialog(ShowNetworkDialogEvent event) {
    completeHandler.hide();
    if (dialogNetworkNotification == null) {
        dialogNetworkNotification = DialogFactory.createCancellableSimpleActionDialog(this, R.string.net_unavailable, R.string.turn_on, R.string.ok, R.string.cancel, (dialogInterface, button) -> {
            switch(button) {
                case DialogInterface.BUTTON_POSITIVE:
                    Intent setNetworkIntent = new Intent(Settings.ACTION_SETTINGS);
                    startActivity(setNetworkIntent);
                    break;
                case DialogInterface.BUTTON_NEGATIVE:
                    dialogNetworkNotification.dismiss();
                    return;
                default:
            }
        });
    }
    dialogNetworkNotification.show();
}
Also used : Bundle(android.os.Bundle) Completable(io.reactivex.Completable) ImageView(android.widget.ImageView) DataDownloadEvent(org.fossasia.openevent.common.events.DataDownloadEvent) Track(org.fossasia.openevent.data.Track) Handler(android.os.Handler) ConnectivityManager(android.net.ConnectivityManager) SmoothActionBarDrawerToggle(org.fossasia.openevent.common.ui.SmoothActionBarDrawerToggle) Realm(io.realm.Realm) TracksDownloadEvent(org.fossasia.openevent.common.events.TracksDownloadEvent) SessionType(org.fossasia.openevent.data.SessionType) Fragment(android.support.v4.app.Fragment) LocationsFragment(org.fossasia.openevent.core.location.LocationsFragment) Snackbar(android.support.design.widget.Snackbar) DialogFactory(org.fossasia.openevent.common.ui.DialogFactory) Sponsor(org.fossasia.openevent.data.Sponsor) ConstantStrings(org.fossasia.openevent.common.ConstantStrings) FacebookApi(org.fossasia.openevent.core.feed.facebook.api.FacebookApi) ButterKnife(butterknife.ButterKnife) UserProfileActivity(org.fossasia.openevent.core.auth.profile.UserProfileActivity) Dialog(android.app.Dialog) SponsorsFragment(org.fossasia.openevent.core.sponsor.SponsorsFragment) BaseActivity(org.fossasia.openevent.common.ui.base.BaseActivity) CommonTaskLoop(org.fossasia.openevent.common.utils.CommonTaskLoop) SpeakerDownloadEvent(org.fossasia.openevent.common.events.SpeakerDownloadEvent) Menu(android.view.Menu) DownloadCompleteHandler(org.fossasia.openevent.common.api.DownloadCompleteHandler) Settings(android.provider.Settings) Observable(io.reactivex.Observable) DrawerLayout(android.support.v4.widget.DrawerLayout) StrategyRegistry(org.fossasia.openevent.config.StrategyRegistry) ComponentName(android.content.ComponentName) DataDownloadManager(org.fossasia.openevent.common.api.DataDownloadManager) TextUtils(android.text.TextUtils) IOException(java.io.IOException) CounterEvent(org.fossasia.openevent.common.events.CounterEvent) Subscribe(com.squareup.otto.Subscribe) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) Toolbar(android.support.v7.widget.Toolbar) Microlocation(org.fossasia.openevent.data.Microlocation) Session(org.fossasia.openevent.data.Session) JsonReadEvent(org.fossasia.openevent.common.events.JsonReadEvent) RealmDataRepository(org.fossasia.openevent.data.repository.RealmDataRepository) EditText(android.widget.EditText) NavigationView(android.support.design.widget.NavigationView) Rect(android.graphics.Rect) SocialLink(org.fossasia.openevent.data.extras.SocialLink) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SessionDownloadEvent(org.fossasia.openevent.common.events.SessionDownloadEvent) BindView(butterknife.BindView) TracksFragment(org.fossasia.openevent.core.track.TracksFragment) SettingsActivity(org.fossasia.openevent.core.settings.SettingsActivity) EventDownloadEvent(org.fossasia.openevent.common.events.EventDownloadEvent) CustomTabsServiceConnection(android.support.customtabs.CustomTabsServiceConnection) APIClient(org.fossasia.openevent.common.api.APIClient) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) CustomTabsClient(android.support.customtabs.CustomTabsClient) R(org.fossasia.openevent.R) RetrofitResponseEvent(org.fossasia.openevent.common.events.RetrofitResponseEvent) NetworkInfo(android.net.NetworkInfo) SponsorDownloadEvent(org.fossasia.openevent.common.events.SponsorDownloadEvent) Urls(org.fossasia.openevent.common.api.Urls) DiscountCodeFragment(org.fossasia.openevent.core.discount.DiscountCodeFragment) ScheduleFragment(org.fossasia.openevent.core.schedule.ScheduleFragment) SharedPreferencesUtil(org.fossasia.openevent.common.utils.SharedPreferencesUtil) Timber(timber.log.Timber) AuthUtil(org.fossasia.openevent.core.auth.AuthUtil) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) NetworkUtils(org.fossasia.openevent.common.network.NetworkUtils) Nullable(android.support.annotation.Nullable) AboutFragment(org.fossasia.openevent.core.about.AboutFragment) ShowNetworkDialogEvent(org.fossasia.openevent.common.events.ShowNetworkDialogEvent) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) DownloadEvent(org.fossasia.openevent.common.events.DownloadEvent) Utils(org.fossasia.openevent.common.utils.Utils) RealmList(io.realm.RealmList) ZoomableImageUtil(org.fossasia.openevent.common.ui.image.ZoomableImageUtil) Intent(android.content.Intent) FAQFragment(org.fossasia.openevent.core.faqs.FAQFragment) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) GravityCompat(android.support.v4.view.GravityCompat) RetrofitError(org.fossasia.openevent.common.events.RetrofitError) Event(org.fossasia.openevent.data.Event) MotionEvent(android.view.MotionEvent) NotificationsFragment(org.fossasia.openevent.core.notifications.NotificationsFragment) Speaker(org.fossasia.openevent.data.Speaker) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ActionBar(android.support.v7.app.ActionBar) EventLoadedEvent(org.fossasia.openevent.common.events.EventLoadedEvent) DialogInterface(android.content.DialogInterface) MicrolocationDownloadEvent(org.fossasia.openevent.common.events.MicrolocationDownloadEvent) RealmResults(io.realm.RealmResults) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateConverter(org.fossasia.openevent.common.date.DateConverter) NoInternetEvent(org.fossasia.openevent.common.events.NoInternetEvent) FeedFragment(org.fossasia.openevent.core.feed.FeedFragment) SessionTypesDownloadEvent(org.fossasia.openevent.common.events.SessionTypesDownloadEvent) SpeakersListFragment(org.fossasia.openevent.core.speaker.SpeakersListFragment) InputStream(java.io.InputStream) Intent(android.content.Intent) Subscribe(com.squareup.otto.Subscribe)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)2 NetworkInfo (android.net.NetworkInfo)2 Subscribe (com.squareup.otto.Subscribe)2 IOException (java.io.IOException)2 ShowNetworkDialogEvent (org.fossasia.openevent.common.events.ShowNetworkDialogEvent)2 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Rect (android.graphics.Rect)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Settings (android.provider.Settings)1 Nullable (android.support.annotation.Nullable)1 CustomTabsClient (android.support.customtabs.CustomTabsClient)1 CustomTabsServiceConnection (android.support.customtabs.CustomTabsServiceConnection)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1