Commit 2d8285a1 by Kunj Gupta

Changed locally saving functionality and put refresh icon on each screen.

parent 9dde565e
......@@ -95,71 +95,6 @@ public class CatalogueVariableApiManager {
}
})
.create();
/*JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
JSONArray variableSetJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME);
List<CatalogueVariableSet> variableSetList = new ArrayList<>(variableSetJsonArray.length());
List<CatalogueVariable> finalVariableList = new ArrayList<>();
for (int i = 0; i < variableSetJsonArray.length(); i++) {
JSONObject variableSetJsonObject = variableSetJsonArray.getJSONObject(i);
CatalogueVariableSet catalogueVariableSet = gson.fromJson(variableSetJsonObject.toString(), CatalogueVariableSet.class);
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME);
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length());
for (int j = 0; j < variableJsonArray.length(); j++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(j);
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class);
catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable);
}
Collections.sort(variableList, new Comparator<CatalogueVariable>() {
@Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
catalogueVariableSet.setVariables(variableList);
variableSetList.add(catalogueVariableSet);
}
Collections.sort(variableSetList, new Comparator<CatalogueVariableSet>() {
@Override
public int compare(CatalogueVariableSet lhs, CatalogueVariableSet rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
JSONArray variableJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME);
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length());
for (int i = 0; i < variableJsonArray.length(); i++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(i);
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class);
catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable);
}
Collections.sort(variableList, new Comparator<CatalogueVariable>() {
@Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
*//*For variableset *//*
for (int i = 0; i < variableSetList.size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i);
finalVariableList.addAll(catalogueVariableSet.getVariables());
}
*//*For variable list*//*
finalVariableList.addAll(variableList);
listener.onDoneApiCall(finalVariableList);
} else {
listener.onDoneApiCall(new ArrayList<CatalogueVariable>(0));*/
JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
JSONArray variableSetJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME);
List<CatalogueVariableSet> variableSetList = new ArrayList<>(variableSetJsonArray.length());
......
......@@ -3,6 +3,7 @@ package com.vsoft.uoflservicenow.api.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.utils.DBConstants;
......@@ -47,8 +48,45 @@ public class VariableChoiceManager implements DBConstants {
}
}
public static void handleGetVariableChoice(long variableId, List<VariableChoice> serverVariableChoiceList) {
public static boolean handleGetVariableChoice(long variableId, List<VariableChoice> serverVariableChoiceList) {
boolean hasChanged = false;
if(serverVariableChoiceList != null && !serverVariableChoiceList.isEmpty()) {
List<VariableChoice> localVariableChoiceList = getAllVariableChoices(variableId);
if(!localVariableChoiceList.isEmpty()) {
for (int i = 0; i < serverVariableChoiceList.size(); i++) {
VariableChoice serverVariableChoice = serverVariableChoiceList.get(i);
for (int j = 0; j < localVariableChoiceList.size(); j++) {
VariableChoice localVariableChoice = localVariableChoiceList.get(j);
if (serverVariableChoice.getVariableId() != localVariableChoice.getVariableId()) {
continue;
} else {
if (!localVariableChoice.getValue().equals(serverVariableChoice.getValue())) {
hasChanged = true;
continue;
}
if (!localVariableChoice.getText().equals(serverVariableChoice.getText())) {
hasChanged = true;
continue;
}
if (localVariableChoice.getMisc() != serverVariableChoice.getMisc()) {
hasChanged = true;
continue;
}
if (localVariableChoice.getOrder() != serverVariableChoice.getOrder()) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged = true;
}
/*First delete all existing variable choice for particular variable then we will save*/
deleteAll(variableId);
......@@ -64,6 +102,7 @@ public class VariableChoiceManager implements DBConstants {
/*localVariableChoiceList is contain all local Catalogues */
deleteAll(variableId);
}
return hasChanged;
}
public static List<VariableChoice> getAllVariableChoices(long variableId) {
......
......@@ -21,7 +21,6 @@ import java.util.List;
public class CatalogueVariableManager implements DBConstants {
public static long save(CatalogueVariable catalogueVariable, int syncDirty) {
CatalogueLog.e("CatalogueVariableManager: save");
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
catalogueVariable.setSyncDirty(syncDirty);
......@@ -97,8 +96,66 @@ public class CatalogueVariableManager implements DBConstants {
}
}
public static void handleGetVariable(long catalogueItemId, List<CatalogueVariable> serverVariableList) {
public static boolean handleGetVariable(long catalogueItemId, List<CatalogueVariable> serverVariableList) {
boolean hasChanged = false;
if(serverVariableList != null && !serverVariableList.isEmpty()) {
/*localVariableList is contain all local catalogueVariable */
List<CatalogueVariable> localVariableList = getAllVariable(catalogueItemId);
if(!localVariableList.isEmpty()) {
for (int i = 0; i < serverVariableList.size(); i++) {
CatalogueVariable serverCatalogueVariable = serverVariableList.get(i);
for (int j = 0; j < localVariableList.size(); j++) {
CatalogueVariable localCatalogueVariable = localVariableList.get(j);
if (serverCatalogueVariable.getSysId() != localCatalogueVariable.getSysId()) {
continue;
} else {
if (!localCatalogueVariable.getName().equals(serverCatalogueVariable.getName())) {
hasChanged = true;
continue;
}
if (!localCatalogueVariable.getQuestionText().equals(serverCatalogueVariable.getQuestionText())) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getOrder() != serverCatalogueVariable.getOrder()) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getActive() != serverCatalogueVariable.getActive()) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getType().getId() != serverCatalogueVariable.getType().getId()) {
hasChanged = true;
continue;
}
if (!localCatalogueVariable.getDefaultValue().equals(serverCatalogueVariable.getDefaultValue())) {
hasChanged = true;
continue;
}
if (!localCatalogueVariable.getReferenceColumnName().equals(serverCatalogueVariable.getReferenceColumnName())) {
hasChanged = true;
continue;
}
if (!localCatalogueVariable.getReferenceTable().equals(serverCatalogueVariable.getReferenceTable())) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged =true;
}
/*variableSysIdMap contain all server response catalogueVariable Sys Id*/
HashMap<String, Integer> variableSysIdMap = new HashMap<>(0);
Integer intObj = Integer.valueOf(1);
......@@ -107,8 +164,6 @@ public class CatalogueVariableManager implements DBConstants {
variableSysIdMap.put(sysId, intObj);
}
/*localVariableList is contain all local catalogueVariable */
List<CatalogueVariable> localVariableList = getAllVariable(catalogueItemId);
if (localVariableList != null && !localVariableList.isEmpty()) {
for (int i = 0; i < localVariableList.size(); i++) {
CatalogueVariable localVariable = localVariableList.get(i);
......@@ -160,6 +215,8 @@ public class CatalogueVariableManager implements DBConstants {
}
}
}
return hasChanged;
}
public static List<CatalogueVariable> getAllVariable(long catalogueItemId) {
......
......@@ -71,14 +71,50 @@ public class UiPolicyActionManager implements DBConstants {
}
}
public static void handleGetUiPolicyAction(List<UiPolicyAction> uiPolicyActionList, long uiPolicyItemId) {
if(uiPolicyActionList != null && !uiPolicyActionList.isEmpty()) {
public static boolean handleGetUiPolicyAction(List<UiPolicyAction> serverUiPolicyActionList, long uiPolicyItemId) {
boolean hasChanged = false;
if(serverUiPolicyActionList != null && !serverUiPolicyActionList.isEmpty()) {
/*localPolicyActionList is contain all local Catalogues */
List<UiPolicyAction> localPolicyActionList = getAllUiPolicyActions(uiPolicyItemId);
if(!localPolicyActionList.isEmpty()) {
for (int i = 0; i < serverUiPolicyActionList.size(); i++) {
UiPolicyAction serverUiPolicyAction = serverUiPolicyActionList.get(i);
for (int j = 0; j < localPolicyActionList.size(); j++) {
UiPolicyAction localUiPolicyAction = localPolicyActionList.get(j);
if (serverUiPolicyAction.getUiPolicyItemId() != localUiPolicyAction.getUiPolicyItemId()) {
continue;
} else {
if (!localUiPolicyAction.getMandatory().equals(serverUiPolicyAction.getMandatory())) {
hasChanged = true;
continue;
}
if (!localUiPolicyAction.getDisabled().equals(serverUiPolicyAction.getDisabled())) {
hasChanged = true;
continue;
}
if (!localUiPolicyAction.getVisible().equals(serverUiPolicyAction.getVisible())) {
hasChanged = true;
continue;
}
if (!localUiPolicyAction.getVariableName().equals(serverUiPolicyAction.getVariableName())) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged = true;
}
/*Check this UiPolicyItem is exist in local DB or not
* If doesn't exist in local, save it
* If exist in local, update the local item with data from server item.
* */
for (int i = 0; i < uiPolicyActionList.size(); i++) {
UiPolicyAction uiPolicyAction = uiPolicyActionList.get(i);
for (int i = 0; i < serverUiPolicyActionList.size(); i++) {
UiPolicyAction uiPolicyAction = serverUiPolicyActionList.get(i);
uiPolicyAction.setUiPolicyItemId(uiPolicyItemId);
save(uiPolicyAction, DBConstants.SYNC_FLAG_NONE);
}
......@@ -93,6 +129,8 @@ public class UiPolicyActionManager implements DBConstants {
}
}
}
return hasChanged;
}
public static List<UiPolicyAction> getAllUiPolicyActions(long uiPolicyItemId) {
......
......@@ -72,18 +72,39 @@ public class UiPolicyItemManager implements DBConstants {
}
}
public static void handleGetUiPolicyItem(List<UiPolicyItem> uiPolicyItemList, long catalogueItemId) {
if(uiPolicyItemList != null && !uiPolicyItemList.isEmpty()) {
public static boolean handleGetUiPolicyItem(List<UiPolicyItem> serverUiPolicyItemList, long catalogueItemId) {
boolean hasChanged = false;
if(serverUiPolicyItemList != null && !serverUiPolicyItemList.isEmpty()) {
/*localUiPolicyItemList is contain all local uiPolicyItem */
List<UiPolicyItem> localUiPolicyItemList = getAllUiPolicyItems(catalogueItemId);
if(!localUiPolicyItemList.isEmpty()) {
for (int i = 0; i < serverUiPolicyItemList.size(); i++) {
UiPolicyItem serverUiPolicyItem = serverUiPolicyItemList.get(i);
for (int j = 0; j < localUiPolicyItemList.size(); j++) {
UiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(j);
if (serverUiPolicyItem.getSysId() != localUiPolicyItem.getSysId()) {
continue;
} else {
if (!localUiPolicyItem.getCondition().equals(serverUiPolicyItem.getCondition())) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged = true;
}
/*uiPolicyItemSysIdMap contain all server response uiPolicyItem Sys Id*/
HashMap<String, Integer> uiPolicyItemSysIdMap = new HashMap<>(0);
Integer intObj = Integer.valueOf(1);
for (int i = 0; i < uiPolicyItemList.size(); i++) {
String sysId = uiPolicyItemList.get(i).getSysId();
for (int i = 0; i < serverUiPolicyItemList.size(); i++) {
String sysId = serverUiPolicyItemList.get(i).getSysId();
uiPolicyItemSysIdMap.put(sysId, intObj);
}
/*localUiPolicyItemList is contain all local uiPolicyItem */
List<UiPolicyItem> localUiPolicyItemList = getAllUiPolicyItems(catalogueItemId);
if (localUiPolicyItemList != null && !localUiPolicyItemList.isEmpty()) {
for (int i = 0; i < localUiPolicyItemList.size(); i++) {
UiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(i);
......@@ -103,8 +124,8 @@ public class UiPolicyItemManager implements DBConstants {
* If doesn't exist in local, save it
* If exist in local, update the local item with data from server item.
* */
for (int i = 0; i < uiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = uiPolicyItemList.get(i);
for (int i = 0; i < serverUiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = serverUiPolicyItemList.get(i);
UiPolicyItem localUiPolicyItem = getUiPolicyItemFromSysId(uiPolicyItem.getSysId());
if (localUiPolicyItem == null) {
......@@ -135,6 +156,8 @@ public class UiPolicyItemManager implements DBConstants {
}
}
}
return hasChanged;
}
public static List<UiPolicyItem> getAllUiPolicyItems(long catalogueItemId) {
......
......@@ -12,7 +12,9 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.android.gms.analytics.Tracker;
......@@ -37,6 +39,7 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
......@@ -46,8 +49,12 @@ public class CatalogueItemScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.catalogue_item_screen_list_view) ListView mListView;
@BindView(R.id.catalogue_item_screen_empty_text_view) TextView mEmptyTextView;
@BindView(R.id.toolbar_refresh_icon) ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon) ProgressBar mProgressBar;
private Catalogue mCatalogue;
private boolean isProgressRequire;
private CatalogueApplication mApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -57,7 +64,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
setContentView(R.layout.catalogue_item_screen);
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
mApplication = (CatalogueApplication) getApplication();
String catalogueSysId = getIntent().getExtras().getString(Constants.DATA_KEY_SYS_ID);
String catalogueTitle = getIntent().getExtras().getString(Constants.DATA_KEY_CATALOGUE_TITLE);
......@@ -82,19 +89,27 @@ public class CatalogueItemScreen extends AppCompatActivity {
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = application.getDefaultTracker();
Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
if(application.isNetConnected()) {
new FetchCatalogueItem().execute();
} else {
List<CatalogueItem> catalogueItemList = CatalogueItemManager.getAllCatalogueItems(mCatalogue.getId());
if(catalogueItemList.isEmpty()) {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueItemScreen.this);
} else {
if(!catalogueItemList.isEmpty()) {
setData(catalogueItemList);
}
if(mApplication.isNetConnected()) {
isProgressRequire = catalogueItemList.isEmpty();
new FetchCatalogueItem().execute();
}
}
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
new FetchCatalogueItem().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueItemScreen.this);
}
}
......@@ -105,10 +120,15 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override
protected void onPreExecute() {
super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(CatalogueItemScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
......@@ -117,7 +137,6 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override
public void onDoneApiCall(List<CatalogueItem> catalogueItemList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: catalogueItemList: "+catalogueItemList);
CatalogueItemManager.handleGetCatalogueItem(mCatalogue.getId(), catalogueItemList);
}
......@@ -134,9 +153,14 @@ public class CatalogueItemScreen extends AppCompatActivity {
super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
if(syncStatus == SyncStatus.SUCCESS) {
setData(CatalogueItemManager.getAllCatalogueItems(mCatalogue.getId()));
List<CatalogueItem> catalogueItemList = CatalogueItemManager.getAllCatalogueItems(mCatalogue.getId());
isProgressRequire = catalogueItemList.isEmpty();
setData(catalogueItemList);
} else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_items_string);
}
......
......@@ -12,7 +12,9 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication;
......@@ -34,6 +36,7 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
......@@ -42,6 +45,12 @@ public class CatalogueScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.catalogue_screen_list_view) ListView mListView;
@BindView(R.id.toolbar_refresh_icon) ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon) ProgressBar mProgressBar;
/*isProgressRequire variable is use for showing progress bar in middle of screen during fetch data from server*/
private boolean isProgressRequire;
private CatalogueApplication mApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -51,7 +60,7 @@ public class CatalogueScreen extends AppCompatActivity {
setContentView(R.layout.catalogue_screen);
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
mApplication = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
......@@ -63,21 +72,29 @@ public class CatalogueScreen extends AppCompatActivity {
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = application.getDefaultTracker();
Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
if(application.isNetConnected()) {
new FetchCatalogue().execute();
} else {
List<Catalogue> catalogueList = CatalogueManager.getAllCatalogues();
if(!catalogueList.isEmpty()) {
setData(catalogueList);
}
if(mApplication.isNetConnected()) {
isProgressRequire = catalogueList.isEmpty();
new FetchCatalogue().execute();
}
}
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
new FetchCatalogue().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueScreen.this);
}
}
}
class FetchCatalogue extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
......@@ -86,10 +103,15 @@ public class CatalogueScreen extends AppCompatActivity {
@Override
protected void onPreExecute() {
super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(CatalogueScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
......@@ -98,7 +120,6 @@ public class CatalogueScreen extends AppCompatActivity {
@Override
public void onDoneApiCall(List<Catalogue> catalogueList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: catalogueList: "+catalogueList);
CatalogueManager.handleGetCatalogue(catalogueList);
}
......@@ -115,9 +136,14 @@ public class CatalogueScreen extends AppCompatActivity {
super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
if(syncStatus == SyncStatus.SUCCESS) {
setData(CatalogueManager.getAllCatalogues());
List<Catalogue> catalogueList = CatalogueManager.getAllCatalogues();
isProgressRequire = catalogueList.isEmpty();
setData(catalogueList);
} else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_string);
}
......
......@@ -42,7 +42,9 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Spinner;
......@@ -115,6 +117,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.variable_screen_container_layout) LinearLayout mContainerLayout;
@BindView(R.id.variable_screen_bottom_layout) RelativeLayout mBottomLayout;
@BindView(R.id.toolbar_refresh_icon) ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon) ProgressBar mProgressBar;
private List<CatalogueVariable> mCatalogueVariableList = new ArrayList<>();
private CatalogueApplication mApplication;
......@@ -129,6 +133,10 @@ public class CatalogueVariableScreen extends AppCompatActivity {
private CatalogueItem mCatalogueItem;
private Attachment mAttachment;
/*isProgressRequire variable is use for showing progress bar in middle of screen during fetch data from server*/
private boolean isProgressRequire;
private boolean mFormHasChanged;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
......@@ -171,17 +179,26 @@ public class CatalogueVariableScreen extends AppCompatActivity {
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
if (mApplication.isNetConnected()) {
new FetchCatalogueVariable().execute();
} else {
mCatalogueVariableList = CatalogueVariableManager.getAllVariable(mCatalogueItem.getId());
if (mCatalogueVariableList.isEmpty()) {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueVariableScreen.this);
} else {
/*Create dynamic layout and set Ui Policy*/
setVariableChoices();
createView();
runUIPolicyActions(null);
if (mApplication.isNetConnected()) {
isProgressRequire = mCatalogueVariableList.isEmpty();
new FetchCatalogueVariable().execute();
}
}
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
/*Reset variable*/
mFormHasChanged = false;
new FetchCatalogueVariable().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueVariableScreen.this);
}
}
......@@ -191,10 +208,15 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
protected void onPreExecute() {
super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(CatalogueVariableScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
......@@ -216,7 +238,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
/*After added first variableList then we will add other variableList*/
completeCatalogueVariableList.addAll(variableList);
CatalogueVariableManager.handleGetVariable(mCatalogueItem.getId(), completeCatalogueVariableList);
boolean variableHasChanged = CatalogueVariableManager.handleGetVariable(mCatalogueItem.getId(), completeCatalogueVariableList);
mFormHasChanged = variableHasChanged ? variableHasChanged : mFormHasChanged;
if(mSyncStatus != SyncStatus.FAIL) {
/*For variable list*/
mSyncStatus = fetchVariableChoiceData(variableList);
......@@ -225,8 +248,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
public void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList) {
/*Save UiPolicyItem in local DB*/
UiPolicyItemManager.handleGetUiPolicyItem(uiPolicyItemList, mCatalogueItem.getId());
boolean uiPolicyItemHasChanged = UiPolicyItemManager.handleGetUiPolicyItem(uiPolicyItemList, mCatalogueItem.getId());
mFormHasChanged = uiPolicyItemHasChanged ? uiPolicyItemHasChanged : mFormHasChanged;
/*Get all recently saved all items because we need local id of each item for save UiPolicyAction with respect to UiPolicyItem*/
List<UiPolicyItem> localUiPolicyItemList = UiPolicyItemManager.getAllUiPolicyItems(mCatalogueItem.getId());
......@@ -243,7 +266,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
for (int i = 0; i < localUiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = localUiPolicyItemList.get(i);
/*Save UiPolicyAction in local DB*/
UiPolicyActionManager.handleGetUiPolicyAction(uiPolicyItem.getUiPolicyActions(), uiPolicyItem.getId());
boolean uiPolicyActionHasChanged = UiPolicyActionManager.handleGetUiPolicyAction(uiPolicyItem.getUiPolicyActions(), uiPolicyItem.getId());
mFormHasChanged = uiPolicyActionHasChanged ? uiPolicyActionHasChanged : mFormHasChanged;
String condition = uiPolicyItem.getCondition();
if (condition != null) {
......@@ -273,16 +297,47 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
if(syncStatus == SyncStatus.SUCCESS) {
mCatalogueVariableList = CatalogueVariableManager.getAllVariable(mCatalogueItem.getId());
if (mCatalogueVariableList != null) {
/*This if condition is use for, when variable form will load very first time
* Other wise according to our logic we have to show dialog because we will get mFormHasChanged is "true"
* Reason behind is getting "true" is -
* Very first time, locally we don't have data and compare server response with locally so mFormHasChanged is always true.*/
if(isProgressRequire) {
isProgressRequire = mCatalogueVariableList.isEmpty();
/*Create dynamic layout and set Ui Policy*/
/*-----------------------------*/
setVariableChoices();
createView();
runUIPolicyActions(null);
} else if(mFormHasChanged && !isProgressRequire) {
AlertDialog.Builder builder = new AlertDialog.Builder(CatalogueVariableScreen.this);
builder.setMessage("Do you want to update your form with server changes?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mContainerLayout.removeAllViews();
/*Create dynamic layout and set Ui Policy*/
/*-----------------------------*/
setVariableChoices();
createView();
runUIPolicyActions(null);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
} else {
showFetchVariableErrorDialog(R.string.failed_to_fetch_catalogue_form_string);
}
......@@ -348,7 +403,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
VariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), variableChoiceList);
boolean choiceHasChanged = VariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), variableChoiceList);
mFormHasChanged = choiceHasChanged ? choiceHasChanged : mFormHasChanged;
mSyncStatus = SyncStatus.SUCCESS;
}
......@@ -386,9 +443,11 @@ public class CatalogueVariableScreen extends AppCompatActivity {
LinearLayout.LayoutParams childLabelViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
if(mCatalogueItemTitle != null && !mCatalogueItemTitle.isEmpty()) {
/*This check will prevent to add description and short description text view multiple time when we refresh the screen */
if(mContainerLayout.getChildCount() <= 0) {
if (mCatalogueItemTitle != null && !mCatalogueItemTitle.isEmpty()) {
TextView headerView = new TextView(CatalogueVariableScreen.this);
headerView.setPadding(0, 0, 0, (int)getResources().getDimension(R.dimen.normal_margin));
headerView.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.normal_margin));
headerView.setTypeface(null, Typeface.BOLD);
headerView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.normal_text_size));
headerView.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.black));
......@@ -397,9 +456,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
/*Added item Description in form*/
if(mCatalogueItemShortDescription != null && !mCatalogueItemShortDescription.isEmpty()) {
if (mCatalogueItemShortDescription != null && !mCatalogueItemShortDescription.isEmpty()) {
TextView shortDescriptionView = new TextView(CatalogueVariableScreen.this);
shortDescriptionView.setPadding(0, 0, 0, (int)getResources().getDimension(R.dimen.normal_margin));
shortDescriptionView.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.normal_margin));
shortDescriptionView.setTypeface(null, Typeface.BOLD);
shortDescriptionView.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.black));
shortDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
......@@ -412,7 +471,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
mContainerLayout.addView(shortDescriptionView, childControlViewLayoutParams);
}
if(mCatalogueItemDescription != null && !mCatalogueItemDescription.isEmpty()) {
if (mCatalogueItemDescription != null && !mCatalogueItemDescription.isEmpty()) {
/*Replace /r/n with blank string*/
StringBuilder builder = new StringBuilder();
builder.append(mCatalogueItemDescription.replaceAll("\r\n", "<br />"));
......@@ -422,6 +481,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
descriptionView.loadData(builder.toString(), "text/html; charset=UTF-8", "UTF-8");
mContainerLayout.addView(descriptionView, childControlViewLayoutParams);
}
}
if(!mCatalogueVariableList.isEmpty()) {
VariableViewContainer container;
......
package com.vsoft.uoflservicenow.utils;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -45,14 +44,13 @@ public class DialogUtils {
@Override
public void onClick(DialogInterface dialog, int id) {
context.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
((Activity)context).finish();
}
})
.setNegativeButton(context.getString(R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((Activity)context).finish();
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
......
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:drawable="@drawable/refresh_icon"
android:toDegrees="1080">
</rotate>
\ No newline at end of file
......@@ -2,6 +2,7 @@
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar_view"
style="@style/WhiteBackgroundStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
......@@ -10,5 +11,26 @@
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
style="@style/WhiteBackgroundStyle"/>
\ No newline at end of file
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right">
<ImageView
android:id="@+id/toolbar_refresh_icon"
android:layout_width="@dimen/uofl_tool_bar_refresh_button_width"
android:layout_height="@dimen/uofl_tool_bar_refresh_button_height"
android:src="@drawable/refresh_icon" />
<ProgressBar
android:id="@+id/toolbar_progress_icon"
android:layout_width="@dimen/uofl_tool_bar_refresh_button_width"
android:layout_height="@dimen/uofl_tool_bar_refresh_button_height"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/circular"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
\ No newline at end of file
......@@ -38,4 +38,9 @@
<!--Report Incident screen-->
<dimen name="impact_spinner_drop_down_height">50dp</dimen>
<!--Action bar refresh icon size-->
<dimen name="progress_bar_padding_size">13dp</dimen>
<dimen name="uofl_tool_bar_refresh_button_width">40dp</dimen>
<dimen name="uofl_tool_bar_refresh_button_height">40dp</dimen>
</resources>
\ No newline at end of file
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