Removes char limit

This commit is contained in:
tom79 2017-08-18 16:54:43 +02:00
parent f323857ef3
commit 53175e187c
6 changed files with 16 additions and 53 deletions

View File

@ -23,15 +23,12 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable; 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.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable; 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 { public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostStatusActionInterface {
private int maxChar;
private String visibility; private String visibility;
private final int PICK_IMAGE = 56556; private final int PICK_IMAGE = 56556;
private ProgressBar loading_picture; private ProgressBar loading_picture;
@ -144,7 +140,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private LinearLayout drawer_layout; private LinearLayout drawer_layout;
private HorizontalScrollView picture_scrollview; private HorizontalScrollView picture_scrollview;
private int currentCursorPosition, searchLength; private int currentCursorPosition, searchLength;
private boolean canDisplayMessage; private TextView toot_space_left;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { 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); 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
currentToId = -1; currentToId = -1;
@ -199,7 +193,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_it = (Button) findViewById(R.id.toot_it); toot_it = (Button) findViewById(R.id.toot_it);
Button toot_cw = (Button) findViewById(R.id.toot_cw); 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_visibility = (ImageButton) findViewById(R.id.toot_visibility);
toot_picture = (ImageButton) findViewById(R.id.toot_picture); toot_picture = (ImageButton) findViewById(R.id.toot_picture);
loading_picture = (ProgressBar) findViewById(R.id.loading_picture); loading_picture = (ProgressBar) findViewById(R.id.loading_picture);
@ -285,12 +279,9 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
attachments = new ArrayList<>(); attachments = new ArrayList<>();
int charsInCw = 0; int charsInCw = 0;
int charsInToot = 0; int charsInToot = 0;
maxChar = 500;
boolean isAccountPrivate = account.isLocked(); boolean isAccountPrivate = account.isLocked();
if(isAccountPrivate){ if(isAccountPrivate){
visibility = "private"; visibility = "private";
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed); 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() { toot_cw.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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); 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); toot_space_left.setText(String.valueOf(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));
} }
}); });
//Allow scroll of the EditText though it's embedded in a scrollview //Allow scroll of the EditText though it's embedded in a scrollview
@ -494,17 +464,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
int totalChar = toot_cw_content.length() + toot_content.length(); int totalChar = toot_cw_content.length() + toot_content.length();
int remainChar = (maxChar - totalChar); toot_space_left.setText(String.valueOf(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));
} }
}); });
if( restored != -1 ){ if( restored != -1 ){
@ -909,10 +869,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
@Override @Override
public void onPostStatusAction(APIResponse apiResponse) { public void onPostStatusAction(APIResponse apiResponse) {
if( apiResponse.getError() != null){ if( apiResponse.getError() != null){
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); toot_it.setEnabled(true);
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true); if( apiResponse.getError().getError().contains("422")){
if( show_error_messages) showAToast(getString(R.string.toast_error_char_limit));
Toast.makeText(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show(); }else {
showAToast(apiResponse.getError().getError());
}
return; return;
} }
//Clear the toot //Clear the toot
@ -1104,6 +1066,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
else else
setTitle(R.string.toot_title); setTitle(R.string.toot_title);
} }
toot_space_left.setText(String.valueOf(toot_content.getText().length() + toot_cw_content.getText().length()));
} }

View File

@ -30,7 +30,6 @@ import android.support.v7.widget.CardView;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -748,7 +747,6 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
*/ */
private void moreOptionDialog(final Status status){ private void moreOptionDialog(final Status status){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
final boolean isOwner = status.getAccount().getId().equals(userId); final boolean isOwner = status.getAccount().getId().equals(userId);

View File

@ -131,7 +131,7 @@
<TextView <TextView
android:id="@+id/toot_space_left" android:id="@+id/toot_space_left"
android:layout_width="0dp" android:layout_width="0dp"
android:textColor="?attr/colorAccent" android:textColor="@color/mastodonC4"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center" android:gravity="center"
android:layout_gravity="center" android:layout_gravity="center"

View File

@ -131,7 +131,7 @@
<TextView <TextView
android:id="@+id/toot_space_left" android:id="@+id/toot_space_left"
android:layout_width="0dp" android:layout_width="0dp"
android:textColor="?attr/colorAccent" android:textColor="@color/mastodonC4"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center" android:gravity="center"
android:layout_gravity="center" android:layout_gravity="center"

View File

@ -263,6 +263,7 @@
<string name="toast_error_translate">Une erreur est survenue lors de la traduction !</string> <string name="toast_error_translate">Une erreur est survenue lors de la traduction !</string>
<string name="toast_toot_saved">Brouillon enregistré !</string> <string name="toast_toot_saved">Brouillon enregistré !</string>
<string name="toast_visibility_changed">La visibilité des pouets a été changée pour le compte %1$s</string> <string name="toast_visibility_changed">La visibilité des pouets a été changée pour le compte %1$s</string>
<string name="toast_error_char_limit">Etes-vous sûr que cette instance autorise ce nombre de caractères ? Habituellement, cette valeur est proche de 500 caractères.</string>
<!-- Settings --> <!-- Settings -->
<string name="settings_title_optimisation">Optimisation du chargement</string> <string name="settings_title_optimisation">Optimisation du chargement</string>
<string name="set_toots_page">Nombre de pouets par chargement</string> <string name="set_toots_page">Nombre de pouets par chargement</string>

View File

@ -267,6 +267,7 @@
<string name="toast_saved">The media has been saved!</string> <string name="toast_saved">The media has been saved!</string>
<string name="toast_error_translate">An error occurred while translating!</string> <string name="toast_error_translate">An error occurred while translating!</string>
<string name="toast_toot_saved">Draft saved!</string> <string name="toast_toot_saved">Draft saved!</string>
<string name="toast_error_char_limit">Are you sure this instance allows this number of characters? Usually, this value is close to 500 characters.</string>
<string name="toast_visibility_changed">Visibility of the toots has been changed for the account %1$s</string> <string name="toast_visibility_changed">Visibility of the toots has been changed for the account %1$s</string>
<!-- Settings --> <!-- Settings -->
<string name="settings_title_optimisation">Optimisation of loading</string> <string name="settings_title_optimisation">Optimisation of loading</string>