Add listener
This commit is contained in:
parent
0618e1b5d1
commit
2b546afa45
|
@ -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.Helper.PREF_USER_TOKEN;
|
||||
import static app.fedilab.android.helper.Helper.displayReleaseNotesIfNeeded;
|
||||
import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -718,6 +719,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
Cyanea.getInstance().edit().apply().recreate(BaseMainActivity.this);
|
||||
} else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
|
||||
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)
|
||||
.setAction(getString(R.string.display), view -> {
|
||||
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))
|
||||
.setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,6 +213,8 @@ public class Helper {
|
|||
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_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_ACTION = "ARG_STATUS_ACTION";
|
||||
public static final String ARG_STATUS_ACCOUNT_ID_DELETED = "ARG_STATUS_ACCOUNT_ID_DELETED";
|
||||
|
@ -1604,10 +1606,15 @@ public class Helper {
|
|||
* @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.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) {
|
||||
|
||||
|
@ -1615,7 +1622,7 @@ public class Helper {
|
|||
}
|
||||
|
||||
public void onFinish() {
|
||||
tvDate.setText(dateDiff(context, date));
|
||||
tvDate.setText(String.format(Locale.getDefault(), "%s%s", dateDiff(context, date), (dateEdit != null ? "*" : "")));
|
||||
}
|
||||
}.start();
|
||||
});
|
||||
|
|
|
@ -328,6 +328,7 @@ public class ComposeWorker extends Worker {
|
|||
if (dataPost.scheduledDate == null && dataPost.token != null && firstSendMessage != null) {
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true);
|
||||
b.putString(Helper.ARG_EDIT_STATUS_ID, dataPost.statusEditId);
|
||||
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
|
||||
b.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage);
|
||||
intentBD.putExtras(b);
|
||||
|
|
|
@ -980,7 +980,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
holder.binding.statusInfo.setVisibility(View.VISIBLE);
|
||||
holder.binding.reblogsCount.setText(String.valueOf(status.reblogs_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.dateShort.setVisibility(View.GONE);
|
||||
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.reblogsCount.setText(String.valueOf(statusToDeal.reblogs_count));
|
||||
holder.binding.favoritesCount.setText(String.valueOf(statusToDeal.favourites_count));
|
||||
holder.binding.time.setText(Helper.dateDiff(context, statusToDeal.created_at));
|
||||
Helper.absoluteDateTimeReveal(context, holder.binding.time, statusToDeal.created_at);
|
||||
if (statusToDeal.edited_at != null) {
|
||||
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.time.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.binding.statusInfo.setVisibility(View.GONE);
|
||||
holder.binding.dateShort.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);
|
||||
Helper.absoluteDateTimeReveal(context, holder.binding.dateShort, statusToDeal.created_at);
|
||||
Helper.absoluteDateTimeReveal(context, holder.binding.dateShort, statusToDeal.created_at, statusToDeal.edited_at);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION);
|
||||
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_update = (Status) b.getSerializable(Helper.ARG_STATUS_UPDATED);
|
||||
Status statusPosted = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED);
|
||||
if (receivedStatus != null && statusAdapter != null) {
|
||||
int position = getPosition(receivedStatus);
|
||||
|
@ -124,6 +125,12 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
timelineStatuses.remove(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) {
|
||||
timelineStatuses.add(0, statusPosted);
|
||||
statusAdapter.notifyItemInserted(0);
|
||||
|
|
|
@ -1556,4 +1556,5 @@
|
|||
<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="edit_message">Edit message</string>
|
||||
<string name="full_date_edited">%1$s edited %2$s</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue