forked from LibreMV/GridFlow
removed add subs activity and made it to a fragment
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
package sh.sar.gridflow
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import sh.sar.gridflow.R
|
||||
import sh.sar.gridflow.databinding.ActivityAddSubscriptionBinding
|
||||
|
||||
class AddSubscriptionActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private lateinit var binding: ActivityAddSubscriptionBinding
|
||||
private lateinit var drawerToggle: ActionBarDrawerToggle
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityAddSubscriptionBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setupViews()
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
// Setup toolbar with hamburger menu
|
||||
setSupportActionBar(binding.toolbar)
|
||||
supportActionBar?.apply {
|
||||
title = "Add Subscription"
|
||||
}
|
||||
|
||||
// Setup drawer toggle
|
||||
drawerToggle = ActionBarDrawerToggle(
|
||||
this, binding.drawerLayout, binding.toolbar,
|
||||
R.string.navigation_drawer_open, R.string.navigation_drawer_close
|
||||
)
|
||||
binding.drawerLayout.addDrawerListener(drawerToggle)
|
||||
drawerToggle.syncState()
|
||||
|
||||
// Setup navigation
|
||||
binding.navView.setNavigationItemSelectedListener(this)
|
||||
|
||||
// Handle continue button click
|
||||
binding.btnContinue.setOnClickListener {
|
||||
val subscriptionNumber = binding.editSubscriptionNumber.text.toString().trim()
|
||||
val billNumber = binding.editBillNumber.text.toString().trim()
|
||||
val alias = binding.editAlias.text.toString().trim()
|
||||
|
||||
if (validateInputs(subscriptionNumber, billNumber, alias)) {
|
||||
Toast.makeText(this, "Continue action not implemented yet", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateInputs(subscriptionNumber: String, billNumber: String, alias: String): Boolean {
|
||||
var isValid = true
|
||||
|
||||
if (subscriptionNumber.isEmpty()) {
|
||||
binding.editSubscriptionNumber.error = "Subscription number is required"
|
||||
isValid = false
|
||||
}
|
||||
|
||||
if (billNumber.isEmpty()) {
|
||||
binding.editBillNumber.error = "Bill number is required"
|
||||
isValid = false
|
||||
}
|
||||
|
||||
if (alias.isEmpty()) {
|
||||
binding.editAlias.error = "Alias/Description is required"
|
||||
isValid = false
|
||||
}
|
||||
|
||||
return isValid
|
||||
}
|
||||
|
||||
override fun onNavigationItemSelected(item: 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()
|
||||
}
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
package sh.sar.gridflow.ui.subscriptions
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -10,7 +9,6 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import sh.sar.gridflow.AddSubscriptionActivity
|
||||
import sh.sar.gridflow.data.CustomerSubscription
|
||||
import sh.sar.gridflow.databinding.DialogDeleteSubscriptionBinding
|
||||
import sh.sar.gridflow.databinding.DialogEditSubscriptionBinding
|
||||
@@ -55,8 +53,24 @@ class SubscriptionsFragment : Fragment() {
|
||||
|
||||
// Handle FAB click
|
||||
binding.fabAddSubscription.setOnClickListener {
|
||||
val intent = Intent(requireContext(), AddSubscriptionActivity::class.java)
|
||||
startActivity(intent)
|
||||
showAddSubscriptionForm()
|
||||
}
|
||||
|
||||
// Handle cancel button click
|
||||
binding.btnCancelAdd.setOnClickListener {
|
||||
hideAddSubscriptionForm()
|
||||
}
|
||||
|
||||
// Handle continue button click
|
||||
binding.btnContinue.setOnClickListener {
|
||||
val subscriptionNumber = binding.editSubscriptionNumber.text.toString().trim()
|
||||
val billNumber = binding.editBillNumber.text.toString().trim()
|
||||
val alias = binding.editAlias.text.toString().trim()
|
||||
|
||||
if (validateInputs(subscriptionNumber, billNumber, alias)) {
|
||||
Toast.makeText(requireContext(), "Continue action not implemented yet", Toast.LENGTH_SHORT).show()
|
||||
hideAddSubscriptionForm()
|
||||
}
|
||||
}
|
||||
|
||||
// Handle retry button
|
||||
@@ -165,6 +179,55 @@ class SubscriptionsFragment : Fragment() {
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun showAddSubscriptionForm() {
|
||||
binding.scrollAddForm.visibility = View.VISIBLE
|
||||
binding.recyclerSubscriptions.visibility = View.GONE
|
||||
binding.layoutError.visibility = View.GONE
|
||||
binding.layoutEmpty.visibility = View.GONE
|
||||
binding.progressLoading.visibility = View.GONE
|
||||
binding.fabAddSubscription.visibility = View.GONE
|
||||
|
||||
// Clear form fields
|
||||
binding.editSubscriptionNumber.text?.clear()
|
||||
binding.editBillNumber.text?.clear()
|
||||
binding.editAlias.text?.clear()
|
||||
}
|
||||
|
||||
private fun hideAddSubscriptionForm() {
|
||||
binding.scrollAddForm.visibility = View.GONE
|
||||
binding.fabAddSubscription.visibility = View.VISIBLE
|
||||
|
||||
// Show appropriate state based on subscriptions
|
||||
subscriptionsViewModel.subscriptions.value?.let { subscriptions ->
|
||||
if (subscriptions.isEmpty()) {
|
||||
showEmptyState()
|
||||
} else {
|
||||
showSubscriptionsList()
|
||||
}
|
||||
} ?: showEmptyState()
|
||||
}
|
||||
|
||||
private fun validateInputs(subscriptionNumber: String, billNumber: String, alias: String): Boolean {
|
||||
var isValid = true
|
||||
|
||||
if (subscriptionNumber.isEmpty()) {
|
||||
binding.editSubscriptionNumber.error = "Subscription number is required"
|
||||
isValid = false
|
||||
}
|
||||
|
||||
if (billNumber.isEmpty()) {
|
||||
binding.editBillNumber.error = "Bill number is required"
|
||||
isValid = false
|
||||
}
|
||||
|
||||
if (alias.isEmpty()) {
|
||||
binding.editAlias.error = "Alias/Description is required"
|
||||
isValid = false
|
||||
}
|
||||
|
||||
return isValid
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
|
@@ -1,178 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".AddSubscriptionActivity">
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/colorBackground">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/Theme.GridFlow.AppBarOverlay">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:layout_marginTop="?attr/actionBarSize">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="32dp"
|
||||
android:gravity="center">
|
||||
|
||||
<!-- Logo and Title Section -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_app_logo"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:contentDescription="GridFlow Logo" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add New Subscription"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enter your subscription details below"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:alpha="0.7"
|
||||
android:layout_marginBottom="32dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Subscription Form -->
|
||||
<LinearLayout
|
||||
android:id="@+id/input_form_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="32dp">
|
||||
|
||||
<!-- Input Fields Container -->
|
||||
<LinearLayout
|
||||
android:id="@+id/input_fields_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Subscription Number Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:hint="Subscription Number"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_subscription_number"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- Bill Number Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:hint="Bill Number"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_bill_number"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- Alias/Description Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:hint="Alias/Description"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_alias"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Continue Button -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_continue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:text="Continue"
|
||||
android:textSize="16sp"
|
||||
android:textAllCaps="false"
|
||||
android:layout_marginBottom="24dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Spacer for bottom -->
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="32dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer" />
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
@@ -82,6 +82,140 @@
|
||||
android:paddingBottom="80dp"
|
||||
tools:listitem="@layout/item_subscription_detailed" />
|
||||
|
||||
<!-- Add subscription form -->
|
||||
<ScrollView
|
||||
android:id="@+id/scroll_add_form"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:visibility="gone"
|
||||
android:background="?android:attr/colorBackground">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="32dp"
|
||||
android:gravity="center">
|
||||
|
||||
<!-- Header Section -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="32dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Add New Subscription"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enter your subscription details below"
|
||||
android:textSize="14sp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:alpha="0.7" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Form Fields -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Subscription Number Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:hint="Subscription Number"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_subscription_number"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- Bill Number Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:hint="Bill Number"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_bill_number"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- Alias/Description Input -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:hint="Alias/Description"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_alias"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- Buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_cancel_add"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="56dp"
|
||||
android:text="Cancel"
|
||||
android:textSize="16sp"
|
||||
android:textAllCaps="false"
|
||||
android:layout_marginEnd="8dp"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_continue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="56dp"
|
||||
android:text="Continue"
|
||||
android:textSize="16sp"
|
||||
android:textAllCaps="false"
|
||||
android:paddingHorizontal="24dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_add_subscription"
|
||||
android:layout_width="wrap_content"
|
||||
|
Reference in New Issue
Block a user