Merged tom79/mastodon_etalab into master

This commit is contained in:
PhotonQyv 2017-08-10 17:27:34 +01:00
commit 0ff7c2b7ba
31 changed files with 423 additions and 235 deletions

View File

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

Binary file not shown.

View File

@ -105,7 +105,7 @@ public class InstanceActivity extends AppCompatActivity implements OnRetrieveIns
instance_title.setText(instance.getTitle());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
instance_description.setText(Html.fromHtml(instance.getDescription(), Html.FROM_HTML_MODE_COMPACT));
instance_description.setText(Html.fromHtml(instance.getDescription(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
instance_description.setText(Html.fromHtml(instance.getDescription()));

View File

@ -19,6 +19,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -26,6 +27,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SearchView;
@ -132,17 +134,7 @@ public class MainActivity extends AppCompatActivity
finish();
return;
}
if( theme == Helper.THEME_DARK){
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_home_tl,R.color.dark_text);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_users_tl,R.color.dark_text);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe_tl,R.color.dark_text);
changeDrawableColor(getApplicationContext(), R.drawable.ic_notifications_tl,R.color.dark_text);
}else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_home_tl,R.color.black);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_users_tl,R.color.black);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe_tl,R.color.black);
changeDrawableColor(getApplicationContext(), R.drawable.ic_notifications_tl,R.color.black);
}
Helper.fillMapEmoji(getApplicationContext());
//Here, the user is authenticated
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
@ -227,7 +219,15 @@ public class MainActivity extends AppCompatActivity
}
});
if( theme == Helper.THEME_DARK){
for(int i = 0 ; i < 4 ; i++)
if( tabLayout.getTabAt(i) != null && tabLayout.getTabAt(i).getIcon() != null)
tabLayout.getTabAt(i).getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN);
}else {
for(int i = 0 ; i < 4 ; i++)
if( tabLayout.getTabAt(i) != null && tabLayout.getTabAt(i).getIcon() != null)
tabLayout.getTabAt(i).getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.black), PorterDuff.Mode.SRC_IN);
}
toolbar_search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
@ -533,7 +533,7 @@ public class MainActivity extends AppCompatActivity
}
}
final float finalCacheSize = cacheSize;
builder.setMessage(getString(R.string.cache_message, String.format("%s Mo", String.format(Locale.getDefault(), "%.2f", cacheSize))))
builder.setMessage(getString(R.string.cache_message, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", cacheSize), getString(R.string.cache_units))))
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
@ -544,7 +544,7 @@ public class MainActivity extends AppCompatActivity
Helper.deleteDir(dir);
}
} catch (Exception ignored) {}
Toast.makeText(MainActivity.this, getString(R.string.toast_cache_clear,String.format("%s Mo", String.format(Locale.getDefault(), "%.2f", finalCacheSize))), Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, getString(R.string.toast_cache_clear,String.format("%s %s", String.format(Locale.getDefault(), "%.2f", finalCacheSize), getString(R.string.cache_units))), Toast.LENGTH_LONG).show();
dialog.dismiss();
}
})

View File

