Search in sources :

Example 1 with VoipGridResponse

use of com.voipgrid.vialer.api.models.VoipGridResponse in project vialer-android by VoIPGRID.

the class CallRecordFragment method loadCallRecordsFromApi.

private void loadCallRecordsFromApi() {
    mHaveNetworkRecords = false;
    AccountHelper accountHelper = new AccountHelper(getActivity());
    Api api = ServiceGenerator.createService(getContext(), Api.class, getString(R.string.api_url), accountHelper.getEmail(), accountHelper.getPassword());
    Call<VoipGridResponse<CallRecord>> call = api.getRecentCalls(50, 0, CallRecord.getLimitDate());
    call.enqueue(this);
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) VoipGridResponse(com.voipgrid.vialer.api.models.VoipGridResponse) Api(com.voipgrid.vialer.api.Api)

Example 2 with VoipGridResponse

use of com.voipgrid.vialer.api.models.VoipGridResponse in project vialer-android by VoIPGRID.

the class NavigationDrawerActivity method onResponse.

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
    if (!response.isSuccessful()) {
        if (mDrawerLayout != null && mDrawerLayout.isDrawerVisible(GravityCompat.START)) {
            Toast.makeText(this, getString(R.string.set_userdestination_api_fail), Toast.LENGTH_LONG).show();
        }
        if (!mConnectivityHelper.hasNetworkConnection()) {
            // First check if there is a entry already to avoid duplicates.
            if (mSpinner != null && mNoConnectionText != null) {
                mSpinner.setVisibility(View.GONE);
                mNoConnectionText.setVisibility(View.VISIBLE);
            }
        }
    }
    if (response.body() instanceof VoipGridResponse) {
        List<UserDestination> userDestinationObjects = ((VoipGridResponse<UserDestination>) response.body()).getObjects();
        if (userDestinationObjects == null || userDestinationObjects.size() <= 0 || mSpinnerAdapter == null) {
            return;
        }
        UserDestination userDestination = userDestinationObjects.get(0);
        // Create not available destination.
        Destination notAvailableDestination = new FixedDestination();
        notAvailableDestination.setDescription(getString(R.string.not_available));
        // Clear old list and add the not available destination.
        mSpinnerAdapter.clear();
        mSpinnerAdapter.add(notAvailableDestination);
        // Set current destination.
        mSelectedUserDestinationId = userDestination.getSelectedUserDestination().getId();
        Destination activeDestination = userDestination.getActiveDestination();
        List<Destination> destinations = userDestination.getDestinations();
        int activeIndex = 0;
        // Add all possible destinations to array.
        for (int i = 0, size = destinations.size(); i < size; i++) {
            Destination destination = destinations.get(i);
            mSpinnerAdapter.add(destination);
            if (activeDestination != null && destination.getId().equals(activeDestination.getId())) {
                activeIndex = i + 1;
            }
        }
        // Create add destination field.
        Destination addDestination = new FixedDestination();
        String addDestinationText = getString(R.string.fa_plus_circle) + "   " + getString(R.string.add_availability);
        addDestination.setDescription(addDestinationText);
        mSpinnerAdapter.add(addDestination);
        mSpinnerAdapter.notifyDataSetChanged();
        mSpinner.setSelection(activeIndex);
    }
}
Also used : VoipGridResponse(com.voipgrid.vialer.api.models.VoipGridResponse) FixedDestination(com.voipgrid.vialer.api.models.FixedDestination) Destination(com.voipgrid.vialer.api.models.Destination) UserDestination(com.voipgrid.vialer.api.models.UserDestination) FixedDestination(com.voipgrid.vialer.api.models.FixedDestination) UserDestination(com.voipgrid.vialer.api.models.UserDestination)

Example 3 with VoipGridResponse

use of com.voipgrid.vialer.api.models.VoipGridResponse in project vialer-android by VoIPGRID.

the class NavigationDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mConnectivityHelper = new ConnectivityHelper((ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE), (TelephonyManager) getSystemService(TELEPHONY_SERVICE));
    mJsonStorage = new JsonStorage(this);
    mSystemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
    if (mSystemUser != null && !TextUtils.isEmpty(getPassword())) {
        mApi = ServiceGenerator.createService(this, Api.class, getString(R.string.api_url), getEmail(), getPassword());
        // Preload availability.
        Call<VoipGridResponse<UserDestination>> call = mApi.getUserDestination();
        call.enqueue(this);
    }
}
Also used : VoipGridResponse(com.voipgrid.vialer.api.models.VoipGridResponse) ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) TelephonyManager(android.telephony.TelephonyManager) ConnectivityManager(android.net.ConnectivityManager) Api(com.voipgrid.vialer.api.Api) JsonStorage(com.voipgrid.vialer.util.JsonStorage)

Aggregations

VoipGridResponse (com.voipgrid.vialer.api.models.VoipGridResponse)3 Api (com.voipgrid.vialer.api.Api)2 ConnectivityManager (android.net.ConnectivityManager)1 TelephonyManager (android.telephony.TelephonyManager)1 Destination (com.voipgrid.vialer.api.models.Destination)1 FixedDestination (com.voipgrid.vialer.api.models.FixedDestination)1 UserDestination (com.voipgrid.vialer.api.models.UserDestination)1 AccountHelper (com.voipgrid.vialer.util.AccountHelper)1 ConnectivityHelper (com.voipgrid.vialer.util.ConnectivityHelper)1 JsonStorage (com.voipgrid.vialer.util.JsonStorage)1