Advertisement
Mujiburrohman

GetActivity

Apr 3rd, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 KB | None | 0 0
  1. package com.mozeeb.crudmvp.get;
  2.  
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.support.v7.app.AlertDialog;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.support.v7.widget.LinearLayoutManager;
  10. import android.support.v7.widget.RecyclerView;
  11. import android.widget.Toast;
  12.  
  13. import com.mozeeb.crudmvp.R;
  14. import com.mozeeb.crudmvp.adapter.AdapterSiswa;
  15. import com.mozeeb.crudmvp.model.DataItem;
  16. import com.mozeeb.crudmvp.update.UpdateActivity;
  17.  
  18. import java.util.List;
  19.  
  20. public class GetActivity extends AppCompatActivity implements GetSiswaContruct.View {
  21.  
  22.     private GetSiswaPresenter getSiswaPresenter;
  23.     private RecyclerView recyclerView;
  24.     private AdapterSiswa adapterSiswa;
  25.  
  26. //    ImageButton btnhapus;
  27.  
  28.     private Context context;
  29.  
  30.     @Override
  31.     protected void onCreate(Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.activity_get);
  34. //        final DataItem dataItem = (DataItem) getIntent().getSerializableExtra("data");
  35. //        btnhapus = findViewById(R.id.delete);
  36.  
  37.  
  38.  
  39.         recyclerView = findViewById(R.id.rv_getSiswa);
  40.         getSiswaPresenter = new GetSiswaPresenter(this);
  41.  
  42.         getSiswaPresenter.getDataSiswa();
  43.  
  44.         recyclerView.setHasFixedSize(true);
  45.         recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
  46.  
  47.  
  48.  
  49.  
  50.     }
  51.  
  52. //
  53.  
  54.     @Override
  55.     public void ShowBiodata(List dataSiswa) {
  56.         adapterSiswa = new AdapterSiswa(dataSiswa, getSiswaPresenter);
  57.         recyclerView.setAdapter(adapterSiswa);
  58.  
  59.         if (dataSiswa.size() > 1){
  60.             Toast.makeText(this, "data sudah ada!", Toast.LENGTH_SHORT).show();
  61.  
  62.         }else {
  63.             Toast.makeText(this, "data kosong!", Toast.LENGTH_SHORT).show();
  64.         }
  65.  
  66.  
  67.  
  68.     }
  69.  
  70.     @Override
  71.     public void goToEditBiodata(DataItem  dataItem) {
  72.         Intent intent = new Intent(GetActivity.this, UpdateActivity.class);
  73.         intent.putExtra("data", dataItem);
  74.         startActivity(intent);
  75.     }
  76.  
  77.     @Override
  78.     protected void onResume() {
  79.         super.onResume();
  80.  
  81.         getSiswaPresenter.getDataSiswa();
  82.     }
  83.  
  84.     @Override
  85.     public void showError(String message) {
  86.         Toast.makeText(this, "tidak ada data", Toast.LENGTH_SHORT).show();
  87.     }
  88.  
  89.     @Override
  90.     public void showSucceed(String message) {
  91.         Toast.makeText(this, "Data Success", Toast.LENGTH_SHORT).show();
  92.  
  93.     }
  94.  
  95.     @Override
  96.     public void showDeleteSuccess(String message) {
  97.         Toast.makeText(this, "Delete Success!", Toast.LENGTH_SHORT).show();
  98.  
  99.     }
  100.  
  101.     @Override
  102.     public void showDeleteFailder(String message) {
  103.         Toast.makeText(this, "Delete Failed!", Toast.LENGTH_SHORT).show();
  104.  
  105.     }
  106.  
  107.     @Override
  108.     public void showDeletetion(final String id) {
  109.         AlertDialog.Builder builder = new AlertDialog.Builder(GetActivity.this)
  110.                 .setMessage("Hapus Biodata Ini?")
  111.                 .setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
  112.                     @Override
  113.                     public void onClick(DialogInterface dialog, int which) {
  114.                         dialog.dismiss();
  115.                     }
  116.                 })
  117.                 .setPositiveButton("Ya", new DialogInterface.OnClickListener() {
  118.                     @Override
  119.                     public void onClick(DialogInterface dialog, int which) {
  120.                         dialog.dismiss();
  121.                         getSiswaPresenter.deleteBiodata(id);
  122.  
  123.                     }
  124.                 });
  125.         AlertDialog build = builder.create();
  126.         build.show();
  127.  
  128.     }
  129.  
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement