Delete & redraft

This commit is contained in:
stom79 2018-08-14 14:33:52 +02:00
parent 5c1eab2299
commit 938c83f106
55 changed files with 43 additions and 3 deletions

View File

@ -1833,14 +1833,22 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
//Sensitive content
toot_sensitive.setChecked(status.isSensitive());
if( status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0 ){
toot_cw_content.setText(status.getSpoiler_text());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
toot_cw_content.setText(Html.fromHtml(status.getSpoiler_text(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
toot_cw_content.setText(Html.fromHtml(status.getSpoiler_text()));
toot_cw_content.setVisibility(View.VISIBLE);
}else {
toot_cw_content.setText("");
toot_cw_content.setVisibility(View.GONE);
}
String content = status.getContent();
toot_content.setText(content);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
toot_content.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
toot_content.setText(Html.fromHtml(content));
toot_space_left.setText(String.valueOf(toot_content.length()));
toot_content.setSelection(toot_content.getText().length());
switch (status.getVisibility()){

View File

@ -45,6 +45,8 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private boolean muteNotifications;
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface){
this.contextReference = new WeakReference<>(context);
this.listener = onPostActionInterface;

View File

@ -115,6 +115,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO;
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
import static fr.gouv.etalab.mastodon.activities.MainActivity.currentLocale;
@ -144,7 +145,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private final int COMPACT_STATUS = 3;
private int conversationPosition;
private List<String> timedMute;
private boolean redraft;
public StatusListAdapter(Context context, List<String> timedMute, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
@ -159,6 +160,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
this.targetedId = targetedId;
this.translator = translator;
this.timedMute = timedMute;
redraft = false;
}
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
@ -172,6 +174,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
this.type = type;
this.targetedId = targetedId;
this.translator = translator;
redraft = false;
}
public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
@ -185,6 +188,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
this.conversationPosition = position;
this.targetedId = targetedId;
this.translator = translator;
redraft = false;
}
public void updateMuted(List<String> timedMute){
@ -1259,6 +1263,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
}else {
popup.getMenu().findItem(R.id.action_redraft).setVisible(false);
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
if( type != RetrieveFeedsAsyncTask.Type.HOME){
@ -1270,6 +1275,17 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
AlertDialog.Builder builderInner;
final API.StatusAction doAction;
switch (item.getItemId()) {
case R.id.action_redraft:
builderInner = new AlertDialog.Builder(context);
builderInner.setTitle(stringArrayConf[1]);
redraft = true;
doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_remove:
builderInner = new AlertDialog.Builder(context);
builderInner.setTitle(stringArrayConf[0]);
@ -1523,6 +1539,14 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if(doAction == API.StatusAction.UNSTATUS ){
String targetedId = status.getId();
new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( redraft ){
long id = new StatusStoredDAO(context, db).insertStatus(status, null);
Intent intentToot = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
b.putLong("restored", id);
intentToot.putExtras(b);
context.startActivity(intentToot);
}
}else if(doAction == API.StatusAction.REPORT ){
String comment = null;
if( finalInput.getText() != null)

View File

@ -17,6 +17,10 @@
android:id="@+id/action_report"
android:title="@string/more_action_3"
app:showAsAction="never" />
<item
android:id="@+id/action_redraft"
android:title="@string/more_action_9"
app:showAsAction="never" />
<item
android:id="@+id/action_remove"
android:title="@string/more_action_4"

View File

@ -124,6 +124,7 @@
<string name="more_action_6">Share</string>
<string name="more_action_7">Mention</string>
<string name="more_action_8">Timed mute</string>
<string name="more_action_9">Delete &amp; re-draft</string>
<string-array name="more_action_confirm">
<item>Mute this account?</item>
<item>Block this account?</item>
@ -132,6 +133,7 @@
<string-array name="more_action_owner_confirm">
<item>Remove this toot?</item>
<item>Delete &amp; re-draft this toot?</item>
</string-array>
<plurals name="preview_replies">