Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
379b1157
Commit
379b1157
authored
Jul 04, 2017
by
Sajal Narang
Committed by
GitHub
Jul 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24 from yvsriram/master
Created tables: userprofile, followers, follows
parents
8da030db
9f2ed8f5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
365 additions
and
56 deletions
+365
-56
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DatabaseContract.java
...va/in/ac/iitb/gymkhana/iitbapp/data/DatabaseContract.java
+49
-0
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DatabaseHelper.java
...java/in/ac/iitb/gymkhana/iitbapp/data/DatabaseHelper.java
+67
-0
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/IITBAppContentProvider.java
...ac/iitb/gymkhana/iitbapp/data/IITBAppContentProvider.java
+249
-23
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/MapDbHelper.java
...in/java/in/ac/iitb/gymkhana/iitbapp/data/MapDbHelper.java
+0
-33
No files found.
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DatabaseContract.java
View file @
379b1157
...
@@ -7,6 +7,9 @@ public class DatabaseContract {
...
@@ -7,6 +7,9 @@ public class DatabaseContract {
public
static
final
String
CONTENT_AUTHORITY
=
"in.ac.iitb.gymkhana.iitbapp"
;
public
static
final
String
CONTENT_AUTHORITY
=
"in.ac.iitb.gymkhana.iitbapp"
;
public
static
final
Uri
BASE_CONTENT_URI
=
Uri
.
parse
(
"content://"
+
CONTENT_AUTHORITY
);
public
static
final
Uri
BASE_CONTENT_URI
=
Uri
.
parse
(
"content://"
+
CONTENT_AUTHORITY
);
public
static
final
String
PATH_MAP
=
"map"
;
public
static
final
String
PATH_MAP
=
"map"
;
public
static
final
String
PATH_USER_PROFILE
=
"userProfile"
;
public
static
final
String
PATH_USER_FOLLOWERS
=
"userFollowers"
;
public
static
final
String
PATH_USER_FOLLOWS
=
"userFollows"
;
public
static
final
class
MapEntry
implements
BaseColumns
{
public
static
final
class
MapEntry
implements
BaseColumns
{
public
static
final
Uri
CONTENT_URI
=
BASE_CONTENT_URI
.
buildUpon
()
public
static
final
Uri
CONTENT_URI
=
BASE_CONTENT_URI
.
buildUpon
()
...
@@ -20,4 +23,50 @@ public class DatabaseContract {
...
@@ -20,4 +23,50 @@ public class DatabaseContract {
}
}
public
static
final
class
UserProfileEntry
implements
BaseColumns
{
public
static
final
Uri
CONTENT_URI
=
BASE_CONTENT_URI
.
buildUpon
()
.
appendPath
(
PATH_USER_PROFILE
)
.
build
();
public
static
final
String
TABLE_NAME
=
"userProfile"
;
public
static
final
String
COLUMN_USER_NAME
=
"user_name"
;
public
static
final
String
COLUMN_USER_ROLLNO
=
"user_rollno"
;
public
static
final
String
COLUMN_USER_POR
=
"user_por"
;
public
static
final
String
COLUMN_USER_PROFILE_PICTURE
=
"user_profile_picture"
;
public
static
final
String
COLUMN_USER_HOSTELNO
=
"user_hostelno"
;
public
static
final
String
COLUMN_USER_ABOUTME
=
"user_aboutme"
;
public
static
final
String
COLUMN_USER_FOLLOWING_COUNT
=
"user_following_count"
;
public
static
final
String
COLUMN_USER_FOLLOWERS_COUNT
=
"user_follwers_count"
;
public
static
final
String
COLUMN_USER_EVENTS_COUNT
=
"user_events_count"
;
public
static
final
String
COLUMN_IS_FOLLOWED
=
"isFollowed"
;
public
static
final
String
COLUMN_FOLLOWS_YOU
=
"followsYou"
;
public
static
final
String
COLUMN_USER_ROOM_NO
=
"user_roomno"
;
public
static
final
String
COLUMN_USER_PHONE_NO
=
"user_phoneno"
;
}
public
static
final
class
UserFollowersEntry
implements
BaseColumns
{
public
static
final
Uri
CONTENT_URI
=
BASE_CONTENT_URI
.
buildUpon
()
.
appendPath
(
PATH_USER_FOLLOWERS
)
.
build
();
public
static
final
String
TABLE_NAME
=
"userFollowers"
;
public
static
final
String
COLUMN_USER_PROFILE_PICTURE
=
"user_profile_picture"
;
public
static
final
String
COLUMN_USER_NAME
=
"user_name"
;
public
static
final
String
COLUMN_USER_PROFILE
=
"userProfile"
;
}
public
static
final
class
UserFollowsEntry
implements
BaseColumns
{
public
static
final
Uri
CONTENT_URI
=
BASE_CONTENT_URI
.
buildUpon
()
.
appendPath
(
PATH_USER_FOLLOWS
)
.
build
();
public
static
final
String
TABLE_NAME
=
"userFollows"
;
public
static
final
String
COLUMN_USER_PROFILE_PICTURE
=
"user_profile_picture"
;
public
static
final
String
COLUMN_USER_NAME
=
"user_name"
;
public
static
final
String
COLUMN_USER_PROFILE
=
"userProfile"
;
}
}
}
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/DatabaseHelper.java
0 → 100644
View file @
379b1157
package
in.ac.iitb.gymkhana.iitbapp.data
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
public
class
DatabaseHelper
extends
SQLiteOpenHelper
{
private
static
final
String
DATABASE_NAME
=
"IITBAppDb.db"
;
private
static
final
int
VERSION
=
1
;
DatabaseHelper
(
Context
context
)
{
super
(
context
,
DATABASE_NAME
,
null
,
VERSION
);
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
final
String
CREATE_TABLE_MAP
=
"CREATE TABLE "
+
DatabaseContract
.
MapEntry
.
TABLE_NAME
+
" ("
+
DatabaseContract
.
MapEntry
.
_ID
+
" INTEGER PRIMARY KEY, "
+
DatabaseContract
.
MapEntry
.
COLUMN_LATITUDE
+
" DOUBLE NOT NULL, "
+
DatabaseContract
.
MapEntry
.
COLUMN_LONGITUDE
+
" DOUBLE NOT NULL, "
+
DatabaseContract
.
MapEntry
.
COLUMN_NAME
+
" TEXT NOT NULL, "
+
DatabaseContract
.
MapEntry
.
COLUMN_TYPE
+
" TEXT NOT NULL);"
;
final
String
CREATE_TABLE_USER_PROFILE
=
"CREATE TABLE "
+
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
+
" ("
+
DatabaseContract
.
UserProfileEntry
.
_ID
+
" INTEGER PRIMARY KEY, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_NAME
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_ROLLNO
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_POR
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_PROFILE_PICTURE
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_HOSTELNO
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_ABOUTME
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_FOLLOWING_COUNT
+
" INTEGER NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_FOLLOWERS_COUNT
+
" INTEGER NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_EVENTS_COUNT
+
" INTEGER NOT NULL, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_IS_FOLLOWED
+
" BOOLEAN, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_FOLLOWS_YOU
+
" BOOLEAN, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_ROOM_NO
+
" TEXT, "
+
DatabaseContract
.
UserProfileEntry
.
COLUMN_USER_PHONE_NO
+
" TEXT);"
;
final
String
CREATE_TABLE_USER_FOLLOWERS
=
"CREATE TABLE "
+
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
+
" ("
+
DatabaseContract
.
UserFollowersEntry
.
_ID
+
" INTEGER PRIMARY KEY, "
+
DatabaseContract
.
UserFollowersEntry
.
COLUMN_USER_PROFILE_PICTURE
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserFollowersEntry
.
COLUMN_USER_NAME
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserFollowersEntry
.
COLUMN_USER_PROFILE
+
" TEXT NOT NULL);"
;
final
String
CREATE_TABLE_USER_FOLLOWS
=
"CREATE TABLE "
+
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
+
" ("
+
DatabaseContract
.
UserFollowsEntry
.
_ID
+
" INTEGER PRIMARY KEY, "
+
DatabaseContract
.
UserFollowsEntry
.
COLUMN_USER_PROFILE_PICTURE
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserFollowsEntry
.
COLUMN_USER_NAME
+
" TEXT NOT NULL, "
+
DatabaseContract
.
UserFollowsEntry
.
COLUMN_USER_PROFILE
+
" TEXT NOT NULL);"
;
db
.
execSQL
(
CREATE_TABLE_MAP
);
db
.
execSQL
(
CREATE_TABLE_USER_PROFILE
);
db
.
execSQL
(
CREATE_TABLE_USER_FOLLOWERS
);
db
.
execSQL
(
CREATE_TABLE_USER_FOLLOWS
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
DatabaseContract
.
MapEntry
.
TABLE_NAME
);
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
);
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
);
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
);
onCreate
(
db
);
}
}
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/IITBAppContentProvider.java
View file @
379b1157
...
@@ -12,19 +12,29 @@ import android.net.Uri;
...
@@ -12,19 +12,29 @@ import android.net.Uri;
import
android.support.annotation.NonNull
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
static
in
.
ac
.
iitb
.
gymkhana
.
iitbapp
.
data
.
DatabaseContract
.
MapEntry
.
TABLE_NAME
;
public
class
IITBAppContentProvider
extends
ContentProvider
{
public
class
IITBAppContentProvider
extends
ContentProvider
{
public
static
final
int
LOCS
=
100
;
public
static
final
int
LOCS
=
100
;
public
static
final
int
LOC_WITH_ID
=
101
;
public
static
final
int
LOC_WITH_ID
=
101
;
public
static
final
int
USER_PROFILES
=
200
;
public
static
final
int
USER_PROFILE_WITH_ID
=
201
;
public
static
final
int
USER_FOLLOWERS
=
300
;
public
static
final
int
USER_FOLLOWER_WITH_ID
=
301
;
public
static
final
int
USER_FOLLOWS
=
400
;
public
static
final
int
USER_FOLLOWS_WITH_ID
=
401
;
private
static
final
UriMatcher
sUriMatcher
=
buildUriMatcher
();
private
static
final
UriMatcher
sUriMatcher
=
buildUriMatcher
();
private
MapDbHelper
mapDb
Helper
;
private
DatabaseHelper
database
Helper
;
public
static
UriMatcher
buildUriMatcher
()
{
public
static
UriMatcher
buildUriMatcher
()
{
final
UriMatcher
matcher
=
new
UriMatcher
(
UriMatcher
.
NO_MATCH
);
final
UriMatcher
matcher
=
new
UriMatcher
(
UriMatcher
.
NO_MATCH
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_MAP
,
LOCS
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_MAP
,
LOCS
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_MAP
+
"/#"
,
LOC_WITH_ID
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_MAP
+
"/#"
,
LOC_WITH_ID
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_USER_PROFILE
,
USER_PROFILES
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_USER_PROFILE
+
"/#"
,
USER_PROFILE_WITH_ID
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_USER_FOLLOWERS
,
USER_FOLLOWERS
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_USER_FOLLOWERS
+
"/#"
,
USER_FOLLOWER_WITH_ID
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_USER_FOLLOWS
,
USER_FOLLOWS
);
matcher
.
addURI
(
DatabaseContract
.
CONTENT_AUTHORITY
,
DatabaseContract
.
PATH_USER_FOLLOWS
+
"/#"
,
USER_FOLLOWS_WITH_ID
);
return
matcher
;
return
matcher
;
}
}
...
@@ -32,19 +42,21 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -32,19 +42,21 @@ public class IITBAppContentProvider extends ContentProvider {
@Override
@Override
public
boolean
onCreate
()
{
public
boolean
onCreate
()
{
Context
context
=
getContext
();
Context
context
=
getContext
();
mapDbHelper
=
new
MapDb
Helper
(
context
);
databaseHelper
=
new
Database
Helper
(
context
);
return
true
;
return
true
;
}
}
@Nullable
@Nullable
@Override
@Override
public
Cursor
query
(
@NonNull
Uri
uri
,
@Nullable
String
[]
projection
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
,
@Nullable
String
sortOrder
)
{
public
Cursor
query
(
@NonNull
Uri
uri
,
@Nullable
String
[]
projection
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
,
@Nullable
String
sortOrder
)
{
final
SQLiteDatabase
db
=
mapDb
Helper
.
getReadableDatabase
();
final
SQLiteDatabase
db
=
database
Helper
.
getReadableDatabase
();
int
match
=
sUriMatcher
.
match
(
uri
);
int
match
=
sUriMatcher
.
match
(
uri
);
Cursor
cursor
;
Cursor
cursor
;
String
id
;
String
selectionArguments
[];
switch
(
match
)
{
switch
(
match
)
{
case
LOCS:
case
LOCS:
cursor
=
db
.
query
(
TABLE_NAME
,
cursor
=
db
.
query
(
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
projection
,
projection
,
selection
,
selection
,
selectionArgs
,
selectionArgs
,
...
@@ -53,9 +65,69 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -53,9 +65,69 @@ public class IITBAppContentProvider extends ContentProvider {
sortOrder
);
sortOrder
);
break
;
break
;
case
LOC_WITH_ID:
case
LOC_WITH_ID:
String
id
=
uri
.
getPathSegments
().
get
(
1
);
id
=
uri
.
getPathSegments
().
get
(
1
);
String
[]
selectionArguments
=
new
String
[]{
id
};
selectionArguments
=
new
String
[]{
id
};
cursor
=
db
.
query
(
TABLE_NAME
,
cursor
=
db
.
query
(
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
projection
,
"_id=?"
,
selectionArguments
,
null
,
null
,
sortOrder
);
break
;
case
USER_PROFILES:
cursor
=
db
.
query
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
projection
,
selection
,
selectionArgs
,
null
,
null
,
sortOrder
);
break
;
case
USER_PROFILE_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
selectionArguments
=
new
String
[]{
id
};
cursor
=
db
.
query
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
projection
,
"_id=?"
,
selectionArguments
,
null
,
null
,
sortOrder
);
break
;
case
USER_FOLLOWERS:
cursor
=
db
.
query
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
projection
,
selection
,
selectionArgs
,
null
,
null
,
sortOrder
);
break
;
case
USER_FOLLOWER_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
selectionArguments
=
new
String
[]{
id
};
cursor
=
db
.
query
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
projection
,
"_id=?"
,
selectionArguments
,
null
,
null
,
sortOrder
);
break
;
case
USER_FOLLOWS:
cursor
=
db
.
query
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
projection
,
selection
,
selectionArgs
,
null
,
null
,
sortOrder
);
break
;
case
USER_FOLLOWS_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
selectionArguments
=
new
String
[]{
id
};
cursor
=
db
.
query
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
projection
,
projection
,
"_id=?"
,
"_id=?"
,
selectionArguments
,
selectionArguments
,
...
@@ -81,6 +153,18 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -81,6 +153,18 @@ public class IITBAppContentProvider extends ContentProvider {
return
"vnd.android.cursor.dir"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_MAP
;
return
"vnd.android.cursor.dir"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_MAP
;
case
LOC_WITH_ID:
case
LOC_WITH_ID:
return
"vnd.android.cursor.item"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_MAP
;
return
"vnd.android.cursor.item"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_MAP
;
case
USER_PROFILES:
return
"vnd.android.cursor.dir"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_USER_PROFILE
;
case
USER_PROFILE_WITH_ID:
return
"vnd.android.cursor.item"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_USER_PROFILE
;
case
USER_FOLLOWERS:
return
"vnd.android.cursor.dir"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_USER_FOLLOWERS
;
case
USER_FOLLOWER_WITH_ID:
return
"vnd.android.cursor.item"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_USER_FOLLOWERS
;
case
USER_FOLLOWS:
return
"vnd.android.cursor.dir"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_USER_FOLLOWS
;
case
USER_FOLLOWS_WITH_ID:
return
"vnd.android.cursor.item"
+
"/"
+
DatabaseContract
.
CONTENT_AUTHORITY
+
"/"
+
DatabaseContract
.
PATH_USER_FOLLOWS
;
default
:
default
:
throw
new
UnsupportedOperationException
(
"Unknown uri: "
+
uri
);
throw
new
UnsupportedOperationException
(
"Unknown uri: "
+
uri
);
}
}
...
@@ -89,17 +173,40 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -89,17 +173,40 @@ public class IITBAppContentProvider extends ContentProvider {
@Nullable
@Nullable
@Override
@Override
public
Uri
insert
(
@NonNull
Uri
uri
,
@Nullable
ContentValues
values
)
{
public
Uri
insert
(
@NonNull
Uri
uri
,
@Nullable
ContentValues
values
)
{
final
SQLiteDatabase
db
=
mapDb
Helper
.
getWritableDatabase
();
final
SQLiteDatabase
db
=
database
Helper
.
getWritableDatabase
();
int
match
=
sUriMatcher
.
match
(
uri
);
int
match
=
sUriMatcher
.
match
(
uri
);
Uri
returnUri
;
Uri
returnUri
;
long
id
;
switch
(
match
)
{
switch
(
match
)
{
case
LOCS:
case
LOCS:
long
id
=
db
.
insert
(
TABLE_NAME
,
null
,
values
);
id
=
db
.
insert
(
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
null
,
values
);
if
(
id
>
0
)
{
if
(
id
>
0
)
{
returnUri
=
ContentUris
.
withAppendedId
(
DatabaseContract
.
MapEntry
.
CONTENT_URI
,
id
);
returnUri
=
ContentUris
.
withAppendedId
(
DatabaseContract
.
MapEntry
.
CONTENT_URI
,
id
);
}
else
}
else
throw
new
SQLException
(
"Failed to insert row into "
+
uri
);
throw
new
SQLException
(
"Failed to insert row into "
+
uri
);
break
;
break
;
case
USER_PROFILES:
id
=
db
.
insert
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
null
,
values
);
if
(
id
>
0
)
{
returnUri
=
ContentUris
.
withAppendedId
(
DatabaseContract
.
UserProfileEntry
.
CONTENT_URI
,
id
);
}
else
throw
new
SQLException
(
"Failed to insert row into "
+
uri
);
break
;
case
USER_FOLLOWERS:
id
=
db
.
insert
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
null
,
values
);
if
(
id
>
0
)
{
returnUri
=
ContentUris
.
withAppendedId
(
DatabaseContract
.
UserFollowersEntry
.
CONTENT_URI
,
id
);
}
else
throw
new
SQLException
(
"Failed to insert row into "
+
uri
);
break
;
case
USER_FOLLOWS:
id
=
db
.
insert
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
null
,
values
);
if
(
id
>
0
)
{
returnUri
=
ContentUris
.
withAppendedId
(
DatabaseContract
.
UserFollowsEntry
.
CONTENT_URI
,
id
);
}
else
throw
new
SQLException
(
"Failed to insert row into "
+
uri
);
break
;
default
:
default
:
throw
new
SQLException
(
"Wrong uri: "
+
uri
);
throw
new
SQLException
(
"Wrong uri: "
+
uri
);
...
@@ -110,18 +217,39 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -110,18 +217,39 @@ public class IITBAppContentProvider extends ContentProvider {
@Override
@Override
public
int
bulkInsert
(
@NonNull
Uri
uri
,
@NonNull
ContentValues
[]
values
)
{
public
int
bulkInsert
(
@NonNull
Uri
uri
,
@NonNull
ContentValues
[]
values
)
{
final
SQLiteDatabase
db
=
mapDb
Helper
.
getWritableDatabase
();
final
SQLiteDatabase
db
=
database
Helper
.
getWritableDatabase
();
int
rowsInserted
;
switch
(
sUriMatcher
.
match
(
uri
))
{
switch
(
sUriMatcher
.
match
(
uri
))
{
case
LOCS:
case
LOCS:
db
.
beginTransaction
();
db
.
beginTransaction
();
int
rowsInserted
=
0
;
rowsInserted
=
0
;
try
{
for
(
ContentValues
value
:
values
)
{
long
_id
=
db
.
insert
(
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
null
,
value
);
if
(
_id
!=
-
1
)
{
rowsInserted
++;
}
}
db
.
setTransactionSuccessful
();
}
finally
{
db
.
endTransaction
();
}
if
(
rowsInserted
>
0
)
{
getContext
().
getContentResolver
().
notifyChange
(
uri
,
null
);
}
return
rowsInserted
;
case
USER_PROFILES:
db
.
beginTransaction
();
rowsInserted
=
0
;
try
{
try
{
for
(
ContentValues
value
:
values
)
{
for
(
ContentValues
value
:
values
)
{
long
_id
=
db
.
insert
(
TABLE_NAME
,
null
,
value
);
long
_id
=
db
.
insert
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
null
,
value
);
if
(
_id
!=
-
1
)
{
if
(
_id
!=
-
1
)
{
rowsInserted
++;
rowsInserted
++;
}
}
...
@@ -134,7 +262,48 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -134,7 +262,48 @@ public class IITBAppContentProvider extends ContentProvider {
if
(
rowsInserted
>
0
)
{
if
(
rowsInserted
>
0
)
{
getContext
().
getContentResolver
().
notifyChange
(
uri
,
null
);
getContext
().
getContentResolver
().
notifyChange
(
uri
,
null
);
}
}
return
rowsInserted
;
case
USER_FOLLOWERS:
db
.
beginTransaction
();
rowsInserted
=
0
;
try
{
for
(
ContentValues
value
:
values
)
{
long
_id
=
db
.
insert
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
null
,
value
);
if
(
_id
!=
-
1
)
{
rowsInserted
++;
}
}
db
.
setTransactionSuccessful
();
}
finally
{
db
.
endTransaction
();
}
if
(
rowsInserted
>
0
)
{
getContext
().
getContentResolver
().
notifyChange
(
uri
,
null
);
}
return
rowsInserted
;
case
USER_FOLLOWS:
db
.
beginTransaction
();
rowsInserted
=
0
;
try
{
for
(
ContentValues
value
:
values
)
{
long
_id
=
db
.
insert
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
null
,
value
);
if
(
_id
!=
-
1
)
{
rowsInserted
++;
}
}
db
.
setTransactionSuccessful
();
}
finally
{
db
.
endTransaction
();
}
if
(
rowsInserted
>
0
)
{
getContext
().
getContentResolver
().
notifyChange
(
uri
,
null
);
}
return
rowsInserted
;
return
rowsInserted
;
default
:
default
:
...
@@ -145,25 +314,64 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -145,25 +314,64 @@ public class IITBAppContentProvider extends ContentProvider {
@Override
@Override
public
int
delete
(
@NonNull
Uri
uri
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
)
{
public
int
delete
(
@NonNull
Uri
uri
,
@Nullable
String
selection
,
@Nullable
String
[]
selectionArgs
)
{
int
numRowsDeleted
;
int
numRowsDeleted
;
String
id
;
if
(
null
==
selection
)
selection
=
"1"
;
if
(
null
==
selection
)
selection
=
"1"
;
switch
(
sUriMatcher
.
match
(
uri
))
{
switch
(
sUriMatcher
.
match
(
uri
))
{
case
LOCS:
case
LOCS:
numRowsDeleted
=
mapDbHelper
.
getWritableDatabase
().
delete
(
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
TABLE_NAME
,
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
selection
,
selectionArgs
);
break
;
case
USER_PROFILES:
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
selection
,
selectionArgs
);
break
;
case
USER_FOLLOWERS:
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
selection
,
selection
,
selectionArgs
);
selectionArgs
);
break
;
break
;
case
USER_FOLLOWS:
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
selection
,
selectionArgs
);
break
;
case
LOC_WITH_ID:
case
LOC_WITH_ID:
String
id
=
uri
.
getPathSegments
().
get
(
1
);
id
=
uri
.
getPathSegments
().
get
(
1
);
numRowsDeleted
=
mapDbHelper
.
getWritableDatabase
().
delete
(
TABLE_NAME
,
"_id=?"
,
new
String
[]{
id
});
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
"_id=?"
,
new
String
[]{
id
});
break
;
break
;
case
USER_PROFILE_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
"_id=?"
,
new
String
[]{
id
});
break
;
case
USER_FOLLOWER_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
"_id=?"
,
new
String
[]{
id
});
break
;
case
USER_FOLLOWS_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
numRowsDeleted
=
databaseHelper
.
getWritableDatabase
().
delete
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
"_id=?"
,
new
String
[]{
id
});
break
;
default
:
default
:
throw
new
UnsupportedOperationException
(
"Unknown uri: "
+
uri
);
throw
new
UnsupportedOperationException
(
"Unknown uri: "
+
uri
);
}
}
...
@@ -184,13 +392,31 @@ public class IITBAppContentProvider extends ContentProvider {
...
@@ -184,13 +392,31 @@ public class IITBAppContentProvider extends ContentProvider {
int
match
=
sUriMatcher
.
match
(
uri
);
int
match
=
sUriMatcher
.
match
(
uri
);
String
id
;
switch
(
match
)
{
switch
(
match
)
{
case
LOC_WITH_ID:
case
LOC_WITH_ID:
String
id
=
uri
.
getPathSegments
().
get
(
1
);
id
=
uri
.
getPathSegments
().
get
(
1
);
itemsUpdated
=
databaseHelper
.
getWritableDatabase
().
update
(
DatabaseContract
.
MapEntry
.
TABLE_NAME
,
values
,
"_id=?"
,
new
String
[]{
id
});
break
;
case
USER_PROFILE_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
itemsUpdated
=
databaseHelper
.
getWritableDatabase
().
update
(
DatabaseContract
.
UserProfileEntry
.
TABLE_NAME
,
values
,
"_id=?"
,
new
String
[]{
id
});
break
;
case
USER_FOLLOWER_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
itemsUpdated
=
databaseHelper
.
getWritableDatabase
().
update
(
DatabaseContract
.
UserFollowersEntry
.
TABLE_NAME
,
values
,
"_id=?"
,
new
String
[]{
id
});
break
;
case
USER_FOLLOWS_WITH_ID:
id
=
uri
.
getPathSegments
().
get
(
1
);
itemsUpdated
=
mapDbHelper
.
getWritableDatabase
().
update
(
TABLE_NAME
,
values
,
"_id=?"
,
new
String
[]{
id
});
itemsUpdated
=
databaseHelper
.
getWritableDatabase
().
update
(
DatabaseContract
.
UserFollowsEntry
.
TABLE_NAME
,
values
,
"_id=?"
,
new
String
[]{
id
});
break
;
break
;
default
:
default
:
throw
new
UnsupportedOperationException
(
"Unknown uri: "
+
uri
);
throw
new
UnsupportedOperationException
(
"Unknown uri: "
+
uri
);
...
...
app/src/main/java/in/ac/iitb/gymkhana/iitbapp/data/MapDbHelper.java
deleted
100644 → 0
View file @
8da030db
package
in.ac.iitb.gymkhana.iitbapp.data
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
public
class
MapDbHelper
extends
SQLiteOpenHelper
{
private
static
final
String
DATABASE_NAME
=
"mapDb.db"
;
private
static
final
int
VERSION
=
1
;
MapDbHelper
(
Context
context
)
{
super
(
context
,
DATABASE_NAME
,
null
,
VERSION
);
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
final
String
CREATE_TABLE
=
"CREATE TABLE "
+
DatabaseContract
.
MapEntry
.
TABLE_NAME
+
" ("
+
DatabaseContract
.
MapEntry
.
_ID
+
" INTEGER PRIMARY KEY, "
+
DatabaseContract
.
MapEntry
.
COLUMN_LATITUDE
+
" DOUBLE NOT NULL, "
+
DatabaseContract
.
MapEntry
.
COLUMN_LONGITUDE
+
" DOUBLE NOT NULL, "
+
DatabaseContract
.
MapEntry
.
COLUMN_NAME
+
" TEXT NOT NULL, "
+
DatabaseContract
.
MapEntry
.
COLUMN_TYPE
+
" TEXT NOT NULL);"
;
db
.
execSQL
(
CREATE_TABLE
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
DatabaseContract
.
MapEntry
.
TABLE_NAME
);
onCreate
(
db
);
}
}
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