daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.wsmodule.clients.observers;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.text.TextUtils;
  5. import android.widget.EditText;
  6.  
  7. import com.wsmodule.clients.R;
  8. import com.wsmodule.clients.models.CompanyModel;
  9. import com.wsmodule.clients.ui.viewmodel.ClientsViewModel;
  10. import com.wsmodule.structure.ui.dialogs.MessageDialog;
  11. import com.wsmodule.structure.ui.dialogs.ProgressDialog;
  12.  
  13. import io.reactivex.Observer;
  14. import io.reactivex.disposables.Disposable;
  15.  
  16. public class NipObserver implements Observer<CompanyModel> {
  17.  
  18.     private final ProgressDialog progressDialog;
  19.     private final AppCompatActivity context;
  20.  
  21.     public NipObserver(AppCompatActivity context, String nip, ClientsViewModel clientsViewModel) {
  22.         this.progressDialog = new ProgressDialog(context, context.getResources()
  23.                 .getString(R.string.prosze_czekac));
  24.         this.context = context;
  25.         clientsViewModel.ceidg(nip, this);
  26.     }
  27.  
  28.     @Override
  29.     public void onSubscribe(Disposable d) {
  30.         this.progressDialog.show();
  31.     }
  32.  
  33.     @Override
  34.     public void onNext(CompanyModel companyModel) {
  35.         this.progressDialog.dismiss();
  36.         updateClientData(companyModel);
  37.     }
  38.  
  39.     private void updateClientData(CompanyModel companyModel) {
  40.         EditText nameEditText = context.findViewById(R.id.nameEditText);
  41.         EditText postCodeEditText = context.findViewById(R.id.postCodeEditText);
  42.         EditText cityEditText = context.findViewById(R.id.cityEditText);
  43.         EditText districtEditText = context.findViewById(R.id.districtEditText);
  44.         EditText addressEditText = context.findViewById(R.id.addressEditText);
  45.         EditText numberHouseEditText = context.findViewById(R.id.numberHouseEditText);
  46.         EditText apartmentEditText = context.findViewById(R.id.apartmentEditText);
  47.  
  48.         if (!TextUtils.isEmpty(companyModel.name)) {
  49.             nameEditText.setText(companyModel.name);
  50.         }
  51.         if (!TextUtils.isEmpty(companyModel.postCode)) {
  52.             postCodeEditText.setText(companyModel.postCode);
  53.         }
  54.         if (!TextUtils.isEmpty(companyModel.city)) {
  55.             cityEditText.setText(companyModel.city);
  56.         }
  57.         if (!TextUtils.isEmpty(companyModel.province)) {
  58.             districtEditText.setText(companyModel.province);
  59.         }
  60.         if (!TextUtils.isEmpty(companyModel.street)) {
  61.             addressEditText.setText(companyModel.street);
  62.         }
  63.         if (!TextUtils.isEmpty(companyModel.buildingNumber)) {
  64.             numberHouseEditText.setText(companyModel.buildingNumber);
  65.         }
  66.         if (!TextUtils.isEmpty(companyModel.localNumber)) {
  67.             apartmentEditText.setText(companyModel.localNumber);
  68.         }
  69.     }
  70.  
  71.     @Override
  72.     public void onError(Throwable e) {
  73.         this.progressDialog.dismiss();
  74.         new MessageDialog(this.context, e.getMessage()).show();
  75.     }
  76.  
  77.     @Override
  78.     public void onComplete() {
  79.         this.progressDialog.dismiss();
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top