use of com.voipgrid.vialer.api.models.FixedDestination in project vialer-android by VoIPGRID.
the class NavigationDrawerActivity method onItemSelected.
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (mFirstTimeOnItemSelected) {
mFirstTimeOnItemSelected = false;
} else {
if (parent.getCount() - 1 == position) {
startWebActivity(getString(R.string.add_destination_title), getString(R.string.web_add_destination), getString(R.string.analytics_add_destination_title));
} else {
Destination destination = (Destination) parent.getAdapter().getItem(position);
if (destination.getDescription().equals(getString(R.string.not_available))) {
MiddlewareHelper.unregister(this);
}
SelectedUserDestinationParams params = new SelectedUserDestinationParams();
params.fixedDestination = destination instanceof FixedDestination ? destination.getId() : null;
params.phoneAccount = destination instanceof PhoneAccount ? destination.getId() : null;
Call<Object> call = mApi.setSelectedUserDestination(mSelectedUserDestinationId, params);
call.enqueue(this);
if (!MiddlewareHelper.isRegistered(this)) {
// If the previous destination was not available, or if we're not registered
// for another reason, register again.
MiddlewareHelper.registerAtMiddleware(this);
}
}
}
}
use of com.voipgrid.vialer.api.models.FixedDestination 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);
}
}
Aggregations