refactor: Show Error UI, If API request fails in Deposit Account or Deposit account are empty
diff --git a/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsContract.java b/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsContract.java
index 2d457f5..859d138 100644
--- a/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsContract.java
+++ b/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsContract.java
@@ -17,6 +17,8 @@
void showCustomerDeposits(List<DepositAccount> customerDepositAccounts);
+ void showEmptyDepositAccounts();
+
void showError(String errorMessage);
void showRecyclerView(boolean status);
diff --git a/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsFragment.java b/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsFragment.java
index 6ce7c0b..3354e65 100644
--- a/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsFragment.java
+++ b/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsFragment.java
@@ -8,9 +8,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
import com.mifos.apache.fineract.R;
import com.mifos.apache.fineract.data.models.deposit.DepositAccount;
@@ -18,9 +15,13 @@
import com.mifos.apache.fineract.ui.base.MifosBaseActivity;
import com.mifos.apache.fineract.ui.base.MifosBaseFragment;
import com.mifos.apache.fineract.ui.base.OnItemClickListener;
-import com.mifos.apache.fineract.ui.online.depositaccounts.createdepositaccount.createdepositactivity.CreateDepositActivity;
+import com.mifos.apache.fineract.ui.uierrorhandler.MifosUIErrorHandler;
+import com.mifos.apache.fineract.ui.uierrorhandler.UIType;
import com.mifos.apache.fineract.ui.online.depositaccounts.createdepositaccount.DepositAction;
-import com.mifos.apache.fineract.ui.online.depositaccounts.depositaccountdetails.DepositAccountDetailsFragment;
+import com.mifos.apache.fineract.ui.online.depositaccounts.createdepositaccount
+ .createdepositactivity.CreateDepositActivity;
+import com.mifos.apache.fineract.ui.online.depositaccounts.depositaccountdetails
+ .DepositAccountDetailsFragment;
import com.mifos.apache.fineract.utils.ConstantKeys;
import java.util.ArrayList;
@@ -42,14 +43,8 @@
@BindView(R.id.rv_customers_deposit_accounts)
RecyclerView rvCustomerDepositAccounts;
- @BindView(R.id.rl_error)
- RelativeLayout rlError;
-
- @BindView(R.id.iv_retry)
- ImageView ivRetry;
-
- @BindView(R.id.tv_error)
- TextView tvError;
+ @BindView(R.id.layout_error)
+ View layoutError;
@Inject
DepositAccountsPresenter customerDepositPresenter;
@@ -61,6 +56,7 @@
private String customerIdentifier;
private List<DepositAccount> customerDepositAccounts;
+ private MifosUIErrorHandler mifosUIErrorHandler;
public static DepositAccountsFragment newInstance(String customerIdentifier) {
DepositAccountsFragment fragment = new DepositAccountsFragment();
@@ -85,6 +81,7 @@
rootView = inflater.inflate(R.layout.fragment_customer_deposit, container, false);
((MifosBaseActivity) getActivity()).getActivityComponent().inject(this);
ButterKnife.bind(this, rootView);
+ mifosUIErrorHandler = new MifosUIErrorHandler(getActivity(), rootView);
setToolbarTitle(getString(R.string.deposit_accounts));
customerDepositPresenter.attachView(this);
@@ -98,12 +95,12 @@
public void onResume() {
super.onResume();
rvCustomerDepositAccounts.setVisibility(View.GONE);
- rlError.setVisibility(View.GONE);
+ layoutError.setVisibility(View.GONE);
customerDepositPresenter.fetchCustomerDepositAccounts(customerIdentifier);
}
- @OnClick(R.id.iv_retry)
- void onRetry() {
+ @OnClick(R.id.btn_try_again)
+ public void reTry() {
showRecyclerView(true);
customerDepositPresenter.fetchCustomerDepositAccounts(customerIdentifier);
}
@@ -134,19 +131,30 @@
}
@Override
+ public void showEmptyDepositAccounts() {
+ showRecyclerView(false);
+ mifosUIErrorHandler.showEmptyOrErrorUI(UIType.EMPTY_UI,
+ getString(R.string.deposit_accounts),
+ getString(R.string.deposit_account),
+ R.drawable.ic_monetization_on_black_24dp);
+ }
+
+ @Override
public void showError(String errorMessage) {
showRecyclerView(false);
- tvError.setText(errorMessage);
+ mifosUIErrorHandler.showEmptyOrErrorUI(UIType.ERROR_UI,
+ getString(R.string.deposit_accounts),
+ null, null);
}
@Override
public void showRecyclerView(boolean status) {
if (status) {
rvCustomerDepositAccounts.setVisibility(View.VISIBLE);
- rlError.setVisibility(View.GONE);
+ layoutError.setVisibility(View.GONE);
} else {
rvCustomerDepositAccounts.setVisibility(View.GONE);
- rlError.setVisibility(View.VISIBLE);
+ layoutError.setVisibility(View.VISIBLE);
}
}
diff --git a/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsPresenter.java b/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsPresenter.java
index fc5fd62..990e877 100644
--- a/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsPresenter.java
+++ b/app/src/main/java/com/mifos/apache/fineract/ui/online/depositaccounts/depositaccountslist/DepositAccountsPresenter.java
@@ -59,7 +59,11 @@
@Override
public void onNext(List<DepositAccount> customerDepositAccounts) {
getMvpView().hideProgressbar();
- getMvpView().showCustomerDeposits(customerDepositAccounts);
+ if (!customerDepositAccounts.isEmpty()) {
+ getMvpView().showCustomerDeposits(customerDepositAccounts);
+ } else {
+ getMvpView().showEmptyDepositAccounts();
+ }
}
@Override
diff --git a/app/src/main/java/com/mifos/apache/fineract/ui/uierrorhandler/MifosUIErrorHandler.java b/app/src/main/java/com/mifos/apache/fineract/ui/uierrorhandler/MifosUIErrorHandler.java
new file mode 100644
index 0000000..37fcbc1
--- /dev/null
+++ b/app/src/main/java/com/mifos/apache/fineract/ui/uierrorhandler/MifosUIErrorHandler.java
@@ -0,0 +1,63 @@
+package com.mifos.apache.fineract.ui.uierrorhandler;
+
+import android.content.Context;
+import android.support.annotation.Nullable;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.mifos.apache.fineract.R;
+
+import butterknife.ButterKnife;
+
+/**
+ * @author Rajan Maurya
+ * On 03/09/17.
+ */
+public class MifosUIErrorHandler {
+
+ private ImageView ivEmptyFeatureImage;
+ private TextView tvFeatureName;
+ private TextView tvSubFeatureName;
+ private LinearLayout llEmptyUI;
+ private LinearLayout llErrorToLoad;
+ private TextView tvErrorFeatureName;
+
+ private Context context;
+ private View view;
+
+ public MifosUIErrorHandler(Context context, View view) {
+ this.context = context;
+ this.view = view;
+ initializeUI();
+ }
+
+ public void showEmptyOrErrorUI(UIType errorType, String featureName,
+ @Nullable String subFeatureName, @Nullable Integer featureImage) {
+ switch (errorType) {
+ case EMPTY_UI:
+ llEmptyUI.setVisibility(View.VISIBLE);
+ ivEmptyFeatureImage.setImageResource(featureImage);
+ tvFeatureName.setText(context.getString(R.string.empty_ui_message, featureName));
+ tvSubFeatureName.setText(
+ context.getString(R.string.empty_ui_sub_message, subFeatureName));
+ llErrorToLoad.setVisibility(View.GONE);
+ break;
+ case ERROR_UI:
+ llErrorToLoad.setVisibility(View.VISIBLE);
+ tvErrorFeatureName.setText(featureName);
+ llEmptyUI.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ private void initializeUI() {
+ ivEmptyFeatureImage = ButterKnife.findById(view, R.id.iv_empty_feature_image);
+ tvFeatureName = ButterKnife.findById(view, R.id.tv_empty_feature_name);
+ tvSubFeatureName = ButterKnife.findById(view, R.id.tv_empty_sub_feature_name);
+ llEmptyUI = ButterKnife.findById(view, R.id.ll_empty_ui);
+ llErrorToLoad = ButterKnife.findById(view, R.id.ll_error_to_load);
+ tvErrorFeatureName = ButterKnife.findById(view, R.id.tv_error_feature_name);
+ }
+}
diff --git a/app/src/main/java/com/mifos/apache/fineract/ui/uierrorhandler/UIType.java b/app/src/main/java/com/mifos/apache/fineract/ui/uierrorhandler/UIType.java
new file mode 100644
index 0000000..9ee92ff
--- /dev/null
+++ b/app/src/main/java/com/mifos/apache/fineract/ui/uierrorhandler/UIType.java
@@ -0,0 +1,12 @@
+package com.mifos.apache.fineract.ui.uierrorhandler;
+
+/**
+ * @author Rajan Maurya
+ * On 03/09/17.
+ */
+public enum UIType {
+
+ EMPTY_UI,
+
+ ERROR_UI
+}
diff --git a/app/src/main/res/drawable/ic_cloud_off_black_24dp.xml b/app/src/main/res/drawable/ic_cloud_off_black_24dp.xml
new file mode 100644
index 0000000..1e753cf
--- /dev/null
+++ b/app/src/main/res/drawable/ic_cloud_off_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_monetization_on_black_24dp.xml b/app/src/main/res/drawable/ic_monetization_on_black_24dp.xml
new file mode 100644
index 0000000..5d1dc64
--- /dev/null
+++ b/app/src/main/res/drawable/ic_monetization_on_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13.41,18.09L13.41,20h-2.67v-1.93c-1.71,-0.36 -3.16,-1.46 -3.27,-3.4h1.96c0.1,1.05 0.82,1.87 2.65,1.87 1.96,0 2.4,-0.98 2.4,-1.59 0,-0.83 -0.44,-1.61 -2.67,-2.14 -2.48,-0.6 -4.18,-1.62 -4.18,-3.67 0,-1.72 1.39,-2.84 3.11,-3.21L10.74,4h2.67v1.95c1.86,0.45 2.79,1.86 2.85,3.39L14.3,9.34c-0.05,-1.11 -0.64,-1.87 -2.22,-1.87 -1.5,0 -2.4,0.68 -2.4,1.64 0,0.84 0.65,1.39 2.67,1.91s4.18,1.39 4.18,3.91c-0.01,1.83 -1.38,2.83 -3.12,3.16z"/>
+</vector>
diff --git a/app/src/main/res/layout/fragment_customer_deposit.xml b/app/src/main/res/layout/fragment_customer_deposit.xml
index 9a09f60..7b0c0b6 100644
--- a/app/src/main/res/layout/fragment_customer_deposit.xml
+++ b/app/src/main/res/layout/fragment_customer_deposit.xml
@@ -13,8 +13,8 @@
android:layout_width="match_parent"/>
<include
- layout="@layout/layout_error"
- android:id="@+id/rl_error"
+ layout="@layout/layout_exception_handler"
+ android:id="@+id/layout_error"
android:visibility="gone"/>
<android.support.design.widget.FloatingActionButton
diff --git a/app/src/main/res/layout/layout_exception_handler.xml b/app/src/main/res/layout/layout_exception_handler.xml
new file mode 100644
index 0000000..8b97843
--- /dev/null
+++ b/app/src/main/res/layout/layout_exception_handler.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.design.widget.CoordinatorLayout
+ 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:background="#F4F1F1"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+
+ <LinearLayout
+ android:id="@+id/ll_error_to_load"
+ android:gravity="center"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:contentDescription="@string/status_image"
+ android:layout_gravity="center|center_horizontal"
+ android:layout_height="70dp"
+ android:layout_marginBottom="@dimen/layout_padding_16dp"
+ android:layout_width="70dp"
+ android:tint="@color/grey_500"
+ app:srcCompat="@drawable/ic_cloud_off_black_24dp"/>
+
+ <TextView
+ style="@style/Base.TextAppearance.AppCompat.Medium"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/error_sorry_not_able_to_load"
+ android:textColor="@color/grey_500"
+ android:textSize="@dimen/text_size_14sp"
+ android:typeface="monospace" />
+
+ <TextView
+ android:id="@+id/tv_error_feature_name"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:textColor="@color/grey_500"
+ android:textSize="@dimen/text_size_14sp"
+ tools:text="Deposit Accounts"/>
+
+ <Button
+ android:id="@+id/btn_try_again"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/layout_padding_16dp"
+ android:layout_width="wrap_content"
+ android:paddingLeft="@dimen/layout_padding_24dp"
+ android:paddingRight="@dimen/layout_padding_24dp"
+ android:text="@string/try_again" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/ll_empty_ui"
+ android:gravity="center"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:id="@+id/iv_empty_feature_image"
+ android:contentDescription="@string/status_image"
+ android:layout_gravity="center|center_horizontal"
+ android:layout_height="70dp"
+ android:layout_marginBottom="@dimen/layout_padding_16dp"
+ android:layout_width="70dp"
+ android:tint="@color/grey_500"
+ app:srcCompat="@drawable/ic_monetization_on_black_24dp"/>
+
+ <TextView
+ android:id="@+id/tv_empty_feature_name"
+ style="@style/Base.TextAppearance.AppCompat.Medium"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:textColor="@color/grey_500"
+ android:textSize="@dimen/text_size_20sp"
+ android:typeface="monospace"
+ tools:text="No Deposit accounts Found"/>
+
+ <TextView
+ android:id="@+id/tv_empty_sub_feature_name"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:textColor="@color/grey_500"
+ android:textSize="@dimen/text_size_14sp"
+ tools:text="Top to add Deposit account"/>
+
+
+ </LinearLayout>
+
+</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index 8470d61..05edc43 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -25,6 +25,8 @@
<dimen name="text_size_12sp">12sp</dimen>
+ <dimen name="text_size_14sp">14sp</dimen>
+ <dimen name="text_size_20sp">20sp</dimen>
<!-- Dimen values for text size -->
<dimen name="text_headline">24sp</dimen>
<dimen name="text_large">20sp</dimen>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7cb87ff..0c4467c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -171,6 +171,9 @@
<string name="activities_created_by_on">%1$s, %2$s</string>
<string name="logout">Logout</string>
<string name="manage_roles">Manage roles</string>
+ <string name="try_again">Try Again</string>
+ <string name="empty_ui_message">No %1$s Found</string>
+ <string name="empty_ui_sub_message">Tap to add %1$s</string>
<!--Edit Text hint required-->
<string name="required_account">Account*</string>
@@ -243,6 +246,7 @@
<string name="error_updating_deposit_account">Error updating deposit account</string>
<string name="error_fetching_customer_activities">Error fetching customer activities</string>
<string name="error_fetching_roles">Error fetching roles</string>
+ <string name="error_sorry_not_able_to_load">Sorry we weren\'t able to load</string>
<!--Material Dialog-->