Implement BantuanFormActivity API
This commit is contained in:
parent
ddf76d2540
commit
9dac55d07a
@ -37,23 +37,17 @@ import java.util.concurrent.Executors;
|
||||
public class BantuanFormActivity extends AppCompatActivity {
|
||||
|
||||
// UI Components
|
||||
private EditText etTerminalId, etNomorTelepon, etDeskripsiMasalah;
|
||||
private Spinner spinnerTanggalKejadian, spinnerJenisMasalah;
|
||||
private LinearLayout uploadContainer;
|
||||
private TextView uploadText;
|
||||
private EditText etTicketCode;
|
||||
private Spinner spinnerSource, spinnerIssue, spinnerMerchant, spinnerAssign, spinnerResolvedDate;
|
||||
private TextView tvStatus;
|
||||
private Button btnKirim;
|
||||
private LinearLayout backNavigation;
|
||||
|
||||
// Data
|
||||
private String selectedDate = "";
|
||||
private String selectedFileName = "";
|
||||
private Uri selectedFileUri = null;
|
||||
private String selectedResolvedDate = "";
|
||||
private ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
private Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
// File picker launcher
|
||||
private ActivityResultLauncher<Intent> filePickerLauncher;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -69,8 +63,6 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
initViews();
|
||||
setupSpinners();
|
||||
setupListeners();
|
||||
setupFilePicker();
|
||||
loadUserData();
|
||||
|
||||
// Initialize button state
|
||||
updateButtonState();
|
||||
@ -78,17 +70,17 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
|
||||
private void initViews() {
|
||||
// Form fields
|
||||
etTerminalId = findViewById(R.id.et_terminal_id);
|
||||
etNomorTelepon = findViewById(R.id.et_nomor_telepon);
|
||||
etDeskripsiMasalah = findViewById(R.id.et_deskripsi_masalah);
|
||||
etTicketCode = findViewById(R.id.et_ticket_code);
|
||||
|
||||
// Spinners
|
||||
spinnerTanggalKejadian = findViewById(R.id.spinner_tanggal_kejadian);
|
||||
spinnerJenisMasalah = findViewById(R.id.spinner_jenis_masalah);
|
||||
spinnerSource = findViewById(R.id.spinner_source);
|
||||
spinnerIssue = findViewById(R.id.spinner_issue);
|
||||
spinnerMerchant = findViewById(R.id.spinner_merchant);
|
||||
spinnerAssign = findViewById(R.id.spinner_assign);
|
||||
spinnerResolvedDate = findViewById(R.id.spinner_resolved_date);
|
||||
|
||||
// Upload section
|
||||
uploadContainer = findViewById(R.id.upload_container);
|
||||
uploadText = findViewById(R.id.upload_text);
|
||||
// Status (read-only)
|
||||
tvStatus = findViewById(R.id.tv_status);
|
||||
|
||||
// Buttons
|
||||
btnKirim = findViewById(R.id.btn_kirim);
|
||||
@ -96,31 +88,77 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setupSpinners() {
|
||||
// Setup Date Spinner with date picker
|
||||
String[] dateOptions = {"Pilih Tanggal Kejadian", "Pilih dari kalender"};
|
||||
// Setup Source Spinner
|
||||
String[] sourceOptions = {
|
||||
"Pilih Source",
|
||||
"WhatsApp",
|
||||
"Website Hubungi Kami"
|
||||
};
|
||||
ArrayAdapter<String> sourceAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, sourceOptions);
|
||||
sourceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerSource.setAdapter(sourceAdapter);
|
||||
|
||||
// Setup Issue Spinner
|
||||
String[] issueOptions = {
|
||||
"Pilih Issue",
|
||||
"Koneksi EDC Bermasalah",
|
||||
"Permintaan Tambahan EDC",
|
||||
"Pergantian EDC"
|
||||
};
|
||||
ArrayAdapter<String> issueAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, issueOptions);
|
||||
issueAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerIssue.setAdapter(issueAdapter);
|
||||
|
||||
// Setup Merchant Spinner
|
||||
String[] merchantOptions = {
|
||||
"Pilih Merchant",
|
||||
"Surabaya",
|
||||
"Jakarta Selatan",
|
||||
"Jakarta Pusat",
|
||||
"Jakarta Barat",
|
||||
"Palembang",
|
||||
"Bogor Timur",
|
||||
"Bandung Utara",
|
||||
"Yogyakarta Selatan",
|
||||
"Cilacap Barat",
|
||||
"Bekasi Timur",
|
||||
"Tangerang Selatan",
|
||||
"Depok Tengah",
|
||||
"Kediri Kota"
|
||||
};
|
||||
ArrayAdapter<String> merchantAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, merchantOptions);
|
||||
merchantAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerMerchant.setAdapter(merchantAdapter);
|
||||
|
||||
// Setup Assign Spinner
|
||||
String[] assignOptions = {
|
||||
"Pilih Assign",
|
||||
"welno hedi prabowo putro jenaka prima",
|
||||
"rizqika",
|
||||
"budi",
|
||||
"binomo",
|
||||
"budi",
|
||||
"Irfan Muslim Saputra"
|
||||
};
|
||||
ArrayAdapter<String> assignAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, assignOptions);
|
||||
assignAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerAssign.setAdapter(assignAdapter);
|
||||
|
||||
// Setup Resolved Date Spinner with date picker
|
||||
String[] dateOptions = {"Pilih Tanggal Resolved", "Pilih dari kalender"};
|
||||
ArrayAdapter<String> dateAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, dateOptions);
|
||||
dateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerTanggalKejadian.setAdapter(dateAdapter);
|
||||
spinnerResolvedDate.setAdapter(dateAdapter);
|
||||
|
||||
// Setup Issue Type Spinner
|
||||
String[] issueTypes = {
|
||||
"Pilih Jenis Masalah",
|
||||
"Transaksi gagal tapi saldo terpotong",
|
||||
"QRIS tidak terbaca",
|
||||
"EDC tidak merespon / hang",
|
||||
"Gagal cetak struk",
|
||||
"Masalah koneksi internet",
|
||||
"Error pada aplikasi",
|
||||
"Masalah settlement",
|
||||
"Kartu tidak terbaca",
|
||||
"Printer bermasalah",
|
||||
"Lainnya"
|
||||
};
|
||||
ArrayAdapter<String> issueAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, issueTypes);
|
||||
issueAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerJenisMasalah.setAdapter(issueAdapter);
|
||||
// Set status to fixed value
|
||||
if (tvStatus != null) {
|
||||
tvStatus.setText("Pengajuan");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
@ -129,8 +167,52 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
backNavigation.setOnClickListener(v -> onBackPressed());
|
||||
}
|
||||
|
||||
// Date spinner listener
|
||||
spinnerTanggalKejadian.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
// Source spinner listener
|
||||
spinnerSource.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Issue spinner listener
|
||||
spinnerIssue.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Merchant spinner listener
|
||||
spinnerMerchant.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Assign spinner listener
|
||||
spinnerAssign.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Resolved Date spinner listener
|
||||
spinnerResolvedDate.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position == 1) { // "Pilih dari kalender"
|
||||
@ -143,24 +225,8 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Issue type spinner listener
|
||||
spinnerJenisMasalah.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// Text watchers for EditText fields
|
||||
setupTextWatchers();
|
||||
|
||||
// Upload container listener
|
||||
if (uploadContainer != null) {
|
||||
uploadContainer.setOnClickListener(v -> openFilePicker());
|
||||
}
|
||||
// Text watcher for EditText field
|
||||
setupTextWatcher();
|
||||
|
||||
// Submit button listener
|
||||
if (btnKirim != null) {
|
||||
@ -172,7 +238,7 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTextWatchers() {
|
||||
private void setupTextWatcher() {
|
||||
android.text.TextWatcher textWatcher = new android.text.TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@ -186,14 +252,8 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
}
|
||||
};
|
||||
|
||||
if (etTerminalId != null) {
|
||||
etTerminalId.addTextChangedListener(textWatcher);
|
||||
}
|
||||
if (etNomorTelepon != null) {
|
||||
etNomorTelepon.addTextChangedListener(textWatcher);
|
||||
}
|
||||
if (etDeskripsiMasalah != null) {
|
||||
etDeskripsiMasalah.addTextChangedListener(textWatcher);
|
||||
if (etTicketCode != null) {
|
||||
etTicketCode.addTextChangedListener(textWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,67 +264,29 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
|
||||
if (isFormValid) {
|
||||
// Active state - Red background
|
||||
btnKirim.setBackgroundResource(R.drawable.button_active_background);
|
||||
btnKirim.setBackgroundColor(0xFFDE0701); // Red color matching theme
|
||||
btnKirim.setTextColor(getResources().getColor(android.R.color.white));
|
||||
btnKirim.setEnabled(true);
|
||||
btnKirim.setAlpha(1.0f);
|
||||
} else {
|
||||
// Inactive state - Gray background
|
||||
btnKirim.setBackgroundResource(R.drawable.button_inactive_background);
|
||||
btnKirim.setTextColor(getResources().getColor(android.R.color.darker_gray));
|
||||
btnKirim.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
|
||||
btnKirim.setTextColor(getResources().getColor(android.R.color.white));
|
||||
btnKirim.setEnabled(false);
|
||||
btnKirim.setAlpha(0.6f);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkFormValidity() {
|
||||
// Check if all required fields have values
|
||||
boolean hasTerminalId = etTerminalId != null && !etTerminalId.getText().toString().trim().isEmpty();
|
||||
boolean hasPhoneNumber = etNomorTelepon != null && !etNomorTelepon.getText().toString().trim().isEmpty();
|
||||
boolean hasDate = !selectedDate.isEmpty();
|
||||
boolean hasIssueType = spinnerJenisMasalah != null && spinnerJenisMasalah.getSelectedItemPosition() > 0;
|
||||
boolean hasDescription = etDeskripsiMasalah != null && !etDeskripsiMasalah.getText().toString().trim().isEmpty();
|
||||
boolean hasTicketCode = etTicketCode != null && !etTicketCode.getText().toString().trim().isEmpty();
|
||||
boolean hasSource = spinnerSource != null && spinnerSource.getSelectedItemPosition() > 0;
|
||||
boolean hasIssue = spinnerIssue != null && spinnerIssue.getSelectedItemPosition() > 0;
|
||||
boolean hasMerchant = spinnerMerchant != null && spinnerMerchant.getSelectedItemPosition() > 0;
|
||||
boolean hasAssign = spinnerAssign != null && spinnerAssign.getSelectedItemPosition() > 0;
|
||||
boolean hasResolvedDate = !selectedResolvedDate.isEmpty();
|
||||
|
||||
return hasTerminalId && hasPhoneNumber && hasDate && hasIssueType && hasDescription;
|
||||
}
|
||||
|
||||
private void setupFilePicker() {
|
||||
filePickerLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
|
||||
selectedFileUri = result.getData().getData();
|
||||
if (selectedFileUri != null) {
|
||||
selectedFileName = getFileName(selectedFileUri);
|
||||
if (uploadText != null) {
|
||||
uploadText.setText(selectedFileName);
|
||||
uploadText.setTextColor(getResources().getColor(android.R.color.black));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadUserData() {
|
||||
try {
|
||||
JSONObject userData = LoginActivity.getUserDataAsJson(this);
|
||||
if (userData != null) {
|
||||
// Auto-fill phone number if available
|
||||
String phone = userData.optString("phone", userData.optString("mobile", ""));
|
||||
if (!phone.isEmpty() && etNomorTelepon != null) {
|
||||
etNomorTelepon.setText(phone);
|
||||
}
|
||||
|
||||
// Auto-fill terminal ID if available
|
||||
String terminalId = userData.optString("terminal_id", userData.optString("tid", ""));
|
||||
if (!terminalId.isEmpty() && etTerminalId != null) {
|
||||
etTerminalId.setText(terminalId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Silent fail - user can fill manually
|
||||
}
|
||||
|
||||
// Update button state after loading data
|
||||
updateButtonState();
|
||||
return hasTicketCode && hasSource && hasIssue && hasMerchant && hasAssign && hasResolvedDate;
|
||||
}
|
||||
|
||||
private void showDatePicker() {
|
||||
@ -275,16 +297,21 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
Calendar selectedCalendar = Calendar.getInstance();
|
||||
selectedCalendar.set(year, month, dayOfMonth);
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
|
||||
selectedDate = dateFormat.format(selectedCalendar.getTime());
|
||||
// Format for API (ISO 8601)
|
||||
SimpleDateFormat apiFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault());
|
||||
selectedResolvedDate = apiFormat.format(selectedCalendar.getTime());
|
||||
|
||||
// Format for display
|
||||
SimpleDateFormat displayFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
|
||||
String displayDate = displayFormat.format(selectedCalendar.getTime());
|
||||
|
||||
// Update spinner to show selected date
|
||||
String[] updatedOptions = {"Pilih Tanggal Kejadian", selectedDate};
|
||||
String[] updatedOptions = {"Pilih Tanggal Resolved", displayDate};
|
||||
ArrayAdapter<String> updatedAdapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, updatedOptions);
|
||||
updatedAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerTanggalKejadian.setAdapter(updatedAdapter);
|
||||
spinnerTanggalKejadian.setSelection(1);
|
||||
spinnerResolvedDate.setAdapter(updatedAdapter);
|
||||
spinnerResolvedDate.setSelection(1);
|
||||
|
||||
// Update button state after date selection
|
||||
updateButtonState();
|
||||
@ -294,43 +321,55 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
calendar.get(Calendar.DAY_OF_MONTH)
|
||||
);
|
||||
|
||||
// Set max date to today
|
||||
datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis());
|
||||
datePickerDialog.show();
|
||||
}
|
||||
|
||||
private void openFilePicker() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
||||
// Add multiple MIME types for different file types
|
||||
String[] mimeTypes = {"image/*", "application/pdf", "text/*"};
|
||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
|
||||
|
||||
try {
|
||||
filePickerLauncher.launch(Intent.createChooser(intent, "Pilih File Pendukung"));
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "Error opening file picker: " + e.getMessage(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
private int getSourceId(int position) {
|
||||
switch (position) {
|
||||
case 1: return 1; // WhatsApp
|
||||
case 2: return 2; // Website Hubungi Kami
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(Uri uri) {
|
||||
String fileName = "File terpilih";
|
||||
try {
|
||||
android.database.Cursor cursor = getContentResolver().query(uri, null, null, null, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int nameIndex = cursor.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME);
|
||||
if (nameIndex != -1) {
|
||||
fileName = cursor.getString(nameIndex);
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Return default name if error
|
||||
private int getIssueId(int position) {
|
||||
switch (position) {
|
||||
case 1: return 4; // Koneksi EDC Bermasalah
|
||||
case 2: return 5; // Permintaan Tambahan EDC
|
||||
case 3: return 6; // Pergantian EDC
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int getMerchantId(int position) {
|
||||
switch (position) {
|
||||
case 1: return 1; // Surabaya
|
||||
case 2: return 2; // Jakarta Selatan
|
||||
case 3: return 3; // Jakarta Pusat
|
||||
case 4: return 4; // Jakarta Barat
|
||||
case 5: return 5; // Palembang
|
||||
case 6: return 6; // Bogor Timur
|
||||
case 7: return 7; // Bandung Utara
|
||||
case 8: return 8; // Yogyakarta Selatan
|
||||
case 9: return 9; // Cilacap Barat
|
||||
case 10: return 10; // Bekasi Timur
|
||||
case 11: return 11; // Tangerang Selatan
|
||||
case 12: return 12; // Depok Tengah
|
||||
case 13: return 13; // Kediri Kota
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int getAssignId(int position) {
|
||||
switch (position) {
|
||||
case 1: return 1; // welno hedi prabowo putro jenaka prima
|
||||
case 2: return 2; // rizqika
|
||||
case 3: return 3; // budi
|
||||
case 4: return 4; // binomo
|
||||
case 5: return 5; // budi
|
||||
case 6: return 6; // Irfan Muslim Saputra
|
||||
default: return 0;
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private void submitForm() {
|
||||
@ -343,52 +382,59 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
btnKirim.setText("Mengirim...");
|
||||
|
||||
// Prepare form data
|
||||
String terminalId = etTerminalId.getText().toString().trim();
|
||||
String nomorTelepon = etNomorTelepon.getText().toString().trim();
|
||||
String deskripsiMasalah = etDeskripsiMasalah.getText().toString().trim();
|
||||
String jenisMasalah = spinnerJenisMasalah.getSelectedItem().toString();
|
||||
String ticketCode = etTicketCode.getText().toString().trim();
|
||||
int sourceId = getSourceId(spinnerSource.getSelectedItemPosition());
|
||||
int issueId = getIssueId(spinnerIssue.getSelectedItemPosition());
|
||||
int merchantId = getMerchantId(spinnerMerchant.getSelectedItemPosition());
|
||||
int assignId = getAssignId(spinnerAssign.getSelectedItemPosition());
|
||||
|
||||
submitToAPI(terminalId, nomorTelepon, selectedDate, jenisMasalah, deskripsiMasalah);
|
||||
submitToAPI(ticketCode, sourceId, issueId, merchantId, assignId, selectedResolvedDate);
|
||||
}
|
||||
|
||||
private boolean validateForm() {
|
||||
boolean isValid = true;
|
||||
|
||||
// Validate Terminal ID
|
||||
if (etTerminalId.getText().toString().trim().isEmpty()) {
|
||||
etTerminalId.setError("Terminal ID wajib diisi");
|
||||
// Validate Ticket Code
|
||||
if (etTicketCode.getText().toString().trim().isEmpty()) {
|
||||
etTicketCode.setError("Ticket Code wajib diisi");
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// Validate Phone Number
|
||||
if (etNomorTelepon.getText().toString().trim().isEmpty()) {
|
||||
etNomorTelepon.setError("Nomor telepon wajib diisi");
|
||||
// Validate Source
|
||||
if (spinnerSource.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(this, "Pilih Source", Toast.LENGTH_SHORT).show();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// Validate Date
|
||||
if (selectedDate.isEmpty()) {
|
||||
Toast.makeText(this, "Pilih tanggal kejadian", Toast.LENGTH_SHORT).show();
|
||||
// Validate Issue
|
||||
if (spinnerIssue.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(this, "Pilih Issue", Toast.LENGTH_SHORT).show();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// Validate Issue Type
|
||||
if (spinnerJenisMasalah.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(this, "Pilih jenis masalah", Toast.LENGTH_SHORT).show();
|
||||
// Validate Merchant
|
||||
if (spinnerMerchant.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(this, "Pilih Merchant", Toast.LENGTH_SHORT).show();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// Validate Description
|
||||
if (etDeskripsiMasalah.getText().toString().trim().isEmpty()) {
|
||||
etDeskripsiMasalah.setError("Deskripsi masalah wajib diisi");
|
||||
// Validate Assign
|
||||
if (spinnerAssign.getSelectedItemPosition() == 0) {
|
||||
Toast.makeText(this, "Pilih Assign", Toast.LENGTH_SHORT).show();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// Validate Resolved Date
|
||||
if (selectedResolvedDate.isEmpty()) {
|
||||
Toast.makeText(this, "Pilih tanggal resolved", Toast.LENGTH_SHORT).show();
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
private void submitToAPI(String terminalId, String nomorTelepon, String tanggalKejadian,
|
||||
String jenisMasalah, String deskripsiMasalah) {
|
||||
private void submitToAPI(String ticketCode, int sourceId, int issueId, int merchantId,
|
||||
int assignId, String resolvedAt) {
|
||||
|
||||
String authToken = LoginActivity.getToken(this);
|
||||
if (authToken == null || authToken.isEmpty()) {
|
||||
@ -403,7 +449,7 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
executor.execute(() -> {
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
URL url = new URL("https://be-edc.msvc.app/tickets/create");
|
||||
URL url = new URL("https://be-edc.msvc.app/tickets");
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
connection.setRequestMethod("POST");
|
||||
@ -415,22 +461,14 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
|
||||
// Create JSON payload
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("terminal_id", terminalId);
|
||||
payload.put("phone_number", nomorTelepon);
|
||||
payload.put("incident_date", tanggalKejadian);
|
||||
payload.put("issue_type", jenisMasalah);
|
||||
payload.put("description", deskripsiMasalah);
|
||||
|
||||
// Add user info
|
||||
try {
|
||||
JSONObject userData = LoginActivity.getUserDataAsJson(this);
|
||||
if (userData != null) {
|
||||
payload.put("user_name", userData.optString("name", ""));
|
||||
payload.put("user_email", userData.optString("email", ""));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Continue without user info
|
||||
}
|
||||
payload.put("ticket_code", ticketCode);
|
||||
payload.put("source_id", sourceId);
|
||||
payload.put("issue_id", issueId);
|
||||
payload.put("merchant_id", merchantId);
|
||||
payload.put("status", "new");
|
||||
payload.put("is_sla_violated", true);
|
||||
payload.put("assigned_to", assignId);
|
||||
payload.put("resolved_at", resolvedAt);
|
||||
|
||||
// Send request
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
@ -471,9 +509,6 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
// Clear form
|
||||
clearForm();
|
||||
|
||||
// Optionally go back to previous screen
|
||||
// finish();
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "Tiket berhasil dikirim!", Toast.LENGTH_LONG).show();
|
||||
clearForm();
|
||||
@ -511,24 +546,15 @@ public class BantuanFormActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void clearForm() {
|
||||
if (etTerminalId != null) etTerminalId.setText("");
|
||||
if (etNomorTelepon != null) etNomorTelepon.setText("");
|
||||
if (etDeskripsiMasalah != null) etDeskripsiMasalah.setText("");
|
||||
if (etTicketCode != null) etTicketCode.setText("");
|
||||
|
||||
if (spinnerTanggalKejadian != null) spinnerTanggalKejadian.setSelection(0);
|
||||
if (spinnerJenisMasalah != null) spinnerJenisMasalah.setSelection(0);
|
||||
if (spinnerSource != null) spinnerSource.setSelection(0);
|
||||
if (spinnerIssue != null) spinnerIssue.setSelection(0);
|
||||
if (spinnerMerchant != null) spinnerMerchant.setSelection(0);
|
||||
if (spinnerAssign != null) spinnerAssign.setSelection(0);
|
||||
if (spinnerResolvedDate != null) spinnerResolvedDate.setSelection(0);
|
||||
|
||||
selectedDate = "";
|
||||
selectedFileName = "";
|
||||
selectedFileUri = null;
|
||||
|
||||
if (uploadText != null) {
|
||||
uploadText.setText("Pilih di sini");
|
||||
uploadText.setTextColor(getResources().getColor(android.R.color.darker_gray));
|
||||
}
|
||||
|
||||
// Reload user data for next form
|
||||
loadUserData();
|
||||
selectedResolvedDate = "";
|
||||
|
||||
// Update button state after clearing form
|
||||
updateButtonState();
|
||||
|
@ -1,188 +1,234 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#f5f5f5">
|
||||
android:background="#F5F5F5">
|
||||
|
||||
<!-- Custom AppBar -->
|
||||
<include layout="@layout/component_appbar_small" />
|
||||
|
||||
<!-- Form Content -->
|
||||
<!-- Main Content -->
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
android:layout_weight="1"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="@android:color/white">
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
<!-- Form Card -->
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Formulir Helpdesk untuk Merchant"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@android:color/black"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="2dp"
|
||||
app:cardBackgroundColor="@android:color/white">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Mohon isi data Anda pada formulir di bawah ini untuk melaporkan masalah yang terjadi."
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<!-- Terminal ID -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Terminal ID (TID)"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_terminal_id"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="123456789011"
|
||||
android:padding="16dp"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Nomor Telepon -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Nomor Telepon"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_nomor_telepon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="+62 8xxxxxxxxx"
|
||||
android:inputType="phone"
|
||||
android:padding="16dp"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Tanggal Kejadian -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Tanggal Kejadian"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_tanggal_kejadian"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Jenis Masalah -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Jenis Masalah"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_jenis_masalah"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Deskripsi Masalah -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Deskripsi Masalah"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_deskripsi_masalah"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
android:hint="Tulis di sini..."
|
||||
android:inputType="textMultiLine"
|
||||
android:gravity="top"
|
||||
android:padding="16dp"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<!-- Upload Dokumen -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Upload Dokumen Pendukung"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/upload_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/upload_text"
|
||||
android:layout_width="0dp"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Pilih di sini"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="14sp"/>
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="+"
|
||||
android:textSize="24sp"
|
||||
android:textColor="@android:color/darker_gray"/>
|
||||
<!-- Form Title -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Formulir Helpdesk untuk Merchant"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#DE0701"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
</LinearLayout>
|
||||
<!-- Form Subtitle -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Mohon isi data Anda pada formulir di bawah ini untuk melaporkan masalah yang terjadi."
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:lineSpacingExtra="2dp" />
|
||||
|
||||
<!-- Ticket Code Field -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Ticket Code"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_ticket_code"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:hint="Masukkan kode tiket (contoh: #20240312)"
|
||||
android:padding="16dp"
|
||||
android:textSize="14sp"
|
||||
android:textColorHint="#AAAAAA"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:singleLine="true" />
|
||||
|
||||
<!-- Source Field -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Source"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_source"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:padding="16dp" />
|
||||
|
||||
<!-- Issue Field -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Issue"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_issue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:padding="16dp" />
|
||||
|
||||
<!-- Merchant Field -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Merchant"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_merchant"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:padding="16dp" />
|
||||
|
||||
<!-- Status Field (Read-only) -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Status"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="16dp"
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Pengajuan"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#666666" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Assign Field -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Assign To"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_assign"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:padding="16dp" />
|
||||
|
||||
<!-- Resolved Date Field -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Resolved Date"
|
||||
android:textSize="14sp"
|
||||
android:textColor="#333333"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_resolved_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/editbox_background"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:padding="16dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<Button
|
||||
android:id="@+id/btn_kirim"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:layout_margin="16dp"
|
||||
android:text="Kirim Sekarang"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/button_inactive_background"
|
||||
android:elevation="2dp"
|
||||
android:enabled="false"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="@android:color/white"
|
||||
android:elevation="4dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_kirim"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="52dp"
|
||||
android:text="Kirim Sekarang"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="false"
|
||||
android:background="@android:color/darker_gray"
|
||||
android:textColor="@android:color/white"
|
||||
android:enabled="false"
|
||||
android:stateListAnimator="@null"
|
||||
android:elevation="0dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user