Show absolute time

This commit is contained in:
kyori 2018-08-16 22:51:23 +09:00
parent 4b4e58302f
commit ca3a5791e3
5 changed files with 60 additions and 26 deletions

View File

@ -34,8 +34,10 @@ public class PreferencesActivity extends BaseActivity
implements SharedPreferences.OnSharedPreferenceChangeListener { implements SharedPreferences.OnSharedPreferenceChangeListener {
private boolean restartActivitiesOnExit; private boolean restartActivitiesOnExit;
private @XmlRes int currentPreferences; private @XmlRes
private @StringRes int currentTitle; int currentPreferences;
private @StringRes
int currentTitle;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -124,6 +126,10 @@ public class PreferencesActivity extends BaseActivity
restartActivitiesOnExit = true; restartActivitiesOnExit = true;
break; break;
} }
case "absoluteTimeView": {
restartActivitiesOnExit = true;
break;
}
case "notificationsEnabled": { case "notificationsEnabled": {
boolean enabled = sharedPreferences.getBoolean("notificationsEnabled", true); boolean enabled = sharedPreferences.getBoolean("notificationsEnabled", true);
if (enabled) { if (enabled) {

View File

@ -1,7 +1,9 @@
package com.keylesspalace.tusky.adapter; package com.keylesspalace.tusky.adapter;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -30,8 +32,10 @@ import com.keylesspalace.tusky.viewdata.StatusViewData;
import com.mikepenz.iconics.utils.Utils; import com.mikepenz.iconics.utils.Utils;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
import at.connyduck.sparkbutton.SparkButton; import at.connyduck.sparkbutton.SparkButton;
import at.connyduck.sparkbutton.SparkEventListener; import at.connyduck.sparkbutton.SparkEventListener;
@ -126,6 +130,20 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
protected void setCreatedAt(@Nullable Date createdAt) { protected void setCreatedAt(@Nullable Date createdAt) {
SharedPreferences defPrefs = PreferenceManager.getDefaultSharedPreferences(timestampInfo.getContext());
if (defPrefs.getBoolean("absoluteTimeView", true)) {
String time = "ERROR!";
if (createdAt != null) {
SimpleDateFormat sdf;
if (new Date().getTime() - createdAt.getTime() > 86400000L) {
sdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
} else {
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
}
time = sdf.format(createdAt);
timestampInfo.setText(time);
}
} else {
// This is the visible timestampInfo. // This is the visible timestampInfo.
String readout; String readout;
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m" /* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
@ -146,6 +164,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
timestampInfo.setText(readout); timestampInfo.setText(readout);
timestampInfo.setContentDescription(readoutAloud); timestampInfo.setContentDescription(readoutAloud);
} }
}
protected void showContent(boolean show) { protected void showContent(boolean show) {
if (show) { if (show) {

View File

@ -277,4 +277,6 @@
<string name="action_set_caption">説明を設定</string> <string name="action_set_caption">説明を設定</string>
<string name="action_remove_media">消去</string> <string name="action_remove_media">消去</string>
<string name="pref_title_absolute_time">絶対時間で表示</string>
</resources> </resources>

View File

@ -347,4 +347,6 @@
<string name="profile_metadata_label_label">Label</string> <string name="profile_metadata_label_label">Label</string>
<string name="profile_metadata_content_label">Content</string> <string name="profile_metadata_content_label">Content</string>
<string name="pref_title_absolute_time">Use absolute time</string>
</resources> </resources>

View File

@ -42,6 +42,11 @@
android:key="alwaysShowSensitiveMedia" android:key="alwaysShowSensitiveMedia"
android:title="@string/pref_title_alway_show_sensitive_media" /> android:title="@string/pref_title_alway_show_sensitive_media" />
<CheckBoxPreference
android:defaultValue="true"
android:key="absoluteTimeView"
android:title="@string/pref_title_absolute_time" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_publishing"> <PreferenceCategory android:title="@string/pref_publishing">