Add listener

This commit is contained in:
Thomas 2022-10-31 18:05:32 +01:00
parent 0618e1b5d1
commit 2b546afa45
6 changed files with 57 additions and 8 deletions

View file

@ -19,6 +19,7 @@ import static app.fedilab.android.BaseMainActivity.status.UNKNOWN;
import static app.fedilab.android.helper.CacheHelper.deleteDir; import static app.fedilab.android.helper.CacheHelper.deleteDir;
import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN; import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN;
import static app.fedilab.android.helper.Helper.displayReleaseNotesIfNeeded; import static app.fedilab.android.helper.Helper.displayReleaseNotesIfNeeded;
import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -718,6 +719,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
Cyanea.getInstance().edit().apply().recreate(BaseMainActivity.this); Cyanea.getInstance().edit().apply().recreate(BaseMainActivity.this);
} else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) { } else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION); Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION);
String statusEditId = b.getString(Helper.ARG_EDIT_STATUS_ID, null);
Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG) Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
.setAction(getString(R.string.display), view -> { .setAction(getString(R.string.display), view -> {
Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class); Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
@ -729,6 +731,24 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
.setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference)) .setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference))
.setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference)) .setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
.show(); .show();
//The message was edited, we need to update the timeline
if (statusEditId != null) {
//Update message in cache
new Thread(() -> {
StatusCache statusCache = new StatusCache();
statusCache.instance = BaseMainActivity.currentInstance;
statusCache.user_id = BaseMainActivity.currentUserID;
statusCache.status = statusSent;
statusCache.status_id = statusEditId;
try {
new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
//Update timelines
sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null);
}
} }
} }
} }

View file

@ -213,6 +213,8 @@ public class Helper {
public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE"; public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE";
public static final String ARG_STATUS = "ARG_STATUS"; public static final String ARG_STATUS = "ARG_STATUS";
public static final String ARG_STATUS_DELETED = "ARG_STATUS_DELETED"; public static final String ARG_STATUS_DELETED = "ARG_STATUS_DELETED";
public static final String ARG_STATUS_UPDATED = "ARG_STATUS_UPDATED";
public static final String ARG_STATUS_POSTED = "ARG_STATUS_POSTED"; public static final String ARG_STATUS_POSTED = "ARG_STATUS_POSTED";
public static final String ARG_STATUS_ACTION = "ARG_STATUS_ACTION"; public static final String ARG_STATUS_ACTION = "ARG_STATUS_ACTION";
public static final String ARG_STATUS_ACCOUNT_ID_DELETED = "ARG_STATUS_ACCOUNT_ID_DELETED"; public static final String ARG_STATUS_ACCOUNT_ID_DELETED = "ARG_STATUS_ACCOUNT_ID_DELETED";
@ -1604,10 +1606,15 @@ public class Helper {
* @param date Date * @param date Date
*/ */
public static void absoluteDateTimeReveal(final Context context, final TextView tvDate, final Date date) { public static void absoluteDateTimeReveal(final Context context, final TextView tvDate, final Date date, final Date dateEdit) {
tvDate.setOnClickListener(v -> { tvDate.setOnClickListener(v -> {
tvDate.setText(dateDiffFull(date)); if (dateEdit == null) {
tvDate.setText(dateDiffFull(date));
} else {
String dateEditText = context.getString(R.string.full_date_edited, dateDiffFull(date), dateDiffFull(dateEdit));
tvDate.setText(dateEditText);
}
new CountDownTimer((5 * 1000), 1000) { new CountDownTimer((5 * 1000), 1000) {
@ -1615,7 +1622,7 @@ public class Helper {
} }
public void onFinish() { public void onFinish() {
tvDate.setText(dateDiff(context, date)); tvDate.setText(String.format(Locale.getDefault(), "%s%s", dateDiff(context, date), (dateEdit != null ? "*" : "")));
} }
}.start(); }.start();
}); });

View file

@ -328,6 +328,7 @@ public class ComposeWorker extends Worker {
if (dataPost.scheduledDate == null && dataPost.token != null && firstSendMessage != null) { if (dataPost.scheduledDate == null && dataPost.token != null && firstSendMessage != null) {
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true); b.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true);
b.putString(Helper.ARG_EDIT_STATUS_ID, dataPost.statusEditId);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
b.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage); b.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage);
intentBD.putExtras(b); intentBD.putExtras(b);

View file

@ -980,7 +980,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.statusInfo.setVisibility(View.VISIBLE); holder.binding.statusInfo.setVisibility(View.VISIBLE);
holder.binding.reblogsCount.setText(String.valueOf(status.reblogs_count)); holder.binding.reblogsCount.setText(String.valueOf(status.reblogs_count));
holder.binding.favoritesCount.setText(String.valueOf(status.favourites_count)); holder.binding.favoritesCount.setText(String.valueOf(status.favourites_count));
holder.binding.time.setText(Helper.longDateToString(status.created_at));
if (statusToDeal.edited_at != null) {
holder.binding.time.setText(context.getString(R.string.full_date_edited, Helper.longDateToString(status.created_at), Helper.longDateToString(status.edited_at)));
} else {
holder.binding.time.setText(Helper.longDateToString(status.created_at));
}
holder.binding.time.setVisibility(View.VISIBLE); holder.binding.time.setVisibility(View.VISIBLE);
holder.binding.dateShort.setVisibility(View.GONE); holder.binding.dateShort.setVisibility(View.GONE);
holder.binding.visibility.setImageResource(ressource); holder.binding.visibility.setImageResource(ressource);
@ -994,17 +999,25 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.visibilitySmall.setVisibility(View.GONE); holder.binding.visibilitySmall.setVisibility(View.GONE);
holder.binding.reblogsCount.setText(String.valueOf(statusToDeal.reblogs_count)); holder.binding.reblogsCount.setText(String.valueOf(statusToDeal.reblogs_count));
holder.binding.favoritesCount.setText(String.valueOf(statusToDeal.favourites_count)); holder.binding.favoritesCount.setText(String.valueOf(statusToDeal.favourites_count));
holder.binding.time.setText(Helper.dateDiff(context, statusToDeal.created_at)); if (statusToDeal.edited_at != null) {
Helper.absoluteDateTimeReveal(context, holder.binding.time, statusToDeal.created_at); holder.binding.time.setText(String.format(Locale.getDefault(), "%s%s", Helper.dateDiff(context, statusToDeal.created_at), "*"));
} else {
holder.binding.time.setText(Helper.dateDiff(context, statusToDeal.created_at));
}
Helper.absoluteDateTimeReveal(context, holder.binding.time, statusToDeal.created_at, statusToDeal.edited_at);
holder.binding.visibility.setImageResource(ressource); holder.binding.visibility.setImageResource(ressource);
holder.binding.time.setVisibility(View.VISIBLE); holder.binding.time.setVisibility(View.VISIBLE);
} else { } else {
holder.binding.statusInfo.setVisibility(View.GONE); holder.binding.statusInfo.setVisibility(View.GONE);
holder.binding.dateShort.setVisibility(View.VISIBLE); holder.binding.dateShort.setVisibility(View.VISIBLE);
holder.binding.visibilitySmall.setVisibility(View.VISIBLE); holder.binding.visibilitySmall.setVisibility(View.VISIBLE);
holder.binding.dateShort.setText(Helper.dateDiff(context, statusToDeal.created_at)); if (statusToDeal.edited_at != null) {
holder.binding.dateShort.setText(String.format(Locale.getDefault(), "%s%s", Helper.dateDiff(context, statusToDeal.created_at), "*"));
} else {
holder.binding.dateShort.setText(Helper.dateDiff(context, statusToDeal.created_at));
}
holder.binding.time.setVisibility(View.GONE); holder.binding.time.setVisibility(View.GONE);
Helper.absoluteDateTimeReveal(context, holder.binding.dateShort, statusToDeal.created_at); Helper.absoluteDateTimeReveal(context, holder.binding.dateShort, statusToDeal.created_at, statusToDeal.edited_at);
} }
} }

