Commit 6d67ba57 by Kunj Gupta

Show error message, if API returned fail.

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