Adds icon for bookmark + handles click and fixes an error
|
@ -1683,11 +1683,13 @@ public class API {
|
||||||
|
|
||||||
//Retrieve Application
|
//Retrieve Application
|
||||||
Application application = new Application();
|
Application application = new Application();
|
||||||
JSONObject arrayApplication = resobj.getJSONObject("application");
|
try {
|
||||||
if( arrayApplication != null){
|
JSONObject arrayApplication = resobj.getJSONObject("application");
|
||||||
application.setName(arrayApplication.get("name").toString());
|
if( arrayApplication != null){
|
||||||
application.setWebsite(arrayApplication.get("website").toString());
|
application.setName(arrayApplication.get("name").toString());
|
||||||
}
|
application.setWebsite(arrayApplication.get("website").toString());
|
||||||
|
}
|
||||||
|
}catch (Exception ignored){}
|
||||||
status.setApplication(application);
|
status.setApplication(application);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1703,7 +1705,7 @@ public class API {
|
||||||
try {
|
try {
|
||||||
status.setFavourited(Boolean.valueOf(resobj.get("favourited").toString()));
|
status.setFavourited(Boolean.valueOf(resobj.get("favourited").toString()));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
status.setReblogged(false);
|
status.setFavourited(false);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
status.setMuted(Boolean.valueOf(resobj.get("muted").toString()));
|
status.setMuted(Boolean.valueOf(resobj.get("muted").toString()));
|
||||||
|
@ -1717,8 +1719,8 @@ public class API {
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
status.setReblog(parseStatuses(context, resobj.getJSONObject("reblog")));
|
status.setReblog(parseStatuses(context, resobj.getJSONObject("reblog")));
|
||||||
}catch (Exception ignored){}
|
}catch (Exception ignored){ignored.printStackTrace();}
|
||||||
} catch (JSONException ignored) {}
|
} catch (JSONException ignored) {ignored.printStackTrace();}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class Status implements Parcelable{
|
||||||
private boolean muted;
|
private boolean muted;
|
||||||
private boolean pinned;
|
private boolean pinned;
|
||||||
private boolean sensitive;
|
private boolean sensitive;
|
||||||
|
private boolean bookmarked;
|
||||||
private String visibility;
|
private String visibility;
|
||||||
private boolean attachmentShown = false;
|
private boolean attachmentShown = false;
|
||||||
private boolean spoilerShown = false;
|
private boolean spoilerShown = false;
|
||||||
|
@ -775,4 +776,12 @@ public class Status implements Parcelable{
|
||||||
public void setMuted(boolean muted) {
|
public void setMuted(boolean muted) {
|
||||||
this.muted = muted;
|
this.muted = muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBookmarked() {
|
||||||
|
return bookmarked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBookmarked(boolean bookmarked) {
|
||||||
|
this.bookmarked = bookmarked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
|
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
|
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
|
||||||
|
|
||||||
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
|
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
|
||||||
|
@ -262,7 +263,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
TextView status_reply;
|
TextView status_reply;
|
||||||
ImageView status_pin;
|
ImageView status_pin;
|
||||||
ImageView status_privacy;
|
ImageView status_privacy;
|
||||||
FloatingActionButton status_translate;
|
FloatingActionButton status_translate, status_bookmark;
|
||||||
LinearLayout status_container2;
|
LinearLayout status_container2;
|
||||||
LinearLayout status_container3;
|
LinearLayout status_container3;
|
||||||
LinearLayout main_container;
|
LinearLayout main_container;
|
||||||
|
@ -316,6 +317,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
status_reply = itemView.findViewById(R.id.status_reply);
|
status_reply = itemView.findViewById(R.id.status_reply);
|
||||||
status_privacy = itemView.findViewById(R.id.status_privacy);
|
status_privacy = itemView.findViewById(R.id.status_privacy);
|
||||||
status_translate = itemView.findViewById(R.id.status_translate);
|
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);
|
status_content_translated_container = itemView.findViewById(R.id.status_content_translated_container);
|
||||||
main_container = itemView.findViewById(R.id.main_container);
|
main_container = itemView.findViewById(R.id.main_container);
|
||||||
status_spoiler_container = itemView.findViewById(R.id.status_spoiler_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);
|
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);
|
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4);
|
||||||
if( status.isNew())
|
if( status.isNew())
|
||||||
holder.new_element.setVisibility(View.VISIBLE);
|
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());
|
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
//-------- END -> Manages translations
|
//-------- END -> Manages translations
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class StatusCacheDAO {
|
||||||
* @param status Status
|
* @param status Status
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public int updateStatus(Status status ) {
|
public int updateStatus(int cacheType, Status status ) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
String instance = Helper.getLiveInstance(context);
|
String instance = Helper.getLiveInstance(context);
|
||||||
values.put(Sqlite.COL_REBLOGS_COUNT, status.getReblogs_count());
|
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_MUTED, status.isMuted());
|
||||||
values.put(Sqlite.COL_PINNED, status.isPinned());
|
values.put(Sqlite.COL_PINNED, status.isPinned());
|
||||||
return db.update(Sqlite.TABLE_STATUSES_CACHE,
|
return db.update(Sqlite.TABLE_STATUSES_CACHE,
|
||||||
values, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_INSTANCE + " = ? ",
|
values, Sqlite.COL_STATUS_ID + " = ? AND " + Sqlite.COL_INSTANCE + " = ? " + Sqlite.COL_CACHED_ACTION + " = ?",
|
||||||
new String[]{String.valueOf(status.getId()), instance});
|
new String[]{String.valueOf(status.getId()), instance, String.valueOf(cacheType)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,9 +121,9 @@ public class StatusCacheDAO {
|
||||||
* Remove stored status
|
* Remove stored status
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public int remove(Status status){
|
public int remove(int cacheType, Status status){
|
||||||
String instance = Helper.getLiveInstance(context);
|
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){
|
public int removeAllStatus(int cacheType){
|
||||||
|
@ -151,7 +151,7 @@ public class StatusCacheDAO {
|
||||||
* Returns a cached status by id in db
|
* Returns a cached status by id in db
|
||||||
* @return stored status StoredStatus
|
* @return stored status StoredStatus
|
||||||
*/
|
*/
|
||||||
public Status getStatus(long id){
|
public Status getStatus(String id){
|
||||||
String instance = Helper.getLiveInstance(context);
|
String instance = Helper.getLiveInstance(context);
|
||||||
try {
|
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);
|
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_STATUS_ID + " = '" + id + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance, null, null, null, null, null);
|
||||||
|
|
After Width: | Height: | Size: 164 B |
After Width: | Height: | Size: 229 B |
After Width: | Height: | Size: 218 B |
After Width: | Height: | Size: 269 B |
After Width: | Height: | Size: 134 B |
After Width: | Height: | Size: 168 B |
After Width: | Height: | Size: 190 B |
After Width: | Height: | Size: 247 B |
After Width: | Height: | Size: 269 B |
After Width: | Height: | Size: 359 B |
After Width: | Height: | Size: 280 B |
After Width: | Height: | Size: 401 B |
|
@ -90,6 +90,14 @@
|
||||||
app:fabSize="mini"
|
app:fabSize="mini"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:src="@drawable/ic_translate" />
|
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>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
|
|
|
@ -138,6 +138,10 @@
|
||||||
<item quantity="one">%d reply</item>
|
<item quantity="one">%d reply</item>
|
||||||
<item quantity="other">%d replies</item>
|
<item quantity="other">%d replies</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
||||||
|
<string name="status_bookmarked">Status has been added to bookmarks!</string>
|
||||||
|
<string name="status_unbookmarked">Status was removed from bookmarks!</string>
|
||||||
|
|
||||||
<!-- Date -->
|
<!-- Date -->
|
||||||
<string name="date_seconds">%d s</string>
|
<string name="date_seconds">%d s</string>
|
||||||
<string name="date_minutes">%d m</string>
|
<string name="date_minutes">%d m</string>
|
||||||
|
|