refuse to add existing subscribtion
This commit is contained in:
		@@ -75,6 +75,12 @@ class SubscriptionsFragment : Fragment() {
 | 
			
		||||
                val billNumber = binding.editBillNumber.text.toString().trim()
 | 
			
		||||
                
 | 
			
		||||
                if (alias.isNotEmpty()) {
 | 
			
		||||
                    // Check if subscription number already exists
 | 
			
		||||
                    if (isSubscriptionNumberExists(subscriptionNumber)) {
 | 
			
		||||
                        Toast.makeText(requireContext(), "Subscription number already added", Toast.LENGTH_SHORT).show()
 | 
			
		||||
                        return@setOnClickListener
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                    subscriptionsViewModel.addSubscription(
 | 
			
		||||
                        name = alias,
 | 
			
		||||
                        subscriptionNumber = subscriptionNumber,
 | 
			
		||||
@@ -389,6 +395,12 @@ class SubscriptionsFragment : Fragment() {
 | 
			
		||||
            inputMethodManager.hideSoftInputFromWindow(currentFocusView.windowToken, 0)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private fun isSubscriptionNumberExists(subscriptionNumber: String): Boolean {
 | 
			
		||||
        return subscriptionsViewModel.subscriptions.value?.any { 
 | 
			
		||||
            it.subscription.subscriptionNumber == subscriptionNumber 
 | 
			
		||||
        } ?: false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun onDestroyView() {
 | 
			
		||||
        super.onDestroyView()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user