Adds icon for bookmark + handles click and fixes an error

This commit is contained in:
stom79 2018-02-15 11:18:40 +01:00
parent c3fa7cd4c5
commit b6751f8852
18 changed files with 65 additions and 15 deletions

View File

@ -1683,11 +1683,13 @@ public class API {
//Retrieve Application
Application application = new Application();
JSONObject arrayApplication = resobj.getJSONObject("application");
if( arrayApplication != null){
application.setName(arrayApplication.get("name").toString());
application.setWebsite(arrayApplication.get("website").toString());
}
try {
JSONObject arrayApplication = resobj.getJSONObject("application");
if( arrayApplication != null){
application.setName(arrayApplication.get("name").toString());
application.setWebsite(arrayApplication.get("website").toString());
}
}catch (Exception ignored){}
status.setApplication(application);
@ -1703,7 +1705,7 @@ public class API {
try {
status.setFavourited(Boolean.valueOf(resobj.get("favourited").toString()));
}catch (Exception e){
status.setReblogged(false);
status.setFavourited(false);
}
try {
status.setMuted(Boolean.valueOf(resobj.get("muted").toString()));
@ -1717,8 +1719,8 @@ public class API {
}
try{
status.setReblog(parseStatuses(context, resobj.getJSONObject("reblog")));
}catch (Exception ignored){}
} catch (JSONException ignored) {}
}catch (Exception ignored){ignored.printStackTrace();}
} catch (JSONException ignored) {ignored.printStackTrace();}
return status;
}

View File

@ -79,6 +79,7 @@ public class Status implements Parcelable{
private boolean muted;
private boolean pinned;
private boolean sensitive;
private boolean bookmarked;
private String visibility;
private boolean attachmentShown = false;
private boolean spoilerShown = false;
@ -775,4 +776,12 @@ public class Status implements Parcelable{
public void setMuted(boolean muted) {
this.muted = muted;
}
public boolean isBookmarked() {
return bookmarked;
}
public void setBookmarked(boolean bookmarked) {
this.bookmarked = bookmarked;
}
}

View File

@ -110,6 +110,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
@ -262,7 +263,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
TextView status_reply;
ImageView status_pin;
ImageView status_privacy;
FloatingActionButton status_translate;
FloatingActionButton status_translate, status_bookmark;
LinearLayout status_container2;
LinearLayout status_container3;
LinearLayout main_container;
@ -316,6 +317,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
status_reply = itemView.findViewById(R.id.status_reply);
status_privacy = itemView.findViewById(R.id.status_privacy);
status_translate = itemView.findViewById(R.id.status_translate);
status_bookmark = itemView.findViewById(R.id.status_bookmark);
status_content_translated_container = itemView.findViewById(R.id.status_content_translated_container);
main_container = itemView.findViewById(R.id.main_container);
status_spoiler_container = itemView.findViewById(R.id.status_spoiler_container);
@ -468,6 +470,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_replies.setVisibility(View.GONE);
}
}
if( status.isBookmarked())
holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark));
else
holder.status_bookmark.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark_border));
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4);
if( status.isNew())
holder.new_element.setVisibility(View.VISIBLE);
@ -596,6 +602,27 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
}
});
holder.status_bookmark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( status.isBookmarked()){
Status status1 = new StatusCacheDAO(context, db).getStatus(status.getId());
if( status1 == null)
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
else
new StatusCacheDAO(context, db).updateStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
status.setBookmarked(true);
Toast.makeText(context, R.string.status_bookmarked, Toast.LENGTH_LONG).show();
}else {
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status);
status.setBookmarked(false);
Toast.makeText(context, R.string.status_unbookmarked, Toast.LENGTH_LONG).show();
}
notifyStatusChanged(status);
}
});
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
//-------- END -> Manages translations

View File

@ -100,7 +100,7 @@ public class StatusCacheDAO {
* @param status Status
* @return boolean
*/
public int updateStatus(Status status ) {
public int updateStatus(int cacheType, Status status ) {
ContentValues values = new ContentValues();
String instance = Helper.getLiveInstance(context);
values.put(Sqlite.COL_REBLOGS_COUNT, status.getReblogs_count());
@ -110,8 +110,8 @@ public class StatusCacheDAO {
values.put(Sqlite.COL_MUTED, status.isMuted());
values.put(Sqlite.COL_PINNED, status.isPinned());
return db.update(Sqlite.TABLE_STATUSES_CACHE,
values, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_INSTANCE + " = ? ",
new String[]{String.valueOf(status.getId()), instance});
values, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_INSTANCE + " = ? " + Sqlite.COL_CACHED_ACTION + " = ?",
new String[]{String.valueOf(status.getId()), instance, String.valueOf(cacheType)});
}
@ -121,9 +121,9 @@ public class StatusCacheDAO {
* Remove stored status
* @return int
*/
public int remove(Status status){
public int remove(int cacheType, Status status){
String instance = Helper.getLiveInstance(context);
return db.delete(Sqlite.TABLE_STATUSES_CACHE, Sqlite.COL_STATUS_ID + " = \"" + status.getId() + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\"", null);
return db.delete(Sqlite.TABLE_STATUSES_CACHE, Sqlite.COL_CACHED_ACTION + " = \""+ cacheType +"\" AND " + Sqlite.COL_STATUS_ID + " = \"" + status.getId() + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\"", null);
}
public int removeAllStatus(int cacheType){
@ -151,7 +151,7 @@ public class StatusCacheDAO {
* Returns a cached status by id in db
* @return stored status StoredStatus
*/
public Status getStatus(long id){
public Status getStatus(String id){
String instance = Helper.getLiveInstance(context);
try {
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_STATUS_ID + " = '" + id + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance, null, null, null, null, null);

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

View File

@ -90,6 +90,14 @@
app:fabSize="mini"
android:layout_marginTop="10dp"
android:src="@drawable/ic_translate" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/status_bookmark"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_horizontal"
app:fabSize="mini"
android:layout_marginTop="10dp"
android:src="@drawable/ic_bookmark_border" />
</LinearLayout>
<LinearLayout
android:layout_marginStart="5dp"

View File

@ -138,6 +138,10 @@
<item quantity="one">%d reply</item>
<item quantity="other">%d replies</item>
</plurals>
<string name="status_bookmarked">Status has been added to bookmarks!</string>
<string name="status_unbookmarked">Status was removed from bookmarks!</string>
<!-- Date -->
<string name="date_seconds">%d s</string>
<string name="date_minutes">%d m</string>