diff --git a/app/build.gradle b/app/build.gradle index bc6efa0d..59cf189b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,8 +26,8 @@ android { applicationId "com.kabouzeid.gramophone" minSdkVersion 16 targetSdkVersion 22 - versionCode 42 - versionName "0.9.26b dev-1" + versionCode 43 + versionName "0.9.27b dev-1" } buildTypes { diff --git a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java index 6a449f72..3918b13a 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java +++ b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java @@ -242,6 +242,7 @@ public class PlayingNotificationHelper { } private void setBackgroundColor(int color) { + notificationLayout.setInt(R.id.root, "setBackgroundColor", color); notificationLayoutExpanded.setInt(R.id.root, "setBackgroundColor", color); } diff --git a/app/src/main/java/com/kabouzeid/gramophone/util/InternalStorageUtil.java b/app/src/main/java/com/kabouzeid/gramophone/util/InternalStorageUtil.java index 66439ea0..ce72f955 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/util/InternalStorageUtil.java +++ b/app/src/main/java/com/kabouzeid/gramophone/util/InternalStorageUtil.java @@ -11,20 +11,38 @@ import java.io.ObjectOutputStream; /** * @author Karim Abou Zeid (kabouzeid) + *

+ * A simple helper class for Android to read and write + * any serializeable object to the internal storage */ public final class InternalStorageUtil { + /** + * @param context a valid {@link Context} + * @param key the filename + * @param object any {@link java.io.Serializable} object which will be written to the internal storage + */ public static synchronized void writeObject(final Context context, final String key, final Object object) throws IOException { - String tempFileName = "TEMP_" + key; + // First write the object to a file with ".tmp" postfix, + // so when an error occurs, we do not overwrite the original + // file (if exists) with a corrupted file. + String tempFileName = key + ".tmp"; FileOutputStream fos; fos = context.openFileOutput(tempFileName, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object); oos.close(); fos.close(); + // after writing was successful we overwrite the original + // file (if exists) with the new file renameAppFile(context, tempFileName, key); } + /** + * @param context a valid {@link Context} + * @param originalFileName the original filename + * @param newFileName the new filename + */ public static synchronized void renameAppFile(final Context context, String originalFileName, String newFileName) { File originalFile = context.getFileStreamPath(originalFileName); File newFile = new File(originalFile.getParent(), newFileName); @@ -35,6 +53,10 @@ public final class InternalStorageUtil { originalFile.renameTo(newFile); } + /** + * @param context a valid {@link Context} + * @param key the filename + */ public static synchronized Object readObject(final Context context, String key) throws IOException, ClassNotFoundException { FileInputStream fis = context.openFileInput(key);