Auto-split long toots
This commit is contained in:
parent
bcfa179e20
commit
c7ebdc50c2
|
@ -50,6 +50,7 @@ import android.text.Html;
|
|||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -192,6 +193,8 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
private String idRedirect;
|
||||
private String userId, instance;
|
||||
private Account account;
|
||||
private ArrayList<String> splitToot;
|
||||
private int stepSpliToot;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -484,6 +487,17 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
toot_it.setEnabled(true);
|
||||
return;
|
||||
}
|
||||
boolean split_toot = sharedpreferences.getBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS, false);
|
||||
int split_toot_size = sharedpreferences.getInt(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE, Helper.SPLIT_TOOT_SIZE);
|
||||
String tootContent;
|
||||
if( !split_toot || (toot_content.getText().toString().trim().length() < split_toot_size)){
|
||||
tootContent = toot_content.getText().toString().trim();
|
||||
}else{
|
||||
|
||||
splitToot = Helper.splitToots(toot_content.getText().toString().trim(), split_toot_size);
|
||||
tootContent = splitToot.get(0);
|
||||
stepSpliToot = 1;
|
||||
}
|
||||
Status toot = new Status();
|
||||
toot.setSensitive(isSensitive);
|
||||
toot.setMedia_attachments(attachments);
|
||||
|
@ -492,7 +506,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
toot.setVisibility(visibility);
|
||||
if( tootReply != null)
|
||||
toot.setIn_reply_to_id(tootReply.getId());
|
||||
toot.setContent(toot_content.getText().toString().trim());
|
||||
toot.setContent(tootContent);
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
@ -1549,6 +1563,27 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
}
|
||||
return;
|
||||
}
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean split_toot = sharedpreferences.getBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS, false);
|
||||
int split_toot_size = sharedpreferences.getInt(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE, Helper.SPLIT_TOOT_SIZE);
|
||||
|
||||
|
||||
if( split_toot && (toot_content.getText().toString().trim().length() >= split_toot_size) && stepSpliToot < splitToot.size()){
|
||||
String tootContent = splitToot.get(stepSpliToot);
|
||||
stepSpliToot += 1;
|
||||
Status toot = new Status();
|
||||
toot.setSensitive(isSensitive);
|
||||
toot.setMedia_attachments(attachments);
|
||||
if( toot_cw_content.getText().toString().trim().length() > 0)
|
||||
toot.setSpoiler_text(toot_cw_content.getText().toString().trim());
|
||||
toot.setVisibility(visibility);
|
||||
if( apiResponse.getStatuses() != null)
|
||||
toot.setIn_reply_to_id(apiResponse.getStatuses().get(0).getId());
|
||||
toot.setContent(tootContent);
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
return;
|
||||
|
||||
}
|
||||
if(restored != -1){
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new StatusStoredDAO(getApplicationContext(), db).remove(restored);
|
||||
|
|
|
@ -671,6 +671,19 @@ public class SettingsFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
boolean split_toot = sharedpreferences.getBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS, false);
|
||||
final CheckBox set_split_toot = rootView.findViewById(R.id.set_automatically_split_toot);
|
||||
set_split_toot.setChecked(split_toot);
|
||||
set_split_toot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS, set_split_toot.isChecked());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
//Translators
|
||||
final Spinner translation_layout_spinner = rootView.findViewById(R.id.translation_layout_spinner);
|
||||
ArrayAdapter<CharSequence> adapterTrans = ArrayAdapter.createFromResource(getContext(),
|
||||
|
|
|
@ -297,6 +297,8 @@ public class Helper {
|
|||
public static final String SET_DISPLAY_GLOBAL = "set_display_global";
|
||||
public static final String SET_ALLOW_CROSS_ACTIONS = "set_allow_cross_actions";
|
||||
public static final String SET_DISPLAY_BOOST_COUNT = "set_display_boost_count";
|
||||
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS = "set_automatically_split_toots";
|
||||
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size";
|
||||
//End points
|
||||
public static final String EP_AUTHORIZE = "/oauth/authorize";
|
||||
|
||||
|
@ -311,6 +313,7 @@ public class Helper {
|
|||
//Refresh job
|
||||
public static final int MINUTES_BETWEEN_NOTIFICATIONS_REFRESH = 15;
|
||||
public static final int MINUTES_BETWEEN_HOME_TIMELINE = 30;
|
||||
public static final int SPLIT_TOOT_SIZE = 500;
|
||||
|
||||
//Translate wait time
|
||||
public static final String LAST_TRANSLATION_TIME = "last_translation_time";
|
||||
|
@ -2202,4 +2205,34 @@ public class Helper {
|
|||
pagerAdapter.addTabPage(title);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allows to split the toot by dot "." for sentences - adds number at the end automatically
|
||||
* @param content String initial content
|
||||
* @param maxChars int the max chars per toot (minus 10 to write the page: 1/x, 2/x etc.)
|
||||
* @return ArrayList<String> split toot
|
||||
*/
|
||||
public static ArrayList<String> splitToots(String content, int maxChars){
|
||||
String[] splitContent = content.split("\\.");
|
||||
ArrayList<String> splitToot = new ArrayList<>();
|
||||
StringBuilder tempContent = new StringBuilder(splitContent[0]);
|
||||
for(int i= 0 ; i < splitContent.length ; i++){
|
||||
if( i < (splitContent.length-1) && (tempContent.length() + splitContent[i+1].length()) < (maxChars-10)) {
|
||||
tempContent.append(".").append(splitContent[i + 1]);
|
||||
}else {
|
||||
splitToot.add(tempContent.toString());
|
||||
if( i < (splitContent.length-1) )
|
||||
tempContent = new StringBuilder(splitContent[i+1]);
|
||||
}
|
||||
}
|
||||
int i=1;
|
||||
ArrayList<String> reply = new ArrayList<>();
|
||||
for(String newContent : splitToot){
|
||||
reply.add((i-1), newContent + " - " + i + "/" + splitToot.size());
|
||||
i++;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -178,6 +178,12 @@
|
|||
android:text="@string/set_share_details"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_automatically_split_toot"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/set_automatically_split_toot"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Resize pictures -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -77,6 +77,8 @@
|
|||
android:text="@string/set_preview_reply"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/set_preview_reply_pp_container"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -177,6 +179,12 @@
|
|||
android:text="@string/set_share_details"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_automatically_split_toot"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/set_automatically_split_toot"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Resize pictures -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -327,6 +327,7 @@
|
|||
<string name="set_preview_reply_pp">Display profile pictures?</string>
|
||||
<string name="set_multiaccount_actions">Allow interactions between accounts?</string>
|
||||
<string name="set_fit_preview">Fit preview images</string>
|
||||
<string name="set_automatically_split_toot">Automatically split toots over 500 chars in replies</string>
|
||||
<string name="note_no_space">You have reached the 160 characters allowed!</string>
|
||||
<string name="username_no_space">You have reached the 30 characters allowed!</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue