Commit 5e659328 by Kunj Gupta

UOFLMA-87 - Implemented Sort categories, items alphabetically.

parent f5cea91c
...@@ -28,6 +28,8 @@ import com.vsoft.uoflservicenow.utils.Constants; ...@@ -28,6 +28,8 @@ import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.uoflservicenow.utils.Util;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
...@@ -113,7 +115,14 @@ public class CatalogueItemScreen extends AppCompatActivity { ...@@ -113,7 +115,14 @@ public class CatalogueItemScreen extends AppCompatActivity {
} }
if(syncStatus == SyncStatus.SUCCESS) { if(syncStatus == SyncStatus.SUCCESS) {
if (mCatalogueItemList != null) { if (mCatalogueItemList != null) {
setData(); /*Sort catalogue items list alphabetically*/
Collections.sort(mCatalogueItemList, new Comparator<CatalogueItem>() {
@Override
public int compare(CatalogueItem lhs, CatalogueItem rhs) {
return lhs.getName().compareToIgnoreCase(rhs.getName());
}
});
setData(mCatalogueItemList);
} }
} else { } else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_items_string); showErrorDialog(R.string.failed_to_fetch_catalogue_category_items_string);
...@@ -121,12 +130,12 @@ public class CatalogueItemScreen extends AppCompatActivity { ...@@ -121,12 +130,12 @@ public class CatalogueItemScreen extends AppCompatActivity {
} }
} }
private void setData() { private void setData(final List<CatalogueItem> catalogueItemList) {
if(!mCatalogueItemList.isEmpty()) { if(!mCatalogueItemList.isEmpty()) {
mListView.setVisibility(View.VISIBLE); mListView.setVisibility(View.VISIBLE);
mEmptyTextView.setVisibility(View.GONE); mEmptyTextView.setVisibility(View.GONE);
CatalogueCategoryItemAdapter adapter = new CatalogueCategoryItemAdapter(CatalogueItemScreen.this); CatalogueCategoryItemAdapter adapter = new CatalogueCategoryItemAdapter(CatalogueItemScreen.this);
adapter.setCatalogueItemList(mCatalogueItemList); adapter.setCatalogueItemList(catalogueItemList);
mListView.setAdapter(adapter); mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
...@@ -134,12 +143,12 @@ public class CatalogueItemScreen extends AppCompatActivity { ...@@ -134,12 +143,12 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, public void onItemClick(AdapterView<?> parent, View view,
int position, long id) { int position, long id) {
CatalogueLog.e("OnItemClickListener: position: " + position + ", Catalogue: " + mCatalogueItemList.get(position)); CatalogueLog.e("OnItemClickListener: position: " + position + ", Catalogue: " + catalogueItemList.get(position));
Intent intent = new Intent(CatalogueItemScreen.this, CatalogueVariableScreen.class); Intent intent = new Intent(CatalogueItemScreen.this, CatalogueVariableScreen.class);
intent.putExtra(Constants.DATA_KEY_SYS_ID, mCatalogueItemList.get(position).getSysId()); intent.putExtra(Constants.DATA_KEY_SYS_ID, catalogueItemList.get(position).getSysId());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, mCatalogueItemList.get(position).getDescription()); intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, catalogueItemList.get(position).getDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION, mCatalogueItemList.get(position).getShortDescription()); intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION, catalogueItemList.get(position).getShortDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, mCatalogueItemList.get(position).getName()); intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, catalogueItemList.get(position).getName());
startActivity(intent); startActivity(intent);
} }
}); });
......
...@@ -27,6 +27,8 @@ import com.vsoft.uoflservicenow.utils.Constants; ...@@ -27,6 +27,8 @@ import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.uoflservicenow.utils.Util;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
...@@ -103,8 +105,16 @@ public class CatalogueScreen extends AppCompatActivity { ...@@ -103,8 +105,16 @@ public class CatalogueScreen extends AppCompatActivity {
progressDialog.dismiss(); progressDialog.dismiss();
} }
if(syncStatus == SyncStatus.SUCCESS) { if(syncStatus == SyncStatus.SUCCESS) {
if(mCatalogueList!=null) if(mCatalogueList!=null) {
/*Sort catalogue list alphabetically*/
Collections.sort(mCatalogueList, new Comparator<Catalogue>() {
@Override
public int compare(Catalogue lhs, Catalogue rhs) {
return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
}
});
setData(mCatalogueList); setData(mCatalogueList);
}
} else { } else {
showErrorDialog(R.string.failed_to_fetch_catalogue_category_string); showErrorDialog(R.string.failed_to_fetch_catalogue_category_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