Implement API ke Form Bantuan
This commit is contained in:
parent
f64779755a
commit
c033a26516
@ -44,8 +44,9 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// UI Components
|
// UI Components
|
||||||
private EditText etTicketCode;
|
private EditText etTicketCode;
|
||||||
private Spinner spinnerSource, spinnerIssue, spinnerMerchant, spinnerAssign, spinnerResolvedDate;
|
private Spinner spinnerSource, spinnerIssue, spinnerMerchant, spinnerAssign;
|
||||||
private TextView tvStatus;
|
private TextView tvStatus, tvResolvedDate;
|
||||||
|
private LinearLayout llResolvedDate;
|
||||||
private Button btnKirim;
|
private Button btnKirim;
|
||||||
private LinearLayout backNavigation;
|
private LinearLayout backNavigation;
|
||||||
private LinearLayout successScreen;
|
private LinearLayout successScreen;
|
||||||
@ -60,6 +61,7 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
private List<ParameterDetail> sourceList = new ArrayList<>();
|
private List<ParameterDetail> sourceList = new ArrayList<>();
|
||||||
private List<ParameterDetail> issueList = new ArrayList<>();
|
private List<ParameterDetail> issueList = new ArrayList<>();
|
||||||
private List<ParameterDetail> assignList = new ArrayList<>();
|
private List<ParameterDetail> assignList = new ArrayList<>();
|
||||||
|
private List<ParameterDetail> merchantList = new ArrayList<>();
|
||||||
|
|
||||||
// Inner class for parameter details
|
// Inner class for parameter details
|
||||||
public static class ParameterDetail {
|
public static class ParameterDetail {
|
||||||
@ -94,6 +96,7 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
// Load dynamic data first, then setup spinners
|
// Load dynamic data first, then setup spinners
|
||||||
loadHeaderParams();
|
loadHeaderParams();
|
||||||
loadUsers();
|
loadUsers();
|
||||||
|
loadMerchants();
|
||||||
|
|
||||||
setupListeners();
|
setupListeners();
|
||||||
|
|
||||||
@ -114,7 +117,10 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
spinnerIssue = findViewById(R.id.spinner_issue);
|
spinnerIssue = findViewById(R.id.spinner_issue);
|
||||||
spinnerMerchant = findViewById(R.id.spinner_merchant);
|
spinnerMerchant = findViewById(R.id.spinner_merchant);
|
||||||
spinnerAssign = findViewById(R.id.spinner_assign);
|
spinnerAssign = findViewById(R.id.spinner_assign);
|
||||||
spinnerResolvedDate = findViewById(R.id.spinner_resolved_date);
|
|
||||||
|
// Resolved Date components
|
||||||
|
llResolvedDate = findViewById(R.id.ll_resolved_date);
|
||||||
|
tvResolvedDate = findViewById(R.id.tv_resolved_date);
|
||||||
|
|
||||||
// Status (read-only)
|
// Status (read-only)
|
||||||
tvStatus = findViewById(R.id.tv_status);
|
tvStatus = findViewById(R.id.tv_status);
|
||||||
@ -232,6 +238,93 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadMerchants() {
|
||||||
|
String authToken = LoginActivity.getToken(this);
|
||||||
|
if (authToken == null || authToken.isEmpty()) {
|
||||||
|
LoginActivity.logout(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
executor.execute(() -> {
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://be-edc.msvc.app/merchants/list?location_id=0");
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setRequestProperty("Authorization", "Bearer " + authToken);
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
connection.setReadTimeout(15000);
|
||||||
|
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
|
||||||
|
if (responseCode == 200) {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
// Parse response
|
||||||
|
JSONObject jsonResponse = new JSONObject(response.toString());
|
||||||
|
JSONArray dataArray = jsonResponse.getJSONArray("data");
|
||||||
|
|
||||||
|
// Clear existing list
|
||||||
|
merchantList.clear();
|
||||||
|
|
||||||
|
// Process each merchant
|
||||||
|
for (int i = 0; i < dataArray.length(); i++) {
|
||||||
|
JSONObject merchant = dataArray.getJSONObject(i);
|
||||||
|
String status = merchant.getString("status");
|
||||||
|
|
||||||
|
// Only add active merchants
|
||||||
|
if ("1".equals(status)) {
|
||||||
|
int id = merchant.getInt("id");
|
||||||
|
String name = merchant.getString("name");
|
||||||
|
String merchantCode = merchant.optString("merchant_code", "");
|
||||||
|
|
||||||
|
// Only add merchants that have merchant_code
|
||||||
|
if (!merchantCode.isEmpty()) {
|
||||||
|
merchantList.add(new ParameterDetail(id, name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update UI on main thread
|
||||||
|
mainHandler.post(() -> {
|
||||||
|
setupSpinners();
|
||||||
|
updateButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (responseCode == 401) {
|
||||||
|
mainHandler.post(() -> {
|
||||||
|
Toast.makeText(this, "Session expired. Please login again.", Toast.LENGTH_LONG).show();
|
||||||
|
LoginActivity.logout(this);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mainHandler.post(() -> {
|
||||||
|
Toast.makeText(this, "Failed to load merchants. Error: " + responseCode, Toast.LENGTH_LONG).show();
|
||||||
|
// Setup with empty data
|
||||||
|
setupSpinners();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
mainHandler.post(() -> {
|
||||||
|
Toast.makeText(this, "Network error loading merchants: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
// Setup with empty data
|
||||||
|
setupSpinners();
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (connection != null) {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void showSuccessScreen() {
|
private void showSuccessScreen() {
|
||||||
Log.d(TAG, "Showing success screen");
|
Log.d(TAG, "Showing success screen");
|
||||||
|
|
||||||
@ -370,23 +463,12 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
issueAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
issueAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
spinnerIssue.setAdapter(issueAdapter);
|
spinnerIssue.setAdapter(issueAdapter);
|
||||||
|
|
||||||
// Setup Merchant Spinner (Static - unchanged)
|
// Setup Merchant Spinner (Dynamic)
|
||||||
String[] merchantOptions = {
|
List<String> merchantOptions = new ArrayList<>();
|
||||||
"Pilih Merchant",
|
merchantOptions.add("Pilih Merchant");
|
||||||
"Surabaya",
|
for (ParameterDetail merchant : merchantList) {
|
||||||
"Jakarta Selatan",
|
merchantOptions.add(merchant.name);
|
||||||
"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,
|
ArrayAdapter<String> merchantAdapter = new ArrayAdapter<>(this,
|
||||||
android.R.layout.simple_spinner_item, merchantOptions);
|
android.R.layout.simple_spinner_item, merchantOptions);
|
||||||
merchantAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
merchantAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
@ -403,12 +485,7 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
assignAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
assignAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
spinnerAssign.setAdapter(assignAdapter);
|
spinnerAssign.setAdapter(assignAdapter);
|
||||||
|
|
||||||
// Setup Resolved Date Spinner with date picker
|
// Setup Resolved Date components (no spinner setup needed)
|
||||||
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);
|
|
||||||
spinnerResolvedDate.setAdapter(dateAdapter);
|
|
||||||
|
|
||||||
// Set status to fixed value
|
// Set status to fixed value
|
||||||
if (tvStatus != null) {
|
if (tvStatus != null) {
|
||||||
@ -466,19 +543,10 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resolved Date spinner listener
|
// Resolved Date click listener
|
||||||
spinnerResolvedDate.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
|
if (llResolvedDate != null) {
|
||||||
@Override
|
llResolvedDate.setOnClickListener(v -> showDatePicker());
|
||||||
public void onItemSelected(android.widget.AdapterView<?> parent, View view, int position, long id) {
|
}
|
||||||
if (position == 1) { // "Pilih dari kalender"
|
|
||||||
showDatePicker();
|
|
||||||
}
|
|
||||||
updateButtonState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Text watcher for EditText field
|
// Text watcher for EditText field
|
||||||
setupTextWatcher();
|
setupTextWatcher();
|
||||||
@ -560,13 +628,13 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
SimpleDateFormat displayFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
|
SimpleDateFormat displayFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
|
||||||
String displayDate = displayFormat.format(selectedCalendar.getTime());
|
String displayDate = displayFormat.format(selectedCalendar.getTime());
|
||||||
|
|
||||||
// Update spinner to show selected date
|
// Update TextView to show selected date
|
||||||
String[] updatedOptions = {"Pilih Tanggal Resolved", displayDate};
|
if (tvResolvedDate != null) {
|
||||||
ArrayAdapter<String> updatedAdapter = new ArrayAdapter<>(this,
|
tvResolvedDate.setText(displayDate);
|
||||||
android.R.layout.simple_spinner_item, updatedOptions);
|
tvResolvedDate.setTextColor(0xFF000000); // Black color for selected date
|
||||||
updatedAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
}
|
||||||
spinnerResolvedDate.setAdapter(updatedAdapter);
|
|
||||||
spinnerResolvedDate.setSelection(1);
|
Log.d(TAG, "Date selected: " + displayDate + " (API format: " + selectedResolvedDate + ")");
|
||||||
|
|
||||||
// Update button state after date selection
|
// Update button state after date selection
|
||||||
updateButtonState();
|
updateButtonState();
|
||||||
@ -576,6 +644,9 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
calendar.get(Calendar.DAY_OF_MONTH)
|
calendar.get(Calendar.DAY_OF_MONTH)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Set minimum date to today to prevent past dates
|
||||||
|
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis());
|
||||||
|
|
||||||
datePickerDialog.show();
|
datePickerDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,22 +665,10 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getMerchantId(int position) {
|
private int getMerchantId(int position) {
|
||||||
switch (position) {
|
if (position > 0 && position <= merchantList.size()) {
|
||||||
case 1: return 1; // Surabaya
|
return merchantList.get(position - 1).id;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAssignId(int position) {
|
private int getAssignId(int position) {
|
||||||
@ -655,6 +714,14 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (merchantId == 0) {
|
||||||
|
Log.e(TAG, "Invalid merchant ID: " + merchantId + ", position: " + spinnerMerchant.getSelectedItemPosition());
|
||||||
|
Toast.makeText(this, "Error: Merchant tidak valid", Toast.LENGTH_SHORT).show();
|
||||||
|
btnKirim.setEnabled(true);
|
||||||
|
btnKirim.setText("Kirim Sekarang");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (assignId == 0) {
|
if (assignId == 0) {
|
||||||
Log.e(TAG, "Invalid assign ID: " + assignId + ", position: " + spinnerAssign.getSelectedItemPosition());
|
Log.e(TAG, "Invalid assign ID: " + assignId + ", position: " + spinnerAssign.getSelectedItemPosition());
|
||||||
Toast.makeText(this, "Error: Assign To tidak valid", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Error: Assign To tidak valid", Toast.LENGTH_SHORT).show();
|
||||||
@ -853,8 +920,12 @@ public class BantuanFormActivity extends AppCompatActivity {
|
|||||||
if (spinnerIssue != null) spinnerIssue.setSelection(0);
|
if (spinnerIssue != null) spinnerIssue.setSelection(0);
|
||||||
if (spinnerMerchant != null) spinnerMerchant.setSelection(0);
|
if (spinnerMerchant != null) spinnerMerchant.setSelection(0);
|
||||||
if (spinnerAssign != null) spinnerAssign.setSelection(0);
|
if (spinnerAssign != null) spinnerAssign.setSelection(0);
|
||||||
if (spinnerResolvedDate != null) spinnerResolvedDate.setSelection(0);
|
|
||||||
|
|
||||||
|
// Reset resolved date
|
||||||
|
if (tvResolvedDate != null) {
|
||||||
|
tvResolvedDate.setText("Pilih Tanggal Resolved");
|
||||||
|
tvResolvedDate.setTextColor(0xFFAAAAAA); // Light gray color
|
||||||
|
}
|
||||||
selectedResolvedDate = "";
|
selectedResolvedDate = "";
|
||||||
|
|
||||||
// Update button state after clearing form
|
// Update button state after clearing form
|
||||||
|
@ -200,13 +200,34 @@
|
|||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<Spinner
|
<LinearLayout
|
||||||
android:id="@+id/spinner_resolved_date"
|
android:id="@+id/ll_resolved_date"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@android:drawable/editbox_background"
|
android:background="@android:drawable/editbox_background"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:padding="16dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="12dp"
|
||||||
android:padding="16dp" />
|
android:clickable="true"
|
||||||
|
android:focusable="true">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_resolved_date"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Pilih Tanggal Resolved"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="#AAAAAA" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:src="@android:drawable/ic_menu_my_calendar"
|
||||||
|
android:contentDescription="Calendar Icon" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@ -262,7 +283,7 @@
|
|||||||
android:id="@+id/success_icon"
|
android:id="@+id/success_icon"
|
||||||
android:layout_width="120dp"
|
android:layout_width="120dp"
|
||||||
android:layout_height="120dp"
|
android:layout_height="120dp"
|
||||||
android:src="@drawable/ic_check_circle"
|
android:src="@drawable/ic_success_payment"
|
||||||
android:layout_marginBottom="32dp"
|
android:layout_marginBottom="32dp"
|
||||||
android:scaleType="centerInside"
|
android:scaleType="centerInside"
|
||||||
android:contentDescription="Success Icon" />
|
android:contentDescription="Success Icon" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user