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
917dc985
authored
Aug 26, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Removed local database and checked internet connection before any API call.
parent
98c7671a
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
79 additions
and
1309 deletions
app/src/main/java/com/vsoft/uofl_catalogue/CatalogueApplication.java
app/src/main/java/com/vsoft/uofl_catalogue/db/DBManager.java
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueItemManager.java
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueManager.java
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueVariableManager.java
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueVariableValueManager.java
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/VariableChoiceManager.java
app/src/main/java/com/vsoft/uofl_catalogue/ui/CatalogueItemScreen.java
app/src/main/java/com/vsoft/uofl_catalogue/ui/CatalogueScreen.java
app/src/main/java/com/vsoft/uofl_catalogue/ui/CatalogueVariableScreen.java
app/src/main/java/com/vsoft/uofl_catalogue/utils/Constants.java
app/src/main/java/com/vsoft/uofl_catalogue/utils/DBConstants.java
app/src/main/java/com/vsoft/uofl_catalogue/utils/Util.java
app/src/main/res/values/colors.xml
app/src/main/res/values/dimen.xml
app/src/main/res/values/strings.xml
app/src/main/java/com/vsoft/uofl_catalogue/CatalogueApplication.java
View file @
917dc985
...
...
@@ -2,15 +2,11 @@ package com.vsoft.uofl_catalogue;
import
android.app.Application
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
import
com.vsoft.uofl_catalogue.db.DBManager
;
public
class
CatalogueApplication
extends
Application
{
private
static
DBManager
sDBManager
;
private
ConnectivityManager
mConMgr
;
private
static
Context
mContext
;
...
...
@@ -19,30 +15,12 @@ public class CatalogueApplication extends Application {
super
.
onCreate
();
mContext
=
getApplicationContext
();
/*Database is created*/
initializeDatabase
();
}
public
static
Context
getContext
()
{
return
mContext
;
}
/*DataBase is created*/
public
void
initializeDatabase
()
{
if
(
sDBManager
==
null
)
{
sDBManager
=
new
DBManager
(
this
);
sDBManager
.
getWritableDatabase
();
}
}
public
static
SQLiteDatabase
getDatabase
()
{
if
(
sDBManager
!=
null
)
{
return
sDBManager
.
getWritableDatabase
();
}
return
null
;
}
public
boolean
isNetConnected
()
{
if
(
mConMgr
==
null
)
mConMgr
=
(
ConnectivityManager
)
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
...
...
app/src/main/java/com/vsoft/uofl_catalogue/db/DBManager.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
db
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
android.preference.PreferenceManager
;
import
com.vsoft.uofl_catalogue.utils.Constants
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
/**
*
* @author Kunj on 11-08-2016.
*/
public
class
DBManager
extends
SQLiteOpenHelper
implements
DBConstants
{
private
static
final
String
DATABASE_NAME
=
"uofl.db"
;
private
static
final
int
DATABASE_VERSION
=
1
;
private
Context
mContext
;
public
DBManager
(
Context
context
)
{
super
(
context
,
DATABASE_NAME
,
null
,
DATABASE_VERSION
);
mContext
=
context
;
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
createCatalogueTable
(
db
);
createCatalogueItemsTable
(
db
);
createVariableTable
(
db
);
createVariableChoiceTable
(
db
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
SharedPreferences
.
Editor
editor
=
PreferenceManager
.
getDefaultSharedPreferences
(
mContext
).
edit
();
editor
.
putInt
(
Constants
.
PREFS_OLD_VERSION_NUMBER
,
oldVersion
);
editor
.
putInt
(
Constants
.
PREFS_NEW_VERSION_NUMBER
,
newVersion
);
editor
.
apply
();
onCreate
(
db
);
}
private
void
createCatalogueTable
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"create table "
+
TABLE_CATALOGUE
+
"("
+
CATALOGUE_ID
+
" integer primary key autoincrement, "
+
CATALOGUE_TITLE
+
" text, "
+
CATALOGUE_DESCRIPTION
+
" text, "
+
CATALOGUE_SYS_ID
+
" text, "
+
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_NAME
+
" integer, "
+
CATALOGUE_ITEM_SHORT_DESCRIPTION
+
" text, "
+
CATALOGUE_ITEM_DESCRIPTION
+
" text, "
+
CATALOGUE_ITEM_SYS_ID
+
" text, "
+
CATALOGUE_ITEM_SYNC_DIRTY
+
" integer default "
+
SYNC_FLAG_NONE
+
");"
);
}
private
void
createVariableTable
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"create table "
+
TABLE_CATALOGUE_VARIABLES
+
"("
+
CATALOGUE_VARIABLE_ID
+
" integer primary key autoincrement, "
+
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
+
" integer default -1, "
+
CATALOGUE_VARIABLE_NAME
+
" text, "
+
CATALOGUE_VARIABLE_QUESTION_TEXT
+
" text, "
+
CATALOGUE_VARIABLE_TYPE
+
" integer, "
+
CATALOGUE_VARIABLE_MANDATORY
+
" integer, "
+
CATALOGUE_VARIABLE_NONE_REQUIRED
+
" integer, "
+
CATALOGUE_VARIABLE_REFERENCE_TABLE
+
" text, "
+
CATALOGUE_VARIABLE_SYS_ID
+
" text, "
+
CATALOGUE_VARIABLE_SYNC_DIRTY
+
" integer default "
+
SYNC_FLAG_NONE
+
");"
);
}
private
void
createVariableChoiceTable
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"create table "
+
TABLE_VARIABLE_CHOICES
+
"("
+
VARIABLE_CHOICE_ID
+
" integer primary key autoincrement, "
+
VARIABLE_CHOICE_VARIABLE_ID
+
" integer default -1, "
+
VARIABLE_CHOICE_TEXT
+
" text, "
+
VARIABLE_CHOICE_VALUE
+
" integer, "
+
VARIABLE_CHOICE_ORDER
+
" integer, "
+
VARIABLE_CHOICE_MISC
+
" real);"
);
}
}
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueItemManager.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueItem
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
/**
* @author Kunj on 11-08-2016.
*/
public
class
CatalogueItemManager
implements
DBConstants
{
public
static
long
save
(
CatalogueItem
catalogueItem
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogueItem
.
setSyncDirty
(
syncDirty
);
long
id
=
db
.
insert
(
TABLE_CATALOGUE_ITEM
,
null
,
getContentValues
(
catalogueItem
));
catalogueItem
.
setId
(
id
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
CatalogueItem
catalogueItem
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
if
(
catalogueItem
.
getSysId
()
==
null
||
catalogueItem
.
getSysId
().
isEmpty
())
{
return
db
.
delete
(
TABLE_CATALOGUE_ITEM
,
CATALOGUE_ITEM_ID
+
"="
+
catalogueItem
.
getId
(),
null
);
}
else
{
return
update
(
catalogueItem
,
SYNC_FLAG_DELETE
);
}
}
return
-
1
;
}
public
static
int
update
(
CatalogueItem
catalogueItem
,
int
syncDirty
)
{
return
update
(
catalogueItem
,
null
,
syncDirty
);
}
public
static
int
update
(
CatalogueItem
catalogueItem
,
List
<
String
>
column
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogueItem
.
setSyncDirty
(
syncDirty
);
if
(
column
==
null
||
column
.
size
()
==
0
)
{
return
db
.
update
(
TABLE_CATALOGUE_ITEM
,
getContentValues
(
catalogueItem
),
CATALOGUE_ITEM_ID
+
"="
+
catalogueItem
.
getId
(),
null
);
}
else
{
ContentValues
contentValues
=
new
ContentValues
(
column
.
size
());
contentValues
.
put
(
CATALOGUE_SYNC_DIRTY
,
catalogueItem
.
getSyncDirty
());
for
(
int
i
=
0
;
i
<
column
.
size
();
i
++)
{
String
columnName
=
column
.
get
(
i
);
if
(
CATALOGUE_ITEM_NAME
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_ITEM_NAME
,
catalogueItem
.
getName
());
}
else
if
(
CATALOGUE_ITEM_CATALOGUE_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_ITEM_CATALOGUE_ID
,
catalogueItem
.
getCatalogueId
());
}
else
if
(
CATALOGUE_ITEM_SHORT_DESCRIPTION
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_ITEM_SHORT_DESCRIPTION
,
catalogueItem
.
getShortDescription
());
}
else
if
(
CATALOGUE_ITEM_DESCRIPTION
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_ITEM_DESCRIPTION
,
catalogueItem
.
getDescription
());
}
else
if
(
CATALOGUE_ITEM_SYS_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_ITEM_SYS_ID
,
catalogueItem
.
getSysId
());
}
}
return
db
.
update
(
TABLE_CATALOGUE_ITEM
,
contentValues
,
CATALOGUE_ITEM_ID
+
"="
+
catalogueItem
.
getId
(),
null
);
}
}
else
{
return
-
1
;
}
}
public
static
void
handleGetCatalogueItem
(
long
catalogueId
,
List
<
CatalogueItem
>
serverCatalogueItemList
)
{
if
(
serverCatalogueItemList
!=
null
&&
!
serverCatalogueItemList
.
isEmpty
())
{
/*catalogueItemSysIdMap contain all server response catalogueItem Sys Id*/
HashMap
<
String
,
Integer
>
catalogueItemSysIdMap
=
new
HashMap
<>(
0
);
Integer
intObj
=
Integer
.
valueOf
(
1
);
for
(
int
i
=
0
;
i
<
serverCatalogueItemList
.
size
();
i
++)
{
String
sysId
=
serverCatalogueItemList
.
get
(
i
).
getSysId
();
catalogueItemSysIdMap
.
put
(
sysId
,
intObj
);
}
/*localCatalogueItemList is contain all local Catalogues */
List
<
CatalogueItem
>
localCatalogueItemList
=
getAllCatalogueItems
(
catalogueId
);
if
(
localCatalogueItemList
!=
null
&&
!
localCatalogueItemList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localCatalogueItemList
.
size
();
i
++)
{
CatalogueItem
localCatalogueItem
=
localCatalogueItemList
.
get
(
i
);
String
localCatalogueItemSysId
=
localCatalogueItem
.
getSysId
();
if
(
localCatalogueItemSysId
!=
null
&&
!
localCatalogueItemSysId
.
isEmpty
()
&&
!
catalogueItemSysIdMap
.
containsKey
(
localCatalogueItemSysId
))
{
//Update sys_id with empty string because required to delete locally
localCatalogueItem
.
setSysId
(
""
);
delete
(
localCatalogueItem
);
}
}
}
/*Check this catalogue 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
<
serverCatalogueItemList
.
size
();
i
++)
{
CatalogueItem
catalogueItem
=
serverCatalogueItemList
.
get
(
i
);
CatalogueItem
localCatalogueItem
=
getCatalogueItemFromSysId
(
catalogueItem
.
getSysId
());
if
(
localCatalogueItem
==
null
)
{
catalogueItem
.
setCatalogueId
(
catalogueId
);
save
(
catalogueItem
,
DBConstants
.
SYNC_FLAG_NONE
);
}
else
{
/*Update complete local Expense object with response Expense object*/
catalogueItem
.
setCatalogueId
(
catalogueId
);
catalogueItem
.
setId
(
localCatalogueItem
.
getId
());
update
(
catalogueItem
,
DBConstants
.
SYNC_FLAG_NONE
);
}
}
}
else
{
/*That means there is no CatalogueItem category in server response, then all local items should be deleted those are contain sys_id*/
/*localCatalogueItemList is contain all local Catalogues */
List
<
CatalogueItem
>
localCatalogueItemList
=
getAllCatalogueItems
(
catalogueId
);
if
(
localCatalogueItemList
!=
null
&&
!
localCatalogueItemList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localCatalogueItemList
.
size
();
i
++)
{
CatalogueItem
localCatalogueItem
=
localCatalogueItemList
.
get
(
i
);
String
localCatalogueSysId
=
localCatalogueItem
.
getSysId
();
if
(
localCatalogueSysId
!=
null
&&
!
localCatalogueSysId
.
isEmpty
())
{
//Update sys_id with empty string because required to delete locally
localCatalogueItem
.
setSysId
(
""
);
delete
(
localCatalogueItem
);
}
}
}
}
}
public
static
List
<
CatalogueItem
>
getAllCatalogueItems
(
long
catalogueId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_ITEM
+
" where "
+
CATALOGUE_ITEM_CATALOGUE_ID
+
"="
+
catalogueId
+
" and "
+
CATALOGUE_ITEM_SYNC_DIRTY
+
"!="
+
DBConstants
.
SYNC_FLAG_DELETE
,
null
);
ArrayList
<
CatalogueItem
>
catalogueItemList
;
if
(
c
.
getCount
()
>
0
)
{
catalogueItemList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
CatalogueItem
.
CatalogueItemBuilder
builder
=
CatalogueItem
.
CatalogueItemBuilder
.
aCatalogueItem
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogueItemList
.
add
(
builder
.
build
());
}
}
else
{
catalogueItemList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
catalogueItemList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
CatalogueItem
get
(
long
catalogueItemId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueItem
catalogueItem
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_ITEM
+
" where "
+
CATALOGUE_ITEM_ID
+
"="
+
catalogueItemId
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueItem
.
CatalogueItemBuilder
builder
=
CatalogueItem
.
CatalogueItemBuilder
.
aCatalogueItem
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogueItem
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueItem
;
}
public
static
CatalogueItem
getCatalogueItemFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueItem
catalogueItem
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_ITEM
+
" where "
+
CATALOGUE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueItem
.
CatalogueItemBuilder
builder
=
CatalogueItem
.
CatalogueItemBuilder
.
aCatalogueItem
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogueItem
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueItem
;
}
private
static
void
fillAllCatalogueDetails
(
Cursor
c
,
CatalogueItem
.
CatalogueItemBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_CATALOGUE_ITEM_ID
));
builder
.
setCatalogueId
(
c
.
getLong
(
INDEX_CATALOGUE_ITEM_CATALOGUE_ID
));
builder
.
setName
(
c
.
getString
(
INDEX_CATALOGUE_ITEM_NAME
));
builder
.
setShortDescription
(
c
.
getString
(
INDEX_CATALOGUE_ITEM_SHORT_DESCRIPTION
));
builder
.
setDescription
(
c
.
getString
(
INDEX_CATALOGUE_ITEM_DESCRIPTION
));
builder
.
setSysId
(
c
.
getString
(
INDEX_CATALOGUE_ITEM_SYS_ID
));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_CATALOGUE_ITEM_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
CatalogueItem
catalogueItem
)
{
ContentValues
cv
=
new
ContentValues
(
CATALOGUE_ITEM_COLUMN_COUNT
-
1
);
cv
.
put
(
CATALOGUE_ITEM_CATALOGUE_ID
,
catalogueItem
.
getCatalogueId
());
cv
.
put
(
CATALOGUE_ITEM_NAME
,
catalogueItem
.
getName
());
cv
.
put
(
CATALOGUE_ITEM_SHORT_DESCRIPTION
,
catalogueItem
.
getShortDescription
());
cv
.
put
(
CATALOGUE_ITEM_DESCRIPTION
,
catalogueItem
.
getDescription
());
cv
.
put
(
CATALOGUE_ITEM_SYS_ID
,
catalogueItem
.
getSysId
());
cv
.
put
(
CATALOGUE_ITEM_SYNC_DIRTY
,
catalogueItem
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueManager.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.db.models.Catalogue
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
/**
*
* @author Kunj on 11-08-2016.
*/
public
class
CatalogueManager
implements
DBConstants
{
public
static
long
save
(
Catalogue
catalogue
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogue
.
setSyncDirty
(
syncDirty
);
long
id
=
db
.
insert
(
TABLE_CATALOGUE
,
null
,
getContentValues
(
catalogue
));
catalogue
.
setId
(
id
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
Catalogue
catalogue
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
if
(
catalogue
.
getSysId
()
==
null
||
catalogue
.
getSysId
().
isEmpty
())
{
return
db
.
delete
(
TABLE_CATALOGUE
,
CATALOGUE_ID
+
"="
+
catalogue
.
getId
(),
null
);
}
else
{
return
update
(
catalogue
,
SYNC_FLAG_DELETE
);
}
}
return
-
1
;
}
public
static
int
update
(
Catalogue
catalogue
,
int
syncDirty
)
{
return
update
(
catalogue
,
null
,
syncDirty
);
}
public
static
int
update
(
Catalogue
catalogue
,
List
<
String
>
column
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogue
.
setSyncDirty
(
syncDirty
);
if
(
column
==
null
||
column
.
size
()
==
0
)
{
return
db
.
update
(
TABLE_CATALOGUE
,
getContentValues
(
catalogue
),
CATALOGUE_ID
+
"="
+
catalogue
.
getId
(),
null
);
}
else
{
ContentValues
contentValues
=
new
ContentValues
(
column
.
size
());
contentValues
.
put
(
CATALOGUE_SYNC_DIRTY
,
catalogue
.
getSyncDirty
());
for
(
int
i
=
0
;
i
<
column
.
size
();
i
++)
{
String
columnName
=
column
.
get
(
i
);
if
(
CATALOGUE_TITLE
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_TITLE
,
catalogue
.
getTitle
());
}
else
if
(
CATALOGUE_DESCRIPTION
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_DESCRIPTION
,
catalogue
.
getDescription
());
}
else
if
(
CATALOGUE_SYS_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_SYS_ID
,
catalogue
.
getSysId
());
}
}
return
db
.
update
(
TABLE_CATALOGUE
,
contentValues
,
CATALOGUE_ID
+
"="
+
catalogue
.
getId
(),
null
);
}
}
else
{
return
-
1
;
}
}
public
static
void
handleGetCatalogue
(
List
<
Catalogue
>
serverCatalogueList
)
{
if
(
serverCatalogueList
!=
null
&&
!
serverCatalogueList
.
isEmpty
())
{
/*catalogueSysIdMap contain all server response catalogues Sys Id*/
HashMap
<
String
,
Integer
>
catalogueSysIdMap
=
new
HashMap
<>(
0
);
Integer
intObj
=
Integer
.
valueOf
(
1
);
for
(
int
i
=
0
;
i
<
serverCatalogueList
.
size
();
i
++)
{
String
sysId
=
serverCatalogueList
.
get
(
i
).
getSysId
();
catalogueSysIdMap
.
put
(
sysId
,
intObj
);
}
/*localCatalogueList is contain all local Catalogues */
List
<
Catalogue
>
localCatalogueList
=
getAllCatalogues
();
if
(
localCatalogueList
!=
null
&&
!
localCatalogueList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localCatalogueList
.
size
();
i
++)
{
Catalogue
localCatalogue
=
localCatalogueList
.
get
(
i
);
String
localCatalogueSysId
=
localCatalogue
.
getSysId
();
if
(
localCatalogueSysId
!=
null
&&
!
localCatalogueSysId
.
isEmpty
()
&&
!
catalogueSysIdMap
.
containsKey
(
localCatalogueSysId
))
{
//Update sys_id with empty string because required to delete locally
localCatalogue
.
setSysId
(
""
);
delete
(
localCatalogue
);
}
}
}
/*Check this catalogue 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
<
serverCatalogueList
.
size
();
i
++)
{
Catalogue
catalogue
=
serverCatalogueList
.
get
(
i
);
Catalogue
localCatalogue
=
getCatalogueFromSysId
(
catalogue
.
getSysId
());
if
(
localCatalogue
==
null
)
{
save
(
catalogue
,
DBConstants
.
SYNC_FLAG_NONE
);
}
else
{
/*Update complete local Catalogue object with response Catalogue object*/
catalogue
.
setId
(
localCatalogue
.
getId
());
update
(
catalogue
,
DBConstants
.
SYNC_FLAG_NONE
);
}
}
}
else
{
/*That means there is no Catalogue category in server response, then all local items should be deleted those are contain sys_id*/
/*localCatalogueList is contain all local Catalogues */
List
<
Catalogue
>
localCatalogueList
=
getAllCatalogues
();
if
(
localCatalogueList
!=
null
&&
!
localCatalogueList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localCatalogueList
.
size
();
i
++)
{
Catalogue
localCatalogue
=
localCatalogueList
.
get
(
i
);
String
localCatalogueSysId
=
localCatalogue
.
getSysId
();
if
(
localCatalogueSysId
!=
null
&&
!
localCatalogueSysId
.
isEmpty
())
{
//Update sys_id with empty string because required to delete locally
localCatalogue
.
setSysId
(
""
);
delete
(
localCatalogue
);
}
}
}
}
}
public
static
List
<
Catalogue
>
getAllCatalogues
()
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE
+
" where "
+
CATALOGUE_SYNC_DIRTY
+
"!="
+
DBConstants
.
SYNC_FLAG_DELETE
,
null
);
ArrayList
<
Catalogue
>
catalogueList
;
if
(
c
.
getCount
()
>
0
)
{
catalogueList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
Catalogue
.
CatalogueBuilder
builder
=
Catalogue
.
CatalogueBuilder
.
aCatalogue
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogueList
.
add
(
builder
.
build
());
}
}
else
{
catalogueList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
catalogueList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
Catalogue
get
(
long
catalogueId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
Catalogue
catalogue
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE
+
" where "
+
CATALOGUE_ID
+
"="
+
catalogueId
,
null
);
if
(
c
.
moveToFirst
())
{
Catalogue
.
CatalogueBuilder
builder
=
Catalogue
.
CatalogueBuilder
.
aCatalogue
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogue
=
builder
.
build
();
}
c
.
close
();
}
return
catalogue
;
}
public
static
Catalogue
getCatalogueFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
Catalogue
catalogue
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE
+
" where "
+
CATALOGUE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
Catalogue
.
CatalogueBuilder
builder
=
Catalogue
.
CatalogueBuilder
.
aCatalogue
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogue
=
builder
.
build
();
}
c
.
close
();
}
return
catalogue
;
}
private
static
void
fillAllCatalogueDetails
(
Cursor
c
,
Catalogue
.
CatalogueBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_CATALOGUE_ID
));
builder
.
setTitle
(
c
.
getString
(
INDEX_CATALOGUE_TITLE
));
builder
.
setDescription
(
c
.
getString
(
INDEX_CATALOGUE_DESCRIPTION
));
builder
.
setSysId
(
c
.
getString
(
INDEX_CATALOGUE_SYS_ID
));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_CATALOGUE_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
Catalogue
catalogue
)
{
ContentValues
cv
=
new
ContentValues
(
CATALOGUE_COLUMN_COUNT
-
1
);
cv
.
put
(
CATALOGUE_TITLE
,
catalogue
.
getTitle
());
cv
.
put
(
CATALOGUE_DESCRIPTION
,
catalogue
.
getDescription
());
cv
.
put
(
CATALOGUE_SYS_ID
,
catalogue
.
getSysId
());
cv
.
put
(
CATALOGUE_SYNC_DIRTY
,
catalogue
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueVariableManager.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueVariable
;
import
com.vsoft.uofl_catalogue.enums.ViewType
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
/**
*
* @author Kunj on 11-08-2016.
*/
public
class
CatalogueVariableManager
implements
DBConstants
{
public
static
long
save
(
CatalogueVariable
catalogueVariable
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogueVariable
.
setSyncDirty
(
syncDirty
);
long
id
=
db
.
insert
(
TABLE_CATALOGUE_VARIABLES
,
null
,
getContentValues
(
catalogueVariable
));
catalogueVariable
.
setId
(
id
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
CatalogueVariable
catalogueVariable
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
if
(
catalogueVariable
.
getSysId
()
==
null
||
catalogueVariable
.
getSysId
().
isEmpty
())
{
return
db
.
delete
(
TABLE_CATALOGUE_VARIABLES
,
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
else
{
return
update
(
catalogueVariable
,
SYNC_FLAG_DELETE
);
}
}
return
-
1
;
}
public
static
int
update
(
CatalogueVariable
catalogueVariable
,
int
syncDirty
)
{
return
update
(
catalogueVariable
,
null
,
syncDirty
);
}
public
static
int
update
(
CatalogueVariable
catalogueVariable
,
List
<
String
>
column
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogueVariable
.
setSyncDirty
(
syncDirty
);
if
(
column
==
null
||
column
.
size
()
==
0
)
{
return
db
.
update
(
TABLE_CATALOGUE_VARIABLES
,
getContentValues
(
catalogueVariable
),
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
else
{
ContentValues
contentValues
=
new
ContentValues
(
column
.
size
());
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
for
(
int
i
=
0
;
i
<
column
.
size
();
i
++)
{
String
columnName
=
column
.
get
(
i
);
if
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
,
catalogueVariable
.
getCatalogueItemId
());
}
else
if
(
CATALOGUE_VARIABLE_NAME
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_NAME
,
catalogueVariable
.
getName
());
}
else
if
(
CATALOGUE_VARIABLE_QUESTION_TEXT
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_QUESTION_TEXT
,
catalogueVariable
.
getQuestionText
());
}
else
if
(
CATALOGUE_VARIABLE_TYPE
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_TYPE
,
ViewType
.
getId
(
catalogueVariable
.
getType
()));
}
else
if
(
CATALOGUE_VARIABLE_MANDATORY
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_MANDATORY
,
catalogueVariable
.
isMandatory
()
?
1
:
0
);
}
else
if
(
CATALOGUE_VARIABLE_NONE_REQUIRED
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_NONE_REQUIRED
,
catalogueVariable
.
isNoneRequired
()
?
1
:
0
);
}
else
if
(
CATALOGUE_VARIABLE_REFERENCE_TABLE
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_REFERENCE_TABLE
,
catalogueVariable
.
getReferenceTable
());
}
else
if
(
CATALOGUE_VARIABLE_SYS_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_SYS_ID
,
catalogueVariable
.
getSysId
());
}
else
if
(
CATALOGUE_VARIABLE_SYNC_DIRTY
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
}
}
return
db
.
update
(
TABLE_CATALOGUE_VARIABLES
,
contentValues
,
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
}
else
{
return
-
1
;
}
}
public
static
void
handleGetVariable
(
long
catalogueItemId
,
List
<
CatalogueVariable
>
serverVariableList
)
{
if
(
serverVariableList
!=
null
&&
!
serverVariableList
.
isEmpty
())
{
/*variableSysIdMap contain all server response catalogues Sys Id*/
HashMap
<
String
,
Integer
>
variableSysIdMap
=
new
HashMap
<>(
0
);
Integer
intObj
=
Integer
.
valueOf
(
1
);
for
(
int
i
=
0
;
i
<
serverVariableList
.
size
();
i
++)
{
String
sysId
=
serverVariableList
.
get
(
i
).
getSysId
();
variableSysIdMap
.
put
(
sysId
,
intObj
);
}
/*localVariableList is contain all local Catalogues */
List
<
CatalogueVariable
>
localVariableList
=
getAllVariable
(
catalogueItemId
);
if
(
localVariableList
!=
null
&&
!
localVariableList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localVariableList
.
size
();
i
++)
{
CatalogueVariable
localVariable
=
localVariableList
.
get
(
i
);
String
localVariableSysId
=
localVariable
.
getSysId
();
if
(
localVariableSysId
!=
null
&&
!
localVariableSysId
.
isEmpty
()
&&
!
variableSysIdMap
.
containsKey
(
localVariableSysId
))
{
//Update sys_id with empty string because required to delete locally
localVariable
.
setSysId
(
""
);
delete
(
localVariable
);
}
}
}
/*Check this catalogueVariable 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
<
serverVariableList
.
size
();
i
++)
{
CatalogueVariable
catalogueVariable
=
serverVariableList
.
get
(
i
);
CatalogueVariable
localVariable
=
getVariableFromSysId
(
catalogueVariable
.
getSysId
());
if
(
localVariable
==
null
)
{
catalogueVariable
.
setCatalogueItemId
(
catalogueItemId
);
save
(
catalogueVariable
,
DBConstants
.
SYNC_FLAG_NONE
);
}
else
{
/*Update complete local CatalogueVariable object with response CatalogueVariable object*/
catalogueVariable
.
setId
(
localVariable
.
getId
());
catalogueVariable
.
setCatalogueItemId
(
catalogueItemId
);
update
(
catalogueVariable
,
DBConstants
.
SYNC_FLAG_NONE
);
}
}
}
else
{
/*That means there is no CatalogueVariable in server response, then all local items should be deleted those are contain sys_id*/
/*localVariableList is contain all local Catalogues */
List
<
CatalogueVariable
>
localVariableList
=
getAllVariable
(
catalogueItemId
);
if
(
localVariableList
!=
null
&&
!
localVariableList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localVariableList
.
size
();
i
++)
{
CatalogueVariable
localVariable
=
localVariableList
.
get
(
i
);
String
localVariableSysId
=
localVariable
.
getSysId
();
if
(
localVariableSysId
!=
null
&&
!
localVariableSysId
.
isEmpty
())
{
//Update sys_id with empty string because required to delete locally
localVariable
.
setSysId
(
""
);
delete
(
localVariable
);
}
}
}
}
}
public
static
List
<
CatalogueVariable
>
getAllVariable
(
long
catalogueItemId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
+
"="
+
catalogueItemId
+
" and "
+
CATALOGUE_VARIABLE_SYNC_DIRTY
+
"!="
+
DBConstants
.
SYNC_FLAG_DELETE
,
null
);
ArrayList
<
CatalogueVariable
>
variableList
;
if
(
c
.
getCount
()
>
0
)
{
variableList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
variableList
.
add
(
builder
.
build
());
}
}
else
{
variableList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
variableList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
CatalogueVariable
get
(
long
catalogueId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueVariable
catalogueVariable
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueId
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
catalogueVariable
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueVariable
;
}
public
static
CatalogueVariable
getVariableFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueVariable
catalogueVariable
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
catalogueVariable
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueVariable
;
}
private
static
void
fillAllVariableDetails
(
Cursor
c
,
CatalogueVariable
.
CatalogueVariableBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_CATALOGUE_VARIABLE_ID
));
builder
.
setCatalogueItemId
(
c
.
getLong
(
INDEX_CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
));
builder
.
setName
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_NAME
));
builder
.
setQuestionText
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_QUESTION_TEXT
));
builder
.
setType
(
ViewType
.
from
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_TYPE
)));
builder
.
setMandatory
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_MANDATORY
)
==
1
);
builder
.
setNoneRequired
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_NONE_REQUIRED
)
==
1
);
builder
.
setReferenceTable
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_REFERENCE
));
builder
.
setSysId
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_SYS_ID
));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
CatalogueVariable
catalogueVariable
)
{
ContentValues
cv
=
new
ContentValues
(
CATALOGUE_VARIABLE_COLUMN_COUNT
-
1
);
cv
.
put
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
,
catalogueVariable
.
getCatalogueItemId
());
cv
.
put
(
CATALOGUE_VARIABLE_NAME
,
catalogueVariable
.
getName
());
cv
.
put
(
CATALOGUE_VARIABLE_QUESTION_TEXT
,
catalogueVariable
.
getQuestionText
());
cv
.
put
(
CATALOGUE_VARIABLE_TYPE
,
catalogueVariable
.
getType
().
getId
());
cv
.
put
(
CATALOGUE_VARIABLE_MANDATORY
,
catalogueVariable
.
isMandatory
()
?
1
:
0
);
cv
.
put
(
CATALOGUE_VARIABLE_NONE_REQUIRED
,
catalogueVariable
.
isNoneRequired
()
?
1
:
0
);
cv
.
put
(
CATALOGUE_VARIABLE_REFERENCE_TABLE
,
catalogueVariable
.
getReferenceTable
());
cv
.
put
(
CATALOGUE_VARIABLE_SYS_ID
,
catalogueVariable
.
getSysId
());
cv
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/CatalogueVariableValueManager.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueVariable
;
import
com.vsoft.uofl_catalogue.enums.ViewType
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
*
* @author Kunj on 11-08-2016.
*/
public
class
CatalogueVariableValueManager
implements
DBConstants
{
public
static
long
save
(
String
tableName
,
List
<
String
>
columnNameList
,
List
<
String
>
valueList
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
ContentValues
contentValues
=
new
ContentValues
(
columnNameList
.
size
());
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
syncDirty
);
for
(
int
i
=
0
;
i
<
columnNameList
.
size
();
i
++)
{
String
columnName
=
columnNameList
.
get
(
i
);
String
value
=
valueList
.
get
(
i
);
if
(
columnName
!=
null
&&
value
!=
null
)
contentValues
.
put
(
columnName
,
value
);
}
long
id
=
db
.
insert
(
tableName
,
null
,
contentValues
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
CatalogueVariable
catalogueVariable
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
if
(
catalogueVariable
.
getSysId
()
==
null
||
catalogueVariable
.
getSysId
().
isEmpty
())
{
return
db
.
delete
(
TABLE_CATALOGUE_VARIABLES
,
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
else
{
return
update
(
catalogueVariable
,
SYNC_FLAG_DELETE
);
}
}
return
-
1
;
}
public
static
int
update
(
CatalogueVariable
catalogueVariable
,
int
syncDirty
)
{
return
update
(
catalogueVariable
,
null
,
syncDirty
);
}
public
static
int
update
(
CatalogueVariable
catalogueVariable
,
List
<
String
>
column
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogueVariable
.
setSyncDirty
(
syncDirty
);
if
(
column
==
null
||
column
.
size
()
==
0
)
{
return
db
.
update
(
TABLE_CATALOGUE_VARIABLES
,
getContentValues
(
catalogueVariable
),
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
else
{
ContentValues
contentValues
=
new
ContentValues
(
column
.
size
());
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
for
(
int
i
=
0
;
i
<
column
.
size
();
i
++)
{
String
columnName
=
column
.
get
(
i
);
if
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
,
catalogueVariable
.
getCatalogueItemId
());
}
else
if
(
CATALOGUE_VARIABLE_NAME
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_NAME
,
catalogueVariable
.
getName
());
}
else
if
(
CATALOGUE_VARIABLE_QUESTION_TEXT
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_QUESTION_TEXT
,
catalogueVariable
.
getQuestionText
());
}
else
if
(
CATALOGUE_VARIABLE_TYPE
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_TYPE
,
ViewType
.
getId
(
catalogueVariable
.
getType
()));
}
else
if
(
CATALOGUE_VARIABLE_SYS_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_SYS_ID
,
catalogueVariable
.
getSysId
());
}
else
if
(
CATALOGUE_VARIABLE_SYNC_DIRTY
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
}
}
return
db
.
update
(
TABLE_CATALOGUE_VARIABLES
,
contentValues
,
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
}
else
{
return
-
1
;
}
}
public
static
List
<
CatalogueVariable
>
getAllVariable
(
long
catalogueItemId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
+
"="
+
catalogueItemId
+
" and "
+
CATALOGUE_VARIABLE_SYNC_DIRTY
+
"!="
+
DBConstants
.
SYNC_FLAG_DELETE
,
null
);
ArrayList
<
CatalogueVariable
>
variableList
;
if
(
c
.
getCount
()
>
0
)
{
variableList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
variableList
.
add
(
builder
.
build
());
}
}
else
{
variableList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
variableList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
CatalogueVariable
get
(
long
catalogueId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueVariable
catalogueVariable
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueId
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
catalogueVariable
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueVariable
;
}
public
static
CatalogueVariable
getVariableFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueVariable
catalogueVariable
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
catalogueVariable
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueVariable
;
}
private
static
void
fillAllVariableDetails
(
Cursor
c
,
CatalogueVariable
.
CatalogueVariableBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_CATALOGUE_VARIABLE_ID
));
builder
.
setCatalogueItemId
(
c
.
getLong
(
INDEX_CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
));
builder
.
setName
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_NAME
));
builder
.
setQuestionText
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_QUESTION_TEXT
));
builder
.
setType
(
ViewType
.
from
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_TYPE
)));
builder
.
setSysId
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_SYS_ID
));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
CatalogueVariable
catalogueVariable
)
{
ContentValues
cv
=
new
ContentValues
(
CATALOGUE_VARIABLE_COLUMN_COUNT
-
1
);
cv
.
put
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
,
catalogueVariable
.
getCatalogueItemId
());
cv
.
put
(
CATALOGUE_VARIABLE_NAME
,
catalogueVariable
.
getName
());
cv
.
put
(
CATALOGUE_VARIABLE_QUESTION_TEXT
,
catalogueVariable
.
getQuestionText
());
cv
.
put
(
CATALOGUE_VARIABLE_TYPE
,
catalogueVariable
.
getType
().
getId
());
cv
.
put
(
CATALOGUE_VARIABLE_SYS_ID
,
catalogueVariable
.
getSysId
());
cv
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/db/managers/VariableChoiceManager.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.db.models.VariableChoice
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author Kunj on 11-08-2016.
*/
public
class
VariableChoiceManager
implements
DBConstants
{
public
static
long
save
(
VariableChoice
variableChoice
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
long
id
=
db
.
insert
(
TABLE_VARIABLE_CHOICES
,
null
,
getContentValues
(
variableChoice
));
variableChoice
.
setId
(
id
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
VariableChoice
variableChoice
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
return
db
.
delete
(
TABLE_VARIABLE_CHOICES
,
VARIABLE_CHOICE_ID
+
"="
+
variableChoice
.
getId
(),
null
);
}
return
-
1
;
}
public
static
void
deleteAll
(
long
variableId
)
{
List
<
VariableChoice
>
localVariableChoiceList
=
getAllVariableChoices
(
variableId
);
if
(!
localVariableChoiceList
.
isEmpty
())
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
for
(
int
i
=
0
;
i
<
localVariableChoiceList
.
size
();
i
++)
{
delete
(
localVariableChoiceList
.
get
(
i
));
}
}
}
}
public
static
void
handleGetVariableChoice
(
long
variableId
,
List
<
VariableChoice
>
serverVariableChoiceList
)
{
if
(
serverVariableChoiceList
!=
null
&&
!
serverVariableChoiceList
.
isEmpty
())
{
/*First delete all existing variable choice for particular variable then we will save*/
deleteAll
(
variableId
);
for
(
int
i
=
0
;
i
<
serverVariableChoiceList
.
size
();
i
++)
{
VariableChoice
variableChoice
=
serverVariableChoiceList
.
get
(
i
);
variableChoice
.
setVariableId
(
variableId
);
save
(
variableChoice
);
}
}
else
{
/*That means there is no VariableChoice in server response,
*then all local items should be deleted those are contain that variable id*/
/*localVariableChoiceList is contain all local Catalogues */
deleteAll
(
variableId
);
}
}
public
static
List
<
VariableChoice
>
getAllVariableChoices
(
long
variableId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_VARIABLE_CHOICES
+
" where "
+
VARIABLE_CHOICE_VARIABLE_ID
+
"="
+
variableId
+
" ORDER BY "
+
VARIABLE_CHOICE_ORDER
+
" ASC"
,
null
);
ArrayList
<
VariableChoice
>
variableChoiceList
;
if
(
c
.
getCount
()
>
0
)
{
variableChoiceList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
VariableChoice
.
VariableChoiceBuilder
builder
=
VariableChoice
.
VariableChoiceBuilder
.
aVariableChoice
();
fillAllVariableChoiceDetails
(
c
,
builder
);
variableChoiceList
.
add
(
builder
.
build
());
}
}
else
{
variableChoiceList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
variableChoiceList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
VariableChoice
get
(
long
variableChoiceId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
VariableChoice
variableChoice
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_VARIABLE_CHOICES
+
" where "
+
VARIABLE_CHOICE_ID
+
"="
+
variableChoiceId
,
null
);
if
(
c
.
moveToFirst
())
{
VariableChoice
.
VariableChoiceBuilder
builder
=
VariableChoice
.
VariableChoiceBuilder
.
aVariableChoice
();
fillAllVariableChoiceDetails
(
c
,
builder
);
variableChoice
=
builder
.
build
();
}
c
.
close
();
}
return
variableChoice
;
}
private
static
void
fillAllVariableChoiceDetails
(
Cursor
c
,
VariableChoice
.
VariableChoiceBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_VARIABLE_CHOICE_ID
));
builder
.
setVariableId
((
c
.
getLong
(
INDEX_VARIABLE_CHOICE_VARIABLE_ID
)));
builder
.
setText
(
c
.
getString
(
INDEX_VARIABLE_CHOICE_TEXT
));
builder
.
setValue
(
c
.
getString
(
INDEX_VARIABLE_CHOICE_VALUE
));
builder
.
setOrder
(
c
.
getInt
(
INDEX_VARIABLE_CHOICE_ORDER
));
builder
.
setMisc
(
c
.
getFloat
(
INDEX_VARIABLE_CHOICE_MISC
));
}
private
static
ContentValues
getContentValues
(
VariableChoice
variableChoice
)
{
ContentValues
cv
=
new
ContentValues
(
VARIABLE_CHOICE_COLUMN_COUNT
-
1
);
cv
.
put
(
VARIABLE_CHOICE_VARIABLE_ID
,
variableChoice
.
getVariableId
());
cv
.
put
(
VARIABLE_CHOICE_TEXT
,
variableChoice
.
getText
());
cv
.
put
(
VARIABLE_CHOICE_VALUE
,
variableChoice
.
getValue
());
cv
.
put
(
VARIABLE_CHOICE_ORDER
,
variableChoice
.
getOrder
());
cv
.
put
(
VARIABLE_CHOICE_MISC
,
variableChoice
.
getMisc
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/ui/CatalogueItemScreen.java
View file @
917dc985
...
...
@@ -2,22 +2,22 @@ package com.vsoft.uofl_catalogue.ui;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.support.v7.app.AlertDialog
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.widget.AdapterView
;
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.adapters.CatalogueCategoryItemAdapter
;
import
com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueItemApiListener
;
import
com.vsoft.uofl_catalogue.api.managers.CatalogueItemApiManager
;
import
com.vsoft.uofl_catalogue.db.managers.CatalogueItemManager
;
import
com.vsoft.uofl_catalogue.db.managers.CatalogueManager
;
import
com.vsoft.uofl_catalogue.db.models.Catalogue
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueItem
;
import
com.vsoft.uofl_catalogue.enums.SyncStatus
;
import
com.vsoft.uofl_catalogue.utils.CatalogueLog
;
...
...
@@ -30,32 +30,37 @@ import java.util.List;
*/
public
class
CatalogueItemScreen
extends
Activity
{
private
Catalogue
mCatalogue
;
private
String
mCatalogueSysId
;
private
List
<
CatalogueItem
>
mCatalogueItemList
;
private
CatalogueApplication
mApplication
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
// TODO Auto-generated method stub
super
.
onCreate
(
savedInstanceState
);
mApplication
=
(
CatalogueApplication
)
getApplication
();
Bundle
extras
=
getIntent
().
getExtras
();
String
catalogueSysId
=
null
;
if
(
extras
!=
null
)
{
c
atalogueSysId
=
extras
.
getString
(
Constants
.
DATA_KEY_SYS_ID
);
mC
atalogueSysId
=
extras
.
getString
(
Constants
.
DATA_KEY_SYS_ID
);
//The key argument here must match that used in the other activity
}
mCatalogue
=
CatalogueManager
.
getCatalogueFromSysId
(
catalogueSysId
);
if
(
mCatalogue
==
null
)
{
CatalogueLog
.
e
(
"CatalogueItemScreen: onCreate: mCatalogue is null"
);
return
;
}
List
<
CatalogueItem
>
catalogueItemList
=
CatalogueItemManager
.
getAllCatalogueItems
(
mCatalogue
.
getId
());
if
(
catalogueItemList
.
isEmpty
())
{
if
(
mApplication
.
isNetConnected
())
{
new
FetchCatalogueItem
().
execute
();
}
else
{
createView
(
catalogueItemList
);
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
();
}
}
class
FetchCatalogueItem
extends
AsyncTask
<
String
,
Void
,
SyncStatus
>
{
...
...
@@ -72,11 +77,11 @@ public class CatalogueItemScreen extends Activity {
@Override
protected
SyncStatus
doInBackground
(
String
...
params
)
{
SyncStatus
syncStatus
=
CatalogueItemApiManager
.
getCatalogueItems
(
mCatalogue
.
getSysId
()
,
new
GetCatalogueItemApiListener
()
{
SyncStatus
syncStatus
=
CatalogueItemApiManager
.
getCatalogueItems
(
mCatalogue
SysId
,
new
GetCatalogueItemApiListener
()
{
@Override
public
void
onDoneApiCall
(
List
<
CatalogueItem
>
catalogueItemList
)
{
CatalogueLog
.
e
(
"Data: catalogueItemList: "
+
catalogueItemList
);
CatalogueItemManager
.
handleGetCatalogueItem
(
mCatalogue
.
getId
(),
catalogueItemList
)
;
mCatalogueItemList
=
catalogueItemList
;
}
});
...
...
@@ -89,7 +94,9 @@ public class CatalogueItemScreen extends Activity {
if
(
progressDialog
!=
null
&&
progressDialog
.
isShowing
())
{
progressDialog
.
dismiss
();
}
createView
(
CatalogueItemManager
.
getAllCatalogueItems
(
mCatalogue
.
getId
()));
if
(
mCatalogueItemList
!=
null
)
{
createView
(
mCatalogueItemList
);
}
}
}
...
...
@@ -112,6 +119,7 @@ public class CatalogueItemScreen extends Activity {
CatalogueLog
.
e
(
"OnItemClickListener: position: "
+
position
+
", Catalogue: "
+
catalogueItemList
.
get
(
position
));
Intent
intent
=
new
Intent
(
CatalogueItemScreen
.
this
,
CatalogueVariableScreen
.
class
);
intent
.
putExtra
(
Constants
.
DATA_KEY_SYS_ID
,
catalogueItemList
.
get
(
position
).
getSysId
());
intent
.
putExtra
(
Constants
.
DATA_KEY_CATALOGUE_ITEM_DESCRIPTION
,
catalogueItemList
.
get
(
position
).
getDescription
());
startActivity
(
intent
);
}
});
...
...
app/src/main/java/com/vsoft/uofl_catalogue/ui/CatalogueScreen.java
View file @
917dc985
package
com
.
vsoft
.
uofl_catalogue
.
ui
;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.AlertDialog
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.widget.Toolbar
;
import
android.view.MenuItem
;
...
...
@@ -12,11 +14,11 @@ import android.view.View;
import
android.widget.AdapterView
;
import
android.widget.ListView
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.R
;
import
com.vsoft.uofl_catalogue.adapters.CatalogueCategoryAdapter
;
import
com.vsoft.uofl_catalogue.api.listeners.get.GetCatalogueApiListener
;
import
com.vsoft.uofl_catalogue.api.managers.CatalogueApiManager
;
import
com.vsoft.uofl_catalogue.db.managers.CatalogueManager
;
import
com.vsoft.uofl_catalogue.db.models.Catalogue
;
import
com.vsoft.uofl_catalogue.enums.SyncStatus
;
import
com.vsoft.uofl_catalogue.utils.CatalogueLog
;
...
...
@@ -35,6 +37,9 @@ public class CatalogueScreen extends AppCompatActivity {
@BindView
(
R
.
id
.
tool_bar_view
)
Toolbar
mToolbar
;
@BindView
(
R
.
id
.
catalogue_screen_list_view
)
ListView
mListView
;
private
List
<
Catalogue
>
mCatalogueList
;
private
CatalogueApplication
mApplication
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
// TODO Auto-generated method stub
...
...
@@ -43,6 +48,8 @@ public class CatalogueScreen extends AppCompatActivity {
setContentView
(
R
.
layout
.
catalogue_screen
);
ButterKnife
.
bind
(
this
);
mApplication
=
(
CatalogueApplication
)
getApplication
();
setSupportActionBar
(
mToolbar
);
ActionBar
actionBar
=
getSupportActionBar
();
if
(
actionBar
!=
null
)
{
...
...
@@ -53,11 +60,19 @@ public class CatalogueScreen extends AppCompatActivity {
actionBar
.
setDisplayShowTitleEnabled
(
true
);
}
List
<
Catalogue
>
catalogueList
=
CatalogueManager
.
getAllCatalogues
();
if
(
catalogueList
.
isEmpty
())
{
if
(
mApplication
.
isNetConnected
())
{
new
FetchCatalogue
().
execute
();
}
else
{
setData
(
catalogueList
);
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
();
}
}
...
...
@@ -79,7 +94,7 @@ public class CatalogueScreen extends AppCompatActivity {
@Override
public
void
onDoneApiCall
(
List
<
Catalogue
>
catalogueList
)
{
CatalogueLog
.
e
(
"Data: catalogueList: "
+
catalogueList
);
CatalogueManager
.
handleGetCatalogue
(
catalogueList
)
;
mCatalogueList
=
catalogueList
;
}
});
...
...
@@ -92,7 +107,8 @@ public class CatalogueScreen extends AppCompatActivity {
if
(
progressDialog
!=
null
&&
progressDialog
.
isShowing
())
{
progressDialog
.
dismiss
();
}
setData
(
CatalogueManager
.
getAllCatalogues
());
if
(
mCatalogueList
!=
null
)
setData
(
mCatalogueList
);
}
}
...
...
app/src/main/java/com/vsoft/uofl_catalogue/ui/CatalogueVariableScreen.java
View file @
917dc985
...
...
@@ -3,11 +3,13 @@ package com.vsoft.uofl_catalogue.ui;
import
android.app.DatePickerDialog
;
import
android.app.ProgressDialog
;
import
android.app.TimePickerDialog
;
import
android.content.DialogInterface
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v7.app.AlertDialog
;
import
android.text.Html
;
import
android.text.TextUtils
;
import
android.view.Gravity
;
...
...
@@ -28,11 +30,6 @@ import com.vsoft.uofl_catalogue.api.listeners.get.GetVariableChoiceApiListener;
import
com.vsoft.uofl_catalogue.api.managers.CatalogueItemApiManager
;
import
com.vsoft.uofl_catalogue.api.managers.CatalogueVariableApiManager
;
import
com.vsoft.uofl_catalogue.api.managers.VariableChoiceApiManager
;
import
com.vsoft.uofl_catalogue.db.managers.CatalogueItemManager
;
import
com.vsoft.uofl_catalogue.db.managers.CatalogueVariableManager
;
import
com.vsoft.uofl_catalogue.db.managers.CatalogueVariableValueManager
;
import
com.vsoft.uofl_catalogue.db.managers.VariableChoiceManager
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueItem
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueVariable
;
import
com.vsoft.uofl_catalogue.db.models.Reference
;
import
com.vsoft.uofl_catalogue.db.models.VariableChoice
;
...
...
@@ -43,7 +40,6 @@ import com.vsoft.uofl_catalogue.listeners.ReferenceListener;
import
com.vsoft.uofl_catalogue.ui.supportviews.DateAndTimePickerFragment
;
import
com.vsoft.uofl_catalogue.utils.CatalogueLog
;
import
com.vsoft.uofl_catalogue.utils.Constants
;
import
com.vsoft.uofl_catalogue.utils.DBConstants
;
import
com.vsoft.uofl_catalogue.utils.TagObject
;
import
com.vsoft.uofl_catalogue.utils.Util
;
...
...
@@ -59,11 +55,11 @@ import java.util.List;
*/
public
class
CatalogueVariableScreen
extends
FragmentActivity
{
private
CatalogueItem
mCatalogueItem
;
private
List
<
CatalogueVariable
>
mCatalogueVariableList
;
private
LinearLayout
mMainLayout
;
private
JSONArray
mJsonArray
;
private
CatalogueApplication
mApplication
;
private
String
mCatalogueItemSysId
,
mCatalogueItemDescription
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -72,28 +68,18 @@ public class CatalogueVariableScreen extends FragmentActivity {
mApplication
=
(
CatalogueApplication
)
getApplication
();
Bundle
extras
=
getIntent
().
getExtras
();
String
c
atalogueItemSysId
=
null
;
mC
atalogueItemSysId
=
null
;
if
(
extras
!=
null
)
{
catalogueItemSysId
=
extras
.
getString
(
Constants
.
DATA_KEY_SYS_ID
);
mCatalogueItemSysId
=
extras
.
getString
(
Constants
.
DATA_KEY_SYS_ID
);
mCatalogueItemDescription
=
extras
.
getString
(
Constants
.
DATA_KEY_CATALOGUE_ITEM_DESCRIPTION
);
//The key argument here must match that used in the other activity
}
mCatalogueItem
=
CatalogueItemManager
.
getCatalogueItemFromSysId
(
catalogueItemSysId
);
if
(
mCatalogueItem
==
null
)
{
CatalogueLog
.
e
(
"CatalogueVariableScreen: onCreate: mCatalogueItem is null"
);
return
;
}
mCatalogueVariableList
=
CatalogueVariableManager
.
getAllVariable
(
mCatalogueItem
.
getId
());
setVariableChoices
();
if
(
mCatalogueVariableList
.
isEmpty
())
{
if
(
mApplication
.
isNetConnected
())
{
new
FetchCatalogueVariable
().
execute
();
}
else
{
createView
();
showNoInternetDialog
();
}
}
class
FetchCatalogueVariable
extends
AsyncTask
<
String
,
Void
,
SyncStatus
>
{
...
...
@@ -110,12 +96,12 @@ public class CatalogueVariableScreen extends FragmentActivity {
@Override
protected
SyncStatus
doInBackground
(
String
...
params
)
{
SyncStatus
syncStatus
=
CatalogueVariableApiManager
.
getCatalogueVariable
(
mCatalogueItem
.
getSysId
()
,
new
GetCatalogueVariableApiListener
()
{
SyncStatus
syncStatus
=
CatalogueVariableApiManager
.
getCatalogueVariable
(
mCatalogueItem
SysId
,
new
GetCatalogueVariableApiListener
()
{
@Override
public
void
onDoneApiCall
(
List
<
CatalogueVariable
>
catalogueVariableList
)
{
CatalogueLog
.
e
(
"Data: catalogueVariableList: "
+
catalogueVariableList
);
mCatalogueVariableList
=
catalogueVariableList
;
CatalogueVariableManager
.
handleGetVariable
(
mCatalogueItem
.
getId
(),
catalogueVariableList
);
if
(!
catalogueVariableList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
catalogueVariableList
.
size
();
i
++)
{
final
CatalogueVariable
catalogueVariable
=
catalogueVariableList
.
get
(
i
);
...
...
@@ -127,13 +113,10 @@ public class CatalogueVariableScreen extends FragmentActivity {
public
void
onDoneApiCall
(
List
<
VariableChoice
>
variableChoiceList
)
{
CatalogueLog
.
e
(
"Data: variableChoiceList: "
+
variableChoiceList
);
catalogueVariable
.
setVariableChoiceList
(
variableChoiceList
);
VariableChoiceManager
.
handleGetVariableChoice
(
catalogueVariable
.
getId
(),
variableChoiceList
);
}
});
}
}
/*Create Dynamic table for CatalogueVariable*/
Util
.
createDynamicTable
(
mCatalogueItem
.
getSysId
(),
catalogueVariableList
);
}
}
});
...
...
@@ -147,23 +130,10 @@ public class CatalogueVariableScreen extends FragmentActivity {
if
(
progressDialog
!=
null
&&
progressDialog
.
isShowing
())
{
progressDialog
.
dismiss
();
}
mCatalogueVariableList
=
CatalogueVariableManager
.
getAllVariable
(
mCatalogueItem
.
getId
());
setVariableChoices
();
if
(
mCatalogueVariableList
!=
null
)
{
createView
();
}
}
private
void
setVariableChoices
()
{
if
(!
mCatalogueVariableList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
mCatalogueVariableList
.
size
();
i
++)
{
CatalogueVariable
catalogueVariable
=
mCatalogueVariableList
.
get
(
i
);
if
(
catalogueVariable
.
getType
()
==
ViewType
.
MULTIPLE_CHOICE
||
catalogueVariable
.
getType
()
==
ViewType
.
SELECT_BOX
)
{
List
<
VariableChoice
>
variableChoiceList
=
VariableChoiceManager
.
getAllVariableChoices
(
catalogueVariable
.
getId
());
catalogueVariable
.
setVariableChoiceList
(
variableChoiceList
);
}
}
}
}
private
void
createView
()
{
...
...
@@ -203,12 +173,12 @@ public class CatalogueVariableScreen extends FragmentActivity {
LinearLayout
.
LayoutParams
.
WRAP_CONTENT
);
/*Added item Description in form*/
if
(!
mCatalogueItem
.
getDescription
()
.
isEmpty
())
{
if
(!
mCatalogueItem
Description
.
isEmpty
())
{
TextView
descriptionView
=
new
TextView
(
CatalogueVariableScreen
.
this
);
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
N
)
{
descriptionView
.
setText
(
Html
.
fromHtml
(
mCatalogueItem
.
getDescription
()
,
Html
.
FROM_HTML_MODE_LEGACY
));
descriptionView
.
setText
(
Html
.
fromHtml
(
mCatalogueItem
Description
,
Html
.
FROM_HTML_MODE_LEGACY
));
}
else
{
descriptionView
.
setText
(
Html
.
fromHtml
(
mCatalogueItem
.
getDescription
()
));
descriptionView
.
setText
(
Html
.
fromHtml
(
mCatalogueItem
Description
));
}
linearLayout
.
addView
(
descriptionView
,
childControlViewLayoutParams
);
...
...
@@ -435,8 +405,7 @@ public class CatalogueVariableScreen extends FragmentActivity {
if
(
mApplication
.
isNetConnected
())
{
new
SubmitCatalogueItem
().
execute
();
}
else
{
CatalogueVariableValueManager
.
save
(
"t_"
+
mCatalogueItem
.
getSysId
(),
columnList
,
valueList
,
DBConstants
.
SYNC_FLAG_CREATE
);
finish
();
showNoInternetDialog
();
}
}
...
...
@@ -528,7 +497,7 @@ public class CatalogueVariableScreen extends FragmentActivity {
@Override
protected
SyncStatus
doInBackground
(
String
...
params
)
{
SyncStatus
syncStatus
=
CatalogueItemApiManager
.
submitCatalogueItem
(
mCatalogueItem
.
getSysId
()
,
mJsonArray
);
SyncStatus
syncStatus
=
CatalogueItemApiManager
.
submitCatalogueItem
(
mCatalogueItem
SysId
,
mJsonArray
);
return
syncStatus
;
}
...
...
@@ -542,6 +511,19 @@ public class CatalogueVariableScreen extends FragmentActivity {
}
}
private
void
showNoInternetDialog
()
{
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
();
}
public
String
getMonth
(
int
month
)
{
return
Constants
.
month
[
month
];
}
...
...
app/src/main/java/com/vsoft/uofl_catalogue/utils/Constants.java
View file @
917dc985
...
...
@@ -12,16 +12,11 @@ public class Constants {
public
static
final
String
[]
month
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
/**
* Preference
*/
public
static
final
String
PREFS_OLD_VERSION_NUMBER
=
"oldVersionNumber"
;
public
static
final
String
PREFS_NEW_VERSION_NUMBER
=
"newVersionNumber"
;
/**
* Intent String
*/
public
static
final
String
DATA_DATE_AND_TIME_PICKER_TITLE
=
"title"
;
public
static
final
String
DATA_KEY_SYS_ID
=
"sys_id"
;
public
static
final
String
DATA_KEY_CATALOGUE_ITEM_DESCRIPTION
=
"catalogue_item_des"
;
public
static
final
String
DATA_KEY_REFERENCE_TABLE_NAME
=
"table_name"
;
/**
...
...
app/src/main/java/com/vsoft/uofl_catalogue/utils/DBConstants.java
deleted
100644 → 0
View file @
98c7671a
package
com
.
vsoft
.
uofl_catalogue
.
utils
;
public
interface
DBConstants
{
//Tables
String
TABLE_CATALOGUE
=
"catalogue_category"
;
String
TABLE_CATALOGUE_ITEM
=
"catalogue_category_item"
;
String
TABLE_CATALOGUE_VARIABLES
=
"catalogue_variable"
;
String
TABLE_VARIABLE_CHOICES
=
"variable_choices"
;
String
ID
=
"_id"
;
String
SYS_ID
=
"sys_id"
;
String
SYNC_DIRTY
=
"sync_dirty"
;
int
SYNC_FLAG_NONE
=
0
;
int
SYNC_FLAG_CREATE
=
1
;
int
SYNC_FLAG_UPDATE
=
2
;
int
SYNC_FLAG_DELETE
=
3
;
/**
* Catalogue table
*/
String
CATALOGUE_ID
=
ID
;
String
CATALOGUE_TITLE
=
"title"
;
String
CATALOGUE_DESCRIPTION
=
"description"
;
String
CATALOGUE_SYS_ID
=
SYS_ID
;
String
CATALOGUE_SYNC_DIRTY
=
SYNC_DIRTY
;
/*
* Indices for Catalogue table. *Use these only if you fetch all columns*
*/
int
INDEX_CATALOGUE_ID
=
0
;
int
INDEX_CATALOGUE_TITLE
=
1
;
int
INDEX_CATALOGUE_DESCRIPTION
=
2
;
int
INDEX_CATALOGUE_SYS_ID
=
3
;
int
INDEX_CATALOGUE_SYNC_DIRTY
=
4
;
int
CATALOGUE_COLUMN_COUNT
=
5
;
/**
* Catalogue_item table
*/
String
CATALOGUE_ITEM_ID
=
ID
;
String
CATALOGUE_ITEM_CATALOGUE_ID
=
"catalogue_id"
;
String
CATALOGUE_ITEM_NAME
=
"name"
;
String
CATALOGUE_ITEM_SHORT_DESCRIPTION
=
"short_description"
;
String
CATALOGUE_ITEM_DESCRIPTION
=
"item_description"
;
String
CATALOGUE_ITEM_SYS_ID
=
SYS_ID
;
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_NAME
=
2
;
int
INDEX_CATALOGUE_ITEM_SHORT_DESCRIPTION
=
3
;
int
INDEX_CATALOGUE_ITEM_DESCRIPTION
=
4
;
int
INDEX_CATALOGUE_ITEM_SYS_ID
=
5
;
int
INDEX_CATALOGUE_ITEM_SYNC_DIRTY
=
6
;
int
CATALOGUE_ITEM_COLUMN_COUNT
=
7
;
/**
* Catalogue variables table
*/
String
CATALOGUE_VARIABLE_ID
=
ID
;
String
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
=
"catalogue_item_id"
;
String
CATALOGUE_VARIABLE_NAME
=
"name"
;
String
CATALOGUE_VARIABLE_QUESTION_TEXT
=
"question_text"
;
String
CATALOGUE_VARIABLE_TYPE
=
"type"
;
String
CATALOGUE_VARIABLE_MANDATORY
=
"mandatory"
;
String
CATALOGUE_VARIABLE_NONE_REQUIRED
=
"isNoneRequired"
;
String
CATALOGUE_VARIABLE_REFERENCE_TABLE
=
"reference_table"
;
String
CATALOGUE_VARIABLE_SYS_ID
=
SYS_ID
;
String
CATALOGUE_VARIABLE_SYNC_DIRTY
=
SYNC_DIRTY
;
/**
* Indices for Catalogue variables table. *Use these only if you fetch all columns*
*/
int
INDEX_CATALOGUE_VARIABLE_ID
=
0
;
int
INDEX_CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
=
1
;
int
INDEX_CATALOGUE_VARIABLE_NAME
=
2
;
int
INDEX_CATALOGUE_VARIABLE_QUESTION_TEXT
=
3
;
int
INDEX_CATALOGUE_VARIABLE_TYPE
=
4
;
int
INDEX_CATALOGUE_VARIABLE_MANDATORY
=
5
;
int
INDEX_CATALOGUE_VARIABLE_NONE_REQUIRED
=
6
;
int
INDEX_CATALOGUE_VARIABLE_REFERENCE
=
7
;
int
INDEX_CATALOGUE_VARIABLE_SYS_ID
=
8
;
int
INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY
=
9
;
int
CATALOGUE_VARIABLE_COLUMN_COUNT
=
10
;
/**
* Variables Choice table
*/
String
VARIABLE_CHOICE_ID
=
ID
;
String
VARIABLE_CHOICE_VARIABLE_ID
=
"variable_id"
;
String
VARIABLE_CHOICE_TEXT
=
"text"
;
String
VARIABLE_CHOICE_VALUE
=
"value"
;
String
VARIABLE_CHOICE_ORDER
=
"choice_order"
;
String
VARIABLE_CHOICE_MISC
=
"misc"
;
/**
* Indices for Variables Choice table. *Use these only if you fetch all columns*
*/
int
INDEX_VARIABLE_CHOICE_ID
=
0
;
int
INDEX_VARIABLE_CHOICE_VARIABLE_ID
=
1
;
int
INDEX_VARIABLE_CHOICE_TEXT
=
2
;
int
INDEX_VARIABLE_CHOICE_VALUE
=
3
;
int
INDEX_VARIABLE_CHOICE_ORDER
=
4
;
int
INDEX_VARIABLE_CHOICE_MISC
=
5
;
int
VARIABLE_CHOICE_COLUMN_COUNT
=
6
;
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/utils/Util.java
View file @
917dc985
package
com
.
vsoft
.
uofl_catalogue
.
utils
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.support.v4.content.ContextCompat
;
import
android.text.InputType
;
import
android.text.method.PasswordTransformationMethod
;
...
...
@@ -19,7 +18,6 @@ import android.widget.RadioGroup;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.R
;
import
com.vsoft.uofl_catalogue.db.models.CatalogueVariable
;
import
com.vsoft.uofl_catalogue.db.models.Reference
;
...
...
@@ -30,7 +28,6 @@ import java.text.ParseException;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Locale
;
/**
...
...
@@ -161,41 +158,6 @@ public class Util {
return
null
;
}
public
static
void
createDynamicTable
(
String
catalogueItemSysId
,
List
<
CatalogueVariable
>
catalogueVariableList
)
{
StringBuilder
queryString
=
new
StringBuilder
();
//Opens database in writable mode.
SQLiteDatabase
database
=
CatalogueApplication
.
getDatabase
();
queryString
.
append
(
"CREATE TABLE IF NOT EXISTS t_"
);
queryString
.
append
(
catalogueItemSysId
);
queryString
.
append
(
" ("
);
queryString
.
append
(
DBConstants
.
ID
);
queryString
.
append
(
" integer primary key autoincrement, "
);
CatalogueVariable
catalogueVariable
=
catalogueVariableList
.
get
(
0
);
if
(
catalogueVariable
.
getName
()
!=
null
)
{
queryString
.
append
(
catalogueVariable
.
getName
());
queryString
.
append
(
" text, "
);
}
for
(
int
i
=
1
;
i
<
catalogueVariableList
.
size
();
i
++)
{
catalogueVariable
=
catalogueVariableList
.
get
(
i
);
if
(
catalogueVariable
.
getName
()!=
null
)
{
queryString
.
append
(
catalogueVariable
.
getName
());
queryString
.
append
(
" text, "
);
}
}
queryString
.
append
(
DBConstants
.
CATALOGUE_VARIABLE_SYNC_DIRTY
);
queryString
.
append
(
" integer default "
);
queryString
.
append
(
DBConstants
.
SYNC_FLAG_NONE
);
queryString
.
append
(
");"
);
System
.
out
.
println
(
"Create Table Stmt : "
+
queryString
);
database
.
execSQL
(
queryString
.
toString
());
}
public
static
String
getVariableViewValue
(
View
view
,
ViewType
viewType
)
{
switch
(
viewType
)
{
case
YES_NO:
...
...
app/src/main/res/values/colors.xml
View file @
917dc985
...
...
@@ -5,7 +5,6 @@
<color
name=
"colorAccent"
>
#FF5252
</color>
<color
name=
"error_color"
>
#FF0000
</color>
<color
name=
"dark_gray_color"
>
#A9A9A9
</color>
<color
name=
"name_null_view_color"
>
#88FFA500
</color>
<color
name=
"view_not_implemented_color"
>
#88ff0000
</color>
...
...
app/src/main/res/values/dimen.xml
View file @
917dc985
...
...
@@ -19,8 +19,5 @@
<!--Home Screen-->
<dimen
name=
"home_screen_item_height"
>
120dp
</dimen>
<!--Spinner Item height-->
<dimen
name=
"spinner_item_height"
>
40dp
</dimen>
<dimen
name=
"list_item_height"
>
100dp
</dimen>
</resources>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
917dc985
...
...
@@ -6,6 +6,7 @@
<string
name=
"error_string"
>
* Required
</string>
<string
name=
"none_string"
>
-None-
</string>
<string
name=
"search_for_reference_string"
>
Reference
</string>
<string
name=
"internet_validation_string"
>
Please connect to internet and try again.
</string>
<string
name=
"loading_string"
>
Loading
…
</string>
<string
name=
"select_date_string"
>
Select Date
</string>
...
...
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