-
Notifications
You must be signed in to change notification settings - Fork 1
/
patchfile
472 lines (466 loc) · 39.3 KB
/
patchfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
diff --git .idea/.name .idea/.name
index 6c4f8be..643bfd9 100644
--- .idea/.name
+++ .idea/.name
@@ -1 +1 @@
-UnlockManager
\ No newline at end of file
+AndroidAchievementUnlocker
\ No newline at end of file
diff --git .idea/gradle.xml .idea/gradle.xml
index 1b60d77..ce2a0a0 100644
--- .idea/gradle.xml
+++ .idea/gradle.xml
@@ -3,10 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
- <option name="distributionType" value="LOCAL" />
+ <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
- <option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.4" />
- <option name="gradleJvm" value="1.8" />
+ <option name="gradleJvm" value="1.7" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
diff --git .idea/misc.xml .idea/misc.xml
index 4716600..a253d3e 100644
--- .idea/misc.xml
+++ .idea/misc.xml
@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
@@ -47,7 +47,7 @@
<states>
<state key="ProjectJDKs.UI">
<settings>
- <last-edited>1.8</last-edited>
+ <last-edited>Android API 21 Platform</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
diff --git .idea/modules.xml .idea/modules.xml
index c647d8c..b0f0eaa 100644
--- .idea/modules.xml
+++ .idea/modules.xml
@@ -2,8 +2,8 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
+ <module fileurl="file://$PROJECT_DIR$/AndroidAchievementUnlocker.iml" filepath="$PROJECT_DIR$/AndroidAchievementUnlocker.iml" />
<module fileurl="file://$PROJECT_DIR$/Example/Example.iml" filepath="$PROJECT_DIR$/Example/Example.iml" />
- <module fileurl="file://$PROJECT_DIR$/UnlockManager.iml" filepath="$PROJECT_DIR$/UnlockManager.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
diff --git .idea/vcs.xml .idea/vcs.xml
index 94a25f7..6564d52 100644
--- .idea/vcs.xml
+++ .idea/vcs.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ <mapping directory="" vcs="" />
</component>
</project>
\ No newline at end of file
diff --git AndroidAchievementUnlocker.iml AndroidAchievementUnlocker.iml
new file mode 100644
index 0000000..565b2b6
--- /dev/null
+++ AndroidAchievementUnlocker.iml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id="AndroidAchievementUnlocker" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="java-gradle" name="Java-Gradle">
+ <configuration>
+ <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
+ <option name="BUILDABLE" value="false" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file
diff --git Example/Example.iml Example/Example.iml
index 8e53635..e33e102 100644
--- Example/Example.iml
+++ Example/Example.iml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":Example" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="UnlockManager" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+<module external.linked.project.id=":Example" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidAchievementUnlocker" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
@@ -85,13 +85,12 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
- <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
+ <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="module" module-name="app" exported="" />
</component>
diff --git app/app.iml app/app.iml
index ac403ea..c05f4f1 100644
--- app/app.iml
+++ app/app.iml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="UnlockManager" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AndroidAchievementUnlocker" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
@@ -91,8 +91,8 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
+ <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
</component>
</module>
\ No newline at end of file
diff --git app/src/androidTest/java/com/kluehspies/marian/unlockmanager/RewardManagerTest.java app/src/androidTest/java/com/kluehspies/marian/unlockmanager/RewardManagerTest.java
index 2f5205f..06b072c 100644
--- app/src/androidTest/java/com/kluehspies/marian/unlockmanager/RewardManagerTest.java
+++ app/src/androidTest/java/com/kluehspies/marian/unlockmanager/RewardManagerTest.java
@@ -59,6 +59,19 @@ public class RewardManagerTest extends ApplicationTestCase<Application> implemen
assertTrue(available);
}
+ /**
+ * tests if trigger gets unregistered
+ */
+ public void testUnregisterTrigger(){
+ boolean registered = unlockManager.isRegistered(unlockTrigger);
+ if (registered) {
+ unlockManager.unregisterTrigger(unlockTrigger);
+ assertFalse(unlockManager.isRegistered(unlockTrigger));
+ }else{
+ fail("Trigger was not registered in first place!");
+ }
+ }
+
@Override
public void rewardNotAvailable(int resourceID, ITrigger trigger) {
available = false;
diff --git app/src/main/java/com/kluehspies/marian/unlockmanager/db/Achievement.java app/src/main/java/com/kluehspies/marian/unlockmanager/db/Achievement.java
new file mode 100644
index 0000000..ddb1eee
--- /dev/null
+++ app/src/main/java/com/kluehspies/marian/unlockmanager/db/Achievement.java
@@ -0,0 +1,30 @@
+package com.kluehspies.marian.unlockmanager.db;
+
+/**
+ * Created by Andy on 16.10.2015.
+ */
+public class Achievement {
+
+ private final String key;
+ private final String action;
+ private final String state;
+
+ public Achievement(String key, String action){
+ this(key,action,null);
+ }
+
+ public Achievement(String key,String action,String state){
+ this.key = key;
+ this.action = action;
+ this.state = state;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+}
diff --git app/src/main/java/com/kluehspies/marian/unlockmanager/db/AchievementDataSource.java app/src/main/java/com/kluehspies/marian/unlockmanager/db/AchievementDataSource.java
new file mode 100644
index 0000000..282662f
--- /dev/null
+++ app/src/main/java/com/kluehspies/marian/unlockmanager/db/AchievementDataSource.java
@@ -0,0 +1,124 @@
+package com.kluehspies.marian.unlockmanager.db;
+
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Andy on 15.10.2015.
+ */
+public class AchievementDataSource {
+
+ private final Database database;
+ private SQLiteDatabase sqLiteDatabase;
+
+ public static final String STATE_UNLOCKED = "UNLOCKED";
+ public static final String STATE_LOCKED = "LOCKED";
+
+ public AchievementDataSource(Database database){
+ this.database = database;
+ }
+
+ public void openDatabase(){
+ sqLiteDatabase = database.getWritableDatabase();
+ }
+
+ public boolean addAchievement(Achievement achievement){
+ return addAchievement(achievement,null);
+ }
+
+ public boolean addAchievement(Achievement achievement,String state){
+ ContentValues cv = new ContentValues();
+ cv.put(AchievementTable.COLUMN_KEY,achievement.getKey());
+ cv.put(AchievementTable.COLUMN_ACTION,achievement.getAction());
+ cv.put(AchievementTable.COLUMN_UNLOCK_STATE, (state == null) ? STATE_LOCKED : state);
+ return sqLiteDatabase.insert(AchievementTable.TABLE_NAME, null, cv) > 0;
+ }
+
+ public boolean updateAchievement(Achievement achievement, String state){
+ ContentValues cv = new ContentValues();
+ cv.put(AchievementTable.COLUMN_UNLOCK_STATE,state);
+ return sqLiteDatabase.update(
+ AchievementTable.TABLE_NAME,
+ cv,
+ String.format("%s = ? AND %s = ?", AchievementTable.COLUMN_KEY, AchievementTable.COLUMN_ACTION),
+ new String[]{achievement.getKey(), achievement.getAction()}
+ ) > 0;
+ }
+
+ public boolean removeAchievement(Achievement achievement){
+ return sqLiteDatabase.delete(
+ AchievementTable.TABLE_NAME,
+ String.format("%s = ? AND %s = ?", AchievementTable.COLUMN_KEY, AchievementTable.COLUMN_ACTION),
+ new String[]{achievement.getKey(), achievement.getAction()}
+ ) > 0;
+ }
+
+ public boolean isAchievementLocked(Achievement achievement){
+ return getAchievementStatus(achievement).equals(STATE_LOCKED);
+ }
+
+ public boolean isAchievementUnlocked(Achievement achievement){
+ return getAchievementStatus(achievement).equals(STATE_UNLOCKED);
+ }
+
+ private String getAchievementStatus(Achievement achievement){
+ String status = null;
+ Cursor cursor = sqLiteDatabase.query(
+ AchievementTable.TABLE_NAME,
+ new String[]{AchievementTable.COLUMN_UNLOCK_STATE},
+ String.format("%s = ? AND %s = ?", AchievementTable.COLUMN_KEY, AchievementTable.COLUMN_ACTION),
+ new String[]{achievement.getKey(), achievement.getAction()},
+ null,null,null
+ );
+ if (cursor.moveToFirst()){
+ status = cursor.getString(0);
+ }
+ cursor.close();
+ return status;
+ }
+
+ public List<Achievement> getAchievements(){
+ return internalGetAchievements(null);
+ }
+
+ public List<Achievement> getLockedAchievements(){
+ return internalGetAchievements(STATE_LOCKED);
+ }
+
+ public List<Achievement> getUnlockedAchievements(){
+ return internalGetAchievements(STATE_UNLOCKED);
+ }
+
+ private List<Achievement> internalGetAchievements(String withState){
+ List<Achievement> achievements = new ArrayList<>();
+ Cursor cursor = sqLiteDatabase.query(
+ AchievementTable.TABLE_NAME,
+ null,
+ String.format("%s = ?", AchievementTable.COLUMN_UNLOCK_STATE),
+ (withState != null) ? new String[]{withState} : null,
+ null,null,null
+ );
+ if (cursor.moveToFirst()){
+ do{
+ String key = cursor.getString(cursor.getColumnIndex(AchievementTable.COLUMN_KEY));
+ String action = cursor.getString(cursor.getColumnIndex(AchievementTable.COLUMN_ACTION));
+ String state = cursor.getString(cursor.getColumnIndex(AchievementTable.COLUMN_UNLOCK_STATE));
+ achievements.add(new Achievement(key,action,state));
+ }while(cursor.moveToNext());
+ }
+ cursor.close();
+ return achievements;
+ }
+
+ public void closeDatabase(){
+ if (sqLiteDatabase != null) {
+ sqLiteDatabase.close();
+ sqLiteDatabase = null;
+ }
+ }
+
+}
diff --git app/src/main/java/com/kluehspies/marian/unlockmanager/db/AchievementTable.java app/src/main/java/com/kluehspies/marian/unlockmanager/db/AchievementTable.java
new file mode 100644
index 0000000..969662c
--- /dev/null
+++ app/src/main/java/com/kluehspies/marian/unlockmanager/db/AchievementTable.java
@@ -0,0 +1,25 @@
+package com.kluehspies.marian.unlockmanager.db;
+
+/**
+ * Created by Andy on 02.10.2015.
+ */
+public class AchievementTable {
+
+ public static final String TABLE_NAME = "resource";
+
+ public static final String COLUMN_KEY = "unique_key";
+ public static final String COLUMN_ACTION = "action";
+ public static final String COLUMN_UNLOCK_STATE = "unlock_state";
+ public static final String COLUMN_TIMESTAMP = "created_at";
+
+ public static final String TABLE_CREATE = "CREATE TABLE IF NOT EXISTS "
+ + TABLE_NAME + "("
+ + COLUMN_KEY + " TEXT NOT NULL, "
+ + COLUMN_ACTION + " TEXT NOT NULL, "
+ + COLUMN_UNLOCK_STATE + " TEXT NOT NULL, "
+ + COLUMN_TIMESTAMP + " TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "
+ + String.format("PRIMARY KEY (%s,%s)",COLUMN_KEY,COLUMN_ACTION)
+ + ");";
+
+ public static final String TABLE_DROP = "DROP TABLE IF EXISTS " + TABLE_NAME;
+}
diff --git app/src/main/java/com/kluehspies/marian/unlockmanager/db/Database.java app/src/main/java/com/kluehspies/marian/unlockmanager/db/Database.java
new file mode 100644
index 0000000..413ade4
--- /dev/null
+++ app/src/main/java/com/kluehspies/marian/unlockmanager/db/Database.java
@@ -0,0 +1,35 @@
+package com.kluehspies.marian.unlockmanager.db;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+public class Database extends SQLiteOpenHelper {
+
+ private static final int DATABASE_VERSION = 1;
+ private static final String DATABASE_NAME = "achievement.db";
+
+ private static Database mDatabase = null;
+
+ protected Database(Context context, String databaseName, int databaseVersion) {
+ super(context, databaseName, null, databaseVersion);
+ }
+
+ public static synchronized Database getInstance(Context context) {
+ if (mDatabase == null) {
+ mDatabase = new Database(context, DATABASE_NAME, DATABASE_VERSION);
+ }
+ return mDatabase;
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL(AchievementTable.TABLE_CREATE);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+
+ }
+
+}
diff --git app/src/main/java/com/kluehspies/marian/unlockmanager/manager/RewardManager.java app/src/main/java/com/kluehspies/marian/unlockmanager/manager/RewardManager.java
index e1946c4..21f1024 100644
--- app/src/main/java/com/kluehspies/marian/unlockmanager/manager/RewardManager.java
+++ app/src/main/java/com/kluehspies/marian/unlockmanager/manager/RewardManager.java
@@ -76,12 +76,20 @@ public final class RewardManager implements IRewardManager {
}
/**
+ * deregisters a trigger
+ * @param trigger
+ */
+ public void unregisterTrigger(ITrigger trigger){
+ if (triggers.contains(trigger)) triggers.remove(trigger);
+ }
+
+ /**
* Check if trigger is already registered
*
* @param trigger
* @return
*/
- private boolean isRegistered(ITrigger trigger) {
+ public boolean isRegistered(ITrigger trigger) {
for (ITrigger unlockTrigger : triggers)
if (unlockTrigger != null && unlockTrigger.equals(trigger))
return true;
diff --git app/src/main/java/com/kluehspies/marian/unlockmanager/persistence/SharedPreferencesHandler.java app/src/main/java/com/kluehspies/marian/unlockmanager/persistence/SharedPreferencesHandler.java
index c28c301..a85ae1b 100644
--- app/src/main/java/com/kluehspies/marian/unlockmanager/persistence/SharedPreferencesHandler.java
+++ app/src/main/java/com/kluehspies/marian/unlockmanager/persistence/SharedPreferencesHandler.java
@@ -3,7 +3,10 @@ package com.kluehspies.marian.unlockmanager.persistence;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+<<<<<<< HEAD
+=======
+>>>>>>> upstream/master
import com.kluehspies.marian.unlockmanager.manager.IRewardManager;
import com.kluehspies.marian.unlockmanager.trigger.ITrigger;
@@ -12,7 +15,11 @@ import com.kluehspies.marian.unlockmanager.trigger.ITrigger;
*
* Default implementation of PersistenceHandler
*/
+<<<<<<< HEAD
+public class SharedPreferencesHandler implements ITrigger {
+=======
public class SharedPreferencesHandler extends PersistenceHandler implements ITrigger {
+>>>>>>> upstream/master
private Context context;
private IRewardManager unlockManager;
@@ -29,7 +36,6 @@ public class SharedPreferencesHandler extends PersistenceHandler implements ITri
this.sharedPreferencesKey = sharedPreferencesKey;
}
- @Override
public void unlockSucceeded(int resourceID, ITrigger trigger) {
setUnlockState(resourceID, true);
}