Created
February 5, 2023 12:43
-
-
Save pamungkasaji/d763a169688ab12e715627be1c7c0437 to your computer and use it in GitHub Desktop.
Aplikasi Donasi Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private boolean validasi(){ | |
| boolean check = true; | |
| if (!Helper.notEmpty(editTextJudul, "Judul")) check = false; | |
| if (!Helper.notEmpty(editTextDeskripsi, "Deskripsi")) check = false; | |
| if (!Helper.notEmpty(editTextTarget, "Target")) check = false; | |
| if (!Helper.notEmpty(editTextNoRek, "Nomor Rekening")) check = false; | |
| if (!Helper.validasiKarakter(editTextNoRek, 7, 24, "No HP")) check = false; | |
| if (tlama_donasi.equals("Jumlah hari penggalangan dana")) { | |
| Toast.makeText(this, "Pilih jumlah hari", Toast.LENGTH_SHORT).show(); | |
| ((TextView)spinner_hari.getSelectedView()).setError("Pilih hari"); | |
| check = false; | |
| }else { | |
| ((TextView)spinner_hari.getSelectedView()).setError(null); | |
| } | |
| if (editTextBank.getVisibility() == View.VISIBLE){ | |
| tbank = editTextBank.getEditText().getText().toString().trim(); | |
| if (tbank.isEmpty()) { | |
| editTextBank.setError("Isi kolom nama bank"); | |
| check = false; | |
| }else { | |
| editTextBank.setError(null); | |
| } | |
| } else { | |
| if (tbank.equals("Pilih Nama Bank")) { | |
| Toast.makeText(this, "Pilih nama bank", Toast.LENGTH_SHORT).show(); | |
| ((TextView)spinner_bank.getSelectedView()).setError("Pilih bank"); | |
| check = false; | |
| }else { | |
| ((TextView)spinner_bank.getSelectedView()).setError(null); | |
| } | |
| } | |
| if(filePath.equals("")){ | |
| Toast.makeText(this, "Upload gambar", Toast.LENGTH_SHORT).show(); | |
| buttonChoose.setError("Upload gambar"); | |
| check = false; | |
| }else { | |
| buttonChoose.setError(null); | |
| } | |
| return check; | |
| } | |
| private void postKonten() { | |
| String tjudul = editTextJudul.getEditText().getText().toString().trim(); | |
| String tdeskripsi = editTextDeskripsi.getEditText().getText().toString().trim(); | |
| String ttarget = editTextTarget.getEditText().getText().toString().trim(); | |
| String tnorek = editTextNoRek.getEditText().getText().toString().trim(); | |
| Retrofit retrofit = NetworkClient.getApiClient(); | |
| KontenClient kontenClient = retrofit.create(KontenClient.class); | |
| //Create a file object using file path | |
| File file = new File(filePath); | |
| // Create a request body with file and image media type | |
| RequestBody fileReqBody = RequestBody.create(file, MediaType.parse("multipart/form-data")); | |
| // Create MultipartBody.Part using file request-body,file name and part name | |
| MultipartBody.Part pic = MultipartBody.Part.createFormData("gambar", file.getName(), fileReqBody); | |
| Map<String, RequestBody> konten = new HashMap<>(); | |
| konten.put("judul", RequestBody.create(tjudul, MediaType.parse("multipart/form-data"))); | |
| konten.put("deskripsi", RequestBody.create(tdeskripsi, MediaType.parse("multipart/form-data"))); | |
| konten.put("target", RequestBody.create(ttarget, MediaType.parse("multipart/form-data"))); | |
| konten.put("lama_donasi", RequestBody.create(tlama_donasi, MediaType.parse("multipart/form-data"))); | |
| konten.put("bank", RequestBody.create(tbank, MediaType.parse("multipart/form-data"))); | |
| konten.put("nomorrekening", RequestBody.create(tnorek, MediaType.parse("multipart/form-data"))); | |
| Call<DefaultResponse> call = kontenClient.createKonten(token, konten, pic); | |
| call.enqueue(new Callback<DefaultResponse>() { | |
| @Override | |
| public void onResponse(@NonNull Call<DefaultResponse> call,@NonNull Response<DefaultResponse> response) { | |
| Helper.hideProgress(progressBar, BuatKontenActivity.this); | |
| if (response.isSuccessful() && response.body()!= null) { | |
| Log.d(TAG, "respon sukses body not null"); | |
| DefaultResponse defaultResponse = response.body(); | |
| Helper.infoDialogFinish(BuatKontenActivity.this, "Tunggu Verifikasi", defaultResponse.getMessage()); | |
| } | |
| else { | |
| if (response.errorBody() != null) { | |
| Log.d(TAG, "respon sukses errorBody not null"); | |
| Gson gson = new Gson(); | |
| DefaultResponse defaultResponse = gson.fromJson(response.errorBody().charStream(), DefaultResponse.class); | |
| buttonUpload.setEnabled(true); | |
| Helper.hideProgress(progressBar, BuatKontenActivity.this); | |
| Helper.warningDialog(BuatKontenActivity.this, "Kesalahan", defaultResponse.getMessage()); | |
| } | |
| } | |
| } | |
| @Override | |
| public void onFailure(Call<DefaultResponse> call, Throwable t) { | |
| Log.e(TAG, "Request gagal"); | |
| buttonUpload.setEnabled(true); | |
| Helper.hideProgress(progressBar, BuatKontenActivity.this); | |
| Helper.warningDialog(BuatKontenActivity.this, "Kesalahan", "Pengajuan penggalangan dana gagal"); | |
| } | |
| }); | |
| } | |
| protected void captureImage(){ | |
| Intent i = new Intent(this, ImageSelectActivity.class); | |
| i.putExtra(ImageSelectActivity.FLAG_COMPRESS, true); | |
| i.putExtra(ImageSelectActivity.FLAG_CAMERA, true); | |
| i.putExtra(ImageSelectActivity.FLAG_GALLERY, true); | |
| startActivityForResult(i, 1213); | |
| } | |
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| super.onActivityResult(requestCode, resultCode, data); | |
| if (requestCode == 1213 && resultCode == Activity.RESULT_OK) { | |
| filePath = data.getStringExtra(ImageSelectActivity.RESULT_FILE_PATH); | |
| Bitmap selectedImage = BitmapFactory.decodeFile(filePath); | |
| gambar.setImageBitmap(selectedImage); | |
| } | |
| buttonChoose.setError(null); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment