mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-24 09:52:18 -05:00
Add an option to show seconds in the timestamp
This commit is contained in:
parent
8858b362fe
commit
170f632c07
@ -15,6 +15,9 @@
|
|||||||
<string name="key_24h_format" translatable="false">24h_format</string>
|
<string name="key_24h_format" translatable="false">24h_format</string>
|
||||||
<string name="default_24h_format" translatable="false">true</string>
|
<string name="default_24h_format" translatable="false">true</string>
|
||||||
|
|
||||||
|
<string name="key_include_seconds" translatable="false">include_seconds</string>
|
||||||
|
<string name="default_include_seconds" translatable="false">true</string>
|
||||||
|
|
||||||
<string name="key_reconnect" translatable="false">reconnect</string>
|
<string name="key_reconnect" translatable="false">reconnect</string>
|
||||||
<string name="default_reconnect" translatable="false">false</string>
|
<string name="default_reconnect" translatable="false">false</string>
|
||||||
|
|
||||||
|
@ -199,6 +199,8 @@
|
|||||||
<string name="settings_timestamp_desc">Prefix all messages with a timestamp</string>
|
<string name="settings_timestamp_desc">Prefix all messages with a timestamp</string>
|
||||||
<string name="settings_24h_title">24 hour format</string>
|
<string name="settings_24h_title">24 hour format</string>
|
||||||
<string name="settings_24h_desc">Use 24 hour format for timestamps</string>
|
<string name="settings_24h_desc">Use 24 hour format for timestamps</string>
|
||||||
|
<string name="settings_include_seconds_title">Show seconds</string>
|
||||||
|
<string name="settings_include_seconds_desc">Include seconds in timestamps</string>
|
||||||
|
|
||||||
<string name="settings_highlight">Highlight</string>
|
<string name="settings_highlight">Highlight</string>
|
||||||
<string name="settings_sound_highlight_title">Play sound on highlight</string>
|
<string name="settings_sound_highlight_title">Play sound on highlight</string>
|
||||||
|
@ -80,6 +80,12 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
android:key="@string/key_24h_format"
|
android:key="@string/key_24h_format"
|
||||||
android:defaultValue="@string/default_24h_format"
|
android:defaultValue="@string/default_24h_format"
|
||||||
android:dependency="@string/key_show_timestamp" />
|
android:dependency="@string/key_show_timestamp" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:title="@string/settings_include_seconds_title"
|
||||||
|
android:summary="@string/settings_include_seconds_desc"
|
||||||
|
android:key="@string/key_include_seconds"
|
||||||
|
android:defaultValue="@string/default_include_seconds"
|
||||||
|
android:dependency="@string/key_show_timestamp" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:title="@string/settings_joinpartquit_title"
|
android:title="@string/settings_joinpartquit_title"
|
||||||
android:summary="@string/settings_joinpartquit_desc"
|
android:summary="@string/settings_joinpartquit_desc"
|
||||||
|
@ -232,7 +232,7 @@ public class Message
|
|||||||
if (canvas == null) {
|
if (canvas == null) {
|
||||||
String prefix = hasIcon() && settings.showIcons() ? " " : "";
|
String prefix = hasIcon() && settings.showIcons() ? " " : "";
|
||||||
String nick = hasSender() ? "<" + sender + "> " : "";
|
String nick = hasSender() ? "<" + sender + "> " : "";
|
||||||
String timestamp = settings.showTimestamp() ? renderTimeStamp(settings.use24hFormat()) : "";
|
String timestamp = settings.showTimestamp() ? renderTimeStamp(settings.use24hFormat(), settings.includeSeconds()) : "";
|
||||||
|
|
||||||
canvas = new SpannableString(prefix + timestamp + nick);
|
canvas = new SpannableString(prefix + timestamp + nick);
|
||||||
SpannableString renderedText;
|
SpannableString renderedText;
|
||||||
@ -353,12 +353,13 @@ public class Message
|
|||||||
* @param use24hFormat
|
* @param use24hFormat
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String renderTimeStamp(boolean use24hFormat)
|
public String renderTimeStamp(boolean use24hFormat, boolean includeSeconds)
|
||||||
{
|
{
|
||||||
Date date = new Date(timestamp);
|
Date date = new Date(timestamp);
|
||||||
|
|
||||||
int hours = date.getHours();
|
int hours = date.getHours();
|
||||||
int minutes = date.getMinutes();
|
int minutes = date.getMinutes();
|
||||||
|
int seconds = date.getSeconds();
|
||||||
|
|
||||||
if (!use24hFormat) {
|
if (!use24hFormat) {
|
||||||
hours = Math.abs(12 - hours);
|
hours = Math.abs(12 - hours);
|
||||||
@ -367,6 +368,17 @@ public class Message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "[" + (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + "] ";
|
if (includeSeconds) {
|
||||||
|
return String.format(
|
||||||
|
"[%02d:%02d:%02d]",
|
||||||
|
hours,
|
||||||
|
minutes,
|
||||||
|
seconds);
|
||||||
|
} else {
|
||||||
|
return String.format(
|
||||||
|
"[%02d:%02d]",
|
||||||
|
hours,
|
||||||
|
minutes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,20 @@ public class Settings
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include seconds in timestamps?
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean includeSeconds()
|
||||||
|
{
|
||||||
|
return preferences.getBoolean(
|
||||||
|
resources.getString(R.string.key_include_seconds),
|
||||||
|
Boolean.parseBoolean(resources.getString(R.string.default_include_seconds))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is reconnect on disconnect enabled?
|
* Is reconnect on disconnect enabled?
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user