Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #72 from mananwason/bookmarks
Browse files Browse the repository at this point in the history
bookmarks issue fixed #70
  • Loading branch information
creativepsyco committed Aug 13, 2015
2 parents 1c5beb7 + d6e39a8 commit 2ecbb01
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,18 @@
import org.fossasia.openevent.R;
import org.fossasia.openevent.data.Session;
import org.fossasia.openevent.data.Speaker;
import org.fossasia.openevent.dbutils.DbContract;
import org.fossasia.openevent.dbutils.DbSingleton;
import org.fossasia.openevent.utils.ISO8601Date;
import org.fossasia.openevent.utils.IntentStrings;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

/**
* Created by MananWason on 08-07-2015.
*/
public class SessionDetailActivity extends AppCompatActivity {
private static final String TAG = "Session Detail";
RecyclerView speakersRecyclerView;
SpeakersListAdapter adapter;
Session session;
Expand Down Expand Up @@ -81,10 +76,9 @@ public void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
}

if((start.equals(null)) && (end.equals(null))) {
if ((start.equals(null)) && (end.equals(null))) {
tv_time.setText("Timings not specified");
}
else {
} else {
String timings = start + " - " + end;
tv_time.setText(timings);
}
Expand All @@ -102,19 +96,33 @@ public boolean onOptionsItemSelected(MenuItem item) {
case android.R.id.home:
finish();
return true;
case R.id.add_bookmark:

Log.d("BOOKMARKS", session.getId() + "");
case R.id.bookmark_status:
DbSingleton dbSingleton = DbSingleton.getInstance();
dbSingleton.addBookmarks(session.getId());

if (dbSingleton.isBookmarked(session.getId())) {
Log.d(TAG, "Bookmark Removed");
dbSingleton.deleteBookmarks(session.getId());
item.setIcon(R.drawable.ic_star_border_bookmark);
} else {
Log.d(TAG, "Bookmarked");
dbSingleton.addBookmarks(session.getId());
item.setIcon(R.drawable.ic_star_bookmark);
}
}
return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_session_detail, menu);
DbSingleton dbSingleton = DbSingleton.getInstance();
MenuItem item = menu.findItem(R.id.bookmark_status);
if (dbSingleton.isBookmarked(session.getId())) {
Log.d(TAG, "Bookmarked");
item.setIcon(R.drawable.ic_star_bookmark);
} else {
Log.d(TAG, "Bookmark Removed");
item.setIcon(R.drawable.ic_star_border_bookmark);
}
return super.onCreateOptionsMenu(menu);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,26 @@ public ArrayList<Speaker> getSpeakersbySessionName(String sessionName, SQLiteDat
return speakers;
}

public boolean isBookmarked(int sessionId, SQLiteDatabase db) {
boolean number = false;
Cursor c = null;
try {
c = db.rawQuery("select " + DbContract.Bookmarks.SESSION_ID + " from " + DbContract.Bookmarks.TABLE_NAME
+ " where session_id = ?", new String[]{String.valueOf(sessionId)});

if (c.getCount() == 1) {
number = true;

}

} catch (Exception e) {
e.printStackTrace();
} finally {
if (c != null) c.close();
}
return number;
}

public Session getSessionbySessionname(String sessionName, SQLiteDatabase mDb) throws ParseException {
String sessionColumnSelection = DbContract.Sessions.TITLE + EQUAL + DatabaseUtils.sqlEscapeString(sessionName);
Cursor cursor = mDb.query(
Expand Down Expand Up @@ -685,7 +705,7 @@ public Session getSessionbySessionname(String sessionName, SQLiteDatabase mDb) t


public ArrayList<Integer> getBookmarkIds(SQLiteDatabase mDb) {
String sortOrder = DbContract.Bookmarks.TRACKS_ID + ASCENDING;
String sortOrder = DbContract.Bookmarks.SESSION_ID + ASCENDING;

Cursor cursor = mDb.query(
DbContract.Bookmarks.TABLE_NAME,
Expand All @@ -700,7 +720,7 @@ public ArrayList<Integer> getBookmarkIds(SQLiteDatabase mDb) {
ArrayList<Integer> ids = new ArrayList<>();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
ids.add(cursor.getInt(cursor.getColumnIndex(DbContract.Bookmarks.TRACKS_ID)));
ids.add(cursor.getInt(cursor.getColumnIndex(DbContract.Bookmarks.SESSION_ID)));
cursor.moveToNext();
}

Expand All @@ -717,7 +737,7 @@ public void insertQuery(String query, DbHelper mDbHelper) {
db.endTransaction();
}

public void addToDb(int id) {
public void addBookmarksToDb(int id) {
String query_normal = "INSERT INTO %s VALUES ('%d');";
String query = String.format(
query_normal,
Expand All @@ -728,6 +748,11 @@ public void addToDb(int id) {
dbSingleton.insertQuery(query);
}

public void deleteBookmarks(int id, SQLiteDatabase db) {
db.delete(DbContract.Bookmarks.TABLE_NAME, DbContract.Bookmarks.SESSION_ID + "=" + id, null);

}

public void deleteAllRecords(String tableName, SQLiteDatabase db) {

db.execSQL("delete from " + DatabaseUtils.sqlEscapeString(tableName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ public static abstract class Event implements BaseColumns {
public static abstract class Bookmarks implements BaseColumns {
public static final String TABLE_NAME = "bookmarks";

public static final String TRACKS_ID = "tracks_id";
public static final String SESSION_ID = "session_id";
public static final String[] FULL_PROJECTION = {
TRACKS_ID
SESSION_ID
};

public static final String CREATE_TABLE =
"CREATE TABLE " + TABLE_NAME
+ " ("
+ TRACKS_ID + INT_TYPE + PRIMARY_KEY
+ SESSION_ID + INT_TYPE + PRIMARY_KEY
+ " );";
public static final String DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public Version getVersionIds() {
}

public void addBookmarks(int bookmarkId) {
databaseOperations.addToDb(bookmarkId);
databaseOperations.addBookmarksToDb(bookmarkId);
}

public void deleteBookmarks(int bookmarkId) {
databaseOperations.deleteBookmarks(bookmarkId, mDb);
}

public Speaker getSpeakerById(int id) {
Expand Down Expand Up @@ -141,6 +145,10 @@ public Session getSessionbySessionname(String sessionName) throws ParseException
return databaseOperations.getSessionbySessionname(sessionName, mDb);
}

public boolean isBookmarked(int sessionId) {
return databaseOperations.isBookmarked(sessionId, mDb);
}

public ArrayList<Integer> getBookmarkIds() throws ParseException {
return databaseOperations.getBookmarkIds(mDb);
}
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_star_bookmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_star_bookmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions app/src/main/res/drawable-v21/fab_background.xml

This file was deleted.

Binary file added app/src/main/res/drawable-xhdpi/ic_star_bookmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions app/src/main/res/menu/menu_session_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/add_bookmark"
android:icon="@drawable/ic_event_add_white_24dp"
android:id="@+id/bookmark_status"
android:menuCategory="secondary"
android:title="Bookmark"
android:title="@string/menu_bookmarks"
app:showAsAction="ifRoom"/>
</menu>

0 comments on commit 2ecbb01

Please sign in to comment.