Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual improvement #86

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ Thumbs.db
app/release/*
*.apk


*.gradle
gradle.*
gradle-wrapper.properties

1.json
2.json
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="org.secuso.privacyfriendlyfoodtracker.ui.MainActivity" />
</activity>
<activity
android:name=".ui.GoalsActivity"
android:label="@string/action_goals"
android:parentActivityName=".ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.secuso.privacyfriendlyfoodtracker.ui.MainActivity" />
</activity>
<activity
android:name=".ui.HelpActivity"
android:label="@string/help"
Expand Down
Binary file added app/src/main/ic_state-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;
import android.arch.persistence.room.migration.Migration;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
Expand All @@ -37,27 +38,38 @@
*
* @author Andre Lutz
*/
@Database(entities = {ConsumedEntries.class, Product.class}, version = 1, exportSchema = true)
@Database(entities = {ConsumedEntries.class, Product.class, Goals.class, Weights.class}, version = 2, exportSchema = true)
@TypeConverters({DateConverter.class})
public abstract class ApplicationDatabase extends RoomDatabase {

public static final String DATABASE_NAME = "consumed_entries_database";
private static final Migration MIGRATION_1_2 = new Migration(1,2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS `Goals` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `dailycalorie` INTEGER NOT NULL, `minweight` INTEGER NOT NULL, `date` INTEGER)");
database.execSQL("CREATE TABLE IF NOT EXISTS `Weights` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `date` INTEGER, `weight` INTEGER NOT NULL)");
}
};

public abstract ConsumedEntriesDao getConsumedEntriesDao();
public abstract ProductDao getProductDao();
public abstract GoalsDao getGoalsDao();
public abstract WeightsDao getWeightsDaoDao();
public abstract ConsumedEntrieAndProductDao getConsumedEntriesAndProductDao();

private static ApplicationDatabase sInstance;

private final MutableLiveData<Boolean> mIsDatabaseCreated = new MutableLiveData<>();

public static ApplicationDatabase getInstance(final Context context) throws Exception {

if (sInstance == null) {
synchronized (ApplicationDatabase.class) {
if (sInstance == null) {
SafeHelperFactory factory = new SafeHelperFactory(KeyGenHelper.getSecretKeyAsChar(context));

sInstance = Room.databaseBuilder(context.getApplicationContext(),ApplicationDatabase.class, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.openHelperFactory(factory)
.allowMainThreadQueries()
.addCallback(new Callback() {
Expand All @@ -72,6 +84,7 @@ public void onCreate(@NonNull SupportSQLiteDatabase db) {
Log.e("ApplicationDatabase", e.getMessage());
}
}

}).build();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
This file is part of Privacy friendly food tracker.

Privacy friendly food tracker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Privacy friendly food tracker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Privacy friendly food tracker. If not, see <https://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlyfoodtracker.database;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.arch.persistence.room.TypeConverters;

import org.secuso.privacyfriendlyfoodtracker.database.converter.DateConverter;

import java.sql.Date;

/**
* Goals
*
* @author fialo4ka
*/
@Entity
public class Goals {
@PrimaryKey(autoGenerate = true)
public final int id;
public final int dailycalorie;
public final int minweight;
@TypeConverters({DateConverter.class}) public final Date date;

public Goals(final int id, int dailycalorie, int minweight, Date date) {
this.id = id;
this.dailycalorie = dailycalorie;
this.minweight = minweight;
this.date = date;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
This file is part of Privacy friendly food tracker.

Privacy friendly food tracker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Privacy friendly food tracker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Privacy friendly food tracker. If not, see <https://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlyfoodtracker.database;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import java.util.List;

/**
* Includes methods that offer abstract access to the app database to manage goals.
*
* @author fialo4ka
*/
@Dao
public interface GoalsDao {
@Insert
void insert(Goals... goals);

@Update
void update(Goals... goals);

@Delete
void delete(Goals... goals);

@Query("DELETE FROM goals")
void deleteAll();

@Query("SELECT * FROM goals")
LiveData<List<Goals>> getAllProducts();

@Query("SELECT * FROM goals WHERE id=:id")
Goals findGoalsById(final int id);

@Query("SELECT max(id), * FROM goals")
Goals findMaxGoals();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
This file is part of Privacy friendly food tracker.

Privacy friendly food tracker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Privacy friendly food tracker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Privacy friendly food tracker. If not, see <https://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlyfoodtracker.database;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.arch.persistence.room.TypeConverters;

import org.secuso.privacyfriendlyfoodtracker.database.converter.DateConverter;

import java.sql.Date;

/**
* A Weights.
*
* @author fialo4ka
*/
@Entity
public class Weights {
@PrimaryKey(autoGenerate = true)
public final int id;
@TypeConverters({DateConverter.class}) public final Date date;
public final int weight;

public Weights(final int id, Date date, int weight) {
this.id = id;
this.date = date;
this.weight = weight;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
This file is part of Privacy friendly food tracker.

Privacy friendly food tracker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Privacy friendly food tracker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Privacy friendly food tracker. If not, see <https://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlyfoodtracker.database;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import java.sql.Date;
import java.util.List;

/**
* Includes methods that offer abstract access to the app database to manage Weights.
*
* @author fialo4ka
*/
@Dao
public interface WeightsDao {
@Insert
void insert(Weights... weights);

@Update
void update(Weights... weights);

@Delete
void delete(Weights... weights);

@Query("DELETE FROM weights")
void deleteAll();

@Query("SELECT * FROM weights")
LiveData<List<Weights>> getAllWeights();

@Query("SELECT * FROM weights WHERE id=:id")
Weights findWeightsById(final int id);

@Query("SELECT * FROM weights WHERE date BETWEEN DATE(:dayst) AND DATE(:dayet)")
List<Weights> findWeightsBetweenDates(final Date dayst, final Date dayet);

}
Loading