View file

@ -92,6 +92,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION); Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION);
String delete_statuses_for_user = b.getString(Helper.ARG_STATUS_ACCOUNT_ID_DELETED); String delete_statuses_for_user = b.getString(Helper.ARG_STATUS_ACCOUNT_ID_DELETED);
Status status_to_delete = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED); Status status_to_delete = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED);
Status status_to_update = (Status) b.getSerializable(Helper.ARG_STATUS_UPDATED);
Status statusPosted = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED); Status statusPosted = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED);
if (receivedStatus != null && statusAdapter != null) { if (receivedStatus != null && statusAdapter != null) {
int position = getPosition(receivedStatus); int position = getPosition(receivedStatus);
@ -124,6 +125,12 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
timelineStatuses.remove(position); timelineStatuses.remove(position);
statusAdapter.notifyItemRemoved(position); statusAdapter.notifyItemRemoved(position);
} }
} else if (status_to_update != null && statusAdapter != null) {
int position = getPosition(status_to_update);
if (position >= 0) {
timelineStatuses.set(position, status_to_update);
statusAdapter.notifyItemChanged(position);
}
} else if (statusPosted != null && statusAdapter != null && timelineType == Timeline.TimeLineEnum.HOME) { } else if (statusPosted != null && statusAdapter != null && timelineType == Timeline.TimeLineEnum.HOME) {
timelineStatuses.add(0, statusPosted); timelineStatuses.add(0, statusPosted);
statusAdapter.notifyItemInserted(0); statusAdapter.notifyItemInserted(0);

View file

@ -1556,4 +1556,5 @@
<string name="set_live_translate_title">Translate messages</string> <string name="set_live_translate_title">Translate messages</string>
<string name="set_live_translate">Force translation to a specific language. Choose first value to reset to device settings</string> <string name="set_live_translate">Force translation to a specific language. Choose first value to reset to device settings</string>
<string name="edit_message">Edit message</string> <string name="edit_message">Edit message</string>
<string name="full_date_edited">%1$s edited %2$s</string>
</resources> </resources>