Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Fix-323: Improved in Adding/Editing Members or Leaders #187

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.apache.fineract.ui.online.groups.creategroup

import android.app.AlertDialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -12,10 +13,9 @@ import butterknife.Optional
import com.stepstone.stepper.Step
import com.stepstone.stepper.VerificationError
import com.wajahatkarim3.easyvalidation.core.view_ktx.validator
import kotlinx.android.synthetic.main.fragment_step_add_group_leader.*
import kotlinx.android.synthetic.main.fragment_step_add_group_leader.view.*
import kotlinx.android.synthetic.main.fragment_step_add_group_member.view.*
import kotlinx.android.synthetic.main.fragment_step_add_group_member.view.rv_name
import kotlinx.android.synthetic.main.member_leader_layout.view.*
import org.apache.fineract.R
import org.apache.fineract.ui.adapters.NameListAdapter
import org.apache.fineract.ui.base.FineractBaseActivity
Expand Down Expand Up @@ -89,36 +89,7 @@ class AddGroupLeaderStepFragment : FineractBaseFragment(), Step, NameListAdapter

private fun showAddLeaderView(action: GroupAction, name: String?) {
currentAction = action
llAddLeader.visibility = View.VISIBLE
when (action) {
GroupAction.CREATE -> {
btnAddLeader.text = getString(R.string.add)
}
GroupAction.EDIT -> {
etNewLeader.setText(name)
btnAddLeader.text = getString(R.string.update)
}
}
}

@Optional
@OnClick(R.id.btnAddLeader)
fun addLeader() {
if (etNewLeader.validator()
.nonEmpty()
.noNumbers()
.addErrorCallback { etNewLeader.error = it }.check()) {
if (currentAction == GroupAction.CREATE) {
leaders.add(etNewLeader.text.toString())
} else {
leaders[editItemPosition] = etNewLeader.text.toString()
}
etNewLeader.text.clear()
llAddLeader.visibility = View.GONE
Utils.hideKeyboard(context, etNewLeader)
showRecyclerView(true)
nameLisAdapter.submitList(leaders)
}
showAddEditDialog(action, name)
}

fun showRecyclerView(isShow: Boolean) {
Expand All @@ -132,13 +103,6 @@ class AddGroupLeaderStepFragment : FineractBaseFragment(), Step, NameListAdapter

}

@Optional
@OnClick(R.id.btnCancelAddLeader)
fun cancelLeaderAddition() {
etNewLeader.text.clear()
llAddLeader.visibility = View.GONE
}

override fun onSelected() {
}

Expand Down Expand Up @@ -178,4 +142,40 @@ class AddGroupLeaderStepFragment : FineractBaseFragment(), Step, NameListAdapter
}.run { show() }
}

private fun showAddEditDialog(action: GroupAction, name: String?) {
val layout = layoutInflater.inflate(R.layout.member_leader_layout, null)
val dialog = AlertDialog.Builder(context)
.setView(layout)
.create()
dialog.show()

if (action == GroupAction.CREATE) {
layout.btnAddMember.text = getString(R.string.add)
layout.tv_member_head.text = getString(R.string.add_new_leader)
}
else if (action == GroupAction.EDIT) {
layout.etNewMember.setText(name)
layout.btnAddMember.text = getString(R.string.update)
layout.tv_member_head.text = getString(R.string.edit_leader)
}

layout.btnAddMember.setOnClickListener {
if (layout.etNewMember.validator()
.nonEmpty()
.noNumbers()
.addErrorCallback { layout.etNewMember.error = it }.check()) {
if (currentAction == GroupAction.CREATE) {
leaders.add(layout.etNewMember.text.toString())
} else {
leaders[editItemPosition] = layout.etNewMember.text.toString()
}
Utils.hideKeyboard(context, layout.etNewMember)
showRecyclerView(true)
nameLisAdapter.submitList(leaders)
dialog.dismiss()
}
}

layout.btnCancelAddMember.setOnClickListener { dialog.dismiss() }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.apache.fineract.ui.online.groups.creategroup

import android.app.AlertDialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -12,8 +13,8 @@ import butterknife.Optional
import com.stepstone.stepper.Step
import com.stepstone.stepper.VerificationError
import com.wajahatkarim3.easyvalidation.core.view_ktx.validator
import kotlinx.android.synthetic.main.fragment_step_add_group_member.*
import kotlinx.android.synthetic.main.fragment_step_add_group_member.view.*
import kotlinx.android.synthetic.main.member_leader_layout.view.*
import org.apache.fineract.R
import org.apache.fineract.ui.adapters.NameListAdapter
import org.apache.fineract.ui.base.FineractBaseActivity
Expand Down Expand Up @@ -87,36 +88,7 @@ class AddGroupMemberStepFragment : FineractBaseFragment(), Step, NameListAdapter

private fun showAddMemberView(action: GroupAction, name: String?) {
currentAction = action
llAddMember.visibility = View.VISIBLE
when (action) {
GroupAction.CREATE -> {
btnAddMember.text = getString(R.string.add)
}
GroupAction.EDIT -> {
etNewMember.setText(name)
btnAddMember.text = getString(R.string.update)
}
}
}

@Optional
@OnClick(R.id.btnAddMember)
fun addMember() {
if (etNewMember.validator()
.nonEmpty()
.noNumbers()
.addErrorCallback { etNewMember.error = it }.check()) {
if (currentAction == GroupAction.CREATE) {
members.add(etNewMember.text.toString())
} else {
members[editItemPosition] = etNewMember.text.toString()
}
etNewMember.text.clear()
llAddMember.visibility = View.GONE
Utils.hideKeyboard(context, etNewMember)
showRecyclerView(true)
nameLisAdapter.submitList(members)
}
showAddEditDialog(action, name)
}

fun showRecyclerView(isShow: Boolean) {
Expand All @@ -127,14 +99,6 @@ class AddGroupMemberStepFragment : FineractBaseFragment(), Step, NameListAdapter
rootView.rv_name.visibility = View.GONE
rootView.tvAddedMember.visibility = View.VISIBLE
}

}

