From d6e39a887c5dab5d5f48c40b11238619f34d05a5 Mon Sep 17 00:00:00 2001 From: mananwason Date: Thu, 13 Aug 2015 12:42:06 +0530 Subject: [PATCH] bookmarks issue fixed #70 --- .../activities/SessionDetailActivity.java | 36 +++++++++++------- .../openevent/dbutils/DatabaseOperations.java | 31 +++++++++++++-- .../openevent/dbutils/DbContract.java | 6 +-- .../openevent/dbutils/DbSingleton.java | 10 ++++- .../res/drawable-hdpi/ic_star_bookmark.png | Bin 0 -> 369 bytes .../drawable-hdpi/ic_star_border_bookmark.png | Bin 0 -> 500 bytes .../res/drawable-mdpi/ic_star_bookmark.png | Bin 0 -> 263 bytes .../drawable-mdpi/ic_star_border_bookmark.png | Bin 0 -> 332 bytes .../main/res/drawable-v21/fab_background.xml | 9 ----- .../res/drawable-xhdpi/ic_star_bookmark.png | Bin 0 -> 467 bytes .../ic_star_border_bookmark.png | Bin 0 -> 674 bytes .../res/drawable-xxhdpi/ic_star_bookmark.png | Bin 0 -> 668 bytes .../ic_star_border_bookmark.png | Bin 0 -> 971 bytes .../res/drawable-xxxhdpi/ic_star_bookmark.png | Bin 0 -> 887 bytes .../ic_star_border_bookmark.png | Bin 0 -> 1301 bytes app/src/main/res/menu/menu_session_detail.xml | 5 +-- 16 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_star_bookmark.png create mode 100644 app/src/main/res/drawable-hdpi/ic_star_border_bookmark.png create mode 100644 app/src/main/res/drawable-mdpi/ic_star_bookmark.png create mode 100644 app/src/main/res/drawable-mdpi/ic_star_border_bookmark.png delete mode 100644 app/src/main/res/drawable-v21/fab_background.xml create mode 100644 app/src/main/res/drawable-xhdpi/ic_star_bookmark.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_star_border_bookmark.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_star_bookmark.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_star_border_bookmark.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_star_bookmark.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_star_border_bookmark.png diff --git a/app/src/main/java/org/fossasia/openevent/activities/SessionDetailActivity.java b/app/src/main/java/org/fossasia/openevent/activities/SessionDetailActivity.java index b903e24e5..b53ae5a35 100644 --- a/app/src/main/java/org/fossasia/openevent/activities/SessionDetailActivity.java +++ b/app/src/main/java/org/fossasia/openevent/activities/SessionDetailActivity.java @@ -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; @@ -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); } @@ -102,12 +96,17 @@ 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); } @@ -115,6 +114,15 @@ public boolean onOptionsItemSelected(MenuItem 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); } diff --git a/app/src/main/java/org/fossasia/openevent/dbutils/DatabaseOperations.java b/app/src/main/java/org/fossasia/openevent/dbutils/DatabaseOperations.java index 175b7a49a..23ce61f32 100644 --- a/app/src/main/java/org/fossasia/openevent/dbutils/DatabaseOperations.java +++ b/app/src/main/java/org/fossasia/openevent/dbutils/DatabaseOperations.java @@ -650,6 +650,26 @@ public ArrayList 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( @@ -685,7 +705,7 @@ public Session getSessionbySessionname(String sessionName, SQLiteDatabase mDb) t public ArrayList 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, @@ -700,7 +720,7 @@ public ArrayList getBookmarkIds(SQLiteDatabase mDb) { ArrayList 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(); } @@ -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, @@ -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)); diff --git a/app/src/main/java/org/fossasia/openevent/dbutils/DbContract.java b/app/src/main/java/org/fossasia/openevent/dbutils/DbContract.java index 2fd95755d..0de189066 100644 --- a/app/src/main/java/org/fossasia/openevent/dbutils/DbContract.java +++ b/app/src/main/java/org/fossasia/openevent/dbutils/DbContract.java @@ -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; diff --git a/app/src/main/java/org/fossasia/openevent/dbutils/DbSingleton.java b/app/src/main/java/org/fossasia/openevent/dbutils/DbSingleton.java index 32f102b0f..bd1657b9d 100644 --- a/app/src/main/java/org/fossasia/openevent/dbutils/DbSingleton.java +++ b/app/src/main/java/org/fossasia/openevent/dbutils/DbSingleton.java @@ -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) { @@ -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 getBookmarkIds() throws ParseException { return databaseOperations.getBookmarkIds(mDb); } diff --git a/app/src/main/res/drawable-hdpi/ic_star_bookmark.png b/app/src/main/res/drawable-hdpi/ic_star_bookmark.png new file mode 100644 index 0000000000000000000000000000000000000000..92a0f586223099f0d3ba629fbfcc44ef4890dec3 GIT binary patch literal 369 zcmV-%0gnEOP)x%~aQ|*Pi>J&v=b3wE$LG8MEr0%P=cnz7#~$g4jD2yc9`&S%#vjw5|Y!>q=2|S(dv( zn7HqV)RG4#LbxN#Tj8|}c5=}h;gt-FN;eeh%)6;{NUP;(ZTgn%+JC00-c21_z>%WekO*bs{6mMG7g+4Q0tmBumImb46~FWEVM0C}|FsQe!D%;$(@q zc+@nODf51M2gPf~{CRGCAOEy@=J_kmIqNSNr^gp#)vQg#9yJ>5wTM>+tH~-65i8W> zmU!Z+xUL4XL~ON9M6*A3LUb8ngf4N^A8PVR98z&ud^FyGW?Evco%T8Dk`B*xizu6- zVw#Bf?4`S|IBmaO)>&$%pS0>05fKp)am{z_A|fIpBD%Gz(&DX%vdd1`Ylk%!Yx3O$ z%dEHC0cTuQ7V*X$eVD9M#6`pW%1{?XJT^%`8nlbJt4V(vb%pf(X7EK+Tu_afR9v`&w>q1sK+W39sKd=Pt8+b`a$Q&_Wz<*K!cn4z%EqHLs! z(T+Q2l!{TxVw1woi$|!pQAxx*8`PmwoK@IMaYTy_5xsgv+&0@$@k~JzMRe*F(V@j$ zcSL;kNW=t%tQHYbvQfQ?dYhC)M66WEVG(7=jrOB4PAZEysE~)^zWMsHzyonl0S!vF qsMnuCwksKKK#dv=q{$fn{kCrli_lEC3K^aN0000ujP)wy>Q~O4(cG+o4>KCu6T+^BCOrw^!GuQE#HdwSrIsaKw_?-sW8HhPsQ^&e^6HMX(vec#v}05LvoCpRlKN)&1ls@r N002ovPDHLkV1jAvcYy!^ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_star_border_bookmark.png b/app/src/main/res/drawable-mdpi/ic_star_border_bookmark.png new file mode 100644 index 0000000000000000000000000000000000000000..b75384809f8060aa996872d02175dc6f30408230 GIT binary patch literal 332 zcmV-S0ki&zP)kRX;*}BSxFTiz03MwODX4suAXp4 zp_;u8JME3Hs#)K>cGeO5?2uTeZ)7f3-2gYms)ez>mBc{!<+=-wYpH^&mJ>RE#({)& zJ*lAsHtjc*>cXbBsflCO9W^o4mZNFpr@E!Og^{KLk4$Y@s`&1qLZ3VbrYj1|}; zT(#R1Aw1S_O=!r~5uTYz-O5V+@KiW2*F7P;bPzPX62e`%-uvvL#8TptFW$;gb6d@( e?e5s-fA$;MJ6x;Jv?K-q0000 - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable-xhdpi/ic_star_bookmark.png b/app/src/main/res/drawable-xhdpi/ic_star_bookmark.png new file mode 100644 index 0000000000000000000000000000000000000000..c636ce8e81bedced667a12e42fae8037f7f932ae GIT binary patch literal 467 zcmV;^0WAKBP)&2LP>Th>G%L(iAzV?AI-i9w zqgElh#qyI1@mef@r2zZIs{7>bzF76HoNe<{tolQfTn&gd`{k(QqgZoFjofsJDo@C$ zq*=QTr}Y_h$A}qG<+KsE4eHaaL%U`r8|XD`%!FA>BI6~qCX5-@Yn>)zBBw7ksiMJ< z$l*iv{%TPC<7;fJ$D+u1(HRMJ`Ytm3rb9w|O^cL2*&~HEZ$*mZTBOwIg-CeRRvFZ~ zB@(=;B%>oD!GkipC=%?K*{DeHxr}Oj6$yTk(Qc9OE}5Ja3HQk4fmruld8~U+CR3u~ zoO5c+&zln!CuPtoDn8cAvNlgd#qCl%C00&2YOQ15iJ69|%3YV* zxDcM&VIw;|6T%xQHTrE*rzDR1V8Irt9Ck^Aq#9gyKtVQb`U4ZVOh=;|ezgDq002ov JPDHLkV1hje(8d4& literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_star_border_bookmark.png b/app/src/main/res/drawable-xhdpi/ic_star_border_bookmark.png new file mode 100644 index 0000000000000000000000000000000000000000..4f978e739be0ed5d39f670f7c0909bc82478b8b2 GIT binary patch literal 674 zcmV;T0$u%yP)K*Y%mIn+Eh%mnZ6d51%gpT2$9ufgb|VCqFT5UYl>n@ zXrjQu+BS$pLAD4+RB{Z{2(^WxQ)=qzS)9ei?p*GDnY#$)_urngdf(?*@V|3MsjWUW zu8o#C@0_c(%^RZhx;E){Oq7o5))tS8Y_+!7BeLDvV3nw8$h`Ydln#}m^nrP{*k7Xb zl2K8bHDF$C6s5EJ4VV?BQS+$NucGum7!#!#o#xFWwVzggZV#%c(^4zlXN~7=w%u2b zUh#A8$p<%S%oZCwY1oiux-_ufgelWbxFqWK7-@~D+a)LMGiAbh|Iu$sH0YRa(jvc$ z27Rkv9X-Z{%vp#1VA7bkz2FH$YTatBm%Za--`MLn=Y-6-9&_59Ll-@#70X>=&h1R5mF}+a>gtl04jYs;I+BQCcf`$YC=^B=M~d*MS>^ zlABcWY+g}%z3FdJ)2vN;@P{Zpt&&gjT#T3z+0UiO4!GZ!qV$nU4&^h8?6eKKN-sJs zvg4w3PzB3HZ9cPHGH8dW%~CB}Eo7$M<4X71CuAPgvaPv##;9)fEV9v=oO(~oeiWt8 zU89j}eIZKUYf+zn>^H0#4>;(&UM;!PYkD-R$0oOHlLZU@1-^1}ixkfOf&c&j07*qo IM6N<$f}P_@hX4Qo literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_star_bookmark.png b/app/src/main/res/drawable-xxhdpi/ic_star_bookmark.png new file mode 100644 index 0000000000000000000000000000000000000000..54d306599a5b5a269a3bd46a7636d5277ee37845 GIT binary patch literal 668 zcmV;N0%QG&P)L>hS~%Lf)(0@qL2a?)n8C8f?8A<)G~?|wF_Da zkx5u&xM?Rr(M8BKvKytAw|sM9a?mp$<2moS1n2i`X8Cf?4D)^;u~_Usv306Qxx;ND zWI3aZP>zBG8k$*1G0j9ok`D+%FG(U{KQdh-k?<6m?lBQijo8{m=x!pmt`o9l{6cIE zvn1S~{c%#*m2!*_CFntB^@aqY*^M|J|ORCBad48k$~%`7K2rEBLUXUO3cX6js(<0G8CYQTSx%iAW6Z_BEB}s zY3AuLqliz9a1a-^@fGo*FXV7(9d8lkUX#Uxa=H-3o>7KJDefUk-K7Kt30e?^E@7eO z1QUpd#%V@b9YcuAezFT6)bJ5;Q6JU#q!V#b2Rrmzc##mNsNgT_{S=S&01^kJ^m*u zDk{bsuSa>$dOb*;RxO6=F_uY^C3=Y74oH&ydg~GHl5)+`BW#s&HBf%nN+Q=NyS0+Y z+sbT+6OzbrgO$}|lKd7cqiRi({2Em&n>(dk2ONyg)0E8?Dc3T~Gm zxuY{KR~D;jpy3KWl zm-5s!)q|e4+6E2wIO2>{q&D>e>a|HlI^(FlzVneaR#<4N!Z6k$siZ!Uk58qNI%KR4 z)Y~nU(9QC3i&R3pU8IOwTROblN9@sHgSRX4Nk9Ac?F{s>k!T*X@Stq8cAdBJY;4HhNi; zzm2Mqfod;HBHuVyaSZf@B=V|inOUe!ihg#nVut%kirPFRV|O@~x2YBLjuag;UG`k> z&lutX#Vm+(|1wTD*%pIbrI^ui?)SP$KP|DfRVk(_w$)bsb&DIMT$>cf#yI~b-QtND z;K>Zm&p`ZQH_BIIrDxR?xuO}1IiW>A0W&n^?o!hP^mS6qIhl)9W1C=vjgrV`E)i@M zt5W7-U-4qBy5(^VA}1`-x7|z80-0Mc<(dv|_p4Mm``ikqiCePFHO6E95cTa|c22gt zRv)_1;CS?Cl(7q9pkF-I?p9Wpdfo0QidX6nc+`=z{2J4a@wNFt}KGC(l{z2uZ6 zGFfI;NYU3um9V>iD@9AQ|9|vB_bAnzc+UJ%MtW(Moc4-AI-}O>+9dy|mWgqa23PBf tF}6v@$i&_5({)wmnW>_pqN1Wy{{hTqL2tK~H?sf$002ovPDHLkV1ioS*IP))Ds3BGE_75> zPOm1pw?+)nYB^WuJ26Dx$hk$LN_Wb&Zc(M}a%`qPQKf%Pms`(^8tRZ!V;mMWbjbN~ zX_ct4R=M*&;+|hhV3$5!baOBGHR<)Qc!23$e?GX=;4&7 z-YKn8wkXA^*K58ETJwf>f2fnG>qWxNlBvf; z!aX8WZ;FK5B2&o^>U}aaU8K-dnR!6e)IqIU9TYWnpUiZMs`YuAYD$nzfRq6~@XO%-$enM!HiMxh8I9(>7vWvYk~)nr@6+1{46v%}ykw@b<$z7|6GP0Fqk z!cmWFl%z)OjtSv%sah#)GesJvc}sXus@lzyrUlxRN~Kb%R4SEf^dI`@Fkg>}l(ql> N002ovPDHLkV1i1ArFsAW literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_star_border_bookmark.png b/app/src/main/res/drawable-xxxhdpi/ic_star_border_bookmark.png new file mode 100644 index 0000000000000000000000000000000000000000..041aa6b035839064904920e78f21ee348d67cacb GIT binary patch literal 1301 zcmV+w1?u{VP)c6JUk$-Lgr zCNmEvXXec3m(kYN*4Eb6K=V)4(jN4H7B<~W{$sk9b(0Xjpha~%EQG_lwWKS>D}6*u zdP2O?E-mPtBG)`E=U$QPUM*&-6C&53GqjZTLfSelq|*T*?SM`#;|fvGGA-kAQPAUB z#9YIopkZ^hgu6tQHfjM=3vs?$MHQ-cn8%44>;)wQm&$UJ8m(Mm(2&aPMFdQoRXRvLxHj*B`v zVQTe*ejOdR*eG4#kQj6Kspft$<_>v>8l2-9Q9~6+{LwExY@<1E0G|F-(MAESJ>a@a1A?+58uvSGRowS1bEz~chJ!GQs)McZPcEm#CWVSyG zX}e4{UM6`=NPEs~<7lcUgtYz6Hy&nqT1fkqGmW#;Y!%Y_El{tw`t9g zVYzzr7Th*()1hHj84^hqYmL>_{wtD(^l7jq1yk=XU26ALA#K1?C79>$LfQ_K)MBCs zg|x%wDM``P+ocvegtR@*Riep$P}koVKNLwnGDXR{Y!(c92y36YP6n|Lc`he2i zByydt*lg!3HcjOElG6QH$oi`yr~9&#r@GncitHD%exhWZ$s+nTNPW=rxi@$@NNq`0 zP?u6&C~~cmI$@ z)!U~RnHQ2%SecSR{V3o~z9&Y}cbx+y&p)I@GexfTnBWG3Vw4S7s~gveTr-vCDv@iU zUi(Br{jNDxzbI(0OI##!eN1UK30cFoi-Icd_IhxJO)8?Gt;yqeE6rXpLQi?Oy!Y5G zMre% zq7=JCLC1Vjr_t#2DgP7&{Xz*Q6byx7_nD>^Z}2U{1!JRI!@XBX`<;u8#ry0L(k{|) z>qM>>t4Ykf?8flTWMyai>t*x!Ct*z~UEXm2dWH1Qc00000 LNkvXXu0mjft+bU- literal 0 HcmV?d00001 diff --git a/app/src/main/res/menu/menu_session_detail.xml b/app/src/main/res/menu/menu_session_detail.xml index 8d85d708a..c5af77cd2 100644 --- a/app/src/main/res/menu/menu_session_detail.xml +++ b/app/src/main/res/menu/menu_session_detail.xml @@ -2,9 +2,8 @@ \ No newline at end of file