Advertisement
AliImran96

fabric error

Oct 25th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.09 KB | None | 0 0
  1. package com.fabric.apps.mobile.activity;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.appcompat.widget.Toolbar;
  5. import androidx.recyclerview.widget.LinearLayoutManager;
  6. import androidx.recyclerview.widget.RecyclerView;
  7. import butterknife.BindView;
  8. import butterknife.ButterKnife;
  9. import retrofit2.Call;
  10. import retrofit2.Callback;
  11. import retrofit2.Response;
  12.  
  13. import android.content.Intent;
  14. import android.os.Bundle;
  15. import android.util.Log;
  16. import android.view.View;
  17. import android.widget.AdapterView;
  18. import android.widget.ArrayAdapter;
  19. import android.widget.Button;
  20. import android.widget.ImageButton;
  21. import android.widget.ImageView;
  22. import android.widget.LinearLayout;
  23. import android.widget.RadioButton;
  24. import android.widget.Spinner;
  25. import android.widget.TextView;
  26. import android.widget.Toast;
  27.  
  28. import com.fabric.apps.mobile.R;
  29. import com.fabric.apps.mobile.adapter.CartListAdapter;
  30. import com.fabric.apps.mobile.adapter.KurirListAdapter;
  31. import com.fabric.apps.mobile.connection.ConfigRetrofit;
  32. import com.fabric.apps.mobile.contoller.CartController;
  33. import com.fabric.apps.mobile.model.cartModel.CartItem;
  34. import com.fabric.apps.mobile.model.cartModel.ResponseCart;
  35. import com.fabric.apps.mobile.model.cekkurirModel.CostItemKurirModel;
  36. import com.fabric.apps.mobile.model.cekkurirModel.CostsItemKurirModel;
  37. import com.fabric.apps.mobile.model.cekkurirModel.ResponseKurirModel;
  38. import com.fabric.apps.mobile.utils.SessionSharedPreferences;
  39. import com.github.ybq.android.spinkit.SpinKitView;
  40.  
  41. import java.util.ArrayList;
  42. import java.util.List;
  43. import java.util.Objects;
  44.  
  45. public class CheckoutActivity extends AppCompatActivity implements View.OnClickListener{
  46.  
  47.     @BindView(R.id.toolbar)
  48.     Toolbar toolbar;
  49.  
  50.     @BindView(R.id.service_provider)
  51.     LinearLayout serviceWrapper;
  52.  
  53.     @BindView(R.id.product_list)
  54.     RecyclerView productList;
  55.  
  56.     @BindView(R.id.rb_jne)
  57.     RadioButton rbJne;
  58.  
  59.     @BindView(R.id.rb_pos)
  60.     RadioButton rbPos;
  61.  
  62.     @BindView(R.id.rb_tiki)
  63.     RadioButton rbTiki;
  64.  
  65.     @BindView(R.id.total_product_price)
  66.     TextView totalPrice;
  67.  
  68.     @BindView(R.id.service_price)
  69.     TextView servicePrice;
  70.  
  71.     @BindView(R.id.total_payment)
  72.     TextView totalPayment;
  73.  
  74.     @BindView(R.id.place_order)
  75.     Button placeOrder;
  76.  
  77.     @BindView(R.id.product_image)
  78.     ImageView productImage;
  79.  
  80.     @BindView(R.id.product_name)
  81.     TextView productName;
  82.  
  83.     @BindView(R.id.product_price)
  84.     TextView productPrice;
  85.  
  86.     @BindView(R.id.product_quantity)
  87.     TextView productQuantity;
  88.  
  89.     @BindView(R.id.increase_product)
  90.     ImageButton increaseProduct;
  91.  
  92.     @BindView(R.id.decrease_product)
  93.     ImageButton decreaseProduct;
  94.  
  95.     @BindView(R.id.button_remove)
  96.     ImageView removeButton;
  97.  
  98.     @BindView(R.id.progress_bar)
  99.     SpinKitView progressBar;
  100.  
  101.     @BindView(R.id.sp_tipekurir)
  102.     Spinner spkurir;
  103.  
  104.     private List<CostsItemKurirModel> costsItemKurirModels;
  105.     private List<ResponseKurirModel> responkurir;
  106.     private List<CostItemKurirModel> kuriritem;
  107.     private KurirListAdapter kurirListAdapter;
  108.  
  109.  
  110.     private CartController cartController = new CartController();
  111.     private Intent intent;
  112.     private CartListAdapter cartListAdapter;
  113.     SessionSharedPreferences preferences;
  114.     private List<CartItem> cartItems;
  115.     private final int REQUEST_ADDRESS_CODE = 100;
  116.     public static String kurir;
  117.     public static int harga;
  118.  
  119.  
  120.     @Override
  121.     protected void onCreate(Bundle savedInstanceState) {
  122.         super.onCreate(savedInstanceState);
  123.         setContentView(R.layout.activity_checkout);
  124.         ButterKnife.bind(this);
  125.  
  126.         intent = getIntent();
  127.         String TAG = intent.getStringExtra("TAG");
  128.         preferences = new SessionSharedPreferences(this);
  129.  
  130.         removeButton.setVisibility(View.GONE);
  131.         increaseProduct.setVisibility(View.GONE);
  132.         decreaseProduct.setVisibility(View.GONE);
  133.  
  134.         setSupportActionBar(toolbar);
  135.         Objects.requireNonNull(getSupportActionBar()).setDisplayShowTitleEnabled(true);
  136.         getSupportActionBar().setTitle("Atur Pesanan");
  137.         toolbar.setNavigationIcon(R.drawable.ic_back);
  138.         toolbar.setNavigationOnClickListener(v -> finish());
  139.  
  140.         productList.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
  141.  
  142.  
  143.         initCheckoutFromProduct();
  144.  
  145.     }
  146.  
  147.     public void onRadioButtonClicked(View view){
  148.         boolean cekradio = ((RadioButton) view).isChecked();
  149.  
  150.         switch (view.getId()){
  151.             case R.id.rb_jne:
  152.                 if (cekradio) {
  153.                    kurir = "jne";
  154.                    initradio();
  155.                 }
  156.                     break;
  157.  
  158.             case R.id.rb_pos:
  159.                 if (cekradio)
  160.                     kurir = "pos";
  161.                     initradio();
  162.                     break;
  163.  
  164.             case R.id.rb_tiki:
  165.                 if (cekradio)
  166.                     kurir = "tiki";
  167.                     initradio();
  168.                     break;
  169.         }
  170.     }
  171.  
  172.  
  173. private void initradio(){
  174.     int id = preferences.getID();
  175.  
  176.     ConfigRetrofit.provideApiService().getKurir(id,kurir).enqueue(new Callback<ResponseKurirModel>() {
  177.         @Override
  178.         public void onResponse(Call<ResponseKurirModel> call, Response<ResponseKurirModel> response) {
  179.             costsItemKurirModels = response.body().getCosts();
  180.  
  181.            initDataSpinner();
  182.         }
  183.  
  184.         @Override
  185.         public void onFailure(Call<ResponseKurirModel> call, Throwable t) {
  186.  
  187.         }
  188.     });
  189. }
  190.  
  191.     private void initDataSpinner() {
  192.         kurirListAdapter = new KurirListAdapter(this,costsItemKurirModels);
  193.  
  194.         kurirListAdapter.notifyDataSetChanged();
  195.         spkurir.setAdapter(kurirListAdapter);
  196.  
  197.         spkurir.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  198.             @Override
  199.             public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  200.                 CostsItemKurirModel cur = (CostsItemKurirModel) parent.getItemAtPosition(position);
  201.  
  202.                 Log.d("TAG", "isi cur" +parent);
  203.  
  204.                servicePrice.setText(cur.getCost().get(position).getValue().toString();
  205.  
  206.             }
  207.  
  208.             @Override
  209.             public void onNothingSelected(AdapterView<?> parent) {
  210.  
  211.             }
  212.         });
  213.  
  214.     }
  215.  
  216.     private void initCheckoutFromProduct() {
  217.         int id = preferences.getID();
  218.         String token = preferences.getAccessToken();
  219.         String key = "oa00000000app";
  220.         ConfigRetrofit.provideApiService().getCart(id,key,token).enqueue(new Callback<ResponseCart>() {
  221.             @Override
  222.             public void onResponse(Call<ResponseCart> call, Response<ResponseCart> response) {
  223.                 if (response.isSuccessful()) {
  224.                     cartItems = response.body().getCart();
  225.                     cartListAdapter = new CartListAdapter(CheckoutActivity.this, cartItems, totalPrice);
  226.                     productList.setAdapter(cartListAdapter);
  227.                     cartListAdapter.notifyDataSetChanged();
  228.                     removeButton.setVisibility(View.GONE);
  229.                     increaseProduct.setVisibility(View.GONE);
  230.                     decreaseProduct.setVisibility(View.GONE);
  231.                 } else {
  232.                     Toast.makeText(CheckoutActivity.this, "Gak Ada Hasil Bro", Toast.LENGTH_LONG).show();
  233.                 }
  234.             }
  235.  
  236.             @Override
  237.             public void onFailure(Call<ResponseCart> call, Throwable t) {
  238.                 Toast.makeText(CheckoutActivity.this, "Gagal bro", Toast.LENGTH_LONG).show();
  239.             }
  240.         });
  241.  
  242.     }
  243.  
  244.  
  245.     @Override
  246.     public void onClick(View v) {
  247.         switch (v.getId()){
  248.             case R.id.service_provider:
  249.                 break;
  250.             default:
  251.                 break;
  252.         }
  253.     }
  254. }
  255.  
  256. ===================================================
  257. This Spinner adapter
  258. ===================================================
  259. public class KurirListAdapter extends ArrayAdapter<CostsItemKurirModel>{
  260.  
  261.   public KurirListAdapter(Context context, List<CostsItemKurirModel> itemKurirModels){
  262.       super(context,0,itemKurirModels);
  263.   }
  264.  
  265.     @Override
  266.     public View getView(int position, View convertView, ViewGroup parent) {
  267.         return initView(position, convertView, parent);
  268.     }
  269.  
  270.  
  271.     @Override
  272.     public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  273.         return initView(position, convertView, parent);
  274.     }
  275.  
  276.     private View initView(int position, View convertView, ViewGroup parent) {
  277.         //todo 21 biarkan merah
  278.         if (convertView == null) {
  279.             convertView = LayoutInflater.from(getContext()).inflate(item_kurir, parent,false);
  280.  
  281.         }
  282.         TextView kurir_tipe = convertView.findViewById(R.id.tv_kurir);
  283.  
  284.  
  285.         //item sama dengan todo20
  286.         CostsItemKurirModel current = getItem(position);
  287.  
  288.  
  289.  
  290.         if (current != null) {
  291.             kurir_tipe.setText(current.getService());
  292.  
  293.         }
  294.  
  295.         return convertView;
  296.     }
  297. }
  298.  
  299. ===================================================
  300. This Apiservis (class interface)
  301. ===================================================
  302.     @FormUrlEncoded
  303.     @POST("cek-ongkir")
  304.     Call<ResponseKurirModel> getKurir(
  305.             @Field("CustomerId") int idcustomer,
  306.             @Field("courier") String kurir);
  307.  
  308. ===================================================
  309. This my model (generate from json to POJO)
  310. ===================================================
  311.  
  312. ResponKurir.class
  313. ===================================================
  314.  
  315. package com.fabric.apps.mobile.model.cekkurirModel;
  316.  
  317. import java.util.List;
  318.  
  319. import com.google.gson.annotations.Expose;
  320. import com.google.gson.annotations.SerializedName;
  321.  
  322. public class ResponseKurirModel {
  323.  
  324.     @SerializedName("code")
  325.     @Expose
  326.     private String code;
  327.     @SerializedName("name")
  328.     @Expose
  329.     private String name;
  330.     @SerializedName("costs")
  331.     @Expose
  332.     private List<CostsItemKurirModel> costs = null;
  333.  
  334.     public String getCode() {
  335.         return code;
  336.     }
  337.  
  338.     public void setCode(String code) {
  339.         this.code = code;
  340.     }
  341.  
  342.     public String getName() {
  343.         return name;
  344.     }
  345.  
  346.     public void setName(String name) {
  347.         this.name = name;
  348.     }
  349.  
  350.     public List<CostsItemKurirModel> getCosts() {
  351.         return costs;
  352.     }
  353.  
  354.     public void setCosts(List<CostsItemKurirModel> costs) {
  355.         this.costs = costs;
  356.     }
  357. }
  358.  
  359. Costs.class
  360. ===================================================
  361. package com.fabric.apps.mobile.model.cekkurirModel;
  362.  
  363. import java.util.List;
  364.  
  365. import com.google.gson.annotations.Expose;
  366. import com.google.gson.annotations.SerializedName;
  367.  
  368. public class CostsItemKurirModel {
  369.  
  370.     @SerializedName("service")
  371.     @Expose
  372.     private String service;
  373.     @SerializedName("description")
  374.     @Expose
  375.     private String description;
  376.     @SerializedName("cost")
  377.     @Expose
  378.     private List<CostItemKurirModel> cost = null;
  379.  
  380.     public String getService() {
  381.         return service;
  382.     }
  383.  
  384.     public void setService(String service) {
  385.         this.service = service;
  386.     }
  387.  
  388.     public String getDescription() {
  389.         return description;
  390.     }
  391.  
  392.     public void setDescription(String description) {
  393.         this.description = description;
  394.     }
  395.  
  396.     public List<CostItemKurirModel> getCost() {
  397.         return cost;
  398.     }
  399.  
  400.     public void setCost(List<CostItemKurirModel> cost) {
  401.         this.cost = cost;
  402.     }
  403.  
  404. }
  405.  
  406. Cost.class
  407. ===================================================
  408. package com.fabric.apps.mobile.model.cekkurirModel;
  409.  
  410. import com.google.gson.annotations.Expose;
  411. import com.google.gson.annotations.SerializedName;
  412.  
  413. public class CostItemKurirModel {
  414.  
  415.     @SerializedName("value")
  416.     @Expose
  417.     private Integer value;
  418.     @SerializedName("etd")
  419.     @Expose
  420.     private String etd;
  421.     @SerializedName("note")
  422.     @Expose
  423.     private String note;
  424.  
  425.     public Integer getValue() {
  426.         return value;
  427.     }
  428.  
  429.     public void setValue(Integer value) {
  430.         this.value = value;
  431.     }
  432.  
  433.     public String getEtd() {
  434.         return etd;
  435.     }
  436.  
  437.     public void setEtd(String etd) {
  438.         this.etd = etd;
  439.     }
  440.  
  441.     public String getNote() {
  442.         return note;
  443.     }
  444.  
  445.     public void setNote(String note) {
  446.         this.note = note;
  447.     }
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement