-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the broadcast receiver, implemented handling of FAILED_CODE, inter…
…action with cache and storage of data
- Loading branch information
Showing
5 changed files
with
91 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/rothschild/henning/jacob/noriginmedia/model/CacheHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package rothschild.henning.jacob.noriginmedia.model; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* Created by Jacob H. Rothschild on 24.07.2017. | ||
*/ | ||
|
||
public class CacheHandler { | ||
|
||
private HashMap<String, Object> cache = new HashMap<>(); | ||
|
||
/** | ||
* Puts key-value pair in cache, if it is NOT identical to something stored there already | ||
* @return Whether this key-value pair is NOT stored in cache | ||
*/ | ||
public boolean ifNewWillCacheAndTell(String key, Object value) { | ||
boolean isNew = isNew(key, value); | ||
if (isNew) putInCache(key, value); | ||
return isNew; | ||
} | ||
|
||
/** @return Whether value is NOT stored in our cache (and thus tells us something new) */ | ||
public boolean isNew(String key, Object value) { | ||
Object cached = cache.get(key); | ||
return cached == null || !value.equals(cached); | ||
} | ||
|
||
/** Puts key-value pair in cache */ | ||
public void putInCache(String key, Object value) { | ||
cache.put(key, value); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/rothschild/henning/jacob/noriginmedia/model/StorageWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package rothschild.henning.jacob.noriginmedia.model; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
|
||
/** | ||
* Created by Jacob H. Rothschild on 24.07.2017. | ||
*/ | ||
|
||
public class StorageWriter { | ||
|
||
public static void writeIfFilenameNotNull(Context appContext, @Nullable String filename, String content) throws IOException { | ||
if (filename != null) write(appContext, filename, content); | ||
} | ||
|
||
public static void write(Context appContext, @NonNull String filename, String content) throws IOException { | ||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(appContext.openFileOutput(filename, Context.MODE_PRIVATE)); | ||
outputStreamWriter.write(content); | ||
outputStreamWriter.close(); | ||
} | ||
|
||
} |