diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index ba3a3082d..951e46bd6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -68,6 +68,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.PopupMenu; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; @@ -210,7 +211,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, private List contacts; private ListView lv_accounts_search; private RelativeLayout loader; - + private String contentType; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -270,7 +271,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, //By default the toot is not restored so the id -1 is defined currentToId = -1; restoredScheduled = false; - + contentType = null; checkedValues = new ArrayList<>(); contacts = new ArrayList<>(); toot_it = findViewById(R.id.toot_it); @@ -513,7 +514,36 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, toot_it.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - sendToot(null); + sendToot(null, null); + } + }); + + toot_it.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + PopupMenu popup = new PopupMenu(TootActivity.this, toot_it); + popup.getMenuInflater() + .inflate(R.menu.main_content_type, popup.getMenu()); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + switch (item.getItemId()){ + case R.id.action_plain_text: + contentType = "text/plain"; + break; + case R.id.action_html: + contentType = "text/html"; + break; + case R.id.action_markdown: + contentType = "text/markdown"; + break; + } + popup.dismiss(); + sendToot(null, contentType); + return false; + } + }); + popup.show(); + return false; } }); @@ -1371,7 +1401,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, } - private void sendToot(String timestamp){ + private void sendToot(String timestamp, String content_type){ toot_it.setEnabled(false); if(toot_content.getText().toString().trim().length() == 0 && attachments.size() == 0){ Toasty.error(getApplicationContext(),getString(R.string.toot_error_no_content),Toast.LENGTH_LONG).show(); @@ -1392,6 +1422,8 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, stepSpliToot = 1; } Status toot = new Status(); + if(content_type != null) + toot.setContentType(content_type); toot.setSensitive(isSensitive); toot.setMedia_attachments(attachments); if( toot_cw_content.getText().toString().trim().length() > 0) @@ -1419,7 +1451,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, private void serverSchedule(String time){ - sendToot(time); + sendToot(time, null); isScheduled = true; resetForNextToot(); } 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 c3f12f2cf..7658522ec 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 @@ -1946,6 +1946,8 @@ public class API { } catch (UnsupportedEncodingException e) { params.put("status", status.getContent()); } + if( status.getContentType() != null) + params.put("content_type", status.getContentType()); if( status.getIn_reply_to_id() != null) params.put("in_reply_to_id", status.getIn_reply_to_id()); if( status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0 ) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index 0537c7717..031cf3608 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -127,6 +127,7 @@ public class Status implements Parcelable{ private boolean isBoostAnimated = false, isFavAnimated = false; private String scheduled_at; + private String contentType; @Override public void writeToParcel(Parcel dest, int flags) { @@ -180,6 +181,7 @@ public class Status implements Parcelable{ dest.writeByte(this.isBoostAnimated ? (byte) 1 : (byte) 0); dest.writeByte(this.isFavAnimated ? (byte) 1 : (byte) 0); dest.writeString(this.scheduled_at); + dest.writeString(this.contentType); } protected Status(Parcel in) { @@ -235,6 +237,7 @@ public class Status implements Parcelable{ this.isBoostAnimated = in.readByte() != 0; this.isFavAnimated = in.readByte() != 0; this.scheduled_at = in.readString(); + this.contentType = in.readString(); } public static final Creator CREATOR = new Creator() { @@ -1280,4 +1283,12 @@ public class Status implements Parcelable{ public void setScheduled_at(String scheduled_at) { this.scheduled_at = scheduled_at; } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } } diff --git a/app/src/main/res/menu/main_content_type.xml b/app/src/main/res/menu/main_content_type.xml new file mode 100644 index 000000000..1cf304cd6 --- /dev/null +++ b/app/src/main/res/menu/main_content_type.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f2f03ab7..c6acf9b92 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -863,6 +863,9 @@ Add a public comment Send comment There is no Internet connection. Your message has been stored in drafts. + Plain text + HTML + Markdown