show participants count/last seen in toolbar indicator

This commit is contained in:
kosyak 2024-09-02 01:00:39 +02:00
parent 00817b79be
commit ffbdad7503
4 changed files with 100 additions and 12 deletions

View file

@ -504,7 +504,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
&& contact.getLastseen() > 0 && contact.getLastseen() > 0
&& contact.getPresences().allOrNonSupport(Namespace.IDLE)) { && contact.getPresences().allOrNonSupport(Namespace.IDLE)) {
binding.detailsLastseen.setVisibility(View.VISIBLE); binding.detailsLastseen.setVisibility(View.VISIBLE);
binding.detailsLastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen())); binding.detailsLastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen(), false));
} else { } else {
binding.detailsLastseen.setVisibility(View.GONE); binding.detailsLastseen.setVisibility(View.GONE);
} }

View file

@ -42,10 +42,14 @@ import android.app.FragmentTransaction;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -95,7 +99,9 @@ import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.PhoneNumberUtilWrapper; import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
import eu.siacs.conversations.utils.SignupUtils; import eu.siacs.conversations.utils.SignupUtils;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import io.michaelrocks.libphonenumber.android.NumberParseException; import io.michaelrocks.libphonenumber.android.NumberParseException;
@ -135,6 +141,10 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
private boolean mActivityPaused = true; private boolean mActivityPaused = true;
private final AtomicBoolean mRedirectInProcess = new AtomicBoolean(false); private final AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
private final Handler handler = new Handler(Looper.getMainLooper());
private final Runnable refreshTitleRunnable = this::invalidateActionBarTitle;
private boolean showLastSeen = false;
private static boolean isViewOrShareIntent(Intent i) { private static boolean isViewOrShareIntent(Intent i) {
Log.d(Config.LOGTAG, "action: " + (i == null ? null : i.getAction())); Log.d(Config.LOGTAG, "action: " + (i == null ? null : i.getAction()));
return i != null && VIEW_AND_SHARE_ACTIONS.contains(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION); return i != null && VIEW_AND_SHARE_ACTIONS.contains(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
@ -660,6 +670,8 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
this.mSkipBackgroundBinding = false; this.mSkipBackgroundBinding = false;
} }
mRedirectInProcess.set(false); mRedirectInProcess.set(false);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
this.showLastSeen = preferences.getBoolean("last_activity", false);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation); BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setSelectedItemId(R.id.chats); bottomNavigationView.setSelectedItemId(R.id.chats);
@ -735,6 +747,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
if (actionBar == null) { if (actionBar == null) {
return; return;
} }
final FragmentManager fragmentManager = getFragmentManager(); final FragmentManager fragmentManager = getFragmentManager();
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment); final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
if (mainFragment instanceof ConversationFragment) { if (mainFragment instanceof ConversationFragment) {
@ -750,10 +763,38 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
binding.toolbar, binding.toolbar,
(v) -> openConversationDetails(conversation) (v) -> openConversationDetails(conversation)
); );
if (conversation.getMode() == Conversation.MODE_MULTI && conversation.getNextCounterpart() == null) {
int usersCount = conversation.getMucOptions().getUserCount();
if (usersCount > 0) {
actionBar.setSubtitle(getResources().getQuantityString(R.plurals.x_participants, conversation.getMucOptions().getUserCount(), conversation.getMucOptions().getUserCount()));
} else {
actionBar.setSubtitle("");
}
handler.postDelayed(refreshTitleRunnable, 5000L);
} else if (conversation.getMode() == Conversation.MODE_SINGLE) {
Contact contact = conversation.getContact();
if (showLastSeen
&& contact.getLastseen() > 0
&& contact.getPresences().allOrNonSupport(Namespace.IDLE)) {
actionBar.setSubtitle(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen(), true));
} else {
actionBar.setSubtitle("");
handler.removeCallbacks(refreshTitleRunnable);
}
} else {
actionBar.setSubtitle("");
handler.removeCallbacks(refreshTitleRunnable);
}
return; return;
} }
} }
handler.removeCallbacks(refreshTitleRunnable);
actionBar.setTitle(R.string.app_name); actionBar.setTitle(R.string.app_name);
actionBar.setSubtitle("");
actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false);
ActionBarUtil.resetActionBarOnClickListeners(binding.toolbar); ActionBarUtil.resetActionBarOnClickListeners(binding.toolbar);
} }