@Optional
@OnClick(R.id.btnCancelAddMember)
fun cancelMemberAddition() {
etNewMember.text.clear()
llAddMember.visibility = View.GONE
}

override fun onSelected() {
Expand Down Expand Up @@ -175,4 +139,41 @@ class AddGroupMemberStepFragment : FineractBaseFragment(), Step, NameListAdapter
createMaterialDialog()
}.run { show() }
}

private fun showAddEditDialog(action: GroupAction, name: String?) {
val layout = layoutInflater.inflate(R.layout.member_leader_layout, null)
val dialog = AlertDialog.Builder(context)
.setView(layout)
.create()
dialog.show()

if (action == GroupAction.CREATE) {
layout.btnAddMember.text = getString(R.string.add)
layout.tv_member_head.text = getString(R.string.add_new_member)
}
else if (action == GroupAction.EDIT) {
layout.etNewMember.setText(name)
layout.btnAddMember.text = getString(R.string.update)
layout.tv_member_head.text = getString(R.string.edit_member)
}

layout.btnAddMember.setOnClickListener {
if (layout.etNewMember.validator()
.nonEmpty()
.noNumbers()
.addErrorCallback { layout.etNewMember.error = it }.check()) {
if (currentAction == GroupAction.CREATE) {
members.add(layout.etNewMember.text.toString())
} else {
members[editItemPosition] = layout.etNewMember.text.toString()
}
Utils.hideKeyboard(context, layout.etNewMember)
showRecyclerView(true)
nameLisAdapter.submitList(members)
dialog.dismiss()
}
}

layout.btnCancelAddMember.setOnClickListener { dialog.dismiss() }
}
}
47 changes: 0 additions & 47 deletions app/src/main/res/layout/fragment_step_add_group_leader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,53 +61,6 @@
android:text="@string/no_group_leader_added"
android:visibility="visible" />

<LinearLayout
android:id="@+id/llAddLeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_padding_12dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="@dimen/layout_padding_16dp"
android:visibility="gone">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/etNewLeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name" />

</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_padding_16dp"
android:gravity="right">

<Button
android:id="@+id/btnCancelAddLeader"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:textSize="@dimen/text_size_14sp" />

<Button
android:id="@+id/btnAddLeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add" />

</LinearLayout>

</LinearLayout>


</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down
47 changes: 0 additions & 47 deletions app/src/main/res/layout/fragment_step_add_group_member.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,6 @@
android:text="@string/no_group_member_added"
android:visibility="visible" />

<LinearLayout
android:id="@+id/llAddMember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_padding_12dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="@dimen/layout_padding_16dp"
android:visibility="gone">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/etNewMember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name" />

</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_padding_16dp"
android:gravity="right">

<Button
android:id="@+id/btnCancelAddMember"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:textSize="@dimen/text_size_14sp" />

<Button
android:id="@+id/btnAddMember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add" />

</LinearLayout>

</LinearLayout>


</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/res/layout/member_leader_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llAddMember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_padding_12dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="@dimen/layout_padding_16dp">

<TextView
android:id="@+id/tv_member_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_new_member"
android:textColor="@color/colorPrimary"
android:layout_marginBottom="@dimen/layout_padding_16dp"
/>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/etNewMember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name" />

</com.google.android.material.textfield.TextInputLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_padding_16dp"
android:gravity="right">

<Button
android:id="@+id/btnCancelAddMember"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:textSize="@dimen/text_size_14sp" />

<Button
android:id="@+id/btnAddMember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add" />

</LinearLayout>
</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,9 @@
<string name="please_wait_updating_group_status">"Updating group status, please wait... "</string>
<string name="error_while_updating_group_status">Error while updating group status</string>
<string name="error_while_creating_group">Error while creating group</string>

<string name="add_new_member">Add New Member</string>
<string name="edit_member">Edit Member</string>
<string name="add_new_leader">Add New Leader</string>
<string name="edit_leader">Edit Leader</string>
</resources>