-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification signal settings. #305 #403
Changes from 1 commit
1e7cf56
011b091
4b37347
5635239
562d08b
c4281ce
0abbd2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
|
||
/** | ||
* Represents {@link NotificationSignal} for {@link Notification#DEFAULT_ALL}. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class AllSignal implements NotificationSignal | ||
{ | ||
@Override | ||
public int value() | ||
{ | ||
return Notification.DEFAULT_ALL; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.notification.signals; | ||
|
||
/** | ||
* Abstract base class for {@link NotificationSignal}s that simply delegate to another instance, composed in the constructor. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public abstract class DelegatingNotificationSignal implements NotificationSignal | ||
{ | ||
private final NotificationSignal mDelegate; | ||
|
||
|
||
public DelegatingNotificationSignal(NotificationSignal delegate) | ||
{ | ||
mDelegate = delegate; | ||
} | ||
|
||
|
||
@Override | ||
public final int value() | ||
{ | ||
return mDelegate.value(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
|
||
/** | ||
* {@link NotificationSignal} for representing, adding, or toggling {@link Notification#DEFAULT_LIGHTS} | ||
* value. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class Lights extends DelegatingNotificationSignal | ||
{ | ||
public Lights(boolean enable, NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_LIGHTS, enable, original)); | ||
} | ||
|
||
|
||
public Lights(NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_LIGHTS, true, original)); | ||
} | ||
|
||
|
||
public Lights() | ||
{ | ||
super(new Toggled(Notification.DEFAULT_LIGHTS, true, new NoSignal())); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
|
||
/** | ||
* {@link NotificationSignal} for representing, adding, or toggling {@link Notification#DEFAULT_SOUND} | ||
* value. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class Sound extends DelegatingNotificationSignal | ||
{ | ||
public Sound(boolean enable, NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_SOUND, enable, original)); | ||
} | ||
|
||
|
||
public Sound(NotificationSignal original) | ||
{ | ||
super(new Toggled(Notification.DEFAULT_SOUND, true, original)); | ||
} | ||
|
||
|
||
public Sound() | ||
{ | ||
super(new Toggled(Notification.DEFAULT_SOUND, true, new NoSignal())); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,24 +20,26 @@ | |
|
||
|
||
/** | ||
* {@link NotificationSignal} that delegates to either {@link NoSignal} or {@link SettingsSignal} based on the received boolean. | ||
* {@link NotificationSignal} that evaluates to either {@link NoSignal} or {@link SettingsSignal} based on the received boolean. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class SwitchableSignal implements NotificationSignal | ||
{ | ||
private final NotificationSignal mDelegate; | ||
private final Context mContext; | ||
private final boolean mWithoutSignal; | ||
|
||
|
||
public SwitchableSignal(Context context, boolean withoutSignal) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not happy with this class. As mentioned before this should be a decorator which takes the "enabled" signal in the constructor. There could be a secondary constructor which then passes a public final class Conditional implements NotificationSignal
{
private final NotificationSignal mDelegate;
private final boolean mCondition;
public Conditional(Context context, boolean condition)
{
this(new SettingsSignal(mContext), condition);
}
public Conditional(NotificationSignal delegate, boolean condition)
{
mDelegate = delegate;
mCondition = contition;
}
@Override
public int value()
{
return (mWithoutSignal ? new NoSignal() : mDelegate).value();
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it's better that way, I missed the decoration the first time. Updated now. |
||
{ | ||
mDelegate = withoutSignal ? new NoSignal() : new SettingsSignal(context); | ||
mContext = context; | ||
mWithoutSignal = withoutSignal; | ||
} | ||
|
||
|
||
@Override | ||
public int defaultsValue() | ||
public int value() | ||
{ | ||
return mDelegate.defaultsValue(); | ||
return (mWithoutSignal ? new NoSignal() : new SettingsSignal(mContext)).value(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.notification.signals; | ||
|
||
import android.app.Notification; | ||
|
||
import org.dmfs.tasks.utils.BitFlagUtils; | ||
|
||
|
||
/** | ||
* Decorator for {@link NotificationSignal} that toggles a flag value. Flag must be one of | ||
* {@link Notification#DEFAULT_LIGHTS}, {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE}. | ||
* <p> | ||
* Intended for internal use in the package only since it exposes the bit flag mechanism. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
final class Toggled implements NotificationSignal | ||
{ | ||
private final int mFlag; | ||
private final boolean mEnable; | ||
private final NotificationSignal mOriginal; | ||
|
||
|
||
/** | ||
* @param flag | ||
* must be one of {@link Notification#DEFAULT_LIGHTS}, {@link Notification#DEFAULT_SOUND}, {@link Notification#DEFAULT_VIBRATE} | ||
*/ | ||
Toggled(int flag, boolean enable, NotificationSignal original) | ||
{ | ||
if (flag != Notification.DEFAULT_VIBRATE && flag != Notification.DEFAULT_SOUND && flag != Notification.DEFAULT_LIGHTS) | ||
{ | ||
throw new IllegalArgumentException("Notification signal flag is not valid: " + flag); | ||
} | ||
mFlag = flag; | ||
mEnable = enable; | ||
mOriginal = original; | ||
} | ||
|
||
|
||
@Override | ||
public int value() | ||
{ | ||
return mEnable ? BitFlagUtils.addFlag(mOriginal.value(), mFlag) : mOriginal.value(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a decorator which evaluates lazily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.