diff --git a/app/build.gradle b/app/build.gradle index f9ec5c589..d3a7f5e87 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -80,7 +80,7 @@ dependencies { implementation "com.github.stom79:SwipeBackLayout:$swipebackLibraryVersion" implementation 'com.github.stom79:country-picker-android:1.2.0' implementation 'com.github.stom79:mytransl:1.5' - implementation 'com.github.stom79:SparkButton:1.0.10' + implementation 'com.github.stom79:SparkButton:1.0.12' implementation "com.koushikdutta.async:androidasync:2.+" implementation 'com.vanniktech:emoji-one:0.6.0-SNAPSHOT' implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2' diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 1b228cdb7..3c24b545a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -260,6 +260,9 @@ public class API { try { String response = new HttpsConnection(context).get(getAbsoluteUrl("/accounts/verify_credentials"), 60, null, prefKeyOauthTokenT); account = parseAccountResponse(context, new JSONObject(response)); + if( account.getSocial().equals("PLEROMA")){ + isPleromaAdmin(account.getAcct()); + } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); @@ -286,6 +289,11 @@ public class API { try { String response = new HttpsConnection(context).get(getAbsoluteUrl(String.format("/accounts/%s",accountId)), 60, null, prefKeyOauthTokenT); account = parseAccountResponse(context, new JSONObject(response)); + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + if( account.getSocial().equals("PLEROMA") && accountId.equals(userId)){ + isPleromaAdmin(account.getAcct()); + } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); } catch (NoSuchAlgorithmException e) { @@ -2281,18 +2289,22 @@ public class API { //Pleroma admin calls /** - * Retrieves Accounts when searching (ie: via @...) *synchronously* - * @return boolean + * Check if it's a Pleroma admin account and change in settings *synchronously* */ - public boolean isPleromaAdmin(String nickname) { + private void isPleromaAdmin(String nickname) { + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean isAdmin; try { HttpsConnection httpsConnection = new HttpsConnection(context); String response = httpsConnection.get(String.format(Helper.getLiveInstanceWithProtocol(context)+"/api/pleroma/admin/permission_group/%s/admin",nickname), 60, null, prefKeyOauthTokenT); //Call didn't return a 404, so the account is admin - return true; + isAdmin = true; } catch (Exception e) { - return false; + isAdmin = false; } + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, isAdmin); + editor.apply(); } /** @@ -2879,52 +2891,49 @@ public class API { card.setTitle(resobj.get("title").toString()); card.setDescription(resobj.get("description").toString()); card.setImage(resobj.get("image").toString()); - card.setHtml(resobj.get("html").toString()); + card.setType(resobj.get("type").toString()); try { card.setAuthor_name(resobj.get("author_name").toString()); }catch (Exception e){ - e.printStackTrace(); card.setAuthor_name(null); } try { card.setAuthor_url(resobj.get("author_url").toString()); }catch (Exception e){ - e.printStackTrace(); card.setAuthor_url(null); } + try { + card.setHtml(resobj.get("html").toString()); + }catch (Exception e){ + card.setHtml(null); + } try { card.setEmbed_url(resobj.get("embed_url").toString()); }catch (Exception e){ - e.printStackTrace(); card.setEmbed_url(null); } try { card.setProvider_name(resobj.get("provider_name").toString()); }catch (Exception e){ - e.printStackTrace(); card.setProvider_name(null); } try { card.setProvider_url(resobj.get("provider_url").toString()); }catch (Exception e){ - e.printStackTrace(); card.setProvider_url(null); } try { card.setHeight(Integer.parseInt(resobj.get("height").toString())); }catch (Exception e){ - e.printStackTrace(); card.setHeight(0); } try { card.setWidth(Integer.parseInt(resobj.get("width").toString())); }catch (Exception e){ - e.printStackTrace(); card.setWidth(0); } } catch (JSONException e) { - e.printStackTrace(); card = null; } return card; @@ -3352,7 +3361,6 @@ public class API { } try { - status.setCard(parseCardResponse(resobj.getJSONObject("card"))); }catch (Exception e){status.setCard(null);} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 293f0c309..5626279cf 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -293,6 +293,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct RelativeLayout status_prev4_container; TextView status_reply; ImageView status_pin; + ImageView status_remove; ImageView status_privacy; ImageButton status_translate, status_bookmark; LinearLayout status_container2; @@ -344,6 +345,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status_favorite_count = itemView.findViewById(R.id.status_favorite_count); status_reblog_count = itemView.findViewById(R.id.status_reblog_count); status_pin = itemView.findViewById(R.id.status_pin); + status_remove = itemView.findViewById(R.id.status_remove); status_toot_date = itemView.findViewById(R.id.status_toot_date); status_show_more = itemView.findViewById(R.id.status_show_more); status_more = itemView.findViewById(R.id.status_more); @@ -643,6 +645,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct changeDrawableColor(context, R.drawable.video_preview, R.color.white); if (theme == Helper.THEME_BLACK) { + changeDrawableColor(context, holder.status_remove, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_black); changeDrawableColor(context, holder.status_more, R.color.action_black); changeDrawableColor(context, holder.status_privacy, R.color.action_black); @@ -669,7 +672,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct changeDrawableColor(context, R.drawable.ic_translate, R.color.black); holder.status_cardview.setBackgroundResource(R.drawable.card_border_black); } else if (theme == Helper.THEME_DARK) { - + changeDrawableColor(context, holder.status_remove, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_dark); changeDrawableColor(context, holder.status_more, R.color.action_dark); changeDrawableColor(context, R.drawable.ic_repeat, R.color.action_dark); @@ -696,6 +699,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct changeDrawableColor(context, R.drawable.ic_bookmark_border, R.color.mastodonC1); changeDrawableColor(context, R.drawable.ic_translate, R.color.mastodonC1); } else { + changeDrawableColor(context, holder.status_remove, R.color.action_light); changeDrawableColor(context, R.drawable.ic_fetch_more, R.color.action_light); changeDrawableColor(context, R.drawable.ic_reply, R.color.action_light); changeDrawableColor(context, R.drawable.ic_conversation, R.color.action_light); @@ -1410,6 +1414,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_pin.setVisibility(View.GONE); } + if( (isAdmin || isModerator) && !isCompactMode && getItemViewType(viewHolder.getAdapterPosition()) != FOCUSED_STATUS){ + holder.status_remove.setVisibility(View.VISIBLE); + }else { + holder.status_remove.setVisibility(View.GONE); + } if (status.getWebviewURL() != null) { holder.status_cardview_webview.loadUrl(status.getWebviewURL()); @@ -1536,7 +1545,86 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct CrossActions.doCrossAction(context, type, status, null, (status.isPinned() || (status.getReblog() != null && status.getReblog().isPinned())) ? API.StatusAction.UNPIN : API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true); } }); + int style; + if (theme == Helper.THEME_DARK) { + style = R.style.DialogDark; + } else if (theme == Helper.THEME_BLACK) { + style = R.style.DialogBlack; + } else { + style = R.style.Dialog; + } + holder.status_remove.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); + AlertDialog.Builder builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[0]); + API.StatusAction 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 + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + + + //Text for report + EditText input = null; + if (doAction == API.StatusAction.REPORT) { + input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); + } + builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + final EditText finalInput = input; + builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String targetedId = status.getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (redraft) { + if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) { + toot = new Status(); + toot.setIn_reply_to_id(status.getIn_reply_to_id()); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setContent(status.getContent()); + toot.setVisibility(status.getVisibility()); + new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + toot = new Status(); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setVisibility(status.getVisibility()); + toot.setContent(status.getContent()); + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + long id = new StatusStoredDAO(context, db).insertStatus(toot, null); + Intent intentToot = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + b.putLong("restored", id); + b.putBoolean("removed", true); + intentToot.putExtras(b); + context.startActivity(intentToot); + } + } + dialog.dismiss(); + } + }); + builderInner.show(); + } + }); if (!status.getVisibility().equals("direct")) holder.spark_button_fav.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -1604,14 +1692,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } } }); - int style; - if (theme == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme == Helper.THEME_BLACK) { - style = R.style.DialogBlack; - } else { - style = R.style.Dialog; - } if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) holder.status_more.setVisibility(View.GONE); diff --git a/app/src/main/res/drawable-anydpi/ic_clear_toot.xml b/app/src/main/res/drawable-anydpi/ic_clear_toot.xml new file mode 100644 index 000000000..ede4b7108 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_clear_toot.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index 4a127bb39..3618fd783 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -164,6 +164,17 @@ android:src="@drawable/ic_bookmark_border" android:layout_marginTop="5dp" /> + diff --git a/app/src/main/res/layout/drawer_status_compact.xml b/app/src/main/res/layout/drawer_status_compact.xml index 0b87cbb12..b0baca78b 100644 --- a/app/src/main/res/layout/drawer_status_compact.xml +++ b/app/src/main/res/layout/drawer_status_compact.xml @@ -744,7 +744,19 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> - + - +