Commit 6d67ba57 by Kunj Gupta

Show error message, if API returned fail.

parent 3584c95b
......@@ -2,11 +2,13 @@ package com.vsoft.uofl_catalogue.dialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
......@@ -18,6 +20,7 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.vsoft.uofl_catalogue.CatalogueApplication;
import com.vsoft.uofl_catalogue.R;
import com.vsoft.uofl_catalogue.api.listeners.get.GetReferenceApiListener;
import com.vsoft.uofl_catalogue.api.managers.VariableChoiceApiManager;
......@@ -52,6 +55,7 @@ public class SelectReferenceDialog extends DialogFragment {
private Unbinder mUnbinder;
private List<Reference> mReferenceList;
private String mReferenceTableName;
private CatalogueApplication mApplication;
public SelectReferenceDialog() {
......@@ -76,6 +80,7 @@ public class SelectReferenceDialog extends DialogFragment {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, R.style.CustomDialog);
mApplication = (CatalogueApplication) getActivity().getApplication();
mReferenceTableName = getArguments().getString(Constants.DATA_KEY_REFERENCE_TABLE_NAME);
}
......@@ -133,7 +138,11 @@ public class SelectReferenceDialog extends DialogFragment {
if(actionId == EditorInfo.IME_ACTION_SEARCH) {
Util.hideSoftKeyboard(getActivity(), v);
if(!mEditText.getText().toString().isEmpty()) {
if(mApplication.isNetConnected()) {
new FetchReference().execute(mEditText.getText().toString());
} else {
showErrorDialog(R.string.internet_validation_string);
}
}
return false;
}
......@@ -168,11 +177,15 @@ public class SelectReferenceDialog extends DialogFragment {
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if(syncStatus == SyncStatus.SUCCESS) {
mAdapter = new ArrayAdapter(getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
getReferenceForDisplay());
mListView.setAdapter(mAdapter);
} else {
showErrorDialog(R.string.failed_to_fetch_reference_string);
}
}
}
......@@ -189,4 +202,17 @@ public class SelectReferenceDialog extends DialogFragment {
super.onDestroyView();
mUnbinder.unbind();
}
private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
\ No newline at end of file
......@@ -72,16 +72,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
if(mApplication.isNetConnected()) {
new FetchCatalogueItem().execute();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.internet_validation_string)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
showErrorDialog(R.string.internet_validation_string);
}
}
......@@ -116,9 +107,13 @@ public class CatalogueItemScreen extends AppCompatActivity {
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if(mCatalogueItemList!=null) {
if(syncStatus == SyncStatus.SUCCESS) {
if (mCatalogueItemList != null) {
setData();
}
} else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_items_string);
}
}
}
......@@ -157,4 +152,17 @@ public class CatalogueItemScreen extends AppCompatActivity {
}
return super.onOptionsItemSelected(menuItem);
}
private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
......@@ -63,16 +63,7 @@ public class CatalogueScreen extends AppCompatActivity {
if(mApplication.isNetConnected()) {
new FetchCatalogue().execute();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.internet_validation_string)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
showErrorDialog(R.string.internet_validation_string);
}
}
......@@ -107,8 +98,12 @@ public class CatalogueScreen extends AppCompatActivity {
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if(syncStatus == SyncStatus.SUCCESS) {
if(mCatalogueList!=null)
setData(mCatalogueList);
} else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_string);
}
}
}
......@@ -138,4 +133,17 @@ public class CatalogueScreen extends AppCompatActivity {
}
return super.onOptionsItemSelected(menuItem);
}
private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
......@@ -106,12 +106,13 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if(mApplication.isNetConnected()) {
new FetchCatalogueVariable().execute();
} else {
showNoInternetDialog();
showErrorDialog(R.string.internet_validation_string);
}
}
class FetchCatalogueVariable extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -124,7 +125,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
SyncStatus syncStatus = CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItemSysId, new GetCatalogueVariableApiListener() {
syncStatus = CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItemSysId, new GetCatalogueVariableApiListener() {
@Override
public void onDoneApiCall(List<CatalogueVariable> catalogueVariableList) {
CatalogueLog.e("Data: catalogueVariableList: " + catalogueVariableList);
......@@ -136,7 +137,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
/*Fetch multi choice variable values*/
VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
syncStatus = VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
CatalogueLog.e("Data: variableChoiceList: " + variableChoiceList);
......@@ -148,7 +149,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
}
});
return syncStatus;
}
......@@ -158,9 +158,13 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if(mCatalogueVariableList!=null) {
if(syncStatus == SyncStatus.SUCCESS) {
if (mCatalogueVariableList != null) {
createView();
}
} else {
showErrorDialog(R.string.failed_to_fetch_catalogue_form_string);
}
}
}
......@@ -365,9 +369,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
return;
if(mApplication.isNetConnected()) {
new SubmitCatalogueItem().execute();
new SubmitForm().execute();
} else {
showNoInternetDialog();
showErrorDialog(R.string.internet_validation_string);
}
}
......@@ -445,7 +449,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
};
class SubmitCatalogueItem extends AsyncTask<String, Void, SyncStatus> {
class SubmitForm extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
@Override
......@@ -469,13 +473,17 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if(syncStatus == SyncStatus.SUCCESS) {
finish();
} else {
showErrorDialog(R.string.failed_to_submit_form_string);
}
}
}
private void showNoInternetDialog() {
private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.internet_validation_string)
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
......
......@@ -20,6 +20,14 @@
<string name="date_string">%1$s %2$s, %3$s</string>
<string name="date_and_time_string"> %1$s:%2$s</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string>
<string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string>
<string name="failed_to_fetch_variable_choice_string">Failed to fetch Choice Items.</string>
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
<string name="failed_to_submit_form_string">Failed to submit form.</string>
<!--Login Screen-->
<string name="login_screen_user_name_string">Username</string>
<string name="login_screen_password_string">Password</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment