Merged with tom-repo/develop and simplified Kludge to just add a ' . ', and then strip it before positing to Mastodon. To fix capitalisation issue.

This commit is contained in:
PhotonQyv 2017-08-10 18:57:14 +01:00
commit 95f48842a8
6 changed files with 99 additions and 48 deletions

View File

@ -7,8 +7,8 @@ android {
applicationId "fr.gouv.etalab.mastodon" applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 25 targetSdkVersion 25
versionCode 44 versionCode 45
versionName "1.4.4" versionName "1.4.5"
} }
buildTypes { buildTypes {
release { release {

Binary file not shown.

View File

@ -28,6 +28,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.speech.RecognizerIntent; import android.speech.RecognizerIntent;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -36,6 +37,7 @@ import android.support.v7.app.AppCompatActivity;
import android.text.Editable; import android.text.Editable;
import android.text.Html; import android.text.Html;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -142,7 +144,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private Toast mToast; private Toast mToast;
private LinearLayout drawer_layout; private LinearLayout drawer_layout;
private HorizontalScrollView picture_scrollview; private HorizontalScrollView picture_scrollview;
private String search; private int currentCursorPosition, searchLength;
private boolean canDisplayMessage;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -177,7 +180,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
pp_progress = (ProgressBar) actionBar.getCustomView().findViewById(R.id.pp_progress); pp_progress = (ProgressBar) actionBar.getCustomView().findViewById(R.id.pp_progress);
} }
canDisplayMessage = true;
//By default the toot is not restored so the id -1 is defined //By default the toot is not restored so the id -1 is defined
@ -402,29 +405,42 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}); });
String pattern = "^(.|\\s)*(@([a-zA-Z0-9_]{2,}))$"; String pattern = "^(.|\\s)*(@([a-zA-Z0-9_]{2,}))$";
final Pattern sPattern = Pattern.compile(pattern); final Pattern sPattern = Pattern.compile(pattern);
toot_content.addTextChangedListener(new TextWatcher() { toot_content.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {} public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
int length; if( toot_content.getSelectionStart() != 0)
//Only check last 20 characters to avoid lags currentCursorPosition = toot_content.getSelectionStart();
if( s.toString().length() < 20 ){ //Less than 20 characters are written if( s.toString().length() == 0 )
length = s.toString().length(); currentCursorPosition = 0;
//Only check last 15 characters before cursor position to avoid lags
if( currentCursorPosition < 15 ){ //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}else { }else {
length = 20; searchLength = 15;
} }
Matcher m = sPattern.matcher(s.toString().substring(s.toString().length()- length, s.toString().length())); if( currentCursorPosition- (searchLength-1) < 0 || currentCursorPosition == 0 || currentCursorPosition > s.toString().length())
return;
Matcher m;
if( s.toString().charAt(0) == '@')
m = sPattern.matcher(s.toString().substring(currentCursorPosition- searchLength, currentCursorPosition));
else
m = sPattern.matcher(s.toString().substring(currentCursorPosition- (searchLength-1), currentCursorPosition));
if(m.matches()) { if(m.matches()) {
search = m.group(3); String search = m.group(3);
if( pp_progress != null && pp_actionBar != null) { if (pp_progress != null && pp_actionBar != null) {
pp_progress.setVisibility(View.VISIBLE); pp_progress.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.GONE); pp_actionBar.setVisibility(View.GONE);
} }
new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{toot_content.dismissDropDown();} }else{toot_content.dismissDropDown();}
int totalChar = toot_cw_content.length() + toot_content.length(); int totalChar = toot_cw_content.length() + toot_content.length();
int remainChar = (maxChar - totalChar); int remainChar = (maxChar - totalChar);
@ -437,8 +453,20 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
} }
}else { }else {
toot_it.setEnabled(false); toot_it.setEnabled(false);
showAToast(getString(R.string.toot_no_space));
toot_space_left.setTextColor( Color.RED); toot_space_left.setTextColor( Color.RED);
//Delay the advertising message to avoid to flood the user
if( canDisplayMessage ){
canDisplayMessage = false;
showAToast(getString(R.string.toot_no_space));
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
canDisplayMessage = true;
}
}, 4000);
}
} }
toot_space_left.setText(String.valueOf(remainChar)); toot_space_left.setText(String.valueOf(remainChar));
} }
@ -930,22 +958,40 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
final List<Account> accounts = apiResponse.getAccounts(); final List<Account> accounts = apiResponse.getAccounts();
if( accounts != null && accounts.size() > 0){ if( accounts != null && accounts.size() > 0){
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts); AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts);
toot_content.showDropDown(); toot_content.setThreshold(1);
toot_content.setThreshold(0);
toot_content.setAdapter(accountsListAdapter); toot_content.setAdapter(accountsListAdapter);
final String toot_content_str = toot_content.getText().toString().replace("@"+search,""); final String oldContent = toot_content.getText().toString();
String[] searchA = oldContent.substring(0,currentCursorPosition).split("@");
final String search = searchA[searchA.length-1];
toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() { toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Account account = accounts.get(position); Account account = accounts.get(position);
toot_content.setText(toot_content_str + " @" + account.getAcct() + " "); String deltaSearch = "";
toot_content.setSelection(toot_content.getText().length()-1); if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() )
toot_content.dismissDropDown(); deltaSearch = oldContent.substring(currentCursorPosition-searchLength, currentCursorPosition);
else {
if( currentCursorPosition >= oldContent.length() )
deltaSearch = oldContent.substring(currentCursorPosition-searchLength, oldContent.length());
}
if( !search.equals(""))
deltaSearch = deltaSearch.replace("@"+search,"");
String newContent = oldContent.substring(0,currentCursorPosition-searchLength);
newContent += deltaSearch;
newContent += "@" + account.getAcct() + " ";
int newPosition = newContent.length();
if( currentCursorPosition < oldContent.length() - 1)
newContent += oldContent.substring(currentCursorPosition, oldContent.length()-1);
toot_content.setText(newContent);
toot_content.setSelection(newPosition);
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, new ArrayList<Account>());
toot_content.setThreshold(1);
toot_content.setAdapter(accountsListAdapter);
} }
}); });
} }
} }
private void restoreToot(long id){ private void restoreToot(long id){
@ -1059,8 +1105,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
ic_show.setOnClickListener(new View.OnClickListener() { ic_show.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(TootActivity.this); AlertDialog.Builder alert = new AlertDialog.Builder(TootActivity.this);
alert.setTitle(R.string.toot_reply_content_title); alert.setTitle(R.string.toot_reply_content_title);
final TextView input = new TextView(TootActivity.this); final TextView input = new TextView(TootActivity.this);
@ -1106,12 +1150,15 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
//If toot is not restored //If toot is not restored
if( restored == -1 ){ if( restored == -1 ){
//Retrieves mentioned accounts + OP and adds them at the beginin of the toot //Retrieves mentioned accounts + OP and adds them at the beginin of the toot
ArrayList<String> mentionedAccountsAdded = new ArrayList<>();
if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userId)) { if( tootReply.getAccount() != null && tootReply.getAccount().getAcct() != null && !tootReply.getAccount().getId().equals(userId)) {
toot_content.setText(String.format("@%s ", tootReply.getAccount().getAcct())); toot_content.setText(String.format("@%s ", tootReply.getAccount().getAcct()));
mentionedAccountsAdded.add(tootReply.getAccount().getAcct());
} }
if( tootReply.getMentions() != null ){ if( tootReply.getMentions() != null ){
for(Mention mention : tootReply.getMentions()){ for(Mention mention : tootReply.getMentions()){
if( mention.getAcct() != null && !mention.getId().equals(userId)) { if( mention.getAcct() != null && !mention.getId().equals(userId) && !mentionedAccountsAdded.contains(mention.getAcct())) {
mentionedAccountsAdded.add(mention.getAcct());
String tootTemp = String.format("@%s ", mention.getAcct()); String tootTemp = String.format("@%s ", mention.getAcct());
toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + tootTemp))); toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + tootTemp)));
} }

View File

@ -31,7 +31,6 @@ public class RetrieveDeveloperAccountsAsyncTask extends AsyncTask<Void, Void, Vo
private Context context; private Context context;
private APIResponse apiResponse; private APIResponse apiResponse;
private OnRetrieveSearcAccountshInterface listener; private OnRetrieveSearcAccountshInterface listener;
private API api;
public RetrieveDeveloperAccountsAsyncTask(Context context, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){ public RetrieveDeveloperAccountsAsyncTask(Context context, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
this.context = context; this.context = context;
@ -40,7 +39,7 @@ public class RetrieveDeveloperAccountsAsyncTask extends AsyncTask<Void, Void, Vo
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
api = new API(context); API api = new API(context);
apiResponse = api.searchDeveloper(); apiResponse = api.searchDeveloper();
return null; return null;
} }

View File

@ -377,7 +377,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(context, TootActivity.class); Intent intent = new Intent(context, TootActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putParcelable("tootReply", status); if( status.getReblog() != null )
b.putParcelable("tootReply", status.getReblog());
else
b.putParcelable("tootReply", status);
intent.putExtras(b); //Put your id to your next Intent intent.putExtras(b); //Put your id to your next Intent
context.startActivity(intent); context.startActivity(intent);
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){ if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){

View File

@ -54,6 +54,7 @@ import android.text.Spanned;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Patterns; import android.util.Patterns;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -1066,25 +1067,26 @@ public class Helper {
String targetedAccount = "@" + mention.getUsername(); String targetedAccount = "@" + mention.getUsername();
if (spannableString.toString().contains(targetedAccount)) { if (spannableString.toString().contains(targetedAccount)) {
int startPosition = spannableString.toString().indexOf(targetedAccount); //Accounts can be mentioned several times so we have to loop
int endPosition = spannableString.toString().lastIndexOf(targetedAccount) + targetedAccount.length(); for(int startPosition = -1 ; (startPosition = spannableString.toString().indexOf(targetedAccount, startPosition + 1)) != -1 ; startPosition++){
spannableString.setSpan(new ClickableSpan() { int endPosition = startPosition + targetedAccount.length();
@Override spannableString.setSpan(new ClickableSpan() {
public void onClick(View textView) { @Override
Intent intent = new Intent(context, ShowAccountActivity.class); public void onClick(View textView) {
Bundle b = new Bundle(); Intent intent = new Intent(context, ShowAccountActivity.class);
b.putString("accountId", mention.getId()); Bundle b = new Bundle();
intent.putExtras(b); b.putString("accountId", mention.getId());
context.startActivity(intent); intent.putExtras(b);
} context.startActivity(intent);
@Override }
public void updateDrawState(TextPaint ds) { @Override
super.updateDrawState(ds); public void updateDrawState(TextPaint ds) {
} super.updateDrawState(ds);
}, }
startPosition, endPosition, },
Spanned.SPAN_INCLUSIVE_EXCLUSIVE); startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
} }
} }