View file

@ -205,26 +205,60 @@ public class UIHelper {
.get(Calendar.DAY_OF_YEAR); .get(Calendar.DAY_OF_YEAR);
} }
public static String lastseen(Context context, boolean active, long time) { public static String lastseen(Context context, boolean active, long time, boolean shortText) {
long difference = (System.currentTimeMillis() - time) / 1000; long difference = (System.currentTimeMillis() - time) / 1000;
if (active) { if (active) {
return context.getString(R.string.online_right_now); if (shortText) {
return context.getString(R.string.online_right_now_short);
} else {
return context.getString(R.string.online_right_now);
}
} else if (difference < 60) { } else if (difference < 60) {
return context.getString(R.string.last_seen_now); if (shortText) {
return context.getString(R.string.last_seen_now_short);
} else {
return context.getString(R.string.last_seen_now);
}
} else if (difference < 60 * 2) { } else if (difference < 60 * 2) {
return context.getString(R.string.last_seen_min); if (shortText) {
return context.getString(R.string.last_seen_min_short);
} else {
return context.getString(R.string.last_seen_min);
}
} else if (difference < 60 * 60) { } else if (difference < 60 * 60) {
return context.getString(R.string.last_seen_mins, Math.round(difference / 60.0)); if (shortText) {
return context.getString(R.string.last_seen_mins_short, Math.round(difference / 60.0));
} else {
return context.getString(R.string.last_seen_mins, Math.round(difference / 60.0));
}
} else if (difference < 60 * 60 * 2) { } else if (difference < 60 * 60 * 2) {
return context.getString(R.string.last_seen_hour); if (shortText) {
return context.getString(R.string.last_seen_hour_short);
} else {
return context.getString(R.string.last_seen_hour);
}
} else if (difference < 60 * 60 * 24) { } else if (difference < 60 * 60 * 24) {
return context.getString(R.string.last_seen_hours, if (shortText) {
Math.round(difference / (60.0 * 60.0))); return context.getString(R.string.last_seen_hours_short,
Math.round(difference / (60.0 * 60.0)));
} else {
return context.getString(R.string.last_seen_hours,
Math.round(difference / (60.0 * 60.0)));
}
} else if (difference < 60 * 60 * 48) { } else if (difference < 60 * 60 * 48) {
return context.getString(R.string.last_seen_day); if (shortText) {
return context.getString(R.string.last_seen_day_short);
} else {
return context.getString(R.string.last_seen_day);
}
} else { } else {
return context.getString(R.string.last_seen_days, if (shortText) {
Math.round(difference / (60.0 * 60.0 * 24.0))); return context.getString(R.string.last_seen_days_short,
Math.round(difference / (60.0 * 60.0 * 24.0)));
} else {
return context.getString(R.string.last_seen_days,
Math.round(difference / (60.0 * 60.0 * 24.0)));
}
} }
} }

View file

@ -1108,6 +1108,19 @@
<string name="avater_shape_rounded_square">Rounded Square</string> <string name="avater_shape_rounded_square">Rounded Square</string>
<string name="avater_shape_square">Square</string> <string name="avater_shape_square">Square</string>
<plurals name="x_participants">
<item quantity="one">%1$d participant</item>
<item quantity="other">%1$d participants</item>
</plurals>
<string name="online_right_now_short">online</string>
<string name="last_seen_now_short">just now</string>
<string name="last_seen_min_short">one minute ago</string>
<string name="last_seen_mins_short">%d minutes ago</string>
<string name="last_seen_hour_short">one hour ago</string>
<string name="last_seen_hours_short">%d hours ago</string>
<string name="last_seen_day_short">one day ago</string>
<string name="last_seen_days_short">%d days ago</string>
<string name="clarendon" translatable="false">Clarendon</string> <string name="clarendon" translatable="false">Clarendon</string>
<string name="oldman" translatable="false">OldMan</string> <string name="oldman" translatable="false">OldMan</string>