Markdown feature

This commit is contained in:
stom79 2019-01-26 20:01:11 +01:00
parent 8683ba2612
commit f4c828eaee
5 changed files with 69 additions and 5 deletions

View File

@ -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<Account> 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();
}

View File

@ -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 ) {

View File

@ -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<Status> CREATOR = new Creator<Status>() {
@ -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;
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_plain_text"
android:title="@string/action_plain_text"
app:showAsAction="always" />
<item
android:id="@+id/action_html"
android:title="@string/action_html"
app:showAsAction="always" />
<item
android:id="@+id/action_markdown"
android:title="@string/action_markdown"
app:showAsAction="always" />
</menu>

View File

@ -863,6 +863,9 @@
<string name="add_public_comment">Add a public comment</string>
<string name="send_comment">Send comment</string>
<string name="toast_toot_saved_error">There is no Internet connection. Your message has been stored in drafts.</string>
<string name="action_plain_text">Plain text</string>
<string name="action_html">HTML</string>
<string name="action_markdown">Markdown</string>
<!-- end languages -->