diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6e22948..8a6c6dc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -87,6 +87,10 @@ android:name=".transaction.ResultTransactionActivity" android:exported="false" /> + + @@ -95,6 +99,10 @@ android:name=".bantuan.BantuanFormActivity" android:exported="false" /> + + diff --git a/app/src/main/java/com/example/bdkipoc/MainActivity.java b/app/src/main/java/com/example/bdkipoc/MainActivity.java index 1a8be72..0d7fa5c 100644 --- a/app/src/main/java/com/example/bdkipoc/MainActivity.java +++ b/app/src/main/java/com/example/bdkipoc/MainActivity.java @@ -32,8 +32,12 @@ import com.example.bdkipoc.histori.HistoryActivity; import com.example.bdkipoc.transaction.CreateTransactionActivity; import com.example.bdkipoc.transaction.ResultTransactionActivity; +import com.example.bdkipoc.settlement.SettlementActivity; + import com.example.bdkipoc.bantuan.BantuanActivity; +import com.example.bdkipoc.infotoko.InfoTokoActivity; + import org.json.JSONObject; public class MainActivity extends AppCompatActivity { @@ -311,23 +315,23 @@ public class MainActivity extends AppCompatActivity { startActivityWithAuth(new Intent(MainActivity.this, QrisActivity.class)); // Col-2 } else if (cardId == R.id.card_transfer) { - navigateToCreateTransaction("transfer", cardId, "Transfer"); + Toast.makeText(this, "Transfer - Coming Soon", Toast.LENGTH_SHORT).show(); } else if (cardId == R.id.card_uang_elektronik) { navigateToCreateTransaction("e_money", cardId, "Uang Elektronik"); } else if (cardId == R.id.card_cetak_ulang) { startActivityWithAuth(new Intent(MainActivity.this, ReprintActivity.class)); // Col-3 } else if (cardId == R.id.card_refund) { - navigateToCreateTransaction("refund", cardId, "Refund"); + Toast.makeText(this, "Refund - Coming Soon", Toast.LENGTH_SHORT).show(); } else if (cardId == R.id.card_settlement) { - Toast.makeText(this, "Settlement - Coming Soon", Toast.LENGTH_SHORT).show(); + startActivityWithAuth(new Intent(MainActivity.this, SettlementActivity.class)); } else if (cardId == R.id.card_histori) { startActivityWithAuth(new Intent(MainActivity.this, HistoryActivity.class)); // Col-4 } else if (cardId == R.id.card_bantuan) { startActivityWithAuth(new Intent(MainActivity.this, BantuanActivity.class)); } else if (cardId == R.id.card_info_toko) { - Toast.makeText(this, "Info Toko - Coming Soon", Toast.LENGTH_SHORT).show(); + startActivityWithAuth(new Intent(MainActivity.this, InfoTokoActivity.class)); } else if (cardId == R.id.card_pengaturan) { Toast.makeText(this, "Pengaturan - Coming Soon", Toast.LENGTH_SHORT).show(); } else { diff --git a/app/src/main/java/com/example/bdkipoc/infotoko/InfoTokoActivity.java b/app/src/main/java/com/example/bdkipoc/infotoko/InfoTokoActivity.java new file mode 100644 index 0000000..dec501d --- /dev/null +++ b/app/src/main/java/com/example/bdkipoc/infotoko/InfoTokoActivity.java @@ -0,0 +1,314 @@ +package com.example.bdkipoc.infotoko; + +import android.os.Bundle; +import android.view.View; +import android.view.ViewParent; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; +import android.util.Log; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.cardview.widget.CardView; + +import com.example.bdkipoc.LoginActivity; +import com.example.bdkipoc.R; +import com.google.android.material.button.MaterialButton; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + +import org.json.JSONException; +import org.json.JSONObject; + +public class InfoTokoActivity extends AppCompatActivity { + + private static final String TAG = "InfoTokoActivity"; + + // Views + private TextView tvStoreName; + private TextView tvMerchantId; + private TextView tvTerminalId; + + private TextInputEditText etEmail; + private TextInputEditText etPassword; + private TextInputEditText etOwnerName; + private TextInputEditText etNik; + private TextInputEditText etPhone; + private TextInputEditText etBusinessType; + private TextInputEditText etBusinessName; + private TextInputEditText etAddress; + + private MaterialButton btnUpdate; + private ImageView btnBack; + + // Data + private String authToken; + private JSONObject userData; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_info_toko); + + // Check if user is logged in + if (!LoginActivity.isLoggedIn(this)) { + finish(); + return; + } + + // Initialize views + initializeViews(); + + // Load user data + loadUserData(); + + // Setup listeners + setupListeners(); + + // Display store information + displayStoreInfo(); + } + + private void initializeViews() { + // Header + tvStoreName = findViewById(R.id.tv_store_name); + tvMerchantId = findViewById(R.id.tv_merchant_id); + tvTerminalId = findViewById(R.id.tv_terminal_id); + btnBack = findViewById(R.id.btn_back); + + // Account Information + etEmail = findViewById(R.id.et_email); + etPassword = findViewById(R.id.et_password); + + // Store Information + etOwnerName = findViewById(R.id.et_owner_name); + etNik = findViewById(R.id.et_nik); + etPhone = findViewById(R.id.et_phone); + etBusinessType = findViewById(R.id.et_business_type); + etBusinessName = findViewById(R.id.et_business_name); + etAddress = findViewById(R.id.et_address); + + // Button + btnUpdate = findViewById(R.id.btn_update); + } + + private void loadUserData() { + // Get authentication token + authToken = getIntent().getStringExtra("AUTH_TOKEN"); + if (authToken == null) { + authToken = LoginActivity.getToken(this); + } + + // Get user data + String userDataString = getIntent().getStringExtra("USER_DATA"); + if (userDataString != null) { + try { + userData = new JSONObject(userDataString); + } catch (JSONException e) { + Log.e(TAG, "Error parsing user data: " + e.getMessage()); + } + } + + if (userData == null) { + userData = LoginActivity.getUserDataAsJson(this); + } + + Log.d(TAG, "Loaded auth token: " + (authToken != null ? "✓" : "✗")); + Log.d(TAG, "Loaded user data: " + (userData != null ? "✓" : "✗")); + } + + private void setupListeners() { + // Back button + if (btnBack != null) { + btnBack.setOnClickListener(v -> finish()); + } + + // Update button + if (btnUpdate != null) { + btnUpdate.setOnClickListener(v -> updateStoreInfo()); + } + } + + private void displayStoreInfo() { + // Display store name and IDs (static for header) + tvStoreName.setText("TOKO KLONTONG PAK EKO"); + tvMerchantId.setText("MID: 12345678901"); + tvTerminalId.setText("TID: 12345678901"); + + // Hide fields that are not needed based on requirements + hideUnnecessaryFields(); + + // Display data from login response + if (userData != null) { + try { + // Email - from API response + String email = userData.optString("email", ""); + if (!email.isEmpty()) { + etEmail.setText(email); + } else { + etEmail.setText("Email tidak tersedia"); + } + + // Password - show masked placeholder (we don't store actual password) + etPassword.setText("••••••••"); + etPassword.setEnabled(false); // Disable editing for security + + // Nama Pemilik - from API response + String ownerName = userData.optString("name", ""); + if (!ownerName.isEmpty()) { + etOwnerName.setText(ownerName); + } else { + etOwnerName.setText("Nama tidak tersedia"); + } + + // Nomor Telepon - from API response + String phone = userData.optString("phone", ""); + if (!phone.isEmpty()) { + etPhone.setText(phone); + } else { + etPhone.setText("Nomor telepon tidak tersedia"); + } + + // Log the user data for debugging + Log.d(TAG, "User Data: " + userData.toString()); + + } catch (Exception e) { + Log.e(TAG, "Error displaying user info: " + e.getMessage()); + Toast.makeText(this, "Error loading user data", Toast.LENGTH_SHORT).show(); + } + } else { + // Show default/empty values if no user data + etEmail.setText("Email tidak tersedia"); + etPassword.setText("••••••••"); + etPassword.setEnabled(false); + etOwnerName.setText("Nama tidak tersedia"); + etPhone.setText("Nomor telepon tidak tersedia"); + } + } + + private void hideUnnecessaryFields() { + // Hide NIK field and its container + ViewParent nikContainer = etNik.getParent(); + if (nikContainer != null && nikContainer instanceof View) { + ((View) nikContainer).setVisibility(View.GONE); + } + + // Hide Business Type field and its container + ViewParent businessTypeContainer = etBusinessType.getParent(); + if (businessTypeContainer != null && businessTypeContainer instanceof View) { + ((View) businessTypeContainer).setVisibility(View.GONE); + } + + // Hide Business Name field and its container + ViewParent businessNameContainer = etBusinessName.getParent(); + if (businessNameContainer != null && businessNameContainer instanceof View) { + ((View) businessNameContainer).setVisibility(View.GONE); + } + + // Hide Address field and its container + ViewParent addressContainer = etAddress.getParent(); + if (addressContainer != null && addressContainer instanceof View) { + ((View) addressContainer).setVisibility(View.GONE); + } + } + + private void updateStoreInfo() { + // Validate inputs + if (!validateInputs()) { + return; + } + + // Show loading + btnUpdate.setEnabled(false); + btnUpdate.setText("Memperbarui..."); + + // Simulate update process (in real app, this would call API) + btnUpdate.postDelayed(() -> { + // In a real implementation, you would: + // 1. Call API to update user info + // 2. Update SharedPreferences with new data + // 3. Show success/error message + + // Show success message + Toast.makeText(this, "Informasi akun berhasil diperbarui", Toast.LENGTH_SHORT).show(); + + // Reset button state + btnUpdate.setEnabled(true); + btnUpdate.setText("Perbarui Informasi Toko"); + + // Optional: Save updated data locally + saveUpdatedData(); + + }, 2000); // Simulate 2 second delay + } + + private boolean validateInputs() { + // Check email + String email = etEmail.getText().toString().trim(); + if (email.isEmpty()) { + etEmail.setError("Email tidak boleh kosong"); + etEmail.requestFocus(); + return false; + } + + if (!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) { + etEmail.setError("Format email tidak valid"); + etEmail.requestFocus(); + return false; + } + + // Check owner name + String ownerName = etOwnerName.getText().toString().trim(); + if (ownerName.isEmpty()) { + etOwnerName.setError("Nama pemilik tidak boleh kosong"); + etOwnerName.requestFocus(); + return false; + } + + // Check phone + String phone = etPhone.getText().toString().trim(); + if (phone.isEmpty()) { + etPhone.setError("Nomor telepon tidak boleh kosong"); + etPhone.requestFocus(); + return false; + } + + if (phone.length() < 10) { + etPhone.setError("Nomor telepon tidak valid"); + etPhone.requestFocus(); + return false; + } + + return true; + } + + private void saveUpdatedData() { + + try { + JSONObject updatedData = new JSONObject(); + updatedData.put("email", etEmail.getText().toString().trim()); + updatedData.put("name", etOwnerName.getText().toString().trim()); + updatedData.put("phone", etPhone.getText().toString().trim()); + + // Merge with existing userData + if (userData != null) { + // Keep other fields from original userData + updatedData.put("id", userData.optString("id", "")); + updatedData.put("role", userData.optString("role", "")); + // Add other fields as needed + } + + Log.d(TAG, "Updated data: " + updatedData.toString()); + + } catch (JSONException e) { + Log.e(TAG, "Error creating updated data: " + e.getMessage()); + } + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + finish(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bdkipoc/settlement/SettlementActivity.java b/app/src/main/java/com/example/bdkipoc/settlement/SettlementActivity.java index ad1f83d..412fd32 100644 --- a/app/src/main/java/com/example/bdkipoc/settlement/SettlementActivity.java +++ b/app/src/main/java/com/example/bdkipoc/settlement/SettlementActivity.java @@ -1,4 +1,4 @@ -package com.example.bdkipoc; +package com.example.bdkipoc.settlement; import android.os.AsyncTask; import android.os.Bundle; @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import com.example.bdkipoc.R; + public class SettlementActivity extends AppCompatActivity { private TextView tvTotalAmount; diff --git a/app/src/main/res/layout/activity_info_toko.xml b/app/src/main/res/layout/activity_info_toko.xml new file mode 100644 index 0000000..cbdfed3 --- /dev/null +++ b/app/src/main/res/layout/activity_info_toko.xml @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file