Commit 9d70433a authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #39 from wncc/classes

Add data classes
parents 36358e7e 8295b8c3
......@@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -29,6 +29,7 @@ ext {
retrofitVersion = '2.1.0'
okhttpVersion = '3.4.1'
picassoVersion = '2.5.0'
archRoomVersion = "1.1.0-alpha3"
}
......@@ -52,5 +53,8 @@ dependencies {
compile "com.squareup.okhttp3:okhttp:${okhttpVersion}"
compile "com.squareup.okhttp3:logging-interceptor:${okhttpVersion}"
compile "com.squareup.picasso:picasso:${picassoVersion}"
compile "com.android.support:customtabs:${supportLibVersion}"
compile "android.arch.persistence.room:runtime:${archRoomVersion}"
annotationProcessor "android.arch.persistence.room:compiler:${archRoomVersion}"
}
apply plugin: 'com.google.gms.google-services'
......@@ -14,7 +14,7 @@ import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.ItemClickListener;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.api.model.Event;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
......@@ -48,7 +48,7 @@ public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.ViewHolder> {
Event currentEvent = posts.get(i);
viewHolder.eventTitle.setText(currentEvent.getEventName());
viewHolder.eventDetails.setText(currentEvent.getEventDescription());
Picasso.with(context).load(currentEvent.getEventImage()).into(viewHolder.eventPicture);
Picasso.with(context).load(currentEvent.getEventImageURL()).into(viewHolder.eventPicture);
}
@Override
......
......@@ -4,23 +4,24 @@ import in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.LoginRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.LoginResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
public interface RetrofitInterface {
@POST("login/")
Call<LoginResponse> login(@Body LoginRequest loginRequest);
@POST("/createEvent/")
Call<EventCreateResponse> eventCreate(@Body EventCreateRequest eventCreateRequest);
@POST("events")
Call<EventCreateResponse> createEvent(@Body EventCreateRequest eventCreateRequest);
@POST("getNewsFeed/")
Call<NewsFeedResponse> getNewsFeed(@Body NewsFeedRequest newsFeedRequest);
@GET("users/{uuid}/followed_bodies_events")
Call<NewsFeedResponse> getNewsFeed(@Path("uuid") String uuid);
@POST("getNotifications/")
Call<NotificationsResponse> getNotifications(@Body NotificationsRequest notificationsRequest);
......
......@@ -7,7 +7,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class ServiceGenerator {
//TODO: Change BASE_URL once the server is hosted
private static final String BASE_URL = "http://127.0.0.1";
private static final String BASE_URL = "https://temp-iitb.radialapps.com/api/";
private static OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
private static Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
.baseUrl(BASE_URL)
......
package in.ac.iitb.gymkhana.iitbapp.api.model;
import com.google.gson.annotations.SerializedName;
public class Event {
@SerializedName("event_name")
String eventName;
@SerializedName("event_description")
String eventDescription;
@SerializedName("event_image")
String eventImage;
@SerializedName("event_creator_name")
String eventCreatorName;
@SerializedName("event_creator_id")
String eventCreatorId;
@SerializedName("event_going_status")
int eventEnthu;
public Event(String eventName, String eventDescription, String eventImage, String eventCreatorName, String eventCreatorId, int eventEnthu) {
this.eventName = eventName;
this.eventDescription = eventDescription;
this.eventImage = eventImage;
this.eventCreatorName = eventCreatorName;
this.eventCreatorId = eventCreatorId;
this.eventEnthu = eventEnthu;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getEventDescription() {
return eventDescription;
}
public void setEventDescription(String eventDescription) {
this.eventDescription = eventDescription;
}
public String getEventImage() {
return eventImage;
}
public void setEventImage(String eventImage) {
this.eventImage = eventImage;
}
public String getEventCreatorName() {
return eventCreatorName;
}
public void setEventCreatorName(String eventCreatorName) {
this.eventCreatorName = eventCreatorName;
}
public String getEventCreatorId() {
return eventCreatorId;
}
public void setEventCreatorId(String eventCreatorId) {
this.eventCreatorId = eventCreatorId;
}
public int getEventEnthu() {
return eventEnthu;
}
public void setEventEnthu(int eventEnthu) {
this.eventEnthu = eventEnthu;
}
}
......@@ -6,43 +6,37 @@ import android.support.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
/**
* Created by mrunz on 15/7/17.
*/
import java.util.List;
public class EventCreateRequest {
@SerializedName("event_name")
@SerializedName("name")
private String eventName;
@SerializedName("event_description")
@SerializedName("description")
private String eventDescription;
@SerializedName("event_timing_from")
private Timestamp eventTimingFrom;
@SerializedName("event_timing_to")
private Timestamp eventTimingTo;
@SerializedName("event_venue_id")
private int eventVenueID;
@SerializedName("event_maplocation_id")
private int eventMapLocationId;
@SerializedName("event_venue")
private String eventVenue;
@SerializedName("public_status")
private int publicStatus;
public EventCreateRequest(String eventName, String eventDescription,String eventVenue,Timestamp eventTimingFrom,Timestamp eventTimingTo,int publicStatus,@Nullable int eventVenueID,@Nullable int eventMapLocationId) {
this.eventName=eventName;
this.eventDescription=eventDescription;
this.eventTimingFrom=eventTimingFrom;
this.eventTimingTo=eventTimingTo;
this.eventVenueID=eventVenueID;
this.eventMapLocationId=eventMapLocationId;
this.eventVenue=eventVenue;
this.publicStatus=publicStatus;
@SerializedName("image_url")
private String eventImageURL;
@SerializedName("start_time")
private String eventStartTime;
@SerializedName("end_time")
private String eventEndTime;
@SerializedName("all_day")
private boolean allDayEvent;
@SerializedName("venue_names")
private List<String> eventVenueNames;
@SerializedName("bodies_id")
private List<String> eventBodiesID;
public EventCreateRequest(String eventName, String eventDescription, String eventImageURL, String eventStartTime, String eventEndTime, boolean allDayEvent, List<String> eventVenueNames, List<String> eventBodiesID) {
this.eventName = eventName;
this.eventDescription = eventDescription;
this.eventImageURL = eventImageURL;
this.eventStartTime = eventStartTime;
this.eventEndTime = eventEndTime;
this.allDayEvent = allDayEvent;
this.eventVenueNames = eventVenueNames;
this.eventBodiesID = eventBodiesID;
}
public String getEventName() {
return eventName;
}
......@@ -59,53 +53,51 @@ public class EventCreateRequest {
this.eventDescription = eventDescription;
}
public Timestamp getEventTimingFrom() {
return eventTimingFrom;
public String getEventImageURL() {
return eventImageURL;
}
public void setEventTimingFrom(Timestamp eventTimingFrom) {
this.eventTimingFrom = eventTimingFrom;
public void setEventImageURL(String eventImageURL) {
this.eventImageURL = eventImageURL;
}
public Timestamp getEventTimingTo() {
return eventTimingTo;
public String getEventStartTime() {
return eventStartTime;
}
public void setEventTimingTo(Timestamp eventTimingTo) {
this.eventTimingTo = eventTimingTo;
public void setEventStartTime(String eventStartTime) {
this.eventStartTime = eventStartTime;
}
public int getEventVenueID() {
return eventVenueID;
public String getEventEndTime() {
return eventEndTime;
}
public void setEventVenueID(@Nullable int eventVenueID) {
this.eventVenueID = eventVenueID;
public void setEventEndTime(String eventEndTime) {
this.eventEndTime = eventEndTime;
}
public int getEventMapLocationId() {
return eventMapLocationId;
public boolean isAllDayEvent() {
return allDayEvent;
}
public void setEventMapLocationId(@Nullable int eventMapLocationId) {
this.eventMapLocationId = eventMapLocationId;
public void setAllDayEvent(boolean allDayEvent) {
this.allDayEvent = allDayEvent;
}
public String getEventVenue() {
return eventVenue;
public List<String> getEventVenueNames() {
return eventVenueNames;
}
public void setEventVenue(String eventVenue) {
this.eventVenue = eventVenue;
public void setEventVenueNames(List<String> eventVenueNames) {
this.eventVenueNames = eventVenueNames;
}
public int getPublicStatus() {
return publicStatus;
public List<String> getEventBodiesID() {
return eventBodiesID;
}
public void setPublicStatus(int publicStatus) {
this.publicStatus = publicStatus;
public void setEventBodiesID(List<String> eventBodiesID) {
this.eventBodiesID = eventBodiesID;
}
}
package in.ac.iitb.gymkhana.iitbapp.api.model;
public class NewsFeedRequest {
public static final int FOLLOWED = 0;
public static final int POPULAR = 1;
private int type;
private int from;
private int to;
public NewsFeedRequest(int type, int from, int to) {
this.type = type;
this.from = from;
this.to = to;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getFrom() {
return from;
}
public void setFrom(int from) {
this.from = from;
}
public int getTo() {
return to;
}
public void setTo(int to) {
this.to = to;
}
}
......@@ -4,12 +4,17 @@ import com.google.gson.annotations.SerializedName;
import java.util.List;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
public class NewsFeedResponse {
@SerializedName("posts")
@SerializedName("data")
private List<Event> events;
@SerializedName("count")
private int count;
public NewsFeedResponse(List<Event> events) {
public NewsFeedResponse(List<Event> events, int count) {
this.events = events;
this.count = count;
}
public List<Event> getEvents() {
......@@ -19,4 +24,12 @@ public class NewsFeedResponse {
public void setEvents(List<Event> events) {
this.events = events;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;
/**
* Created by mrunz on 14/3/18.
*/
@Database(entities = {Event.class, Body.class,Venue.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
private static AppDatabase INSTANCE;
public abstract DbDao dbDao();
public static AppDatabase getAppDatabase(Context context) {
if (INSTANCE == null) {
INSTANCE =
Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "database")
// allow queries on the main thread.
// Don't do this on a real app! See PersistenceBasicSample for an example.
.allowMainThreadQueries()
.build();
}
return INSTANCE;
}
public static void destroyInstance() {
INSTANCE = null;
}
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import com.google.gson.annotations.SerializedName;
import java.util.List;
@Entity(tableName = "bodies")
class Body {
@ColumnInfo(name = "id")
@SerializedName("id")
String bodyID;
@ColumnInfo(name = "name")
@SerializedName("name")
String bodyName;
@ColumnInfo(name = "description")
@SerializedName("description")
String bodyDescription;
@ColumnInfo(name = "image_url")
@SerializedName("image_url")
String bodyImageURL;
@ColumnInfo(name = "children")
@SerializedName("children")
List<Body> bodyChildren;
@ColumnInfo(name = "parents")
@SerializedName("parents")
List<Body> bodyParents;
@ColumnInfo(name = "events")
@SerializedName("events")
List<Event> bodyEvents;
@ColumnInfo(name = "followers_count")
@SerializedName("followers_count")
int bodyFollowersCount;
public Body(String bodyID, String bodyName, String bodyDescription, String bodyImageURL, List<Body> bodyChildren, List<Body> bodyParents, List<Event> bodyEvents, int bodyFollowersCount) {
this.bodyID = bodyID;
this.bodyName = bodyName;
this.bodyDescription = bodyDescription;
this.bodyImageURL = bodyImageURL;
this.bodyChildren = bodyChildren;
this.bodyParents = bodyParents;
this.bodyEvents = bodyEvents;
this.bodyFollowersCount = bodyFollowersCount;
}
public String getBodyID() {
return bodyID;
}
public void setBodyID(String bodyID) {
this.bodyID = bodyID;
}
public String getBodyName() {
return bodyName;
}
public void setBodyName(String bodyName) {
this.bodyName = bodyName;
}
public String getBodyDescription() {
return bodyDescription;
}
public void setBodyDescription(String bodyDescription) {
this.bodyDescription = bodyDescription;
}
public String getBodyImageURL() {
return bodyImageURL;
}
public void setBodyImageURL(String bodyImageURL) {
this.bodyImageURL = bodyImageURL;
}
public List<Body> getBodyChildren() {
return bodyChildren;
}
public void setBodyChildren(List<Body> bodyChildren) {
this.bodyChildren = bodyChildren;
}
public List<Body> getBodyParents() {
return bodyParents;
}
public void setBodyParents(List<Body> bodyParents) {
this.bodyParents = bodyParents;
}
public List<Event> getBodyEvents() {
return bodyEvents;
}
public void setBodyEvents(List<Event> bodyEvents) {
this.bodyEvents = bodyEvents;
}
public int getBodyFollowersCount() {
return bodyFollowersCount;
}
public void setBodyFollowersCount(int bodyFollowersCount) {
this.bodyFollowersCount = bodyFollowersCount;
}
}
\ No newline at end of file
package in.ac.iitb.gymkhana.iitbapp.data;
import android.net.Uri;
import android.provider.BaseColumns;
public class DatabaseContract {
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 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 String PATH_NEWS_FEED = "newsFeed";
public static final class MapEntry implements BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
.appendPath(PATH_MAP)
.build();
public static final String TABLE_NAME = "map";
public static final String COLUMN_LATITUDE = "latitude";
public static final String COLUMN_LONGITUDE = "longitude";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_TYPE = "type";
}
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";
}
public static final class NewsFeedEntry implements BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
.appendPath(PATH_NEWS_FEED)
.build();
public static final String TABLE_NAME = "newsFeed";
public static final String COLUMN_EVENT_NAME = "event_name";
public static final String COLUMN_EVENT_DESCRIPTION = "event_description";
public static final String COLUMN_EVENT_IMAGE = "event_image";
public static final String COLUMN_EVENT_CREATOR_NAME = "event_creator_name";
public static final String COLUMN_EVENT_CREATOR_ID = "event_creator_id";
public static final String COLUMN_EVENT_GOING_STATUS = "event_going_status";
}
}
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);";
final String CREATE_TABLE_NEWS_FEED = "CREATE TABLE " + DatabaseContract.NewsFeedEntry.TABLE_NAME + " (" +
DatabaseContract.NewsFeedEntry._ID + " INTEGER PRIMARY KEY, " +
DatabaseContract.NewsFeedEntry.COLUMN_EVENT_NAME + " TEXT NOT NULL, " +
DatabaseContract.NewsFeedEntry.COLUMN_EVENT_DESCRIPTION + " TEXT NOT NULL, " +
DatabaseContract.NewsFeedEntry.COLUMN_EVENT_IMAGE + " TEXT NOT NULL, " +
DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_NAME + " TEXT NOT NULL, " +
DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_ID + " TEXT NOT NULL, " +
DatabaseContract.NewsFeedEntry.COLUMN_EVENT_GOING_STATUS + " INTEGER 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);
db.execSQL(CREATE_TABLE_NEWS_FEED);
}
@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);
db.execSQL("DROP TABLE IF EXISTS " + DatabaseContract.NewsFeedEntry.TABLE_NAME);
onCreate(db);
}
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import java.util.List;
/**
* Created by mrunz on 13/3/18.
*/
@Dao
public interface DbDao {
@Query("SELECT * FROM events")
List<Event> getAllEvents();
@Query("SELECT * FROM bodies")
List<Body> getAllBodies();
@Query("SELECT * FROM venues")
List<Venue> getAllVenues();
@Query("SELECT COUNT(*) from events")
int countEvents();
@Query("SELECT COUNT(*) from venues")
int countVenues();
@Query("SELECT COUNT(*) from bodies")
int countBodies();
@Insert
void insertEvents(Event... events);
@Insert
void insertBodies(Body... bodies);
@Insert
void insertVenues(Venue... venues);
@Delete
void deleteEvent(Event event);
@Delete
void deleteVenue(Venue venue);
@Delete
void deleteBody(Body body);
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import com.google.gson.annotations.SerializedName;
import java.util.List;
@Entity(tableName = "events")
public class Event {
@ColumnInfo(name = "id")
@SerializedName("id")
String eventID;
@ColumnInfo(name = "name")
@SerializedName("name")
String eventName;
@ColumnInfo(name = "description")
@SerializedName("description")
String eventDescription;
@ColumnInfo(name = "image_url")
@SerializedName("image_url")
String eventImageURL;
@ColumnInfo(name = "start_time")
@SerializedName("start_time")
String eventStartTime;
@ColumnInfo(name = "end_time")
@SerializedName("end_time")
String eventEndTime;
@ColumnInfo(name = "all_day")
@SerializedName("all_day")
boolean allDayEvent;
@ColumnInfo(name = "venues")
@SerializedName("venues")
List<Venue> eventVenues;
@ColumnInfo(name = "bodies")
@SerializedName("bodies")
List<Body> eventBodies;
@ColumnInfo(name = "interested_count")
@SerializedName("interested_count")
int eventInterestedCount;
@ColumnInfo(name = "going_count")
@SerializedName("going_count")
int eventGoingCount;
@ColumnInfo(name = "interested")
@SerializedName("interested")
List<User> eventInterested;
@ColumnInfo(name = "going")
@SerializedName("going")
List<User> eventGoing;
public Event(String eventID, String eventName, String eventDescription, String eventImageURL, String eventStartTime, String eventEndTime, boolean allDayEvent, List<Venue> eventVenues, List<Body> eventBodies, int eventInterestedCount, int eventGoingCount, List<User> eventInterested, List<User> eventGoing) {
this.eventID = eventID;
this.eventName = eventName;
this.eventDescription = eventDescription;
this.eventImageURL = eventImageURL;
this.eventStartTime = eventStartTime;
this.eventEndTime = eventEndTime;
this.allDayEvent = allDayEvent;
this.eventVenues = eventVenues;
this.eventBodies = eventBodies;
this.eventInterestedCount = eventInterestedCount;
this.eventGoingCount = eventGoingCount;
this.eventInterested = eventInterested;
this.eventGoing = eventGoing;
}
public String getEventID() {
return eventID;
}
public void setEventID(String eventID) {
this.eventID = eventID;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getEventDescription() {
return eventDescription;
}
public void setEventDescription(String eventDescription) {
this.eventDescription = eventDescription;
}
public String getEventImageURL() {
return eventImageURL;
}
public void setEventImageURL(String eventImageURL) {
this.eventImageURL = eventImageURL;
}
public String getEventStartTime() {
return eventStartTime;
}
public void setEventStartTime(String eventStartTime) {
this.eventStartTime = eventStartTime;
}
public String getEventEndTime() {
return eventEndTime;
}
public void setEventEndTime(String eventEndTime) {
this.eventEndTime = eventEndTime;
}
public boolean isAllDayEvent() {
return allDayEvent;
}
public void setAllDayEvent(boolean allDayEvent) {
this.allDayEvent = allDayEvent;
}
public List<Venue> getEventVenues() {
return eventVenues;
}
public void setEventVenues(List<Venue> eventVenues) {
this.eventVenues = eventVenues;
}
public List<Body> getEventBodies() {
return eventBodies;
}
public void setEventBodies(List<Body> eventBodies) {
this.eventBodies = eventBodies;
}
public int getEventInterestedCount() {
return eventInterestedCount;
}
public void setEventInterestedCount(int eventInterestedCount) {
this.eventInterestedCount = eventInterestedCount;
}
public int getEventGoingCount() {
return eventGoingCount;
}
public void setEventGoingCount(int eventGoingCount) {
this.eventGoingCount = eventGoingCount;
}
public List<User> getEventInterested() {
return eventInterested;
}
public void setEventInterested(List<User> eventInterested) {
this.eventInterested = eventInterested;
}
public List<User> getEventGoing() {
return eventGoing;
}
public void setEventGoing(List<User> eventGoing) {
this.eventGoing = eventGoing;
}
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
public class IITBAppContentProvider extends ContentProvider {
public static final int LOCS = 100;
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;
public static final int NEWS_FEED = 500;
public static final int NEWS_FEED_WITH_ID = 501;
private static final UriMatcher sUriMatcher = buildUriMatcher();
private DatabaseHelper databaseHelper;
public static UriMatcher buildUriMatcher() {
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 + "/#", 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);
matcher.addURI(DatabaseContract.CONTENT_AUTHORITY, DatabaseContract.PATH_NEWS_FEED, NEWS_FEED);
matcher.addURI(DatabaseContract.CONTENT_AUTHORITY, DatabaseContract.PATH_NEWS_FEED + "/#", NEWS_FEED_WITH_ID);
return matcher;
}
@Override
public boolean onCreate() {
Context context = getContext();
databaseHelper = new DatabaseHelper(context);
return true;
}
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
final SQLiteDatabase db = databaseHelper.getReadableDatabase();
int match = sUriMatcher.match(uri);
Cursor cursor;
String id;
String selectionArguments[];
switch (match) {
case LOCS:
cursor = db.query(DatabaseContract.MapEntry.TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
break;
case LOC_WITH_ID:
id = uri.getPathSegments().get(1);
selectionArguments = new String[]{id};
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,
"_id=?",
selectionArguments,
null,
null,
sortOrder);
break;
case NEWS_FEED:
cursor = db.query(DatabaseContract.NewsFeedEntry.TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
break;
case NEWS_FEED_WITH_ID:
id = uri.getPathSegments().get(1);
selectionArguments = new String[]{id};
cursor = db.query(DatabaseContract.NewsFeedEntry.TABLE_NAME,
projection,
"_id=?",
selectionArguments,
null,
null,
sortOrder);
break;
default:
throw new SQLException("Wrong Uri: " + uri);
}
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
@Nullable
@Override
public String getType(@NonNull Uri uri) {
int match = sUriMatcher.match(uri);
switch (match) {
case LOCS:
return "vnd.android.cursor.dir" + "/" + DatabaseContract.CONTENT_AUTHORITY + "/" + DatabaseContract.PATH_MAP;
case LOC_WITH_ID:
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;
case NEWS_FEED:
return "vnd.android.cursor.dir" + "/" + DatabaseContract.CONTENT_AUTHORITY + "/" + DatabaseContract.PATH_NEWS_FEED;
case NEWS_FEED_WITH_ID:
return "vnd.android.cursor.item" + "/" + DatabaseContract.CONTENT_AUTHORITY + "/" + DatabaseContract.PATH_NEWS_FEED;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
}
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
int match = sUriMatcher.match(uri);
Uri returnUri;
long id;
switch (match) {
case LOCS:
id = db.insert(DatabaseContract.MapEntry.TABLE_NAME, null, values);
if (id > 0) {
returnUri = ContentUris.withAppendedId(DatabaseContract.MapEntry.CONTENT_URI, id);
} else
throw new SQLException("Failed to insert row into " + uri);
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;
case NEWS_FEED:
id = db.insert(DatabaseContract.NewsFeedEntry.TABLE_NAME, null, values);
if (id > 0) {
returnUri = ContentUris.withAppendedId(DatabaseContract.NewsFeedEntry.CONTENT_URI, id);
} else
throw new SQLException("Failed to insert row into " + uri);
break;
default:
throw new SQLException("Wrong uri: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return returnUri;
}
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
int rowsInserted;
switch (sUriMatcher.match(uri)) {
case LOCS:
db.beginTransaction();
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 {
for (ContentValues value : values) {
long _id = db.insert(DatabaseContract.UserProfileEntry.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_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;
case NEWS_FEED:
db.beginTransaction();
rowsInserted = 0;
try {
for (ContentValues value : values) {
long _id = db.insert(DatabaseContract.NewsFeedEntry.TABLE_NAME, null, value);
if (_id != -1) {
rowsInserted++;
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (rowsInserted > 0) {
getContext().getContentResolver().notifyChange(uri, null);
}
return rowsInserted;
default:
return super.bulkInsert(uri, values);
}
}
@Override
public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
int numRowsDeleted;
String id;
if (null == selection) selection = "1";
switch (sUriMatcher.match(uri)) {
case LOCS:
numRowsDeleted = databaseHelper.getWritableDatabase().delete(
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,
selectionArgs);
break;
case USER_FOLLOWS:
numRowsDeleted = databaseHelper.getWritableDatabase().delete(
DatabaseContract.UserFollowsEntry.TABLE_NAME,
selection,
selectionArgs);
break;
case NEWS_FEED:
numRowsDeleted = databaseHelper.getWritableDatabase().delete(
DatabaseContract.NewsFeedEntry.TABLE_NAME,
selection,
selectionArgs);
break;
case LOC_WITH_ID:
id = uri.getPathSegments().get(1);
numRowsDeleted = databaseHelper.getWritableDatabase().delete(DatabaseContract.MapEntry.TABLE_NAME, "_id=?", new String[]{id});
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;
case NEWS_FEED_WITH_ID:
id = uri.getPathSegments().get(1);
numRowsDeleted = databaseHelper.getWritableDatabase().delete(DatabaseContract.NewsFeedEntry.TABLE_NAME, "_id=?", new String[]{id});
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
if (numRowsDeleted != 0) {
getContext().getContentResolver().notifyChange(uri, null);
}
return numRowsDeleted;
}
@Override
public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
int itemsUpdated;
int match = sUriMatcher.match(uri);
String id;
switch (match) {
case LOC_WITH_ID:
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 = databaseHelper.getWritableDatabase().update(DatabaseContract.UserFollowsEntry.TABLE_NAME, values, "_id=?", new String[]{id});
break;
case NEWS_FEED_WITH_ID:
id = uri.getPathSegments().get(1);
itemsUpdated = databaseHelper.getWritableDatabase().update(DatabaseContract.NewsFeedEntry.TABLE_NAME, values, "_id=?", new String[]{id});
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
if (itemsUpdated != 0) {
getContext().getContentResolver().notifyChange(uri, null);
}
return itemsUpdated;
}
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import com.google.gson.annotations.SerializedName;
import java.util.List;
@Entity(tableName = "users")
class User {
@ColumnInfo(name = "id")
@SerializedName("id")
String userID;
@ColumnInfo(name = "name")
@SerializedName("name")
String userName;
@ColumnInfo(name = "profile_pic")
@SerializedName("profile_pic")
String userProfilePictureUrl;
@ColumnInfo(name = "events_interested")
@SerializedName("events_interested")
List<Event> userInterestedEvents;
@ColumnInfo(name = "events_going")
@SerializedName("events_going")
List<Event> userGoingEvents;
@ColumnInfo(name = "email")
@SerializedName("email")
String userEmail;
@ColumnInfo(name = "year")
@SerializedName("year")
int userYear;
@ColumnInfo(name = "roll_no")
@SerializedName("roll_no")
String userRollNumber;
@ColumnInfo(name = "contact_no")
@SerializedName("contact_no")
String userContactNumber;
@ColumnInfo(name = "about")
@SerializedName("about")
String userAbout;
@ColumnInfo(name = "followed_bodies")
@SerializedName("followed_bodies")
List<Body> userFollowedBodies;
@ColumnInfo(name = "followed_bodies_id")
@SerializedName("followed_bodies_id")
List<String> userFollowedBodiesID;
public User(String userID, String userName, String userProfilePictureUrl, List<Event> userInterestedEvents, List<Event> userGoingEvents, String userEmail, int userYear, String userRollNumber, String userContactNumber, String userAbout, List<Body> userFollowedBodies, List<String> userFollowedBodiesID) {
this.userID = userID;
this.userName = userName;
this.userProfilePictureUrl = userProfilePictureUrl;
this.userInterestedEvents = userInterestedEvents;
this.userGoingEvents = userGoingEvents;
this.userEmail = userEmail;
this.userYear = userYear;
this.userRollNumber = userRollNumber;
this.userContactNumber = userContactNumber;
this.userAbout = userAbout;
this.userFollowedBodies = userFollowedBodies;
this.userFollowedBodiesID = userFollowedBodiesID;
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserProfilePictureUrl() {
return userProfilePictureUrl;
}
public void setUserProfilePictureUrl(String userProfilePictureUrl) {
this.userProfilePictureUrl = userProfilePictureUrl;
}
public List<Event> getUserInterestedEvents() {
return userInterestedEvents;
}
public void setUserInterestedEvents(List<Event> userInterestedEvents) {
this.userInterestedEvents = userInterestedEvents;
}
public List<Event> getUserGoingEvents() {
return userGoingEvents;
}
public void setUserGoingEvents(List<Event> userGoingEvents) {
this.userGoingEvents = userGoingEvents;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public int getUserYear() {
return userYear;
}
public void setUserYear(int userYear) {
this.userYear = userYear;
}
public String getUserRollNumber() {
return userRollNumber;
}
public void setUserRollNumber(String userRollNumber) {
this.userRollNumber = userRollNumber;
}
public String getUserContactNumber() {
return userContactNumber;
}
public void setUserContactNumber(String userContactNumber) {
this.userContactNumber = userContactNumber;
}
public String getUserAbout() {
return userAbout;
}
public void setUserAbout(String userAbout) {
this.userAbout = userAbout;
}
public List<Body> getUserFollowedBodies() {
return userFollowedBodies;
}
public void setUserFollowedBodies(List<Body> userFollowedBodies) {
this.userFollowedBodies = userFollowedBodies;
}
public List<String> getUserFollowedBodiesID() {
return userFollowedBodiesID;
}
public void setUserFollowedBodiesID(List<String> userFollowedBodiesID) {
this.userFollowedBodiesID = userFollowedBodiesID;
}
}
package in.ac.iitb.gymkhana.iitbapp.data;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import com.google.gson.annotations.SerializedName;
@Entity(tableName = "venues")
class Venue {
@ColumnInfo(name = "id")
@SerializedName("id")
String venueID;
@ColumnInfo(name = "name")
@SerializedName("name")
String venueName;
@ColumnInfo(name = "lat")
@SerializedName("lat")
double venueLatitude;
@ColumnInfo(name = "lng")
@SerializedName("lng")
double venueLongitude;
public Venue(String venueID, String venueName, double venueLatitude, double venueLongitude) {
this.venueID = venueID;
this.venueName = venueName;
this.venueLatitude = venueLatitude;
this.venueLongitude = venueLongitude;
}
public String getVenueID() {
return venueID;
}
public void setVenueID(String venueID) {
this.venueID = venueID;
}
public String getVenueName() {
return venueName;
}
public void setVenueName(String venueName) {
this.venueName = venueName;
}
public double getVenueLatitude() {
return venueLatitude;
}
public void setVenueLatitude(double venueLatitude) {
this.venueLatitude = venueLatitude;
}
public double getVenueLongitude() {
return venueLongitude;
}
public void setVenueLongitude(double venueLongitude) {
this.venueLongitude = venueLongitude;
}
}
......@@ -22,7 +22,9 @@ import android.widget.TimePicker;
import android.widget.Toast;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
......@@ -203,6 +205,7 @@ public class AddEventFragment extends Fragment {
Toast.makeText(getContext(), "Add Event", Toast.LENGTH_SHORT).show();
//TODO (2) save event
addEvent();
}
});
......@@ -212,9 +215,9 @@ public class AddEventFragment extends Fragment {
}
public void addEvent() {
EventCreateRequest eventCreateRequest = new EventCreateRequest(eventName.getText().toString(), details.getText().toString(), venue.getText().toString(), timestamp_start, timestamp_end, publicStatus, 0, 0);
EventCreateRequest eventCreateRequest = new EventCreateRequest(eventName.getText().toString(), details.getText().toString(), "http://resources.wncc-iitb.org/logo_banner.png", timestamp_start.toString(), timestamp_end.toString(), false, Arrays.asList(new String[]{venue.getText().toString()}), Arrays.asList(new String[]{"bde82d5e-f379-4b8a-ae38-a9f03e4f1c4a"}));
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.eventCreate(eventCreateRequest).enqueue(new Callback<EventCreateResponse>() {
retrofitInterface.createEvent(eventCreateRequest).enqueue(new Callback<EventCreateResponse>() {
@Override
public void onResponse(Call<EventCreateResponse> call, Response<EventCreateResponse> response) {
Toast.makeText(getContext(), "Event Created", Toast.LENGTH_SHORT).show();
......
......@@ -14,7 +14,7 @@ import com.squareup.picasso.Picasso;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.api.model.Event;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
/**
* A simple {@link Fragment} subclass.
......@@ -50,7 +50,7 @@ public class EventFragment extends Fragment {
TextView eventDetails = (TextView) getActivity().findViewById(R.id.event_details_2);
TextView eventDescription = (TextView) getActivity().findViewById(R.id.event_description_2);
Picasso.with(getContext()).load(event.getEventImage()).into(eventPicture);
Picasso.with(getContext()).load(event.getEventImageURL()).into(eventPicture);
eventTitle.setText(event.getEventName());
eventDetails.setText(event.getEventDescription());
eventDescription.setText(event.getEventDescription());
......
......@@ -26,10 +26,9 @@ import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.api.model.Event;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse;
import in.ac.iitb.gymkhana.iitbapp.data.DatabaseContract;
import in.ac.iitb.gymkhana.iitbapp.data.Event;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -57,37 +56,37 @@ public class FeedFragment extends Fragment {
@Override
public void onStart() {
super.onStart();
Cursor cursor = getContext().getContentResolver().query(DatabaseContract.NewsFeedEntry.CONTENT_URI, null, null, null, null);
if (cursor.getCount() != 0) {
final List<Event> events = new ArrayList<>();
while (cursor.moveToNext()) {
Event event = new Event(cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_NAME)),
cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_DESCRIPTION)),
cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_IMAGE)),
cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_NAME)),
cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_ID)),
cursor.getInt(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_GOING_STATUS)));
events.add(event);
}
FeedAdapter feedAdapter = new FeedAdapter(events, new ItemClickListener() {
@Override
public void onItemClick(View v, int position) {
String eventJson = new Gson().toJson(events.get(position));
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, eventJson);
EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle);
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
transaction.commit();
}
});
feedRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feed_recycler_view);
feedRecyclerView.setAdapter(feedAdapter);
feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
// Cursor cursor = getContext().getContentResolver().query(DatabaseContract.NewsFeedEntry.CONTENT_URI, null, null, null, null);
// if (cursor.getCount() != 0) {
// final List<Event> events = new ArrayList<>();
// while (cursor.moveToNext()) {
// Event event = new Event(cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_NAME)),
// cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_DESCRIPTION)),
// cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_IMAGE)),
// cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_NAME)),
// cursor.getString(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_ID)),
// cursor.getInt(cursor.getColumnIndex(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_GOING_STATUS)));
// events.add(event);
// }
// FeedAdapter feedAdapter = new FeedAdapter(events, new ItemClickListener() {
// @Override
// public void onItemClick(View v, int position) {
// String eventJson = new Gson().toJson(events.get(position));
// Bundle bundle = new Bundle();
// bundle.putString(Constants.EVENT_JSON, eventJson);
// EventFragment eventFragment = new EventFragment();
// eventFragment.setArguments(bundle);
// FragmentManager manager = getActivity().getSupportFragmentManager();
// FragmentTransaction transaction = manager.beginTransaction();
// transaction.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
// transaction.commit();
// }
// });
// feedRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feed_recycler_view);
// feedRecyclerView.setAdapter(feedAdapter);
// feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
//
// }
updateFeed();
......@@ -101,9 +100,10 @@ public class FeedFragment extends Fragment {
}
private void updateFeed() {
NewsFeedRequest newsFeedRequest = new NewsFeedRequest(NewsFeedRequest.FOLLOWED, 0, 20);
//TODO: Fetch userID from SharedPreferences
String userID = "51e04db1-040f-406c-8b6f-0c47a1bdc5a4";
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getNewsFeed(newsFeedRequest).enqueue(new Callback<NewsFeedResponse>() {
retrofitInterface.getNewsFeed(userID).enqueue(new Callback<NewsFeedResponse>() {
@Override
public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
if (response.isSuccessful()) {
......@@ -135,10 +135,7 @@ public class FeedFragment extends Fragment {
ContentValues contentValues1 = new ContentValues();
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_NAME, events.get(i).getEventName());
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_DESCRIPTION, events.get(i).getEventDescription());
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_IMAGE, events.get(i).getEventImage());
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_NAME, events.get(i).getEventCreatorName());
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_CREATOR_ID, events.get(i).getEventCreatorId());
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_GOING_STATUS, events.get(i).getEventEnthu());
contentValues1.put(DatabaseContract.NewsFeedEntry.COLUMN_EVENT_IMAGE, events.get(i).getEventImageURL());
contentValues[i] = contentValues1;
}
int insertCount = getContext().getContentResolver().bulkInsert(DatabaseContract.NewsFeedEntry.CONTENT_URI, contentValues);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment