Skip to content

Commit

Permalink
Bug fixes and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
amrabed committed Sep 1, 2019
1 parent 18aeb45 commit 7aaccb5
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 261 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ captures/
# Keystore files
*.jks
*.pepk
*.der
*.der
keystore.properties
18 changes: 16 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
apply plugin: 'com.android.application'

def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
signingConfigs {
release {
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
}
}

compileSdkVersion 29
defaultConfig {
applicationId "amrabed.android.release.evaluation"
minSdkVersion 21
targetSdkVersion 29
versionCode 12
versionName "3.0.2"
versionCode 16
versionName "3.0.3"
multiDexEnabled true
signingConfig signingConfigs.release
}

buildTypes {
Expand Down
191 changes: 82 additions & 109 deletions app/src/main/java/amrabed/android/release/evaluation/core/DayEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,125 +3,98 @@
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import org.joda.time.DateTime;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;

import androidx.annotation.NonNull;

/**
* Entry of a day in the database
*/
public class DayEntry implements Parcelable
{
private final long date;
private final Selections selections;


public DayEntry(long date)
{
this.date = new DateTime(date).withTimeAtStartOfDay().getMillis();
this.selections = new Selections();
}

public DayEntry(long date, byte[] selections) throws IOException, ClassNotFoundException
{
this.date = date;
this.selections = deserialize(selections);
}


private DayEntry(Parcel in)
{
date = in.readLong();
selections = (Selections) in.readSerializable();
}

public static final Creator<DayEntry> CREATOR = new Creator<DayEntry>()
{
@Override
public DayEntry createFromParcel(Parcel in)
{
return new DayEntry(in);
}

@Override
public DayEntry[] newArray(int size)
{
return new DayEntry[size];
}
};

public long getDate()
{
return date;
}

public byte[] getSelections() throws IOException
{
return serialize(selections);
}

public void setSelectionAt(String id, byte selection)
{
selections.put(id, selection);
}

public byte getSelection(@NonNull String id)
{
final Byte value = selections.get(id);
return value == null ? 0 : value;
}

public float[] getRatios()
{
final float[] ratios = {0, 0, 0, 0};
for (Byte selection : selections.values())
{
ratios[selection]++;
}
return ratios;
}

private static byte[] serialize(Selections obj) throws IOException
{
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(obj);
objectOutputStream.flush();
return byteArrayOutputStream.toByteArray();
}

private static Selections deserialize(byte[] data) throws IOException, ClassNotFoundException
{
ByteArrayInputStream byteArrayIS = new ByteArrayInputStream(data);
ObjectInputStream objectIS = new ObjectInputStream(byteArrayIS);
return (Selections) objectIS.readObject();
}

@Override
public int describeContents()
{
return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i)
{
parcel.writeLong(date);
parcel.writeSerializable(selections);
}

/**
* Selections class to avoid 'unchecked cast' warning
*/
private static class Selections extends HashMap<String, Byte> implements Serializable {

}
public class DayEntry implements Parcelable {
public static final Creator<DayEntry> CREATOR = new Creator<DayEntry>() {
@Override
public DayEntry createFromParcel(Parcel in) {
return new DayEntry(in);
}

@Override
public DayEntry[] newArray(int size) {
return new DayEntry[size];
}
};
private final long date;
private final HashMap<String, Byte> selections;

public DayEntry(long date) {
this.date = new DateTime(date).withTimeAtStartOfDay().getMillis();
this.selections = new HashMap<>();
}


public DayEntry(long date, byte[] selections) throws IOException, ClassNotFoundException {
this.date = date;
this.selections = deserialize(selections);
}

private DayEntry(Parcel in) {
date = in.readLong();
selections = (HashMap<String, Byte>) in.readSerializable();
}

private static byte[] serialize(HashMap<String, Byte> obj) throws IOException {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(obj);
objectOutputStream.flush();
return byteArrayOutputStream.toByteArray();
}

private static HashMap<String, Byte> deserialize(byte[] data) throws IOException, ClassNotFoundException {
ByteArrayInputStream byteArrayIS = new ByteArrayInputStream(data);
ObjectInputStream objectIS = new ObjectInputStream(byteArrayIS);
return (HashMap<String, Byte>) objectIS.readObject();
}

public long getDate() {
return date;
}

public byte[] getSelections() throws IOException {
return serialize(selections);
}

public void setSelectionAt(String id, byte selection) {
selections.put(id, selection);
}

public byte getSelection(@NonNull String id) {
final Byte value = selections.get(id);
return value == null ? 0 : value;
}

public float[] getRatios() {
final float[] ratios = {0, 0, 0, 0};
for (Byte selection : selections.values()) {
ratios[selection]++;
}
return ratios;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(date);
parcel.writeSerializable(selections);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import android.os.Parcelable;
import android.util.SparseArray;

import androidx.annotation.NonNull;
import androidx.annotation.RawRes;

import java.util.UUID;

import amrabed.android.release.evaluation.R;
import amrabed.android.release.evaluation.preferences.Preferences;
import androidx.annotation.RawRes;

/**
* Task in the action list
Expand Down Expand Up @@ -47,7 +49,7 @@ public Task(String id, int defaultIndex, @RawRes int guideEntry)
{
this.id = id;
this.defaultIndex = defaultIndex;
this.guideEntry = guideEntry;
this.guideEntry = defaultIndex == -1 ? 0 : TaskList.entries[defaultIndex];
this.activeDays = new boolean[7];
setActiveDays(ACTIVE_EVERYDAY);
}
Expand Down Expand Up @@ -238,7 +240,8 @@ public Task[] newArray(int size)
};

@Override
public String toString()
public @NonNull
String toString()
{
return "Task: {id: " + id + ", title: " + currentTitle + "}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static boolean isFastingDay(Context context, long date)
(isFastingWhiteDays && ((dayOfMonth == 13) || (dayOfMonth == 14) || (dayOfMonth == 15)));
}

private static final int[] entries = {R.raw.wakeup, R.raw.brush, R.raw.night, R.raw.fasting,
static final int[] entries = {R.raw.wakeup, R.raw.brush, R.raw.night, R.raw.fasting,
R.raw.sunna, R.raw.fajr, R.raw.prayer,
R.raw.quran, R.raw.memorize,
R.raw.morning, R.raw.duha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

public class DatabaseTimer extends BroadcastReceiver
{
Context context;

@Override
public void onReceive(Context context, Intent intent)
{
Expand Down
Loading

0 comments on commit 7aaccb5

Please sign in to comment.