From d78e99d9d68c717246af3f53a0d46da8f8249922 Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Tue, 30 May 2017 18:16:51 +0900 Subject: [PATCH] Refactor Badge structure - Change parameter of methods of BadgeManager class from individual infomation to Badge instance. - Adds NotSupported exception. Signed-off-by: Seungha Son Change-Id: I1f140d1995cfffb6cb6bd8f33b0fd8ed4621b32a --- .../Tizen.Applications/Badge.cs | 62 ++++++----- .../Tizen.Applications/BadgeControl.cs | 120 +++++++++++---------- .../Tizen.Applications/BadgeErrorFactory.cs | 11 +- .../Tizen.Applications/BadgeEventArgs.cs | 6 +- 4 files changed, 114 insertions(+), 85 deletions(-) diff --git a/Tizen.Applications.Badge/Tizen.Applications/Badge.cs b/Tizen.Applications.Badge/Tizen.Applications/Badge.cs index 89b317a..2361942 100755 --- a/Tizen.Applications.Badge/Tizen.Applications/Badge.cs +++ b/Tizen.Applications.Badge/Tizen.Applications/Badge.cs @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the License); + * 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, + * 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. @@ -17,19 +17,29 @@ namespace Tizen.Applications { /// - /// Immutable class for getting information of the badge. + /// The class containing common properties of the Badge. /// public class Badge { - private readonly string _appId; - private readonly int _count; - private readonly bool _isDisplay; + private int count = 0; - internal Badge(string appid, int count, bool isDisplay) + /// + /// Initializes a new instance of the Badge class. + /// + /// 3 + /// Application ID + /// Count value + /// True if it should be displayed + /// Thrown when failed because of invalid argument + public Badge(string appId, int count = 1, bool visible = true) { - _appId = appid; - _count = count; - _isDisplay = isDisplay; + if (IsNegativeNumber(count)) + { + throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number"); + } + AppId = appId; + this.count = count; + Visible = visible; } /// @@ -40,7 +50,16 @@ namespace Tizen.Applications { get { - return _count; + return count; + } + set + { + if (IsNegativeNumber(value)) + { + throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number"); + } + + count = value; } } @@ -48,24 +67,17 @@ namespace Tizen.Applications /// Property for the application ID of the badge. /// /// 3 - public string AppId - { - get - { - return _appId; - } - } + public string AppId { get; set; } /// - /// Property for the flag of 'display'. + /// Property for display visibility. True if the badge display visible, otherwise false.. /// /// 3 - public bool IsDisplay + public bool Visible{ get; set; } + + private bool IsNegativeNumber(int number) { - get - { - return _isDisplay; - } + return number < 0; } } } diff --git a/Tizen.Applications.Badge/Tizen.Applications/BadgeControl.cs b/Tizen.Applications.Badge/Tizen.Applications/BadgeControl.cs index 85e72a7..3c5b60e 100755 --- a/Tizen.Applications.Badge/Tizen.Applications/BadgeControl.cs +++ b/Tizen.Applications.Badge/Tizen.Applications/BadgeControl.cs @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the License); + * 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, + * 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. @@ -31,9 +31,11 @@ namespace Tizen.Applications /// Event handler for receiving badge events. /// /// 3 + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown in case of failed conditions. /// Thrown when an application does not have the privilege to access. - /// http://tizen.org/privilege/notification + /// Thrown when Badge is not supported. public static event EventHandler Changed { add @@ -78,10 +80,13 @@ namespace Tizen.Applications /// /// 3 /// Application ID. + /// The Badge object with inputted application ID + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown when failed because of an invalid argument. /// Thrown when an application does not have the privilege to access. /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification + /// Thrown when Badge is not supported. public static Badge Find(string appId) { uint count; @@ -107,10 +112,12 @@ namespace Tizen.Applications /// /// 3 /// Application ID. + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown when failed because of a an invalid argument. /// Thrown when an application does not have the privilege to access. /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification + /// Thrown when Badge is not supported. public static void Remove(string appId) { BadgeError err = Interop.Badge.Remove(appId); @@ -121,51 +128,58 @@ namespace Tizen.Applications } /// - /// Adds the badge information. + /// Removes the badge information. /// /// 3 - /// Application ID. - /// Count value. - /// True if it should be displayed. + /// The Badge object. + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown when failed because of an invalid argument. /// Thrown when an application does not have the privilege to access. /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification - public static void Add(string appId, int count = 1, bool isDisplay = true) + /// Thrown when Badge is not supported. + public static void Remove(Badge badge) { - BadgeError err = Interop.Badge.Add(appId); - if (err != BadgeError.None) + if (badge == null) { - throw BadgeErrorFactory.GetException(err, "Failed to add badge of " + appId); + throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object"); } - try - { - Update(appId, count, isDisplay); - } - catch (Exception e) - { - Remove(appId); - throw e; - } + Remove(badge.AppId); } /// - /// Updates the badge information. + /// Adds the badge information. /// /// 3 - /// Application ID. - /// Count value. + /// The Badge object. + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown when failed because of an invalid argument. /// Thrown when an application does not have the privilege to access. /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification - public static void Update(string appId, int count) + /// Thrown when Badge is not supported. + public static void Add(Badge badge) { - BadgeError err = Interop.Badge.SetCount(appId, (uint)count); + if (badge == null) + { + throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object"); + } + + BadgeError err = Interop.Badge.Add(badge.AppId); if (err != BadgeError.None) { - throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + appId); + throw BadgeErrorFactory.GetException(err, "Failed to add badge of " + badge.AppId); + } + + try + { + Update(badge); + } + catch (Exception e) + { + Remove(badge.AppId); + throw e; } } @@ -173,45 +187,43 @@ namespace Tizen.Applications /// Updates the badge information. /// /// 3 - /// Application ID. - /// True if it should be displayed. + /// The Badge object. + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown when failed because of an invalid argument. /// Thrown when an application does not have the privilege to access. /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification - public static void Update(string appId, bool isDisplay) + /// Thrown when Badge is not supported. + public static void Update(Badge badge) { - BadgeError err = Interop.Badge.SetDisplay(appId, isDisplay ? 1U : 0U); + if (badge == null) + { + throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "Invalid Badge object"); + } + + BadgeError err = Interop.Badge.SetCount(badge.AppId, (uint)badge.Count); if (err != BadgeError.None) { - throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + appId); + throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + badge.AppId); } - } - /// - /// Updates the badge information. - /// - /// 3 - /// Application ID. - /// Count value. - /// True if it should be displayed. - /// Thrown when failed because of invalid argument. - /// Thrown when an application does not have the privilege to access. - /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification - public static void Update(string appId, int count, bool isDisplay) - { - Update(appId, count); - Update(appId, isDisplay); + err = Interop.Badge.SetDisplay(badge.AppId, badge.Visible ? 1U : 0U); + if (err != BadgeError.None) + { + throw BadgeErrorFactory.GetException(err, "Failed to update badge of " + badge.AppId); + } } /// /// Gets all the badge information. /// /// 3 + /// List of all Badge instances. + /// http://tizen.org/feature/badge + /// http://tizen.org/privilege/notification /// Thrown when an application does not have the privilege to access. /// Thrown in case of failed conditions. - /// http://tizen.org/privilege/notification + /// Thrown when Badge is not supported. public static IEnumerable GetBadges() { IList list = new List(); diff --git a/Tizen.Applications.Badge/Tizen.Applications/BadgeErrorFactory.cs b/Tizen.Applications.Badge/Tizen.Applications/BadgeErrorFactory.cs index ff0d909..8a7a0b1 100755 --- a/Tizen.Applications.Badge/Tizen.Applications/BadgeErrorFactory.cs +++ b/Tizen.Applications.Badge/Tizen.Applications/BadgeErrorFactory.cs @@ -1,14 +1,14 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the License); + * 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, + * 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. @@ -26,6 +26,7 @@ namespace Tizen.Applications OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, IoError = Tizen.Internals.Errors.ErrorCode.IoError, + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, DbError = -0x01120000 | 0x01, AlreadyExists = -0x01120000 | 0x02, DBusError = -0x01120000 | 0x03, @@ -51,7 +52,11 @@ namespace Tizen.Applications Log.Error(LogTag, msg); return new ArgumentException(ret + " error occurred."); case BadgeError.PermissionDenied: + Log.Error(LogTag, msg); throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)"); + case BadgeError.NotSupported: + Log.Error(LogTag, msg); + throw new NotSupportedException("Not Supported (http://tizen.org/feature/badge)"); default: Log.Error(LogTag, msg); return new InvalidOperationException(ret + " error occurred."); diff --git a/Tizen.Applications.Badge/Tizen.Applications/BadgeEventArgs.cs b/Tizen.Applications.Badge/Tizen.Applications/BadgeEventArgs.cs index bfcc85f..b93cf66 100755 --- a/Tizen.Applications.Badge/Tizen.Applications/BadgeEventArgs.cs +++ b/Tizen.Applications.Badge/Tizen.Applications/BadgeEventArgs.cs @@ -1,14 +1,14 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the License); + * 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, + * 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. -- 2.7.4