Skip to content

Commit

Permalink
fix: Update client identifier list when identifier is added or removed
Browse files Browse the repository at this point in the history
  • Loading branch information
tarun0 committed Aug 7, 2017
1 parent 82a23f3 commit 11639a7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mifos.mifosxdroid.dialogfragments.identifierdialog;

/**
* Created by Tarun on 07-08-17.
*/

public interface ClientIdentifierCreationListener {

void onClientIdentifierCreationSuccess();

void onClientIdentifierCreationFailure();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class IdentifierDialogFragment extends ProgressableDialogFragment impleme
@Inject
IdentifierDialogPresenter mIdentifierDialogPresenter;

ClientIdentifierCreationListener clientIdentifierCreationListener;

View rootView;
private int clientId;
private IdentifierTemplate identifierTemplate;
Expand Down Expand Up @@ -146,6 +148,9 @@ public void showClientIdentifierTemplate(IdentifierTemplate identifierTemplate)
public void showIdentifierCreatedSuccessfully() {
Toast.makeText(getActivity(), R.string.identifier_created_successfully,
Toast.LENGTH_SHORT).show();
if (clientIdentifierCreationListener != null) {
clientIdentifierCreationListener.onClientIdentifierCreationSuccess();
}
getDialog().dismiss();
}

Expand All @@ -157,6 +162,9 @@ public void showMessage(String message) {
@Override
public void showError(int errorMessage) {
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
if (clientIdentifierCreationListener != null) {
clientIdentifierCreationListener.onClientIdentifierCreationFailure();
}
}

@Override
Expand Down Expand Up @@ -187,4 +195,8 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
public void onNothingSelected(AdapterView<?> parent) {

}

public void setOnClientIdentifierCreationListener(ClientIdentifierCreationListener listener) {
clientIdentifierCreationListener = listener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.mifos.mifosxdroid.adapters.IdentifierListAdapter;
import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.mifosxdroid.core.MifosBaseFragment;
import com.mifos.mifosxdroid.dialogfragments.identifierdialog.ClientIdentifierCreationListener;
import com.mifos.mifosxdroid.dialogfragments.identifierdialog.IdentifierDialogFragment;
import com.mifos.mifosxdroid.online.documentlist.DocumentListFragment;
import com.mifos.objects.noncore.Identifier;
Expand All @@ -43,7 +44,8 @@


public class ClientIdentifiersFragment extends MifosBaseFragment implements
ClientIdentifiersMvpView, IdentifierOptionsListener, SwipeRefreshLayout.OnRefreshListener {
ClientIdentifiersMvpView, IdentifierOptionsListener, SwipeRefreshLayout.OnRefreshListener,
ClientIdentifierCreationListener {

@BindView(R.id.rv_client_identifier)
RecyclerView rv_client_identifier;
Expand Down Expand Up @@ -130,15 +132,33 @@ public void showUserInterface() {
public void showClientIdentifiers(List<Identifier> identifiers) {
this.identifiers = identifiers;
identifierListAdapter.setIdentifiers(identifiers);
identifierListAdapter.notifyDataSetChanged();

if (identifiers.isEmpty()) {
showEmptyClientIdentifier();
} else {
if (ll_error.getVisibility() == View.VISIBLE) {
ll_error.setVisibility(View.GONE);
}
}
}

@Override
public void showEmptyClientIdentifier() {
private void showEmptyClientIdentifier() {
ll_error.setVisibility(View.VISIBLE);
mNoIdentifierText.setText(getResources().getString(R.string.no_identifier_to_show));
mNoIdentifierIcon.setImageResource(R.drawable.ic_assignment_turned_in_black_24dp);
}

@Override
public void onClientIdentifierCreationSuccess() {
loadIdentifiers();
}

@Override
public void onClientIdentifierCreationFailure() {

}

@Override
public void showFetchingError(int errorMessage) {
Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -206,6 +226,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.menu_add:
IdentifierDialogFragment identifierDialogFragment =
IdentifierDialogFragment.newInstance(clientId);
identifierDialogFragment.setOnClientIdentifierCreationListener(this);
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.addToBackStack(FragmentConstants.FRAG_DOCUMENT_LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public interface ClientIdentifiersMvpView extends MvpView {

void showClientIdentifiers(List<Identifier> identifiers);

void showEmptyClientIdentifier();

void showFetchingError(int errorMessage);

void identifierDeletedSuccessfully();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public void onError(Throwable e) {
@Override
public void onNext(List<Identifier> identifiers) {
getMvpView().showProgressbar(false);
if (!identifiers.isEmpty()) {
getMvpView().showClientIdentifiers(identifiers);
} else {
getMvpView().showEmptyClientIdentifier();
}
getMvpView().showClientIdentifiers(identifiers);
}
}));
}
Expand Down

0 comments on commit 11639a7

Please sign in to comment.