Search in sources :

Example 1 with Preferences

use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.

the class SetupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup);
    mJsonStorage = new JsonStorage(this);
    mPreferences = new Preferences(this);
    // Forced logging due to user not being able to set/unset it at this point.
    mRemoteLogger = new RemoteLogger(SetupActivity.class).forceRemoteLogging(true);
    Fragment gotoFragment = null;
    Integer fragmentId = null;
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        fragmentId = bundle.getInt("fragment");
        mActivityToReturnToName = bundle.getString("activity");
        if (fragmentId == R.id.fragment_voip_account_missing) {
            gotoFragment = ((SetUpVoipAccountFragment) getFragmentManager().findFragmentById(fragmentId)).newInstance();
        } else if (fragmentId == R.id.fragment_account) {
            SystemUser systemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
            gotoFragment = ((AccountFragment) getFragmentManager().findFragmentById(fragmentId)).newInstance(systemUser.getMobileNumber(), systemUser.getOutgoingCli());
        }
    }
    if (findViewById(R.id.fragment_container) != null) {
        if (gotoFragment == null) {
            gotoFragment = LogoFragment.newInstance();
        }
        if (fragmentId != null && fragmentId == R.id.fragment_account) {
            swapFragment(gotoFragment, AccountFragment.class.getSimpleName());
        } else {
            swapFragment(gotoFragment, gotoFragment.getClass().getSimpleName());
        }
    }
}
Also used : Bundle(android.os.Bundle) SystemUser(com.voipgrid.vialer.api.models.SystemUser) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) JsonStorage(com.voipgrid.vialer.util.JsonStorage) Preferences(com.voipgrid.vialer.Preferences) Fragment(android.app.Fragment)

Example 2 with Preferences

use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.

the class ConnectivityHelper method hasFastData.

/**
 * Check if the device is connected via wifi or LTE connection.
 * @return
 */
public boolean hasFastData() {
    Preferences pref = new Preferences(mContext);
    Connection connectionType = getConnectionType();
    return sFastDataTypes.contains(connectionType) || (sFast3GDataTypes.contains(connectionType) && pref.has3GEnabled());
}
Also used : Preferences(com.voipgrid.vialer.Preferences)

Example 3 with Preferences

use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.

the class LoginRequiredActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    Preferences prefs = new Preferences(this);
    if (!prefs.isLoggedIn() && prefs.finishedOnboarding()) {
        new RemoteLogger(LoginRequiredActivity.class).w("Not logged in anymore! Redirecting to onboarding");
        // Go to onboarding.
        Intent intent = new Intent(new Intent(this, SetupActivity.class));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        finish();
    }
}
Also used : SetupActivity(com.voipgrid.vialer.onboarding.SetupActivity) Intent(android.content.Intent) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) Preferences(com.voipgrid.vialer.Preferences)

Example 4 with Preferences

use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.

the class WelcomeFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPreferences = new Preferences(getActivity());
}
Also used : Preferences(com.voipgrid.vialer.Preferences)

Example 5 with Preferences

use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.

the class MiddlewareHelper method register.

public static void register(final Context context, String token) {
    Preferences sipPreferences = new Preferences(context);
    Tracker analyticsTracker = ((AnalyticsApplication) context.getApplicationContext()).getDefaultTracker();
    final AnalyticsHelper analyticsHelper = new AnalyticsHelper(analyticsTracker);
    if (!sipPreferences.canUseSip()) {
        return;
    }
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    final SharedPreferences.Editor editor = preferences.edit();
    editor.putLong(LAST_REGISTRATION, System.currentTimeMillis());
    JsonStorage jsonStorage = new JsonStorage(context);
    AccountHelper accountHelper = new AccountHelper(context);
    if (!jsonStorage.has(PhoneAccount.class)) {
        return;
    }
    Registration api = ServiceGenerator.createService(context, Registration.class, getBaseApiUrl(context), accountHelper.getEmail(), accountHelper.getPassword());
    String sipUserId = ((PhoneAccount) jsonStorage.get(PhoneAccount.class)).getAccountId();
    String fullName = ((SystemUser) jsonStorage.get(SystemUser.class)).getFullName();
    String appName = context.getPackageName();
    Call<ResponseBody> call = api.register(fullName, token, sipUserId, Build.VERSION.CODENAME, Build.VERSION.RELEASE, appName);
    editor.putString(CURRENT_TOKEN, token);
    call.enqueue(new Callback<ResponseBody>() {

        @Override
        public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
            if (response.isSuccessful()) {
                setRegistrationStatus(context, STATUS_REGISTERED);
            } else {
                setRegistrationStatus(context, STATUS_FAILED);
                analyticsHelper.sendException(context.getString(R.string.analytics_event_description_registration_failed));
            }
            editor.apply();
        }

        @Override
        public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
            t.printStackTrace();
            setRegistrationStatus(context, STATUS_FAILED);
        }
    });
}
Also used : Tracker(com.google.android.gms.analytics.Tracker) AccountHelper(com.voipgrid.vialer.util.AccountHelper) SharedPreferences(android.content.SharedPreferences) ResponseBody(okhttp3.ResponseBody) PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) AnalyticsApplication(com.voipgrid.vialer.analytics.AnalyticsApplication) Registration(com.voipgrid.vialer.api.Registration) SystemUser(com.voipgrid.vialer.api.models.SystemUser) SharedPreferences(android.content.SharedPreferences) Preferences(com.voipgrid.vialer.Preferences) JsonStorage(com.voipgrid.vialer.util.JsonStorage) AnalyticsHelper(com.voipgrid.vialer.analytics.AnalyticsHelper)

Aggregations

Preferences (com.voipgrid.vialer.Preferences)8 RemoteLogger (com.voipgrid.vialer.logging.RemoteLogger)4 PhoneAccount (com.voipgrid.vialer.api.models.PhoneAccount)3 JsonStorage (com.voipgrid.vialer.util.JsonStorage)3 SharedPreferences (android.content.SharedPreferences)2 Registration (com.voipgrid.vialer.api.Registration)2 SystemUser (com.voipgrid.vialer.api.models.SystemUser)2 AccountHelper (com.voipgrid.vialer.util.AccountHelper)2 ResponseBody (okhttp3.ResponseBody)2 Fragment (android.app.Fragment)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 TelephonyManager (android.telephony.TelephonyManager)1 Tracker (com.google.android.gms.analytics.Tracker)1 AnalyticsApplication (com.voipgrid.vialer.analytics.AnalyticsApplication)1 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)1 NativeCallManager (com.voipgrid.vialer.call.NativeCallManager)1 ToneGenerator (com.voipgrid.vialer.dialer.ToneGenerator)1