make grace period configurable

This commit is contained in:
Daniel Gultsch 2016-06-02 00:24:37 +02:00
parent e43a01159c
commit 25211f13b3
6 changed files with 58 additions and 26 deletions

View File

@ -58,7 +58,6 @@ public final class Config {
public static final int SOCKET_TIMEOUT = 15; public static final int SOCKET_TIMEOUT = 15;
public static final int CONNECT_TIMEOUT = 90; public static final int CONNECT_TIMEOUT = 90;
public static final int CONNECT_DISCO_TIMEOUT = 20; public static final int CONNECT_DISCO_TIMEOUT = 20;
public static final int CARBON_GRACE_PERIOD = 90;
public static final int MINI_GRACE_PERIOD = 750; public static final int MINI_GRACE_PERIOD = 750;
public static final boolean CLOSE_TCP_WHEN_SWITCHING_TO_BACKGROUND = false; public static final boolean CLOSE_TCP_WHEN_SWITCHING_TO_BACKGROUND = false;

View File

@ -542,9 +542,8 @@ public class Account extends AbstractEntity {
return this.avatar; return this.avatar;
} }
public void activateGracePeriod() { public void activateGracePeriod(long duration) {
this.mEndGracePeriod = SystemClock.elapsedRealtime() this.mEndGracePeriod = SystemClock.elapsedRealtime() + duration;
+ (Config.CARBON_GRACE_PERIOD * 1000);
} }
public void deactivateGracePeriod() { public void deactivateGracePeriod() {

View File

@ -7,8 +7,10 @@ import android.util.Pair;
import net.java.otr4j.session.Session; import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -54,7 +56,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
conversation.setOutgoingChatState(state); conversation.setOutgoingChatState(state);
if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) { if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
mXmppConnectionService.markRead(conversation); mXmppConnectionService.markRead(conversation);
account.activateGracePeriod(); activateGracePeriod(account);
} }
return false; return false;
} else { } else {
@ -498,7 +500,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) { if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) {
mXmppConnectionService.markRead(conversation); mXmppConnectionService.markRead(conversation);
if (query == null) { if (query == null) {
account.activateGracePeriod(); activateGracePeriod(account);
} }
} else { } else {
message.markUnread(); message.markUnread();
@ -639,4 +641,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.sendMessagePacket(account, receipt); mXmppConnectionService.sendMessagePacket(account, receipt);
} }
} }
private static SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
private void activateGracePeriod(Account account) {
long duration = mXmppConnectionService.getPreferences().getLong("race_period_length", 144) * 1000;
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": activating grace period till "+TIME_FORMAT.format(new Date(System.currentTimeMillis() + duration)));
account.activateGracePeriod(duration);
}
} }

View File

@ -83,4 +83,16 @@
<item>@string/presence_xa</item> <item>@string/presence_xa</item>
<item>@string/presence_dnd</item> <item>@string/presence_dnd</item>
</string-array> </string-array>
<string-array name="grace_periods">
<item>@string/gp_short</item>
<item>@string/gp_medium</item>
<item>@string/gp_long</item>
</string-array>
<string-array name="grace_periods_values">
<item>144</item>
<item>610</item>
<item>2584</item>
</string-array>
</resources> </resources>

View File

@ -117,8 +117,8 @@
<string name="pref_led_summary">Blink notification light when a new message arrives</string> <string name="pref_led_summary">Blink notification light when a new message arrives</string>
<string name="pref_sound">Ringtone</string> <string name="pref_sound">Ringtone</string>
<string name="pref_sound_summary">Play sound when a new message arrives</string> <string name="pref_sound_summary">Play sound when a new message arrives</string>
<string name="pref_notification_grace_period">Notification grace period</string> <string name="pref_notification_grace_period">Grace Period</string>
<string name="pref_notification_grace_period_summary">Disable notifications for a short time after a carbon copy was received</string> <string name="pref_notification_grace_period_summary">The length of time Conversations keeps quite after seeing activity on another device</string>
<string name="pref_advanced_options">Advanced</string> <string name="pref_advanced_options">Advanced</string>
<string name="pref_never_send_crash">Never send crash reports</string> <string name="pref_never_send_crash">Never send crash reports</string>
<string name="pref_never_send_crash_summary">By sending in stack traces you are helping the ongoing development of Conversations</string> <string name="pref_never_send_crash_summary">By sending in stack traces you are helping the ongoing development of Conversations</string>
@ -649,4 +649,7 @@
<string name="choose_participants">Choose participants</string> <string name="choose_participants">Choose participants</string>
<string name="creating_conference">Creating conference…</string> <string name="creating_conference">Creating conference…</string>
<string name="invite_again">Invite again</string> <string name="invite_again">Invite again</string>
<string name="gp_short">Short</string>
<string name="gp_medium">Medium</string>
<string name="gp_long">Long</string>
</resources> </resources>

View File

@ -36,6 +36,25 @@
android:key="show_notification" android:key="show_notification"
android:summary="@string/pref_notifications_summary" android:summary="@string/pref_notifications_summary"
android:title="@string/pref_notifications"/> android:title="@string/pref_notifications"/>
<CheckBoxPreference
android:defaultValue="true"
android:dependency="show_notification"
android:key="vibrate_on_notification"
android:summary="@string/pref_vibrate_summary"
android:title="@string/pref_vibrate"/>
<CheckBoxPreference
android:defaultValue="true"
android:dependency="show_notification"
android:key="led"
android:title="@string/pref_led"
android:summary="@string/pref_led_summary"/>
<RingtonePreference
android:defaultValue="content://settings/system/notification_sound"
android:dependency="show_notification"
android:key="notification_ringtone"
android:ringtoneType="notification"
android:summary="@string/pref_sound_summary"
android:title="@string/pref_sound"/>
<PreferenceScreen <PreferenceScreen
android:dependency="show_notification" android:dependency="show_notification"
android:key="quiet_hours" android:key="quiet_hours"
@ -59,25 +78,15 @@
android:positiveButtonText="@string/set" android:positiveButtonText="@string/set"
android:title="@string/title_pref_quiet_hours_end_time"/> android:title="@string/title_pref_quiet_hours_end_time"/>
</PreferenceScreen> </PreferenceScreen>
<CheckBoxPreference <ListPreference
android:defaultValue="true"
android:dependency="show_notification" android:dependency="show_notification"
android:key="vibrate_on_notification" android:key="grace_period_length"
android:summary="@string/pref_vibrate_summary" android:title="@string/pref_notification_grace_period"
android:title="@string/pref_vibrate"/> android:summary="@string/pref_notification_grace_period_summary"
<CheckBoxPreference android:defaultValue="144"
android:defaultValue="true" android:entries="@array/grace_periods"
android:dependency="show_notification" android:entryValues="@array/grace_periods_values"
android:key="led" />
android:title="@string/pref_led"
android:summary="@string/pref_led_summary"/>
<RingtonePreference
android:defaultValue="content://settings/system/notification_sound"
android:dependency="show_notification"
android:key="notification_ringtone"
android:ringtoneType="notification"
android:summary="@string/pref_sound_summary"
android:title="@string/pref_sound"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_attachments"> android:title="@string/pref_attachments">