@ -17,11 +17,9 @@ package fr.gouv.etalab.mastodon.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
@ -30,10 +28,10 @@ import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.speech.RecognizerIntent;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
@ -48,6 +46,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
@ -60,7 +59,6 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
@ -134,9 +132,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private Button toot_it;
private AutoCompleteTextView toot_content;
private EditText toot_cw_content;
private TextView toot_reply_content;
private RelativeLayout toot_reply_content_container;
private BroadcastReceiver search_validate;
private LinearLayout toot_reply_content_container;
private Status tootReply = null;
private String sharedContent, sharedSubject;
private CheckBox toot_sensitive;
@ -148,6 +144,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private Toast mToast;
private LinearLayout drawer_layout;
private HorizontalScrollView picture_scrollview;
private int currentCursorPosition, searchLength;
private boolean canDisplayMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -182,7 +180,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
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
@ -209,8 +207,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_picture_container = (LinearLayout) findViewById(R.id.toot_picture_container);
toot_content = (AutoCompleteTextView) 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 = (RelativeLayout) findViewById(R.id.toot_reply_content_container);
toot_reply_content_container = (LinearLayout) findViewById(R.id.toot_reply_content_container);
picture_scrollview = (HorizontalScrollView) findViewById(R.id.picture_scrollview);
toot_sensitive = (CheckBox) findViewById(R.id.toot_sensitive);
//search_small_container = (LinearLayout) findViewById(R.id.search_small_container);
@ -291,46 +288,9 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
int charsInToot = 0;
maxChar = 500;
//Register LocalBroadcast to receive selected accounts after search
search_validate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String acct = intent.getStringExtra("acct");
if( acct != null){
acct = "@" + acct;
String content = toot_content.getText().toString();
String[] splitContent = content.split("@");
String newContent = "";
for(int i = 0 ; i < (splitContent.length -1) ; i++){
newContent += splitContent[i];
}
newContent += acct + " ";
toot_content.setText(newContent);
toot_content.setSelection(toot_content.getText().length());
}
// manageShowUsers(searchAction.CLOSE, false);
}
};
LocalBroadcastManager.getInstance(this).registerReceiver(search_validate, new IntentFilter(Helper.SEARCH_VALIDATE_ACCOUNT));
boolean isAccountPrivate = account.isLocked();
FloatingActionButton ic_close = (FloatingActionButton) findViewById(R.id.toot_close_reply);
/*toot_close_accounts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manageShowUsers(searchAction.CLOSE, true);
}
});
*/
ic_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toot_reply_content_container.setVisibility(View.GONE);
}
});
if(isAccountPrivate){
visibility = "private";
@ -435,29 +395,42 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
});
String pattern = "^(.|\\s)*(@([a-zA-Z0-9_]{2,}))$";
final Pattern sPattern = Pattern.compile(pattern);
toot_content.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
int length;
//Only check last 20 characters to avoid lags
if( s.toString().length() < 20 ){ //Less than 20 characters are written
length = s.toString().length();
if( toot_content.getSelectionStart() != 0)
currentCursorPosition = toot_content.getSelectionStart();
if( s.toString().length() == 0 )
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 {
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()) {
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_actionBar.setVisibility(View.GONE);
}
new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{toot_content.dismissDropDown();}
int totalChar = toot_cw_content.length() + toot_content.length();
int remainChar = (maxChar - totalChar);
@ -470,8 +443,20 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
}else {
toot_it.setEnabled(false);
showAToast(getString(R.string.toot_no_space));
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));
}
@ -762,12 +747,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
return true;
}
@Override
public void onDestroy(){
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(search_validate);
}
@Override
public void onRetrieveAttachment(final Attachment attachment, Error error) {
loading_picture.setVisibility(View.GONE);
@ -965,13 +944,44 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
Toast.makeText(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
return;
}
List<Account> accounts = apiResponse.getAccounts();
final List<Account> accounts = apiResponse.getAccounts();
if( accounts != null && accounts.size() > 0){
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts);
toot_content.showDropDown();
toot_content.setThreshold(0);
toot_content.setThreshold(1);
toot_content.setAdapter(accountsListAdapter);
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() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Account account = accounts.get(position);
String deltaSearch = "";
if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() )
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){
@ -1078,20 +1088,36 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
else
setTitle(R.string.toot_title_reply);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
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.getReblog() != null)
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));
FloatingActionButton ic_show = (FloatingActionButton) findViewById(R.id.toot_show_reply);
ic_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(TootActivity.this);
alert.setTitle(R.string.toot_reply_content_title);
final TextView input = new TextView(TootActivity.this);
//Set the padding
input.setPadding(30, 30, 30, 30);
alert.setView(input);
String content = tootReply.getContent();
if(tootReply.getReblog() != null)
content = tootReply.getReblog().getContent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
input.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
input.setText(Html.fromHtml(content));
alert.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
alert.show();
}
});
toot_reply_content_container.setVisibility(View.VISIBLE);
switch (tootReply.getVisibility()){
case "public":
visibility = "public";
@ -1114,17 +1140,22 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
//If toot is not restored
if( restored == -1 ){
//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)) {
toot_content.setText(String.format("@%s ", tootReply.getAccount().getAcct()));
mentionedAccountsAdded.add(tootReply.getAccount().getAcct());
}
if( tootReply.getMentions() != null ){
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());
toot_content.setText(String.format("%s ", (toot_content.getText().toString() + " " + tootTemp)));
}
}
}
//Put a dot at the end of all mentioned account to force capitalization
toot_content.setText(String.format("%s. ",toot_content.getText().toString().trim()));
toot_content.setSelection(toot_content.getText().length()); //Put cursor at the end
}
}

View File

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

View File

