]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/tips/TipDefinition.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / tips / TipDefinition.java
1 package tim.prune.tips;
2
3 /**
4  * Definition of a tip, including key and whether the tip
5  * has already been shown or not.
6  * This class is only visible within this package
7  */
8 class TipDefinition
9 {
10         /** Key of message to show when fired */
11         private String _messageKey = null;
12         /** Threshold of calls before tip is shown */
13         private int _threshold = 0;
14         /** Number of times this tip has been hit */
15         private int _hitCount = 0;
16         /** Flag whether tip is active or has already been shown */
17         private boolean _active = true;
18
19         /**
20          * Constructor
21          * @param inKey key for message to show
22          */
23         TipDefinition(String inKey)
24         {
25                 this(inKey, 0);
26         }
27
28         /**
29          * Constructor
30          * @param inKey message key
31          * @param inThreshold threshold
32          */
33         TipDefinition(String inKey, int inThreshold)
34         {
35                 _messageKey = inKey;
36                 _threshold  = inThreshold;
37         }
38
39         /**
40          * Hit this definition and check the threshold
41          * @return true if the message should be shown
42          */
43         boolean shouldShowMessage()
44         {
45                 if (_active)
46                 {
47                         boolean overThreshold = (_hitCount >= _threshold);
48                         if (!overThreshold) {
49                                 _hitCount++;
50                         }
51                         else {
52                                 _active = false; // only fire once
53                         }
54                         return overThreshold;
55                 }
56                 // not active
57                 return false;
58         }
59
60         /**
61          * @return message key
62          */
63         String getMessageKey() {
64                 return _messageKey;
65         }
66 }