236194244739703118dd2d7bc89cef66cd400d93
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Badge / Tizen.Applications / Badge.cs
1 /*
2  * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 namespace Tizen.Applications
18 {
19     /// <summary>
20     /// The class containing common properties of the Badge.
21     /// </summary>
22     public class Badge
23     {
24         private int count = 0;
25
26         /// <summary>
27         /// Initializes a new instance of the Badge class.
28         /// </summary>
29         /// <since_tizen> 3 </since_tizen>
30         /// <param name="appId">Application ID</param>
31         /// <param name="count">Count value</param>
32         /// <param name="visible">True if it should be displayed</param>
33         /// <exception cref="ArgumentException">Thrown when failed because of invalid argument</exception>
34         public Badge(string appId, int count = 1, bool visible = true)
35         {
36             if (IsNegativeNumber(count))
37             {
38                 throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number");
39             }
40             AppId = appId;
41             this.count = count;
42             Visible = visible;
43         }
44
45         /// <summary>
46         /// Property for the count value of the badge.
47         /// </summary>
48         /// <since_tizen> 3 </since_tizen>
49         public int Count
50         {
51             get
52             {
53                 return count;
54             }
55             set
56             {
57                 if (IsNegativeNumber(value))
58                 {
59                     throw BadgeErrorFactory.GetException(BadgeError.InvalidParameter, "The count must be positive number");
60                 }
61
62                 count = value;
63             }
64         }
65
66         /// <summary>
67         /// Property for the application ID of the badge.
68         /// </summary>
69         /// <since_tizen> 3 </since_tizen>
70         public string AppId { get; set; }
71
72         /// <summary>
73         /// Property for display visibility. True if the badge display visible, otherwise false..
74         /// </summary>
75         /// <since_tizen> 3 </since_tizen>
76         public bool Visible{ get; set; }
77
78         private bool IsNegativeNumber(int number)
79         {
80             return number < 0;
81         }
82     }
83 }