@ -1567,7 +1567,7 @@ public class API {
private void post(String action, int timeout, RequestParams params, AsyncHttpResponseHandler responseHandler) {
try {
client.setConnectTimeout(timeout); //10s timeout
client.setConnectTimeout(timeout);
client.setUserAgent(USER_AGENT);
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
MastalabSSLSocketFactory mastalabSSLSocketFactory = new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore());

View File

@ -174,7 +174,7 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
else
holder.account_ac.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
holder.account_ds.setText(Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_COMPACT));
holder.account_ds.setText(Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
holder.account_ds.setText(Html.fromHtml(account.getNote()));

View File

@ -16,9 +16,7 @@ package fr.gouv.etalab.mastodon.drawers;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
import android.support.annotation.NonNull;;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -50,7 +48,6 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
private LayoutInflater layoutInflater;
private ImageLoader imageLoader;
private DisplayImageOptions options;
private Context context;
public AccountsSearchAdapter(Context context, List<Account> accounts){
super(context, android.R.layout.simple_list_item_1, accounts);
@ -59,7 +56,6 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
this.suggestions = new ArrayList<>(accounts);
layoutInflater = LayoutInflater.from(context);
imageLoader = ImageLoader.getInstance();
this.context = context;
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
}
@ -103,14 +99,6 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
//Profile picture
imageLoader.displayImage(account.getAvatar(), holder.account_pp, options);
holder.account_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Helper.SEARCH_VALIDATE_ACCOUNT);
intent.putExtra("acct", account.getAcct());
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
});
return convertView;
}
@ -125,7 +113,7 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
@Override
public CharSequence convertResultToString(Object resultValue) {
Account account = (Account) resultValue;
return account.getDisplay_name() + " " + account.getUsername();
return "@" + account.getAcct();
}
@Override
@ -153,8 +141,7 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
add(cust);
notifyDataSetChanged();
}
}
else{
} else{
clear();
notifyDataSetChanged();
}

View File

@ -449,7 +449,7 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
AlertDialog.Builder builder = new AlertDialog.Builder(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT));
builder.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builder.setMessage(Html.fromHtml(status.getContent()));

View File

@ -196,7 +196,7 @@ public class SearchListAdapter extends BaseAdapter {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
holder.status_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
holder.status_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
holder.status_content.setText(Html.fromHtml(content));

View File

@ -30,9 +30,13 @@ import android.os.CountDownTimer;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.text.Html;
import android.text.Selection;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@ -373,7 +377,10 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
public void onClick(View v) {
Intent intent = new Intent(context, TootActivity.class);
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
context.startActivity(intent);
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
@ -386,19 +393,54 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
}
});
SpannableString spannableString = Helper.clickableElements(context,content,
status.getReblog() != null?status.getReblog().getMentions():status.getMentions());
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
if( status.getContent_translated() != null && status.getContent_translated().length() > 0){
SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(),
status.getReblog() != null?status.getReblog().getMentions():status.getMentions());
holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE);
holder.status_content_translated.setMovementMethod(null);
holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.status_content_translated.setFocusableInTouchMode(true);
return false;
}
});
holder.status_content_translated.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.status_content_translated.setFocusableInTouchMode(false);
holder.status_content_translated.clearFocus();
}
return false;
}
});
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
}
holder.status_content.setMovementMethod(null);
final SpannableString spannableString = Helper.clickableElements(context,content,
status.getReblog() != null?status.getReblog().getMentions():status.getMentions());
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
holder.status_content.setFocusableInTouchMode(true);
return false;
}
});
holder.status_content.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.status_content.setFocusableInTouchMode(false);
holder.status_content.clearFocus();
}
return false;
}
});
holder.status_content.setMovementMethod(LinkMovementMethod.getInstance());
if( status.getReblog() == null)
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
else
@ -863,7 +905,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
AlertDialog.Builder builder = new AlertDialog.Builder(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT));
builder.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builder.setMessage(Html.fromHtml(status.getContent()));
@ -929,7 +971,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
if( isOwner) {
if( which == 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT));
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
@ -937,7 +979,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT).toString();
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
content = Html.fromHtml(status.getContent()).toString();
@ -959,7 +1001,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
builderInner.setMessage(status.getAccount().getAcct());
}else if( which == 2) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT));
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
@ -967,7 +1009,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_COMPACT).toString();
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
content = Html.fromHtml(status.getContent()).toString();

View File

@ -23,7 +23,6 @@ import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -45,7 +45,6 @@ import android.widget.TextView;
import android.widget.Toast;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
@ -56,8 +55,6 @@ import static android.app.Activity.RESULT_OK;
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
/**
@ -79,21 +76,9 @@ public class SettingsFragment extends Fragment {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean show_reply = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLY, false);
boolean auto_store = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true);
final CheckBox set_show_reply = (CheckBox) rootView.findViewById(R.id.set_show_reply);
set_show_reply.setChecked(show_reply);
set_show_reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_SHOW_REPLY, set_show_reply.isChecked());
editor.apply();
}
});
final CheckBox set_auto_store = (CheckBox) rootView.findViewById(R.id.set_auto_store);
set_auto_store.setChecked(auto_store);
set_auto_store.setOnClickListener(new View.OnClickListener() {

View File

@ -130,7 +130,7 @@ public class SettingsProfileFragment extends Fragment implements OnRetrieveAccou
final String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_COMPACT).toString();
content = Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
content = Html.fromHtml(account.getNote()).toString();

View File

@ -54,6 +54,7 @@ import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Patterns;
import android.view.Menu;
import android.view.MenuItem;
@ -199,7 +200,6 @@ public class Helper {
public static final String SET_WIFI_ONLY = "set_wifi_only";
public static final String SET_NOTIF_HOMETIMELINE = "set_notif_hometimeline";
public static final String SET_NOTIF_SILENT = "set_notif_silent";
public static final String SET_SHOW_REPLY = "set_show_reply";
public static final String SET_SHOW_ERROR_MESSAGES = "set_show_error_messages";
public static final String SET_EMBEDDED_BROWSER = "set_embedded_browser";
public static final String SET_JAVASCRIPT = "set_javascript";
@ -1022,7 +1022,7 @@ public class Helper {
SpannableString spannableString;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
spannableString = new SpannableString(Html.fromHtml(fullContent, Html.FROM_HTML_MODE_COMPACT));
spannableString = new SpannableString(Html.fromHtml(fullContent, Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
spannableString = new SpannableString(Html.fromHtml(fullContent));
@ -1067,25 +1067,26 @@ public class Helper {
String targetedAccount = "@" + mention.getUsername();
if (spannableString.toString().contains(targetedAccount)) {
int startPosition = spannableString.toString().indexOf(targetedAccount);
int endPosition = spannableString.toString().lastIndexOf(targetedAccount) + targetedAccount.length();
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
intent.putExtras(b);
context.startActivity(intent);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//Accounts can be mentioned several times so we have to loop
for(int startPosition = -1 ; (startPosition = spannableString.toString().indexOf(targetedAccount, startPosition + 1)) != -1 ; startPosition++){
int endPosition = startPosition + targetedAccount.length();
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(View textView) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
intent.putExtras(b);
context.startActivity(intent);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
@ -1128,7 +1129,7 @@ public class Helper {
SpannableString spannableString;
fullContent = Helper.shortnameToUnicode(fullContent, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
spannableString = new SpannableString(Html.fromHtml(fullContent, Html.FROM_HTML_MODE_COMPACT));
spannableString = new SpannableString(Html.fromHtml(fullContent, Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
spannableString = new SpannableString(Html.fromHtml(fullContent));

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -32,8 +32,8 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"

View File

@ -40,42 +40,29 @@
android:hint="@string/toot_cw_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
<LinearLayout
android:id="@+id/toot_reply_content_container"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/toot_reply_content_title"
android:text="@string/toot_reply_content_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/toot_reply_content_title"
android:id="@+id/toot_reply_content"
android:layout_marginTop="10dp"
android:gravity="top|start"
android:maxLines="4"
android:textStyle="italic"
android:autoLink="web"
android:textSize="12sp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:text="@string/show_reply"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_reply"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/toot_show_reply"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_gravity="center_vertical|end"
app:fabSize="mini"
android:layout_margin="5dp"
app:srcCompat="@drawable/ic_close" />
</RelativeLayout>
app:srcCompat="@drawable/ic_action_eye_open" />
</LinearLayout>
<AutoCompleteTextView
android:layout_marginTop="10dp"
android:id="@+id/toot_content"

View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 Thomas Schneider
This file is a part of Mastalab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with Mastalab; if not,
see <http://www.gnu.org/licenses>.
-->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
style="?attr/cardStyle"
android:layout_marginTop="10dp"
card_view:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_container"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_gravity="center_horizontal"
android:id="@+id/account_pp"
android:layout_width="60dp"
android:layout_height="60dp"
tools:ignore="ContentDescription" />
<android.support.design.widget.FloatingActionButton
android:layout_marginTop="20dp"
android:visibility="gone"
android:id="@+id/account_action_block"
app:fabSize="mini"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="center"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_block_white" />
<android.support.design.widget.FloatingActionButton
android:layout_marginTop="20dp"
android:visibility="gone"
android:id="@+id/account_action_mute"
app:fabSize="mini"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="center"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_mute_white" />
</LinearLayout>
<LinearLayout
android:id="@+id/account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/account_dn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="18sp"/>
<TextView
android:id="@+id/account_un"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textSize="14sp"
/>
</LinearLayout>
<TextView
android:id="@+id/account_ac"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:maxLines="1"
android:textSize="16sp"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/toots"/>
<TextView
android:id="@+id/account_sc"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/following"/>
<TextView
android:id="@+id/account_fgc"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="@string/followers"/>
<TextView
android:id="@+id/account_frc"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/account_ds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:autoLink="web"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -46,12 +46,6 @@
android:text="@string/set_show_error_messages"
android:layout_height="wrap_content" />
<CheckBox
android:layout_marginTop="10dp"
android:id="@+id/set_show_reply"
android:layout_width="wrap_content"
android:text="@string/set_display_reply"
android:layout_height="wrap_content" />
<CheckBox
android:layout_marginTop="10dp"

View File

@ -32,7 +32,8 @@
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"

View File

@ -40,42 +40,29 @@
android:hint="@string/toot_cw_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
<LinearLayout
android:id="@+id/toot_reply_content_container"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/toot_reply_content_title"
android:text="@string/toot_reply_content_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/toot_reply_content_title"
android:id="@+id/toot_reply_content"
android:layout_marginTop="10dp"
android:gravity="top|start"
android:maxLines="4"
android:textStyle="italic"
android:autoLink="web"
android:textSize="12sp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:text="@string/show_reply"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_reply"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/toot_show_reply"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_gravity="center_vertical|end"
app:fabSize="mini"
android:layout_margin="5dp"
app:srcCompat="@drawable/ic_close" />
</RelativeLayout>
app:srcCompat="@drawable/ic_action_eye_open" />
</LinearLayout>
<AutoCompleteTextView
android:layout_marginTop="10dp"
android:id="@+id/toot_content"

View File

@ -46,12 +46,6 @@
android:text="@string/set_show_error_messages"
android:layout_height="wrap_content" />
<CheckBox
android:layout_marginTop="10dp"
android:id="@+id/set_show_reply"
android:layout_width="wrap_content"
android:text="@string/set_display_reply"
android:layout_height="wrap_content" />
<CheckBox
android:layout_marginTop="10dp"

View File

@ -170,6 +170,7 @@
<string name="no_draft">Aucun brouillon !</string>
<string name="choose_toot">Choisissez un pouet</string>
<string name="remove_draft">Supprimer le brouillon ?</string>
<string name="show_reply">Cliquer sur le bouton pour afficher le pouet d\'origine</string>
<!-- Instance -->
<string name="instance_no_description">Aucune description !</string>
@ -327,6 +328,7 @@
<!-- CACHE -->
<string name="cache_title">Nettoyage du cache</string>
<string name="cache_message">Il y a %1$s de données en cache.\n\nSouhaitez-vous les supprimer ?</string>
<string name="cache_units">Mo</string>
<string name="toast_cache_clear">Le cache a été nettoyé ! %1$s ont été libérés</string>
<!-- PRIVACY -->

View File

@ -174,6 +174,7 @@
<string name="no_draft">No draft!</string>
<string name="choose_toot">Choose a toot</string>
<string name="remove_draft">Remove draft?</string>
<string name="show_reply">Click on the button to display the original toot</string>
<!-- Instance -->
<string name="instance_no_description">No description available!</string>
@ -330,7 +331,8 @@
<string name="settings_popup_notification">For unread notifications?</string>
<!-- CACHE -->
<string name="cache_title">Clear cache</string>
<string name="cache_message">There are %1$s data in cache.\n\nWould you like to delete them?</string>
<string name="cache_message">There are %1$s of data in cache.\n\nWould you like to delete them?</string>
<string name="cache_units">Mb</string>
<string name="toast_cache_clear">Cache was cleared! %1$s were released</string>
<!-- PRIVACY -->