diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index aa07eb5a3..dd76ffc53 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -22,13 +22,13 @@ import android.os.Build; import android.os.Bundle; import android.text.Html; import android.text.SpannableString; -import android.util.Log; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.json.JSONArray; import org.json.JSONException; @@ -42,7 +42,6 @@ import java.io.IOException; import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; -import java.net.HttpURLConnection; import java.net.URLEncoder; import java.net.UnknownHostException; import java.security.KeyManagementException; @@ -1646,19 +1645,65 @@ public class API { attachment.setRemote_url(resobj.getString("remote_url")); } catch (JSONException ignore) { } + if (attachment.getRemote_url() != null && attachment.getRemote_url().toLowerCase().compareTo("null") == 0) { + attachment.setRemote_url(null); + } try { attachment.setPreview_url(resobj.getString("preview_url")); } catch (JSONException ignore) { } + if (attachment.getPreview_url() != null && attachment.getPreview_url().toLowerCase().compareTo("null") == 0) { + attachment.setPreview_url(null); + } try { attachment.setMeta(resobj.getString("meta")); } catch (JSONException ignore) { } + if (attachment.getMeta() != null && attachment.getMeta().toLowerCase().compareTo("null") == 0) { + attachment.setMeta(null); + } try { attachment.setText_url(resobj.getString("text_url")); } catch (JSONException ignore) { } - + if (attachment.getText_url() != null && attachment.getText_url().toLowerCase().compareTo("null") == 0) { + attachment.setText_url(null); + } + try { + attachment.setMime(resobj.getString("mime")); + } catch (JSONException ignore) { + } + if (attachment.getMime() != null && attachment.getMime().toLowerCase().compareTo("null") == 0) { + attachment.setMime(null); + } + try { + attachment.setFilter_class(resobj.getString("filter_class")); + } catch (JSONException ignore) { + } + if (attachment.getFilter_class() != null && attachment.getFilter_class().toLowerCase().compareTo("null") == 0) { + attachment.setFilter_class(null); + } + try { + attachment.setFilter_name(resobj.getString("filter_name")); + } catch (JSONException ignore) { + } + if (attachment.getFilter_name() != null && attachment.getFilter_name().toLowerCase().compareTo("null") == 0) { + attachment.setFilter_name(null); + } + try { + attachment.setLicense(resobj.getString("license")); + } catch (JSONException ignore) { + } + if (attachment.getLicense() != null && attachment.getLicense().toLowerCase().compareTo("null") == 0) { + attachment.setLicense(null); + } + try { + attachment.setOrientation(resobj.getString("orientation")); + } catch (JSONException ignore) { + } + if (attachment.getOrientation() != null && attachment.getOrientation().toLowerCase().compareTo("null") == 0) { + attachment.setOrientation(null); + } } catch (JSONException ignored) { } return attachment; @@ -4529,9 +4574,9 @@ public class API { default: return -1; } - if (statusAction != StatusAction.UNSTATUS + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED || (statusAction != StatusAction.UNSTATUS && statusAction != StatusAction.ADD_REACTION && statusAction != StatusAction.REMOVE_REACTION - && statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) { + && statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION)) { try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); String url; @@ -4540,25 +4585,23 @@ public class API { } else { url = "https://" + Helper.getLiveInstance(context) + action; } - String resp = httpsConnection.post(getAbsoluteUrl(url), 10, params, prefKeyOauthTokenT); + String resp = httpsConnection.post(url, 10, params, prefKeyOauthTokenT); actionCode = httpsConnection.getActionCode(); - if (statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) { - Bundle b = new Bundle(); - try { - Status status1 = parseStatuses(context, new JSONObject(resp)); - b.putParcelable("status", status1); - } catch (JSONException ignored) { - } - Intent intentBC = new Intent(Helper.RECEIVE_ACTION); - intentBC.putExtras(b); - LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC); - SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT); - Status indb = new TimelineCacheDAO(context, db).getSingle(targetedId); - if (indb != null) { - String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT); - new TimelineCacheDAO(context, db).update(targetedId, response, account.getId(), account.getInstance()); - } + Bundle b = new Bundle(); + try { + Status status1 = parseStatuses(context, new JSONObject(resp)); + b.putParcelable("status", status1); + } catch (JSONException ignored) { + } + Intent intentBC = new Intent(Helper.RECEIVE_ACTION); + intentBC.putExtras(b); + LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC); + SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT); + Status indb = new TimelineCacheDAO(context, db).getSingle(targetedId); + if (indb != null && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { + String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT); + new TimelineCacheDAO(context, db).update(targetedId, response, account.getId(), account.getInstance()); } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); @@ -4816,22 +4859,38 @@ public class API { } else { url = "https://" + Helper.getLiveInstance(context) + "/api/local/status/compose"; jsonObject.addProperty("caption", status.getContent()); - jsonObject.addProperty("comments_disabled", status.getContent()); + jsonObject.addProperty("comments_disabled", false); jsonObject.addProperty("cw", status.isSensitive()); jsonObject.addProperty("visibility", status.getVisibility()); - String attachments = new Gson().toJson(status.getMedia_attachments()); - jsonObject.addProperty("media", attachments); + String attachments = new GsonBuilder().serializeNulls().create().toJson(status.getMedia_attachments()); + jsonObject.addProperty("place", false); + JsonParser parser = new JsonParser(); + JsonArray jsonArrayTags = parser.parse("[]").getAsJsonArray(); + + jsonObject.add("tagged", jsonArrayTags); + JsonArray jsonArrayMedia = parser.parse(attachments).getAsJsonArray(); + jsonObject.add("media", jsonArrayMedia); } } statuses = new ArrayList<>(); try { - HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); String response = httpsConnection.postJson(url, 10, jsonObject, prefKeyOauthTokenT); - Status statusreturned = parseStatuses(context, new JSONObject(response)); - statuses.add(statusreturned); - setStatusesMaxId(httpsConnection, statuses); + if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { + Status statusreturned = parseStatuses(context, new JSONObject(response)); + statuses.add(statusreturned); + setStatusesMaxId(httpsConnection, statuses); + } else { + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); + Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); + status.setAccount(account); + statuses.add(status); + setStatusesMaxId(httpsConnection, statuses); + } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Attachment.java b/app/src/main/java/app/fedilab/android/client/Entities/Attachment.java index ca63af1bc..324198dce 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Attachment.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Attachment.java @@ -37,8 +37,12 @@ public class Attachment implements Parcelable { } }; private String id; - private int viewId; + private transient int viewId; private String type; + private String mime; + private String filter_class; + private String filter_name; + private String license; private String url; private String remote_url; private String preview_url; @@ -46,6 +50,7 @@ public class Attachment implements Parcelable { private String text_url; private String description; private String local_path; + private String orientation; private boolean is_nsfw = false; public Attachment() { @@ -56,6 +61,10 @@ public class Attachment implements Parcelable { this.id = in.readString(); this.viewId = in.readInt(); this.type = in.readString(); + this.mime = in.readString(); + this.filter_class = in.readString(); + this.filter_name = in.readString(); + this.license = in.readString(); this.url = in.readString(); this.remote_url = in.readString(); this.preview_url = in.readString(); @@ -63,6 +72,7 @@ public class Attachment implements Parcelable { this.text_url = in.readString(); this.description = in.readString(); this.local_path = in.readString(); + this.orientation = in.readString(); this.is_nsfw = in.readByte() != 0; } @@ -154,6 +164,46 @@ public class Attachment implements Parcelable { this.is_nsfw = is_nsfw; } + public String getFilter_class() { + return filter_class; + } + + public void setFilter_class(String filter_class) { + this.filter_class = filter_class; + } + + public String getFilter_name() { + return filter_name; + } + + public void setFilter_name(String filter_name) { + this.filter_name = filter_name; + } + + public String getLicense() { + return license; + } + + public void setLicense(String license) { + this.license = license; + } + + public String getMime() { + return mime; + } + + public void setMime(String mime) { + this.mime = mime; + } + + public String getOrientation() { + return orientation; + } + + public void setOrientation(String orientation) { + this.orientation = orientation; + } + @Override public int describeContents() { return 0; @@ -164,6 +214,10 @@ public class Attachment implements Parcelable { dest.writeString(this.id); dest.writeInt(this.viewId); dest.writeString(this.type); + dest.writeString(this.mime); + dest.writeString(this.filter_class); + dest.writeString(this.filter_name); + dest.writeString(this.license); dest.writeString(this.url); dest.writeString(this.remote_url); dest.writeString(this.preview_url); @@ -171,6 +225,7 @@ public class Attachment implements Parcelable { dest.writeString(this.text_url); dest.writeString(this.description); dest.writeString(this.local_path); + dest.writeString(this.orientation); dest.writeByte(this.is_nsfw ? (byte) 1 : (byte) 0); } } diff --git a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java index 57f45b61f..6327b8335 100644 --- a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java +++ b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java @@ -624,6 +624,11 @@ public class HttpsConnection { ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance)); } httpURLConnection.setRequestProperty("User-Agent", USER_AGENT); + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); + String cookie = token.split("\\|")[1]; + httpURLConnection.setRequestProperty("Cookie", cookie); + } int responseCode = httpURLConnection.getResponseCode(); // always check HTTP response code first if (responseCode >= 200 && responseCode < 400) { diff --git a/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java b/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java index 0592d7cd4..0445b204a 100644 --- a/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java +++ b/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -107,9 +108,14 @@ public class PixelfedAPI { pixelFedStory.setName(jsonObject.getString("name")); pixelFedStory.setLink(jsonObject.getString("link")); pixelFedStory.setLastUpdated(new Date(jsonObject.getLong("lastUpdated"))); - pixelFedStory.setSeen(jsonObject.getBoolean("seen")); + if (jsonObject.has("seen") && !jsonObject.isNull("seen")) { + pixelFedStory.setSeen(jsonObject.getBoolean("seen")); + } else { + pixelFedStory.setSeen(false); + } pixelFedStory.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items"))); } catch (JSONException ignored) { + ignored.printStackTrace(); } return pixelFedStory; } @@ -158,6 +164,7 @@ public class PixelfedAPI { pixelFedStoryItem.setExpires_at(new Date(jsonObject.getLong("expires_at"))); pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen")); } catch (JSONException ignored) { + ignored.printStackTrace(); } return pixelFedStoryItem; } @@ -201,7 +208,7 @@ public class PixelfedAPI { params.put("max_id", max_id); try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); - String response = httpsConnection.get(getAbsoluteUrl("/fetch/" + userId), 10, params, prefKeyOauthTokenT); + String response = httpsConnection.get(getAbsoluteUrl("/profile/" + userId), 10, params, prefKeyOauthTokenT); apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setMax_id(httpsConnection.getMax_id()); pixelFedStories = parseStories(new JSONArray(response)); diff --git a/app/src/main/java/app/fedilab/android/drawers/BaseNotificationsListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/BaseNotificationsListAdapter.java index 01f9fddb7..d1ec5fcc2 100644 --- a/app/src/main/java/app/fedilab/android/drawers/BaseNotificationsListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/BaseNotificationsListAdapter.java @@ -33,7 +33,6 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.text.style.ForegroundColorSpan; -import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; diff --git a/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java index 5a4b21191..28ff0f064 100644 --- a/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java @@ -732,161 +732,155 @@ public class PixelfedListAdapter extends RecyclerView.Adapter { AlertDialog.Builder builderInner; final API.StatusAction doAction; - switch (item.getItemId()) { - case R.id.action_redraft: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[1]); - redraft = true; - doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_schedule_boost: - scheduleBoost(status); - return true; - case R.id.action_info: - tootInformation(status); - return true; - case R.id.action_open_browser: - Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); - return true; - case R.id.action_remove: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[0]); - doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_block_domain: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[3]); - doAction = API.StatusAction.BLOCK_DOMAIN; - String domain = status.getAccount().getAcct().split("@")[1]; - builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain)); - break; - case R.id.action_mute: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[0]); - builderInner.setMessage(status.getAccount().getAcct()); - doAction = API.StatusAction.MUTE; - break; - case R.id.action_mute_conversation: - if (status.isMuted()) - doAction = API.StatusAction.UNMUTE_CONVERSATION; - else - doAction = API.StatusAction.MUTE_CONVERSATION; + int itemId = item.getItemId(); + if (itemId == R.id.action_redraft) { + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[1]); + redraft = true; + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + builderInner.setMessage(Html.fromHtml(status.getContent())); + } else if (itemId == R.id.action_schedule_boost) { + scheduleBoost(status); + return true; + } else if (itemId == R.id.action_info) { + tootInformation(status); + return true; + } else if (itemId == R.id.action_open_browser) { + Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); + return true; + } else if (itemId == R.id.action_remove) { + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + builderInner.setMessage(Html.fromHtml(status.getContent())); + } else if (itemId == R.id.action_block_domain) { + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[3]); + doAction = API.StatusAction.BLOCK_DOMAIN; + String domain = status.getAccount().getAcct().split("@")[1]; + builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain)); + } else if (itemId == R.id.action_mute) { + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[0]); + builderInner.setMessage(status.getAccount().getAcct()); + doAction = API.StatusAction.MUTE; + } else if (itemId == R.id.action_mute_conversation) { + if (status.isMuted()) + doAction = API.StatusAction.UNMUTE_CONVERSATION; + else + doAction = API.StatusAction.MUTE_CONVERSATION; - new PostActionAsyncTask(context, doAction, status.getId(), PixelfedListAdapter.this); - return true; - case R.id.action_bookmark: - if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) { - status.setBookmarked(!status.isBookmarked()); - final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - try { - if (status.isBookmarked()) { - new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); - Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show(); - } else { - new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); - Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); - } - notifyStatusChanged(status); - } catch (Exception e) { - e.printStackTrace(); - Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + new PostActionAsyncTask(context, doAction, status.getId(), PixelfedListAdapter.this); + return true; + } else if (itemId == R.id.action_bookmark) { + if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) { + status.setBookmarked(!status.isBookmarked()); + final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + try { + if (status.isBookmarked()) { + new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); + Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show(); + } else { + new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); + Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); } - } else { - int position = 0; - for (Status statustmp : statuses) { - if (statustmp.getId().equals(status.getId())) { - statuses.remove(status); - pixelfedListAdapter.notifyItemRemoved(position); - final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp); - Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); - break; - } - position++; + notifyStatusChanged(status); + } catch (Exception e) { + e.printStackTrace(); + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } + } else { + int position = 0; + for (Status statustmp : statuses) { + if (statustmp.getId().equals(status.getId())) { + statuses.remove(status); + pixelfedListAdapter.notifyItemRemoved(position); + final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp); + Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); + break; } + position++; } - return true; - case R.id.action_timed_mute: - timedMuteAction(status); - return true; - case R.id.action_block: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[1]); - doAction = API.StatusAction.BLOCK; - break; - case R.id.action_translate: - int translator = sharedpreferences1.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE); - if (translator == Helper.TRANS_NONE) - Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show(); + } + return true; + } else if (itemId == R.id.action_timed_mute) { + timedMuteAction(status); + return true; + } else if (itemId == R.id.action_block) { + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[1]); + doAction = API.StatusAction.BLOCK; + } else if (itemId == R.id.action_translate) { + int translator = sharedpreferences1.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE); + if (translator == Helper.TRANS_NONE) + Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show(); + else + translateToot(status); + return true; + } else if (itemId == R.id.action_report) { + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[2]); + doAction = API.StatusAction.REPORT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + builderInner.setMessage(Html.fromHtml(status.getContent())); + } else if (itemId == R.id.action_copy_link) { + ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + + ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); + if (clipboard != null) { + clipboard.setPrimaryClip(clip); + Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); + } + return true; + } else if (itemId == R.id.action_share) { + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); + String url; + + if (status.getReblog() != null) { + if (status.getReblog().getUri().startsWith("http")) + url = status.getReblog().getUri(); else - translateToot(status); - return true; - case R.id.action_report: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[2]); - doAction = API.StatusAction.REPORT; + url = status.getReblog().getUrl(); + } else { + if (status.getUri().startsWith("http")) + url = status.getUri(); + else + url = status.getUrl(); + } + String extra_text; + boolean share_details = sharedpreferences1.getBoolean(Helper.SET_SHARE_DETAILS, true); + if (share_details) { + extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct(); + if (extra_text.split("@").length == 1) + extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context); + else + extra_text = "@" + extra_text; + extra_text += " \uD83D\uDD17 " + url + "\r\n-\n"; + final String contentToot; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); else - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_copy_link: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); - if (clipboard != null) { - clipboard.setPrimaryClip(clip); - Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); - } - return true; - case R.id.action_share: - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - String url; - - if (status.getReblog() != null) { - if (status.getReblog().getUri().startsWith("http")) - url = status.getReblog().getUri(); - else - url = status.getReblog().getUrl(); - } else { - if (status.getUri().startsWith("http")) - url = status.getUri(); - else - url = status.getUrl(); - } - String extra_text; - boolean share_details = sharedpreferences1.getBoolean(Helper.SET_SHARE_DETAILS, true); - if (share_details) { - extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct(); - if (extra_text.split("@").length == 1) - extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context); - else - extra_text = "@" + extra_text; - extra_text += " \uD83D\uDD17 " + url + "\r\n-\n"; - final String contentToot; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString(); - extra_text += contentToot; - } else { - extra_text = url; - } - sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return true; - default: - return true; + contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString(); + extra_text += contentToot; + } else { + extra_text = url; + } + sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); + sendIntent.setType("text/plain"); + context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + return true; + } else { + return true; } //Text for report diff --git a/app/src/main/java/app/fedilab/android/drawers/PixelfedStoriesListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/PixelfedStoriesListAdapter.java index a2fe1adb2..352ac9258 100644 --- a/app/src/main/java/app/fedilab/android/drawers/PixelfedStoriesListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/PixelfedStoriesListAdapter.java @@ -108,28 +108,35 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter(); + if (pixelFedStory != null && pixelFedStory.getPixelFedStoryItems() != null) { + for (PixelFedStoryItem pixelFedStoryItem : pixelFedStory.getPixelFedStoryItems()) { + Attachment attachment = new Attachment(); - for (PixelFedStoryItem pixelFedStoryItem : pixelFedStory.getPixelFedStoryItems()) { - Attachment attachment = new Attachment(); - - if (pixelFedStoryItem.getPreview() != null) { - attachment.setPreview_url(pixelFedStoryItem.getPreview()); - } else { - attachment.setPreview_url(pixelFedStoryItem.getSrc()); + if (pixelFedStoryItem.getPreview() != null && pixelFedStoryItem.getPreview().toLowerCase().compareTo("null") != 0) { + attachment.setPreview_url(pixelFedStoryItem.getPreview()); + } else { + attachment.setPreview_url(pixelFedStoryItem.getSrc()); + } + attachment.setUrl(pixelFedStoryItem.getSrc()); + attachment.setId(pixelFedStoryItem.getId()); + attachment.setId(pixelFedStoryItem.getId()); + attachment.setDescription(pixelFedStoryItem.getLinkText()); + attachment.setType(pixelFedStoryItem.getType()); + attachments.add(attachment); } - attachment.setUrl(pixelFedStoryItem.getSrc()); - attachment.setId(pixelFedStoryItem.getId()); - attachment.setId(pixelFedStoryItem.getId()); - attachment.setDescription(pixelFedStoryItem.getLinkText()); - attachment.setType(pixelFedStoryItem.getType()); + + Glide.with(context) + .load(pixelFedStory.getPhoto()) + .apply(new RequestOptions().transform(new FitCenter(), new RoundedCorners(270))) + .into(holder.pf_pp); + + + holder.pf_date.setText(Helper.longDateToString(pixelFedStory.getLastUpdated())); + + + holder.pf_username.setText(pixelFedStory.getName()); + } - - Glide.with(context) - .load(pixelFedStory.getPhoto()) - .apply(new RequestOptions().transform(new FitCenter(), new RoundedCorners(270))) - .into(holder.pf_pp); - - holder.art_media.setOnClickListener(v -> { Intent intent = new Intent(context, SlideMediaActivity.class); Bundle b = new Bundle(); @@ -150,7 +157,6 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter 1) { SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, attachments); holder.imageSlider.setSliderAdapter(sliderAdapter); @@ -158,7 +164,7 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter 0) { holder.art_media.setVisibility(View.VISIBLE); holder.imageSlider.setVisibility(View.GONE); if (attachments.get(0).getType().toLowerCase().equals("video")) { @@ -177,11 +183,6 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter() { @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayNotificationsFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayNotificationsFragment.java index 249dccb04..ff72e13b1 100644 --- a/app/src/main/java/app/fedilab/android/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/DisplayNotificationsFragment.java @@ -24,7 +24,6 @@ import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;