Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package info.blogbasbas.pendaftranonline;
  2.  
  3. import android.content.DialogInterface;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AlertDialog;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.util.Log;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.RadioButton;
  11. import android.widget.RadioGroup;
  12. import android.widget.Toast;
  13.  
  14. import com.infideap.atomic.Atom;
  15. import com.infideap.atomic.FutureCallback;
  16.  
  17. import butterknife.BindView;
  18. import butterknife.ButterKnife;
  19. import butterknife.OnClick;
  20. import info.blogbasbas.pendaftranonline.respon.ResponseInsert;
  21. import timber.log.Timber;
  22.  
  23. public class MainActivity extends AppCompatActivity {
  24.  
  25. @BindView(R.id.edtName)
  26. EditText edtName;
  27. @BindView(R.id.edtEmail)
  28. EditText edtEmail;
  29. @BindView(R.id.rbLaki)
  30. RadioButton rbLaki;
  31. @BindView(R.id.rbWanita)
  32. RadioButton rbWanita;
  33. @BindView(R.id.rgKelamin)
  34. RadioGroup rgKelamin;
  35. @BindView(R.id.edtAlamat)
  36. EditText edtAlamat;
  37. @BindView(R.id.btnRegister)
  38. Button btnRegister;
  39.  
  40. @Override
  41. protected void onCreate(Bundle savedInstanceState) {
  42. super.onCreate(savedInstanceState);
  43. setContentView(R.layout.activity_main);
  44. ButterKnife.bind(this);
  45. }
  46.  
  47. @OnClick(R.id.btnRegister)
  48. public void onViewClicked() {
  49. String name = edtName.getText().toString();
  50. String email = edtEmail.getText().toString();
  51. String kelamin = "";
  52. String alamat = edtAlamat.getText().toString();
  53. int selectedId = rgKelamin.getCheckedRadioButtonId();
  54. if (selectedId == rbLaki.getId()){
  55. kelamin = rbLaki.getText().toString();
  56. } else if (selectedId == rbWanita.getId()){
  57. kelamin = rbWanita.getText().toString();
  58. } else {
  59. Toast.makeText(this, "Gender Belum Centang", Toast.LENGTH_SHORT).show();
  60. }
  61. if (name.isEmpty()){
  62. edtName.setError("name harus di isi");
  63. } else if (email.isEmpty()){
  64. edtEmail.setError("email harus di isi");
  65. } else if (alamat.isEmpty()){
  66. edtAlamat.setError("alamat harus di isi");
  67. } else {
  68.  
  69.  
  70. Atom.with(MainActivity.this)
  71. .load("https://script.google.com/macros/s/AKfycbwkMGlZbWsYT0ePQKGsAbcaIUkXtGsTzO0wxe_B3mSQTVgVYms/exec")
  72. .setMultipart("nama", name)
  73. .setMultipart("email", email)
  74. .setMultipart("jenis_kelamin", kelamin)
  75. .setMultipart("alamat", alamat)
  76. .as(ResponseInsert.class)
  77. .setCallback(new FutureCallback<ResponseInsert>() {
  78. @Override
  79. public void onCompleted(Exception e, ResponseInsert result) {
  80. if (e != null) {
  81. e.printStackTrace();
  82. return;
  83. }
  84.  
  85. Log.d("Tag", "Status" + result.getStatus());
  86. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  87. builder.setMessage("Sukses Register");
  88. builder.setTitle("Informasi Register");
  89. builder.setCancelable(true);
  90. builder.setIcon(R.drawable.ic_done_black_24dp);
  91. builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  92. @Override
  93. public void onClick(DialogInterface dialogInterface, int i) {
  94. finish();
  95. startActivity(getIntent());
  96.  
  97. }
  98. });
  99. builder.show();
  100. }
  101. });
  102.  
  103. }
  104. }
  105. }