diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a1a4af0..55cc836 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -77,6 +77,11 @@ android:exported="false" android:label="Payment Review" android:theme="@style/Theme.GridFlow.NoActionBar" /> + { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "dashboard") + startActivity(intent) + finish() + } + R.id.nav_bill_history -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "bill_history") + startActivity(intent) + finish() + } + R.id.nav_subscriptions -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "subscriptions") + startActivity(intent) + finish() + } + R.id.nav_band_rates -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "band_rates") + startActivity(intent) + finish() + } + R.id.nav_pay_any_bill -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "pay_any_bill") + startActivity(intent) + finish() + } + } + binding.drawerLayout.closeDrawer(GravityCompat.START) + return true + } + + @Deprecated("Deprecated in Java") + override fun onBackPressed() { + if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { + binding.drawerLayout.closeDrawer(GravityCompat.START) + } else { + super.onBackPressed() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/sh/sar/gridflow/LoginActivity.kt b/app/src/main/java/sh/sar/gridflow/LoginActivity.kt index f9aff32..efe70fc 100644 --- a/app/src/main/java/sh/sar/gridflow/LoginActivity.kt +++ b/app/src/main/java/sh/sar/gridflow/LoginActivity.kt @@ -203,6 +203,7 @@ class LoginActivity : AppCompatActivity() { private fun handlePayWithoutAccount() { Log.d(TAG, "Pay without account button clicked") val intent = Intent(this, PayWithoutAccountActivity::class.java) + intent.putExtra("hide_toolbar", true) startActivity(intent) } diff --git a/app/src/main/java/sh/sar/gridflow/MainActivity.kt b/app/src/main/java/sh/sar/gridflow/MainActivity.kt index a4e19aa..2b229cc 100644 --- a/app/src/main/java/sh/sar/gridflow/MainActivity.kt +++ b/app/src/main/java/sh/sar/gridflow/MainActivity.kt @@ -10,6 +10,7 @@ import android.view.View import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.drawerlayout.widget.DrawerLayout @@ -89,10 +90,15 @@ class MainActivity : AppCompatActivity() { true } R.id.nav_pay_any_bill -> { - val intent = Intent(this, PayWithoutAccountActivity::class.java) - startActivity(intent) - drawerLayout.closeDrawers() - true + // Let default navigation handle it (will navigate to PayAnyBillFragment) + try { + navController.navigate(menuItem.itemId) + menuItem.isChecked = true + drawerLayout.closeDrawers() + true + } catch (e: Exception) { + false + } } else -> { // Let the default navigation handle other items @@ -107,6 +113,30 @@ class MainActivity : AppCompatActivity() { } } } + + // Handle navigation extras from other activities + handleNavigationIntent(intent) + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + intent?.let { handleNavigationIntent(it) } + } + + private fun handleNavigationIntent(intent: Intent) { + val navigateTo = intent.getStringExtra("navigate_to") + if (navigateTo != null) { + val navController = findNavController(R.id.nav_host_fragment_content_main) + when (navigateTo) { + "dashboard" -> navController.navigate(R.id.nav_dashboard) + "bill_history" -> navController.navigate(R.id.nav_bill_history) + "subscriptions" -> navController.navigate(R.id.nav_subscriptions) + "band_rates" -> navController.navigate(R.id.nav_band_rates) + "pay_any_bill" -> navController.navigate(R.id.nav_pay_any_bill) + } + // Close the drawer + binding.drawerLayout.closeDrawers() + } } private fun initializeNavigationHeader(navView: NavigationView) { diff --git a/app/src/main/java/sh/sar/gridflow/PayWithoutAccountActivity.kt b/app/src/main/java/sh/sar/gridflow/PayWithoutAccountActivity.kt index c6ff11b..041276d 100644 --- a/app/src/main/java/sh/sar/gridflow/PayWithoutAccountActivity.kt +++ b/app/src/main/java/sh/sar/gridflow/PayWithoutAccountActivity.kt @@ -1,13 +1,19 @@ package sh.sar.gridflow +import android.content.Intent import android.os.Bundle import android.util.Log +import android.view.MenuItem import android.view.View import android.widget.Toast +import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate +import androidx.core.view.GravityCompat import androidx.lifecycle.lifecycleScope +import com.google.android.material.navigation.NavigationView import kotlinx.coroutines.launch +import sh.sar.gridflow.R import sh.sar.gridflow.data.BillLookupResponse import sh.sar.gridflow.databinding.ActivityPayWithoutAccountBinding import sh.sar.gridflow.network.ApiResult @@ -15,11 +21,12 @@ import sh.sar.gridflow.network.FenakaApiService import java.text.SimpleDateFormat import java.util.* -class PayWithoutAccountActivity : AppCompatActivity() { +class PayWithoutAccountActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener { - private lateinit var binding: ActivityPayWithoutAccountBinding + private var binding: ActivityPayWithoutAccountBinding? = null private lateinit var apiService: FenakaApiService private var currentBill: BillLookupResponse? = null + private var drawerToggle: ActionBarDrawerToggle? = null companion object { private const val TAG = "PayWithoutAccountActivity" @@ -33,34 +40,161 @@ class PayWithoutAccountActivity : AppCompatActivity() { Log.d(TAG, "PayWithoutAccountActivity onCreate") - binding = ActivityPayWithoutAccountBinding.inflate(layoutInflater) - setContentView(binding.root) + // Check if toolbar should be hidden + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + if (hideToolbar) { + // Use original layout for login context + binding = ActivityPayWithoutAccountBinding.inflate(layoutInflater) + setContentView(binding!!.root) + binding!!.toolbar.visibility = View.GONE + // Remove margin since toolbar is hidden + val scrollView = findViewById(R.id.scroll_view) + scrollView?.let { view -> + val params = view.layoutParams as androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams + params.topMargin = 0 + view.layoutParams = params + } + } else { + // Use drawer layout for menu context + setContentView(R.layout.activity_pay_without_account_drawer) + // Don't use ViewBinding for drawer layout, access views manually + setupDrawer() + } apiService = FenakaApiService() setupClickListeners() } - private fun setupClickListeners() { - binding.btnContinue.setOnClickListener { - handleContinue() + private fun setupDrawer() { + val toolbar = findViewById(R.id.toolbar) + setSupportActionBar(toolbar) + supportActionBar?.apply { + title = "Pay Without Account" } - binding.btnPay.setOnClickListener { - handlePayment() + val drawerLayout = findViewById(R.id.drawer_layout) + drawerToggle = ActionBarDrawerToggle( + this, drawerLayout, toolbar, + R.string.navigation_drawer_open, R.string.navigation_drawer_close + ) + drawerLayout.addDrawerListener(drawerToggle!!) + drawerToggle?.syncState() + + val navView = findViewById(R.id.nav_view) + navView.setNavigationItemSelectedListener(this) + } + + // Helper methods to access views regardless of layout type + private fun getBillDetailsCard(): com.google.android.material.card.MaterialCardView { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.billDetailsCard + } else { + findViewById(R.id.bill_details_card) + } + } + + private fun getInputFieldsLayout(): android.widget.LinearLayout { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.inputFieldsLayout + } else { + findViewById(R.id.input_fields_layout) + } + } + + private fun getBillNumberInput(): com.google.android.material.textfield.TextInputEditText { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.etBillNumber + } else { + findViewById(R.id.et_bill_number) + } + } + + private fun getSubscriptionNumberInput(): com.google.android.material.textfield.TextInputEditText { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.etSubscriptionNumber + } else { + findViewById(R.id.et_subscription_number) + } + } + + private fun getContinueButton(): com.google.android.material.button.MaterialButton { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.btnContinue + } else { + findViewById(R.id.btn_continue) + } + } + + // Additional helper methods for views that exist only in the original layout + private fun getTvBillNumber(): android.widget.TextView? { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.tvBillNumber + } else { + findViewById(R.id.tv_bill_number) + } + } + + private fun getTvBillStatus(): android.widget.TextView? { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.tvBillStatus + } else { + findViewById(R.id.tv_bill_status) + } + } + + private fun getPayButton(): com.google.android.material.button.MaterialButton? { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + return if (hideToolbar) { + binding!!.btnPay + } else { + findViewById(R.id.btn_pay) + } + } + + private fun setupClickListeners() { + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + if (hideToolbar) { + // Use ViewBinding for original layout + binding!!.btnContinue.setOnClickListener { + handleContinue() + } + + binding!!.btnPay.setOnClickListener { + handlePayment() + } + } else { + // Use findViewById for drawer layout + val btnContinue = findViewById(R.id.btn_continue) + val btnPay = findViewById(R.id.btn_pay) + + btnContinue.setOnClickListener { + handleContinue() + } + + btnPay.setOnClickListener { + handlePayment() + } } } private fun handleContinue() { // Check if we're showing the card - if so, hide it and show input fields - if (binding.billDetailsCard.visibility == View.VISIBLE) { + if (getBillDetailsCard().visibility == View.VISIBLE) { Log.d(TAG, "Hiding bill details card and showing input fields") showInputFields() return } // Otherwise, perform bill search - val billNumber = binding.etBillNumber.text.toString().trim() - val subscriptionNumber = binding.etSubscriptionNumber.text.toString().trim() + val billNumber = getBillNumberInput().text.toString().trim() + val subscriptionNumber = getSubscriptionNumberInput().text.toString().trim() Log.d(TAG, "handleContinue called with bill: $billNumber, subscription: $subscriptionNumber") @@ -73,11 +207,11 @@ class PayWithoutAccountActivity : AppCompatActivity() { } private fun showInputFields() { - binding.inputFieldsLayout.visibility = View.VISIBLE - binding.billDetailsCard.visibility = View.GONE + getInputFieldsLayout().visibility = View.VISIBLE + getBillDetailsCard().visibility = View.GONE currentBill = null // Update button text to Continue when showing input fields - binding.btnContinue.text = "Continue" + getContinueButton().text = "Continue" } private fun fetchBillDetails(billNumber: String, subscriptionNumber: String) { @@ -149,63 +283,69 @@ class PayWithoutAccountActivity : AppCompatActivity() { private fun showBillDetails(bill: BillLookupResponse) { // Hide input fields and show bill details - binding.inputFieldsLayout.visibility = View.GONE - binding.billDetailsCard.visibility = View.VISIBLE + getInputFieldsLayout().visibility = View.GONE + getBillDetailsCard().visibility = View.VISIBLE // Update button text to Search Another Bill when showing card - binding.btnContinue.text = "Search Another Bill" + getContinueButton().text = "Search Another Bill" - // Set bill information - binding.tvBillNumber.text = bill.billNumber - binding.tvBillAmount.text = "MVR ${bill.billAmount}" - binding.tvBillStatus.text = bill.status.uppercase() - - // Set customer information - binding.tvCustomerName.text = bill.customer.name - binding.tvAccountNumber.text = bill.customer.accountNumber - binding.tvPhoneNumber.text = bill.customer.phone - - // Set address information - val address = "${bill.subscriptionAddress.property.name}, ${bill.subscriptionAddress.property.street.name}" - binding.tvAddress.text = address - - // Set subscription information - binding.tvSubscriptionNumber.text = bill.subscription.subscriptionNumber - binding.tvServiceType.text = if (bill.subscription.serviceId == 1) "Electricity" else "Water" - - // Format and set dates - val dueDateFormatted = formatDate(bill.dueDate) - val billDateFormatted = formatDate(bill.billDate) - binding.tvDueDate.text = dueDateFormatted - binding.tvBillDate.text = billDateFormatted + // Set bill information (only set views that exist in both layouts) + getTvBillNumber()?.text = bill.billNumber + getTvBillStatus()?.text = bill.status.uppercase() // Set payment status and button val isPaid = bill.status == "paid" - binding.btnPay.isEnabled = !isPaid - binding.btnPay.alpha = if (isPaid) 0.5f else 1.0f - binding.btnPay.text = if (isPaid) "Already Paid" else "Pay MVR ${bill.billAmount}" + getPayButton()?.let { payButton -> + payButton.isEnabled = !isPaid + payButton.alpha = if (isPaid) 0.5f else 1.0f + payButton.text = if (isPaid) "Already Paid" else "Pay MVR ${bill.billAmount}" + } - // Set status color - when (bill.status.lowercase()) { - "paid" -> { - binding.tvBillStatus.setTextColor(getColor(android.R.color.holo_green_dark)) - } - "unpaid" -> { - binding.tvBillStatus.setTextColor(getColor(android.R.color.holo_red_dark)) - } - else -> { - binding.tvBillStatus.setTextColor(getColor(android.R.color.holo_orange_dark)) + // Set status color based on payment status + getTvBillStatus()?.let { statusView -> + when (bill.status.lowercase()) { + "paid" -> { + statusView.setTextColor(getColor(android.R.color.holo_green_dark)) + } + "unpaid" -> { + statusView.setTextColor(getColor(android.R.color.holo_red_dark)) + } + else -> { + statusView.setTextColor(getColor(android.R.color.holo_orange_dark)) + } } } - // Show additional payment details if available - bill.billPaymentDetails?.let { paymentDetails -> - if (paymentDetails.paidAmount.toDoubleOrNull() ?: 0.0 > 0.0) { - binding.tvPaidAmount.visibility = View.VISIBLE - binding.tvPaidAmount.text = "Paid: MVR ${paymentDetails.paidAmount}" - - if (paymentDetails.pendingAmount.toDoubleOrNull() ?: 0.0 > 0.0) { - binding.tvPendingAmount.visibility = View.VISIBLE - binding.tvPendingAmount.text = "Pending: MVR ${paymentDetails.pendingAmount}" + // Note: Detailed bill information (customer name, address, etc.) + // is only shown in the original layout from login screen + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + if (hideToolbar) { + // Set detailed information only when using original layout + binding!!.tvBillAmount.text = "MVR ${bill.billAmount}" + binding!!.tvCustomerName.text = bill.customer.name + binding!!.tvAccountNumber.text = bill.customer.accountNumber + binding!!.tvPhoneNumber.text = bill.customer.phone + + val address = "${bill.subscriptionAddress.property.name}, ${bill.subscriptionAddress.property.street.name}" + binding!!.tvAddress.text = address + + binding!!.tvSubscriptionNumber.text = bill.subscription.subscriptionNumber + binding!!.tvServiceType.text = if (bill.subscription.serviceId == 1) "Electricity" else "Water" + + val dueDateFormatted = formatDate(bill.dueDate) + val billDateFormatted = formatDate(bill.billDate) + binding!!.tvDueDate.text = dueDateFormatted + binding!!.tvBillDate.text = billDateFormatted + + // Show payment details if available + bill.billPaymentDetails?.let { paymentDetails -> + if (paymentDetails.paidAmount.toDoubleOrNull() ?: 0.0 > 0.0) { + binding!!.tvPaidAmount.visibility = View.VISIBLE + binding!!.tvPaidAmount.text = "Paid: MVR ${paymentDetails.paidAmount}" + + if (paymentDetails.pendingAmount.toDoubleOrNull() ?: 0.0 > 0.0) { + binding!!.tvPendingAmount.visibility = View.VISIBLE + binding!!.tvPendingAmount.text = "Pending: MVR ${paymentDetails.pendingAmount}" + } } } } @@ -225,23 +365,23 @@ class PayWithoutAccountActivity : AppCompatActivity() { private fun validateInput(billNumber: String, subscriptionNumber: String): Boolean { if (billNumber.isEmpty()) { - binding.etBillNumber.error = "Bill number is required" + getBillNumberInput().error = "Bill number is required" return false } if (subscriptionNumber.isEmpty()) { - binding.etSubscriptionNumber.error = "Subscription number is required" + getSubscriptionNumberInput().error = "Subscription number is required" return false } // Basic validation - you can add more specific validation rules here if (billNumber.length < 3) { - binding.etBillNumber.error = "Bill number must be at least 3 characters" + getBillNumberInput().error = "Bill number must be at least 3 characters" return false } if (subscriptionNumber.length < 3) { - binding.etSubscriptionNumber.error = "Subscription number must be at least 3 characters" + getSubscriptionNumberInput().error = "Subscription number must be at least 3 characters" return false } @@ -249,15 +389,81 @@ class PayWithoutAccountActivity : AppCompatActivity() { } private fun setLoading(isLoading: Boolean) { - binding.btnContinue.isEnabled = !isLoading - binding.btnContinue.text = if (isLoading) "Searching Bill..." else "Continue" + getContinueButton().isEnabled = !isLoading + getContinueButton().text = if (isLoading) "Searching Bill..." else "Continue" - binding.etBillNumber.isEnabled = !isLoading - binding.etSubscriptionNumber.isEnabled = !isLoading + getBillNumberInput().isEnabled = !isLoading + getSubscriptionNumberInput().isEnabled = !isLoading if (isLoading) { - binding.billDetailsCard.visibility = View.GONE - binding.inputFieldsLayout.visibility = View.VISIBLE + getBillDetailsCard().visibility = View.GONE + getInputFieldsLayout().visibility = View.VISIBLE + } + } + + override fun onSupportNavigateUp(): Boolean { + onBackPressedDispatcher.onBackPressed() + return true + } + + override fun onNavigationItemSelected(item: android.view.MenuItem): Boolean { + when (item.itemId) { + R.id.nav_dashboard -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "dashboard") + startActivity(intent) + finish() + } + R.id.nav_bill_history -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "bill_history") + startActivity(intent) + finish() + } + R.id.nav_subscriptions -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "subscriptions") + startActivity(intent) + finish() + } + R.id.nav_band_rates -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "band_rates") + startActivity(intent) + finish() + } + R.id.nav_pay_any_bill -> { + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP + intent.putExtra("navigate_to", "pay_any_bill") + startActivity(intent) + finish() + } + } + val drawerLayout = findViewById(R.id.drawer_layout) + drawerLayout?.closeDrawer(androidx.core.view.GravityCompat.START) + return true + } + + @Deprecated("Deprecated in Java") + override fun onBackPressed() { + // Check if toolbar is hidden (launched from login) + val hideToolbar = intent.getBooleanExtra("hide_toolbar", false) + if (hideToolbar) { + // If launched from login, go back to login + super.onBackPressed() + } else { + // If launched from main menu, check if drawer is open + val drawerLayout = findViewById(R.id.drawer_layout) + if (drawerLayout?.isDrawerOpen(androidx.core.view.GravityCompat.START) == true) { + drawerLayout.closeDrawer(androidx.core.view.GravityCompat.START) + } else { + super.onBackPressed() + } } } } \ No newline at end of file diff --git a/app/src/main/java/sh/sar/gridflow/ui/payanybill/PayAnyBillViewModel.kt b/app/src/main/java/sh/sar/gridflow/ui/payanybill/PayAnyBillViewModel.kt index 58f601c..8129dbe 100644 --- a/app/src/main/java/sh/sar/gridflow/ui/payanybill/PayAnyBillViewModel.kt +++ b/app/src/main/java/sh/sar/gridflow/ui/payanybill/PayAnyBillViewModel.kt @@ -7,7 +7,7 @@ import androidx.lifecycle.ViewModel class PayAnyBillViewModel : ViewModel() { private val _text = MutableLiveData().apply { - value = "Pay Any Bill\n\nComing soon..." + value = "Coming Soon" } val text: LiveData = _text } diff --git a/app/src/main/java/sh/sar/gridflow/ui/subscriptions/DetailedSubscriptionsAdapter.kt b/app/src/main/java/sh/sar/gridflow/ui/subscriptions/DetailedSubscriptionsAdapter.kt index 308d394..3887ebe 100644 --- a/app/src/main/java/sh/sar/gridflow/ui/subscriptions/DetailedSubscriptionsAdapter.kt +++ b/app/src/main/java/sh/sar/gridflow/ui/subscriptions/DetailedSubscriptionsAdapter.kt @@ -9,7 +9,10 @@ import androidx.recyclerview.widget.RecyclerView import sh.sar.gridflow.data.CustomerSubscription import sh.sar.gridflow.databinding.ItemSubscriptionDetailedBinding -class DetailedSubscriptionsAdapter : ListAdapter(SubscriptionDiffCallback()) { +class DetailedSubscriptionsAdapter( + private val onEditClick: (CustomerSubscription) -> Unit, + private val onDeleteClick: (CustomerSubscription) -> Unit +) : ListAdapter(SubscriptionDiffCallback()) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubscriptionViewHolder { val binding = ItemSubscriptionDetailedBinding.inflate( @@ -21,14 +24,18 @@ class DetailedSubscriptionsAdapter : ListAdapter Unit, + onDeleteClick: (CustomerSubscription) -> Unit + ) { with(binding) { // Service icon and category val serviceIcon = when (subscription.subscription.serviceId) { @@ -53,13 +60,13 @@ class DetailedSubscriptionsAdapter : ListAdapter showEditDialog(subscription) }, + onDeleteClick = { subscription -> showDeleteDialog(subscription) } + ) binding.recyclerSubscriptions.apply { layoutManager = LinearLayoutManager(requireContext()) adapter = subscriptionsAdapter @@ -46,7 +55,8 @@ class SubscriptionsFragment : Fragment() { // Handle FAB click binding.fabAddSubscription.setOnClickListener { - Toast.makeText(context, "Add subscription coming soon", Toast.LENGTH_SHORT).show() + val intent = Intent(requireContext(), AddSubscriptionActivity::class.java) + startActivity(intent) } // Handle retry button @@ -112,6 +122,50 @@ class SubscriptionsFragment : Fragment() { binding.textError.text = error } + private fun showEditDialog(subscription: CustomerSubscription) { + val dialogBinding = DialogEditSubscriptionBinding.inflate(layoutInflater) + dialogBinding.editSubscriptionName.setText(subscription.name) + + val dialog = AlertDialog.Builder(requireContext()) + .setView(dialogBinding.root) + .create() + + dialogBinding.btnCancel.setOnClickListener { + dialog.dismiss() + } + + dialogBinding.btnSubmit.setOnClickListener { + val newName = dialogBinding.editSubscriptionName.text.toString().trim() + if (newName.isNotEmpty()) { + Toast.makeText(context, "Edit API call needed for: $newName", Toast.LENGTH_SHORT).show() + dialog.dismiss() + } else { + dialogBinding.editSubscriptionName.error = "Name cannot be empty" + } + } + + dialog.show() + } + + private fun showDeleteDialog(subscription: CustomerSubscription) { + val dialogBinding = DialogDeleteSubscriptionBinding.inflate(layoutInflater) + + val dialog = AlertDialog.Builder(requireContext()) + .setView(dialogBinding.root) + .create() + + dialogBinding.btnCancel.setOnClickListener { + dialog.dismiss() + } + + dialogBinding.btnYes.setOnClickListener { + Toast.makeText(context, "Delete API call needed for: ${subscription.name}", Toast.LENGTH_SHORT).show() + dialog.dismiss() + } + + dialog.show() + } + override fun onDestroyView() { super.onDestroyView() _binding = null diff --git a/app/src/main/res/layout/activity_add_subscription.xml b/app/src/main/res/layout/activity_add_subscription.xml new file mode 100644 index 0000000..10d40c4 --- /dev/null +++ b/app/src/main/res/layout/activity_add_subscription.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_pay_without_account.xml b/app/src/main/res/layout/activity_pay_without_account.xml index fb41d46..050c69f 100644 --- a/app/src/main/res/layout/activity_pay_without_account.xml +++ b/app/src/main/res/layout/activity_pay_without_account.xml @@ -1,10 +1,31 @@ - + android:background="?android:attr/colorBackground" + tools:context=".PayWithoutAccountActivity"> + + + + + + + + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_pay_without_account_drawer.xml b/app/src/main/res/layout/activity_pay_without_account_drawer.xml new file mode 100644 index 0000000..098a09c --- /dev/null +++ b/app/src/main/res/layout/activity_pay_without_account_drawer.xml @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_delete_subscription.xml b/app/src/main/res/layout/dialog_delete_subscription.xml new file mode 100644 index 0000000..b9b66c2 --- /dev/null +++ b/app/src/main/res/layout/dialog_delete_subscription.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_edit_subscription.xml b/app/src/main/res/layout/dialog_edit_subscription.xml new file mode 100644 index 0000000..e41aaab --- /dev/null +++ b/app/src/main/res/layout/dialog_edit_subscription.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_pay_any_bill.xml b/app/src/main/res/layout/fragment_pay_any_bill.xml index ba0fed7..0fc9ca0 100644 --- a/app/src/main/res/layout/fragment_pay_any_bill.xml +++ b/app/src/main/res/layout/fragment_pay_any_bill.xml @@ -1,29 +1,48 @@ - + android:gravity="center" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + + + android:textColor="?android:attr/textColorSecondary" + android:alpha="0.7" /> - +