Adds mentioned accounts in a reply + some previous apk not pushed.
This commit is contained in:
parent
a8570fc44c
commit
12d791b62b
Binary file not shown.
Binary file not shown.
|
@ -58,19 +58,18 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAccountsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UploadActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAttachmentInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
@ -82,10 +81,9 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
* Toot activity class
|
||||
*/
|
||||
|
||||
public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostActionInterface, OnRetrieveFeedsInterface {
|
||||
public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostActionInterface {
|
||||
|
||||
|
||||
private String inReplyTo = null;
|
||||
private int charsInCw;
|
||||
private int charsInToot;
|
||||
private int maxChar;
|
||||
|
@ -105,6 +103,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
private RelativeLayout toot_show_accounts;
|
||||
private ListView toot_lv_accounts;
|
||||
private BroadcastReceiver search_validate;
|
||||
private Status tootReply = null;
|
||||
|
||||
private String pattern = "^.*(@([a-zA-Z0-9_]{2,}))$";
|
||||
@Override
|
||||
|
@ -115,13 +114,66 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
if( getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
toot_it = (Button) findViewById(R.id.toot_it);
|
||||
Button toot_cw = (Button) findViewById(R.id.toot_cw);
|
||||
final TextView toot_space_left = (TextView) findViewById(R.id.toot_space_left);
|
||||
toot_visibility = (ImageButton) findViewById(R.id.toot_visibility);
|
||||
toot_picture = (ImageButton) findViewById(R.id.toot_picture);
|
||||
loading_picture = (RelativeLayout) findViewById(R.id.loading_picture);
|
||||
toot_picture_container = (LinearLayout) findViewById(R.id.toot_picture_container);
|
||||
toot_content = (EditText) findViewById(R.id.toot_content);
|
||||
toot_cw_content = (EditText) findViewById(R.id.toot_cw_content);
|
||||
toot_reply_content = (TextView) findViewById(R.id.toot_reply_content);
|
||||
toot_reply_content_container = (LinearLayout) findViewById(R.id.toot_reply_content_container);
|
||||
toot_show_accounts = (RelativeLayout) findViewById(R.id.toot_show_accounts);
|
||||
toot_lv_accounts = (ListView) findViewById(R.id.toot_lv_accounts);
|
||||
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null)
|
||||
inReplyTo = b.getString("inReplyTo", null);
|
||||
if( inReplyTo != null) {
|
||||
if(b != null) {
|
||||
tootReply = b.getParcelable("tootReply");
|
||||
}
|
||||
if( tootReply != null) {
|
||||
setTitle(R.string.toot_title_reply);
|
||||
new RetrieveFeedsAsyncTask(getApplicationContext(), RetrieveFeedsAsyncTask.Type.ONESTATUS, inReplyTo,null, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_reply = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLY, false);
|
||||
if( show_reply ){
|
||||
toot_reply_content_container.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
toot_reply_content_container.setVisibility(View.GONE);
|
||||
}
|
||||
String content = tootReply.getContent();
|
||||
if(tootReply.isReblogged())
|
||||
content = tootReply.getReblog().getContent();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
toot_reply_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
|
||||
else
|
||||
//noinspection deprecation
|
||||
toot_reply_content.setText(Html.fromHtml(content));
|
||||
switch (tootReply.getVisibility()){
|
||||
case "public":
|
||||
visibility = "public";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_globe);
|
||||
break;
|
||||
case "unlisted":
|
||||
visibility = "unlisted";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
|
||||
break;
|
||||
case "private":
|
||||
visibility = "private";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
|
||||
break;
|
||||
case "direct":
|
||||
visibility = "direct";
|
||||
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
|
||||
break;
|
||||
}
|
||||
//Retrieves mentioned accounts + OP and adds them at the beginin of the toot
|
||||
toot_content.setText(String.format("%s ", tootReply.getAccount().getAcct()));
|
||||
for(Mention mention : tootReply.getMentions()){
|
||||
toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + mention.getAcct())));
|
||||
}
|
||||
toot_content.setSelection(toot_content.getText().length()); //Put cursor at the end
|
||||
}else {
|
||||
setTitle(R.string.toot_title);
|
||||
}
|
||||
|
@ -152,19 +204,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
};
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(search_validate, new IntentFilter(Helper.SEARCH_VALIDATE_ACCOUNT));
|
||||
|
||||
toot_it = (Button) findViewById(R.id.toot_it);
|
||||
Button toot_cw = (Button) findViewById(R.id.toot_cw);
|
||||
final TextView toot_space_left = (TextView) findViewById(R.id.toot_space_left);
|
||||
toot_visibility = (ImageButton) findViewById(R.id.toot_visibility);
|
||||
toot_picture = (ImageButton) findViewById(R.id.toot_picture);
|
||||
loading_picture = (RelativeLayout) findViewById(R.id.loading_picture);
|
||||
toot_picture_container = (LinearLayout) findViewById(R.id.toot_picture_container);
|
||||
toot_content = (EditText) findViewById(R.id.toot_content);
|
||||
toot_cw_content = (EditText) findViewById(R.id.toot_cw_content);
|
||||
toot_reply_content = (TextView) findViewById(R.id.toot_reply_content);
|
||||
toot_reply_content_container = (LinearLayout) findViewById(R.id.toot_reply_content_container);
|
||||
toot_show_accounts = (RelativeLayout) findViewById(R.id.toot_show_accounts);
|
||||
toot_lv_accounts = (ListView) findViewById(R.id.toot_lv_accounts);
|
||||
|
||||
FloatingActionButton toot_close_accounts = (FloatingActionButton) findViewById(R.id.toot_close_accounts);
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
@ -197,8 +237,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
toot_space_left.setText(String.valueOf((maxChar - (charsInToot + charsInCw))));
|
||||
toot_cw.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -239,8 +277,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
toot.setSpoiler_text(toot_cw_content.getText().toString().trim());
|
||||
toot.setVisibility(visibility);
|
||||
toot.setContent(toot_content.getText().toString().trim());
|
||||
if( inReplyTo != null)
|
||||
toot.setIn_reply_to_id(inReplyTo);
|
||||
if( tootReply != null)
|
||||
toot.setIn_reply_to_id(tootReply.getId());
|
||||
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.CREATESTATUS, null, toot, null, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
@ -490,51 +528,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
toot_it.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(List<Status> statuses, Error error) {
|
||||
if( error != null){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if( statuses != null && statuses.size() > 0 ){
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_reply = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLY, false);
|
||||
if( show_reply ){
|
||||
toot_reply_content_container.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
toot_reply_content_container.setVisibility(View.GONE);
|
||||
}
|
||||
String content = statuses.get(0).getContent();
|
||||
if(statuses.get(0).isReblogged())
|
||||
content = statuses.get(0).getReblog().getContent();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
toot_reply_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
|
||||
else
|
||||
//noinspection deprecation
|
||||
toot_reply_content.setText(Html.fromHtml(content));
|
||||
switch (statuses.get(0).getVisibility()){
|
||||
case "public":
|
||||
visibility = "public";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_globe);
|
||||
break;
|
||||
case "unlisted":
|
||||
visibility = "unlisted";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
|
||||
break;
|
||||
case "private":
|
||||
visibility = "private";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
|
||||
break;
|
||||
case "direct":
|
||||
visibility = "direct";
|
||||
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -954,7 +954,21 @@ public class API {
|
|||
attachments.add(attachment);
|
||||
}
|
||||
}
|
||||
List<Mention> mentions = new ArrayList<>();
|
||||
JSONArray arrayMention = resobj.getJSONArray("mentions");
|
||||
if( arrayMention != null){
|
||||
for(int j = 0 ; j < arrayMention.length() ; j++){
|
||||
JSONObject menObj = arrayMention.getJSONObject(j);
|
||||
Mention mention = new Mention();
|
||||
mention.setId(menObj.get("id").toString());
|
||||
mention.setUrl(menObj.get("url").toString());
|
||||
mention.setAcct(menObj.get("acct").toString());
|
||||
mention.setUsername(menObj.get("username").toString());
|
||||
mentions.add(mention);
|
||||
}
|
||||
}
|
||||
status.setMedia_attachments(attachments);
|
||||
status.setMentions(mentions);
|
||||
status.setAccount(parseAccountResponse(resobj.getJSONObject("account")));
|
||||
status.setContent(resobj.get("content").toString());
|
||||
status.setFavourites_count(Integer.valueOf(resobj.get("favourites_count").toString()));
|
||||
|
|
|
@ -14,17 +14,42 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.client.Entities;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 23/04/2017.
|
||||
* Manages mentions in toots
|
||||
*/
|
||||
|
||||
public class Mention {
|
||||
public class Mention implements Parcelable {
|
||||
|
||||
private String url;
|
||||
private String username;
|
||||
private String acct;
|
||||
private String id;
|
||||
|
||||
private Mention(Parcel in) {
|
||||
url = in.readString();
|
||||
username = in.readString();
|
||||
acct = in.readString();
|
||||
id = in.readString();
|
||||
}
|
||||
|
||||
public Mention(){}
|
||||
|
||||
public static final Creator<Mention> CREATOR = new Creator<Mention>() {
|
||||
@Override
|
||||
public Mention createFromParcel(Parcel in) {
|
||||
return new Mention(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mention[] newArray(int size) {
|
||||
return new Mention[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
@ -56,4 +81,17 @@ public class Mention {
|
|||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(url);
|
||||
dest.writeString(username);
|
||||
dest.writeString(acct);
|
||||
dest.writeString(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,11 @@ public class Status implements Parcelable {
|
|||
private String spoiler_text;
|
||||
private String visibility;
|
||||
private boolean attachmentShown = false;
|
||||
private List<Attachment> media_attachments;
|
||||
private List<Mention> mentions;
|
||||
private List<Tag> tags;
|
||||
private Application application;
|
||||
|
||||
|
||||
protected Status(Parcel in) {
|
||||
id = in.readString();
|
||||
|
@ -53,6 +58,8 @@ public class Status implements Parcelable {
|
|||
in_reply_to_id = in.readString();
|
||||
in_reply_to_account_id = in.readString();
|
||||
reblog = in.readParcelable(Status.class.getClassLoader());
|
||||
account = in.readParcelable(Account.class.getClassLoader());
|
||||
mentions = in.readArrayList(Mention.class.getClassLoader());
|
||||
content = in.readString();
|
||||
reblogs_count = in.readInt();
|
||||
favourites_count = in.readInt();
|
||||
|
@ -199,11 +206,6 @@ public class Status implements Parcelable {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private List<Attachment> media_attachments;
|
||||
private List<Mention> mentions;
|
||||
private List<Tag> tags;
|
||||
private Application application;
|
||||
public List<Attachment> getMedia_attachments() {
|
||||
return media_attachments;
|
||||
}
|
||||
|
@ -266,6 +268,8 @@ public class Status implements Parcelable {
|
|||
dest.writeString(in_reply_to_id);
|
||||
dest.writeString(in_reply_to_account_id);
|
||||
dest.writeParcelable(reblog, flags);
|
||||
dest.writeParcelable(account, flags);
|
||||
dest.writeList(mentions);
|
||||
dest.writeString(content);
|
||||
dest.writeInt(reblogs_count);
|
||||
dest.writeInt(favourites_count);
|
||||
|
|
|
@ -213,7 +213,7 @@ public class NotificationsListAdapter extends BaseAdapter {
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("inReplyTo", notification.getStatus().getId());
|
||||
b.putParcelable("tootReply", notification.getStatus());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("inReplyTo", status.getId()); //Your id
|
||||
b.putParcelable("tootReply", status);
|
||||
intent.putExtras(b); //Put your id to your next Intent
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue