From 53175e187cccd7360886f694a2a13ad5d03c8c14 Mon Sep 17 00:00:00 2001 From: tom79 Date: Fri, 18 Aug 2017 16:54:43 +0200 Subject: [PATCH] Removes char limit --- .../mastodon/activities/TootActivity.java | 61 ++++--------------- .../drawers/NotificationsListAdapter.java | 2 - .../main/res/layout-sw600dp/activity_toot.xml | 2 +- app/src/main/res/layout/activity_toot.xml | 2 +- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 16 insertions(+), 53 deletions(-) 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 3436045db..c2dad604e 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 @@ -23,15 +23,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; -import android.graphics.Color; 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.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.text.Editable; @@ -117,7 +114,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostStatusActionInterface { - private int maxChar; private String visibility; private final int PICK_IMAGE = 56556; private ProgressBar loading_picture; @@ -144,7 +140,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc private LinearLayout drawer_layout; private HorizontalScrollView picture_scrollview; private int currentCursorPosition, searchLength; - private boolean canDisplayMessage; + private TextView toot_space_left; @Override protected void onCreate(Bundle savedInstanceState) { @@ -179,8 +175,6 @@ 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 currentToId = -1; @@ -199,7 +193,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc 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_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 = (ProgressBar) findViewById(R.id.loading_picture); @@ -285,12 +279,9 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc attachments = new ArrayList<>(); int charsInCw = 0; int charsInToot = 0; - maxChar = 500; - boolean isAccountPrivate = account.isLocked(); - if(isAccountPrivate){ visibility = "private"; toot_visibility.setImageResource(R.drawable.ic_action_lock_closed); @@ -321,7 +312,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc } }); - toot_space_left.setText(String.valueOf((maxChar - (charsInToot + charsInCw)))); + toot_space_left.setText(String.valueOf(charsInToot + charsInCw)); toot_cw.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -447,28 +438,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc 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); - if( remainChar >= 0){ - toot_it.setEnabled(true); - toot_space_left.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.mastodonC4)); - }else { - toot_it.setEnabled(false); - 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(totalChar)); } }); //Allow scroll of the EditText though it's embedded in a scrollview @@ -494,17 +464,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc @Override public void afterTextChanged(Editable s) { int totalChar = toot_cw_content.length() + toot_content.length(); - int remainChar = (maxChar - totalChar); - if( remainChar >= 0){ - toot_it.setEnabled(true); - toot_space_left.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.mastodonC4)); - }else { - toot_it.setEnabled(false); - showAToast(getString(R.string.toot_no_space)); - toot_space_left.setTextColor(Color.RED); - - } - toot_space_left.setText(String.valueOf(remainChar)); + toot_space_left.setText(String.valueOf(totalChar)); } }); if( restored != -1 ){ @@ -909,10 +869,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc @Override public void onPostStatusAction(APIResponse apiResponse) { if( apiResponse.getError() != 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(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show(); + toot_it.setEnabled(true); + if( apiResponse.getError().getError().contains("422")){ + showAToast(getString(R.string.toast_error_char_limit)); + }else { + showAToast(apiResponse.getError().getError()); + } return; } //Clear the toot @@ -1104,6 +1066,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc else setTitle(R.string.toot_title); } + toot_space_left.setText(String.valueOf(toot_content.getText().length() + toot_cw_content.getText().length())); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index cd8f62e10..848b36295 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -30,7 +30,6 @@ import android.support.v7.widget.CardView; import android.text.Html; import android.text.SpannableString; import android.text.method.LinkMovementMethod; -import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -748,7 +747,6 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio */ private void moreOptionDialog(final Status status){ - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); final boolean isOwner = status.getAccount().getId().equals(userId); diff --git a/app/src/main/res/layout-sw600dp/activity_toot.xml b/app/src/main/res/layout-sw600dp/activity_toot.xml index 3cce119db..301ef658e 100644 --- a/app/src/main/res/layout-sw600dp/activity_toot.xml +++ b/app/src/main/res/layout-sw600dp/activity_toot.xml @@ -131,7 +131,7 @@ Une erreur est survenue lors de la traduction ! Brouillon enregistré ! La visibilité des pouets a été changée pour le compte %1$s + Etes-vous sûr que cette instance autorise ce nombre de caractères ? Habituellement, cette valeur est proche de 500 caractères. Optimisation du chargement Nombre de pouets par chargement diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d8f1a1d8b..c31dbacfe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -267,6 +267,7 @@ The media has been saved! An error occurred while translating! Draft saved! + Are you sure this instance allows this number of characters? Usually, this value is close to 500 characters. Visibility of the toots has been changed for the account %1$s Optimisation of loading