made disabled notifications permanent across restarts
This commit is contained in:
parent
d5227e5c25
commit
919c98207b
|
@ -43,6 +43,7 @@ public class Conversation extends AbstractEntity {
|
||||||
|
|
||||||
public static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption";
|
public static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption";
|
||||||
public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password";
|
public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password";
|
||||||
|
public static final String ATTRIBUTE_MUTED_TILL = "muted_till";
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String contactUuid;
|
private String contactUuid;
|
||||||
|
@ -54,8 +55,6 @@ public class Conversation extends AbstractEntity {
|
||||||
|
|
||||||
private JSONObject attributes = new JSONObject();
|
private JSONObject attributes = new JSONObject();
|
||||||
|
|
||||||
private long mutedTill = 0;
|
|
||||||
|
|
||||||
private String nextPresence;
|
private String nextPresence;
|
||||||
|
|
||||||
private transient CopyOnWriteArrayList<Message> messages = null;
|
private transient CopyOnWriteArrayList<Message> messages = null;
|
||||||
|
@ -452,12 +451,13 @@ public class Conversation extends AbstractEntity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMutedTill(long mutedTill) {
|
public void setMutedTill(long value) {
|
||||||
this.mutedTill = mutedTill;
|
this.setAttribute(ATTRIBUTE_MUTED_TILL, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMuted() {
|
public boolean isMuted() {
|
||||||
return SystemClock.elapsedRealtime() < this.mutedTill;
|
return SystemClock.elapsedRealtime() < this.getLongAttribute(
|
||||||
|
ATTRIBUTE_MUTED_TILL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setAttribute(String key, String value) {
|
public boolean setAttribute(String key, String value) {
|
||||||
|
@ -489,4 +489,17 @@ public class Conversation extends AbstractEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLongAttribute(String key, long defaultValue) {
|
||||||
|
String value = this.getAttribute(key);
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return Long.parseLong(value);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class NotificationService {
|
||||||
public int NOTIFICATION_ID = 0x2342;
|
public int NOTIFICATION_ID = 0x2342;
|
||||||
private Conversation mOpenConversation;
|
private Conversation mOpenConversation;
|
||||||
private boolean mIsInForeground;
|
private boolean mIsInForeground;
|
||||||
|
|
||||||
private long mEndGracePeriod = 0L;
|
private long mEndGracePeriod = 0L;
|
||||||
|
|
||||||
public NotificationService(XmppConnectionService service) {
|
public NotificationService(XmppConnectionService service) {
|
||||||
|
@ -60,8 +60,8 @@ public class NotificationService {
|
||||||
mList.add(message);
|
mList.add(message);
|
||||||
notifications.put(conversationUuid, mList);
|
notifications.put(conversationUuid, mList);
|
||||||
}
|
}
|
||||||
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null)
|
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
|
||||||
|| !isScreenOn) && !inGracePeriod());
|
&& !inGracePeriod());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
@ -226,15 +226,15 @@ public class NotificationService {
|
||||||
this.mIsInForeground = foreground;
|
this.mIsInForeground = foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void activateGracePeriod() {
|
public void activateGracePeriod() {
|
||||||
this.mEndGracePeriod = SystemClock.elapsedRealtime() + (Config.CARBON_GRACE_PERIOD * 1000);
|
this.mEndGracePeriod = SystemClock.elapsedRealtime()
|
||||||
|
+ (Config.CARBON_GRACE_PERIOD * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivateGracePeriod() {
|
public void deactivateGracePeriod() {
|
||||||
this.mEndGracePeriod = 0L;
|
this.mEndGracePeriod = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inGracePeriod() {
|
private boolean inGracePeriod() {
|
||||||
return SystemClock.elapsedRealtime() < this.mEndGracePeriod;
|
return SystemClock.elapsedRealtime() < this.mEndGracePeriod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -585,6 +585,8 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
+ (durations[which] * 1000);
|
+ (durations[which] * 1000);
|
||||||
}
|
}
|
||||||
conversation.setMutedTill(till);
|
conversation.setMutedTill(till);
|
||||||
|
activity.xmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
|
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
|
||||||
.findFragmentByTag("conversation");
|
.findFragmentByTag("conversation");
|
||||||
if (selectedFragment != null) {
|
if (selectedFragment != null) {
|
||||||
|
|
|
@ -131,9 +131,9 @@ public class ConversationFragment extends Fragment {
|
||||||
activity.endConversation(conversation);
|
activity.endConversation(conversation);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private OnClickListener joinMuc = new OnClickListener() {
|
private OnClickListener joinMuc = new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
activity.xmppConnectionService.joinMuc(conversation);
|
activity.xmppConnectionService.joinMuc(conversation);
|
||||||
|
@ -438,6 +438,8 @@ public class ConversationFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
conversation.setMutedTill(0);
|
conversation.setMutedTill(0);
|
||||||
|
activity.xmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
updateMessages();
|
updateMessages();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -502,8 +504,8 @@ public class ConversationFragment extends Fragment {
|
||||||
R.string.leave, leaveMuc);
|
R.string.leave, leaveMuc);
|
||||||
break;
|
break;
|
||||||
case MucOptions.KICKED_FROM_ROOM:
|
case MucOptions.KICKED_FROM_ROOM:
|
||||||
showSnackbar(R.string.conference_kicked,
|
showSnackbar(R.string.conference_kicked, R.string.join,
|
||||||
R.string.join, joinMuc);
|
joinMuc);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -425,7 +425,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
view.getLayoutParams().height = 1;
|
view.getLayoutParams().height = 1;
|
||||||
} else {
|
} else {
|
||||||
view.getLayoutParams().height = 0;
|
view.getLayoutParams().height = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
view.setLayoutParams(view.getLayoutParams());
|
view.setLayoutParams(view.getLayoutParams());
|
||||||
return view;
|
return view;
|
||||||
|
|
Loading…
Reference in New Issue