Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7b78b272
authored
Sep 15, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added Local DB table for storing Catalogue Items.
parent
1be58602
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
182 additions
and
21 deletions
app/src/main/java/com/vsoft/uoflservicenow/db/DBManager.java
app/src/main/java/com/vsoft/uoflservicenow/db/managers/CatalogueItemManager.java
app/src/main/java/com/vsoft/uoflservicenow/db/models/CatalogueItem.java
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueItemScreen.java
app/src/main/java/com/vsoft/uoflservicenow/utils/DBConstants.java
app/src/main/java/com/vsoft/uoflservicenow/db/DBManager.java
View file @
7b78b272
...
@@ -28,6 +28,7 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
...
@@ -28,6 +28,7 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
@Override
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
public
void
onCreate
(
SQLiteDatabase
db
)
{
createCatalogueTable
(
db
);
createCatalogueTable
(
db
);
createCatalogueItemsTable
(
db
);
}
}
@Override
@Override
...
@@ -50,4 +51,17 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
...
@@ -50,4 +51,17 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+
CATALOGUE_SYNC_DIRTY
+
" integer default "
+
SYNC_FLAG_NONE
+
CATALOGUE_SYNC_DIRTY
+
" integer default "
+
SYNC_FLAG_NONE
+
");"
);
+
");"
);
}
}
private
void
createCatalogueItemsTable
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"create table "
+
TABLE_CATALOGUE_ITEM
+
"("
+
CATALOGUE_ITEM_ID
+
" integer primary key autoincrement, "
+
CATALOGUE_ITEM_CATALOGUE_ID
+
" integer default -1, "
+
CATALOGUE_ITEM_SYS_ID
+
" text, "
+
CATALOGUE_ITEM_NAME
+
" integer, "
+
CATALOGUE_ITEM_SHORT_DESCRIPTION
+
" text, "
+
CATALOGUE_ITEM_DESCRIPTION
+
" text, "
+
CATALOGUE_ITEM_ICON
+
" text, "
+
CATALOGUE_ITEM_SYNC_DIRTY
+
" integer default "
+
SYNC_FLAG_NONE
+
");"
);
}
}
}
app/src/main/java/com/vsoft/uoflservicenow/db/managers/CatalogueItemManager.java
0 → 100644
View file @
7b78b272
This diff is collapsed.
Click to expand it.
app/src/main/java/com/vsoft/uoflservicenow/db/models/CatalogueItem.java
View file @
7b78b272
...
@@ -8,6 +8,9 @@ import com.google.gson.annotations.SerializedName;
...
@@ -8,6 +8,9 @@ import com.google.gson.annotations.SerializedName;
*/
*/
public
class
CatalogueItem
{
public
class
CatalogueItem
{
private
long
id
=
-
1
;
private
long
catalogue_id
=
-
1
;
@SerializedName
(
"short_description"
)
@SerializedName
(
"short_description"
)
@Expose
@Expose
private
String
shortDescription
;
private
String
shortDescription
;
...
@@ -24,6 +27,24 @@ public class CatalogueItem {
...
@@ -24,6 +27,24 @@ public class CatalogueItem {
@Expose
@Expose
private
String
icon
;
private
String
icon
;
private
int
syncDirty
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
long
getCatalogueId
()
{
return
catalogue_id
;
}
public
void
setCatalogueId
(
long
catalogueId
)
{
this
.
catalogue_id
=
catalogueId
;
}
/**
/**
*
*
* @return
* @return
...
@@ -114,6 +135,89 @@ public class CatalogueItem {
...
@@ -114,6 +135,89 @@ public class CatalogueItem {
this
.
icon
=
icon
;
this
.
icon
=
icon
;
}
}
public
int
getSyncDirty
()
{
return
syncDirty
;
}
public
void
setSyncDirty
(
int
syncDirty
)
{
this
.
syncDirty
=
syncDirty
;
}
public
static
final
class
CatalogueItemBuilder
{
private
long
id
=
-
1
;
private
long
catalogue_id
=
-
1
;
private
String
shortDescription
;
private
String
description
;
private
String
name
;
private
String
sysId
;
private
String
icon
;
private
int
syncDirty
;
private
CatalogueItemBuilder
()
{
}
public
static
CatalogueItemBuilder
aCatalogueItem
()
{
return
new
CatalogueItemBuilder
();
}
public
CatalogueItemBuilder
setId
(
long
id
)
{
this
.
id
=
id
;
return
this
;
}
public
CatalogueItemBuilder
setCatalogueId
(
long
catalogueId
)
{
this
.
catalogue_id
=
catalogueId
;
return
this
;
}
public
CatalogueItemBuilder
setShortDescription
(
String
shortDescription
)
{
this
.
shortDescription
=
shortDescription
;
return
this
;
}
public
CatalogueItemBuilder
setDescription
(
String
description
)
{
this
.
description
=
description
;
return
this
;
}
public
CatalogueItemBuilder
setName
(
String
name
)
{
this
.
name
=
name
;
return
this
;
}
public
CatalogueItemBuilder
setSysId
(
String
sysId
)
{
this
.
sysId
=
sysId
;
return
this
;
}
public
CatalogueItemBuilder
setIcon
(
String
icon
)
{
this
.
icon
=
icon
;
return
this
;
}
public
CatalogueItemBuilder
setSyncDirty
(
int
syncDirty
)
{
this
.
syncDirty
=
syncDirty
;
return
this
;
}
public
CatalogueItemBuilder
but
()
{
return
aCatalogueItem
().
setId
(
id
).
setCatalogueId
(
catalogue_id
).
setShortDescription
(
shortDescription
).
setDescription
(
description
).
setName
(
name
).
setSysId
(
sysId
).
setIcon
(
icon
).
setSyncDirty
(
syncDirty
);
}
public
CatalogueItem
build
()
{
CatalogueItem
catalogueItem
=
new
CatalogueItem
();
catalogueItem
.
setId
(
id
);
catalogueItem
.
setCatalogueId
(
catalogue_id
);
catalogueItem
.
setShortDescription
(
shortDescription
);
catalogueItem
.
setDescription
(
description
);
catalogueItem
.
setName
(
name
);
catalogueItem
.
setSysId
(
sysId
);
catalogueItem
.
setIcon
(
icon
);
catalogueItem
.
setSyncDirty
(
syncDirty
);
return
catalogueItem
;
}
}
public
static
class
Json
{
public
static
class
Json
{
public
static
final
String
URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE
=
"category"
;
public
static
final
String
URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE
=
"category"
;
public
static
final
String
SYS_ID
=
"sys_id"
;
public
static
final
String
SYS_ID
=
"sys_id"
;
...
@@ -122,11 +226,14 @@ public class CatalogueItem {
...
@@ -122,11 +226,14 @@ public class CatalogueItem {
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"CatalogueItem{"
+
return
"CatalogueItem{"
+
"shortDescription='"
+
shortDescription
+
'\''
+
"id="
+
id
+
", catalogue_id="
+
catalogue_id
+
", shortDescription='"
+
shortDescription
+
'\''
+
", description='"
+
description
+
'\''
+
", description='"
+
description
+
'\''
+
", name='"
+
name
+
'\''
+
", name='"
+
name
+
'\''
+
", sysId='"
+
sysId
+
'\''
+
", sysId='"
+
sysId
+
'\''
+
", icon='"
+
icon
+
'\''
+
", icon='"
+
icon
+
'\''
+
", syncDirty="
+
syncDirty
+
'}'
;
'}'
;
}
}
}
}
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueItemScreen.java
View file @
7b78b272
...
@@ -21,6 +21,9 @@ import com.vsoft.uoflservicenow.R;
...
@@ -21,6 +21,9 @@ import com.vsoft.uoflservicenow.R;
import
com.vsoft.uoflservicenow.adapters.CatalogueCategoryItemAdapter
;
import
com.vsoft.uoflservicenow.adapters.CatalogueCategoryItemAdapter
;
import
com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueItemApiListener
;
import
com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueItemApiListener
;
import
com.vsoft.uoflservicenow.api.managers.CatalogueItemApiManager
;
import
com.vsoft.uoflservicenow.api.managers.CatalogueItemApiManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueItemManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueManager
;
import
com.vsoft.uoflservicenow.db.models.Catalogue
;
import
com.vsoft.uoflservicenow.db.models.CatalogueItem
;
import
com.vsoft.uoflservicenow.db.models.CatalogueItem
;
import
com.vsoft.uoflservicenow.enums.SyncStatus
;
import
com.vsoft.uoflservicenow.enums.SyncStatus
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
...
@@ -42,8 +45,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -42,8 +45,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
@BindView
(
R
.
id
.
catalogue_item_screen_list_view
)
ListView
mListView
;
@BindView
(
R
.
id
.
catalogue_item_screen_list_view
)
ListView
mListView
;
@BindView
(
R
.
id
.
catalogue_item_screen_empty_text_view
)
TextView
mEmptyTextView
;
@BindView
(
R
.
id
.
catalogue_item_screen_empty_text_view
)
TextView
mEmptyTextView
;
private
String
mCatalogueSysId
;
private
Catalogue
mCatalogue
;
private
List
<
CatalogueItem
>
mCatalogueItemList
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -54,11 +56,17 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -54,11 +56,17 @@ public class CatalogueItemScreen extends AppCompatActivity {
ButterKnife
.
bind
(
this
);
ButterKnife
.
bind
(
this
);
CatalogueApplication
application
=
(
CatalogueApplication
)
getApplication
();
CatalogueApplication
application
=
(
CatalogueApplication
)
getApplication
();
mCatalogueSysId
=
getIntent
().
getExtras
().
getString
(
Constants
.
DATA_KEY_SYS_ID
);
Bundle
extras
=
getIntent
().
getExtras
();
String
catalogueTitle
=
getIntent
().
getExtras
().
getString
(
Constants
.
DATA_KEY_CATALOGUE_TITLE
);
String
catalogueSysId
=
null
;
if
(
extras
!=
null
)
{
catalogueSysId
=
extras
.
getString
(
Constants
.
DATA_KEY_SYS_ID
);
//The key argument here must match that used in the other activity
}
if
(
mCatalogueSysId
==
null
)
{
mCatalogue
=
CatalogueManager
.
getCatalogueFromSysId
(
catalogueSysId
);
CatalogueLog
.
e
(
"CatalogueItemScreen: mCatalogueSysId is null"
);
if
(
mCatalogue
==
null
)
{
CatalogueLog
.
e
(
"CatalogueItemScreen: onCreate: mCatalogue is null"
);
return
;
}
}
setSupportActionBar
(
mToolbar
);
setSupportActionBar
(
mToolbar
);
...
@@ -66,7 +74,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -66,7 +74,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
if
(
actionBar
!=
null
)
{
if
(
actionBar
!=
null
)
{
actionBar
.
setDisplayHomeAsUpEnabled
(
true
);
actionBar
.
setDisplayHomeAsUpEnabled
(
true
);
actionBar
.
setElevation
(
0
);
actionBar
.
setElevation
(
0
);
actionBar
.
setTitle
(
catalogueTitle
);
actionBar
.
setTitle
(
mCatalogue
.
getTitle
()
);
actionBar
.
setDisplayShowHomeEnabled
(
false
);
actionBar
.
setDisplayShowHomeEnabled
(
false
);
actionBar
.
setDisplayShowTitleEnabled
(
true
);
actionBar
.
setDisplayShowTitleEnabled
(
true
);
}
}
...
@@ -75,11 +83,16 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -75,11 +83,16 @@ public class CatalogueItemScreen extends AppCompatActivity {
// Send initial screen view hit.
// Send initial screen view hit.
Util
.
sendScreenName
(
tracker
,
actionBar
.
getTitle
().
toString
());
Util
.
sendScreenName
(
tracker
,
actionBar
.
getTitle
().
toString
());
List
<
CatalogueItem
>
catalogueItemList
=
CatalogueItemManager
.
getAllCatalogueItems
(
mCatalogue
.
getId
());
if
(
catalogueItemList
.
isEmpty
())
{
if
(
application
.
isNetConnected
())
{
if
(
application
.
isNetConnected
())
{
new
FetchCatalogueItem
().
execute
();
new
FetchCatalogueItem
().
execute
();
}
else
{
}
else
{
DialogUtils
.
showNoConnectionDialogWithCloseActivity
(
CatalogueItemScreen
.
this
);
DialogUtils
.
showNoConnectionDialogWithCloseActivity
(
CatalogueItemScreen
.
this
);
}
}
}
else
{
setData
(
catalogueItemList
);
}
}
}
class
FetchCatalogueItem
extends
AsyncTask
<
String
,
Void
,
SyncStatus
>
{
class
FetchCatalogueItem
extends
AsyncTask
<
String
,
Void
,
SyncStatus
>
{
...
@@ -96,11 +109,11 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -96,11 +109,11 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override
@Override
protected
SyncStatus
doInBackground
(
String
...
params
)
{
protected
SyncStatus
doInBackground
(
String
...
params
)
{
return
CatalogueItemApiManager
.
getCatalogueItems
(
mCatalogue
SysId
,
new
GetCatalogueItemApiListener
()
{
return
CatalogueItemApiManager
.
getCatalogueItems
(
mCatalogue
.
getSysId
()
,
new
GetCatalogueItemApiListener
()
{
@Override
@Override
public
void
onDoneApiCall
(
List
<
CatalogueItem
>
catalogueItemList
)
{
public
void
onDoneApiCall
(
List
<
CatalogueItem
>
catalogueItemList
)
{
CatalogueLog
.
e
(
"Data: catalogueItemList: "
+
catalogueItemList
);
CatalogueLog
.
e
(
"Data: catalogueItemList: "
+
catalogueItemList
);
mCatalogueItemList
=
catalogueItemList
;
CatalogueItemManager
.
handleGetCatalogueItem
(
mCatalogue
.
getId
(),
catalogueItemList
)
;
}
}
});
});
}
}
...
@@ -112,21 +125,19 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -112,21 +125,19 @@ public class CatalogueItemScreen extends AppCompatActivity {
progressDialog
.
dismiss
();
progressDialog
.
dismiss
();
}
}
if
(
syncStatus
==
SyncStatus
.
SUCCESS
)
{
if
(
syncStatus
==
SyncStatus
.
SUCCESS
)
{
if
(
mCatalogueItemList
!=
null
)
{
setData
(
CatalogueItemManager
.
getAllCatalogueItems
(
mCatalogue
.
getId
()));
setData
();
}
}
else
{
}
else
{
showErrorDialog
(
R
.
string
.
failed_to_fetch_catalogue_category_items_string
);
showErrorDialog
(
R
.
string
.
failed_to_fetch_catalogue_category_items_string
);
}
}
}
}
}
}
private
void
setData
()
{
private
void
setData
(
final
List
<
CatalogueItem
>
catalogueItemList
)
{
if
(!
mC
atalogueItemList
.
isEmpty
())
{
if
(!
c
atalogueItemList
.
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
(
mC
atalogueItemList
);
adapter
.
setCatalogueItemList
(
c
atalogueItemList
);
mListView
.
setAdapter
(
adapter
);
mListView
.
setAdapter
(
adapter
);
mListView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
mListView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
...
@@ -134,12 +145,12 @@ public class CatalogueItemScreen extends AppCompatActivity {
...
@@ -134,12 +145,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: "
+
mC
atalogueItemList
.
get
(
position
));
CatalogueLog
.
e
(
"OnItemClickListener: position: "
+
position
+
", Catalogue: "
+
c
atalogueItemList
.
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
,
mC
atalogueItemList
.
get
(
position
).
getSysId
());
intent
.
putExtra
(
Constants
.
DATA_KEY_SYS_ID
,
c
atalogueItemList
.
get
(
position
).
getSysId
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_ITEM_DESCRIPTION
,
mC
atalogueItemList
.
get
(
position
).
getDescription
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_ITEM_DESCRIPTION
,
c
atalogueItemList
.
get
(
position
).
getDescription
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION
,
mC
atalogueItemList
.
get
(
position
).
getShortDescription
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION
,
c
atalogueItemList
.
get
(
position
).
getShortDescription
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_TITLE
,
mC
atalogueItemList
.
get
(
position
).
getName
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_TITLE
,
c
atalogueItemList
.
get
(
position
).
getName
());
startActivity
(
intent
);
startActivity
(
intent
);
}
}
});
});
...
...
app/src/main/java/com/vsoft/uoflservicenow/utils/DBConstants.java
View file @
7b78b272
...
@@ -3,6 +3,7 @@ package com.vsoft.uoflservicenow.utils;
...
@@ -3,6 +3,7 @@ package com.vsoft.uoflservicenow.utils;
public
interface
DBConstants
{
public
interface
DBConstants
{
//Tables
//Tables
String
TABLE_CATALOGUE
=
"catalogue_category"
;
String
TABLE_CATALOGUE
=
"catalogue_category"
;
String
TABLE_CATALOGUE_ITEM
=
"catalogue_category_item"
;
String
ID
=
"_id"
;
String
ID
=
"_id"
;
String
SYS_ID
=
"sys_id"
;
String
SYS_ID
=
"sys_id"
;
...
@@ -34,4 +35,31 @@ public interface DBConstants {
...
@@ -34,4 +35,31 @@ public interface DBConstants {
int
INDEX_CATALOGUE_SYNC_DIRTY
=
5
;
int
INDEX_CATALOGUE_SYNC_DIRTY
=
5
;
int
CATALOGUE_COLUMN_COUNT
=
6
;
int
CATALOGUE_COLUMN_COUNT
=
6
;
/**
* Catalogue_item table
*/
String
CATALOGUE_ITEM_ID
=
ID
;
String
CATALOGUE_ITEM_CATALOGUE_ID
=
"catalogue_id"
;
String
CATALOGUE_ITEM_SYS_ID
=
SYS_ID
;
String
CATALOGUE_ITEM_NAME
=
"name"
;
String
CATALOGUE_ITEM_SHORT_DESCRIPTION
=
"short_description"
;
String
CATALOGUE_ITEM_DESCRIPTION
=
"item_description"
;
String
CATALOGUE_ITEM_ICON
=
"icon"
;
String
CATALOGUE_ITEM_SYNC_DIRTY
=
SYNC_DIRTY
;
/**
* Indices for Catalogue_item table. *Use these only if you fetch all columns*
*/
int
INDEX_CATALOGUE_ITEM_ID
=
0
;
int
INDEX_CATALOGUE_ITEM_CATALOGUE_ID
=
1
;
int
INDEX_CATALOGUE_ITEM_SYS_ID
=
2
;
int
INDEX_CATALOGUE_ITEM_NAME
=
3
;
int
INDEX_CATALOGUE_ITEM_SHORT_DESCRIPTION
=
4
;
int
INDEX_CATALOGUE_ITEM_DESCRIPTION
=
5
;
int
INDEX_CATALOGUE_ITEM_ICON
=
6
;
int
INDEX_CATALOGUE_ITEM_SYNC_DIRTY
=
7
;
int
CATALOGUE_ITEM_COLUMN_COUNT
=
8
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment