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

Commit

Permalink
Add edit check to the edit activities
Browse files Browse the repository at this point in the history
  • Loading branch information
EGOR-IND committed Apr 21, 2021
1 parent 592099e commit e0ad69d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class CreateCustomerActivity extends FineractBaseActivity
private Customer customer;
private CustomerAction customerAction;
private String customerIdentifier;
private String initCustomerStr;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -82,6 +83,8 @@ protected void onCreate(Bundle savedInstanceState) {
break;
case EDIT:
setToolbarTitle(getString(R.string.edit_customer));
initCustomerStr = customer.toString()
.split(ConstantKeys.STRING_SEPARATOR_FROM_CREATEDBY)[0];
break;
}

Expand Down Expand Up @@ -110,7 +113,12 @@ public void onCompleted(View completeButton) {
createCustomerPresenter.createCustomer(customer);
break;
case EDIT:
createCustomerPresenter.updateCustomer(customerIdentifier, customer);
if (customer.toString().
split(ConstantKeys.STRING_SEPARATOR_FROM_CREATEDBY)[0] != initCustomerStr) {
createCustomerPresenter.updateCustomer(customerIdentifier, customer);
} else {
Toast.makeText(this, "The customer is not edited", Toast.LENGTH_SHORT).show();
}
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.apache.fineract.ui.online.customers.customerpayroll.editcustomerpayr

import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.stepstone.stepper.StepperLayout
import com.stepstone.stepper.VerificationError
import kotlinx.android.synthetic.main.activity_edit_payroll.*
Expand All @@ -20,6 +21,7 @@ class EditPayrollActivity : FineractBaseActivity(), StepperLayout.StepperListene

lateinit var payrollConfig: PayrollConfiguration
lateinit var customerIdentifier: String
private lateinit var initPayrollStr: String

@Inject
lateinit var editPayrollPresenter: EditPayrollPresenter
Expand All @@ -35,7 +37,11 @@ class EditPayrollActivity : FineractBaseActivity(), StepperLayout.StepperListene
}

override fun onCompleted(completeButton: View?) {
editPayrollPresenter.updatePayrollConfiguration(customerIdentifier, payrollConfig)
if (payrollConfig.toString().split(ConstantKeys.STRING_SEPARATOR_FROM_CREATEDON)[0] != initPayrollStr) {
editPayrollPresenter.updatePayrollConfiguration(customerIdentifier, payrollConfig)
} else {
Toast.makeText(this, "The payroll is not edited", Toast.LENGTH_SHORT).show()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -47,6 +53,8 @@ class EditPayrollActivity : FineractBaseActivity(), StepperLayout.StepperListene
editPayrollPresenter.attachView(this)
val payrollConfig = intent.getParcelableExtra<PayrollConfiguration>(ConstantKeys
.PAYROLL_CONFIG)
initPayrollStr = payrollConfig.toString()
.split(ConstantKeys.STRING_SEPARATOR_FROM_CREATEDON)[0]

customerIdentifier = intent.getStringExtra(ConstantKeys.CUSTOMER_IDENTIFIER)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.apache.fineract.ui.base.Toaster
import org.apache.fineract.ui.online.groups.GroupAction
import org.apache.fineract.ui.online.groups.grouplist.GroupViewModelFactory
import org.apache.fineract.ui.online.groups.grouplist.GroupViewModel
import org.apache.fineract.utils.ConstantKeys
import org.apache.fineract.utils.Constants
import org.apache.fineract.utils.DateUtils
import javax.inject.Inject
Expand All @@ -30,6 +31,8 @@ class CreateGroupActivity : FineractBaseActivity(), StepperLayout.StepperListene
private var group = Group()
private var groupAction = GroupAction.CREATE

private lateinit var initGroupStr: String

@Inject
lateinit var groupViewModelFactory: GroupViewModelFactory

Expand All @@ -49,6 +52,8 @@ class CreateGroupActivity : FineractBaseActivity(), StepperLayout.StepperListene
intent?.extras?.getParcelable<Group>(Constants.GROUP)?.let {
group = it
}
initGroupStr = group.toString()
.split(ConstantKeys.STRING_SEPARATOR_FROM_CREATEDON)[0]
}
}
viewModel = ViewModelProviders.of(this, groupViewModelFactory).get(GroupViewModel::class.java)
Expand Down Expand Up @@ -97,8 +102,14 @@ class CreateGroupActivity : FineractBaseActivity(), StepperLayout.StepperListene

override fun onCompleted(completeButton: View?) {
when (groupAction) {
GroupAction.EDIT -> group.identifier?.let {
viewModel.updateGroup(it, group)
GroupAction.EDIT -> {
if (group.toString().split(ConstantKeys.STRING_SEPARATOR_FROM_CREATEDON)[0] != initGroupStr) {
group.identifier?.let {
viewModel.updateGroup(it, group)
}
} else {
Toast.makeText(this, "There is nothing edited in the group", Toast.LENGTH_SHORT).show()
}
}
GroupAction.CREATE -> viewModel.createGroup(group)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/apache/fineract/utils/ConstantKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public class ConstantKeys {
public static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 3;
public static final String PERMISSIONS_READ_EXTERNAL_STORAGE_STATUS = "read_status";

public static final String STRING_SEPARATOR_FROM_CREATEDON = ", createdOn";
public static final String STRING_SEPARATOR_FROM_CREATEDBY = ", createdBy";
}

0 comments on commit e0ad69d

Please sign in to comment.