openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/ProviderRepository.java
/**
     * Delete providers.
     *
     * @param providerUuid the provider uuid
     * @param callback     the callback
     */
Delete providers.
@param providerUuid the provider uuid
@param callback     the callback
Delete providers . @param providerUuid the provider uuid @param callback the callback
public void deleteProviders(String providerUuid, DefaultResponseCallback callback) {
        if (NetworkUtils.isOnline()) {
            restApi.deleteProvider(providerUuid).enqueue(new Callback<ResponseBody>() {
                @Override
                public void onResponse(@NotNull Call<ResponseBody> call, @NotNull Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        providerRoomDao.deleteByUuid(providerUuid);
                        ToastUtil.success(context.getString(R.string.delete_provider_success_msg));
                        logger.e("Deleting Provider Successful " + response.raw());
                        callback.onResponse();
                    }
                }
                @Override
                public void onFailure(@NotNull Call<ResponseBody> call, @NotNull Throwable t) {
                    logger.e("Failed to delete provider. Error:  " + t.getMessage());
                    callback.onErrorResponse(context.getString(R.string.delete_provider_failure_msg));
                }
            });
        } else {
            Data data = new Data.Builder().putString("uuid", providerUuid).build();
            providerRoomDao.deleteByUuid(providerUuid);
            callback.onResponse();
            Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
            workManager.enqueue(new OneTimeWorkRequest.Builder(DeleteProviderWorker.class).setConstraints(constraints).setInputData(data).build());
            ToastUtil.success(context.getString(R.string.offline_provider_delete));
            logger.e("Provider will be removed from the server when you're back online");
        }
    }
public void deleteProviders ( String providerUuid , DefaultResponseCallback callback ) { if ( NetworkUtils . isOnline ( ) ) { restApi . deleteProvider ( providerUuid ) . enqueue ( new Callback < ResponseBody > ( ) { @ Override public void onResponse ( @ NotNull Call < ResponseBody > call , @ NotNull Response < ResponseBody > response ) { if ( response . isSuccessful ( ) ) { providerRoomDao . deleteByUuid ( providerUuid ) ; ToastUtil . success ( context . getString ( R . string . delete_provider_success_msg ) ) ; logger . e ( "Deleting Provider Successful " + response . raw ( ) ) ; callback . onResponse ( ) ; } } @ Override public void onFailure ( @ NotNull Call < ResponseBody > call , @ NotNull Throwable t ) { logger . e ( "Failed to delete provider. Error:  " + t . getMessage ( ) ) ; callback . onErrorResponse ( context . getString ( R . string . delete_provider_failure_msg ) ) ; } } ) ; } else { Data data = new Data . Builder ( ) . putString ( "uuid" , providerUuid ) . build ( ) ; providerRoomDao . deleteByUuid ( providerUuid ) ; callback . onResponse ( ) ; Constraints constraints = new Constraints . Builder ( ) . setRequiredNetworkType ( NetworkType . CONNECTED ) . build ( ) ; workManager . enqueue ( new OneTimeWorkRequest . Builder ( DeleteProviderWorker . class ) . setConstraints ( constraints ) . setInputData ( data ) . build ( ) ) ; ToastUtil . success ( context . getString ( R . string . offline_provider_delete ) ) ; logger . e ( "Provider will be removed from the server when you're back online" ) ; } }
Delete providers.
Delete providers .
//when callback would call onResponse successfull the UI will refresh automatically // offline deletion // offline deletion // enqueue the work to workManager //toast about deferred provider deletion