Skip to content

Commit

Permalink
* Add cheats table
Browse files Browse the repository at this point in the history
* Enable Aapt2
  • Loading branch information
Andr3Carvalh0 committed Mar 26, 2018
1 parent cdbc2a3 commit 6e72451
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 12 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation "com.android.support:preference-v14:" + project.ext.AppCompatVersion

//Tests
testCompile 'org.mockito:mockito-core:2.15.0'
testImplementation 'org.mockito:mockito-core:2.15.0'
androidTestImplementation 'org.mockito:mockito-android:2.6.3'
testImplementation "android.arch.persistence.room:testing:1.0.0"
testImplementation 'junit:junit:4.12'
Expand Down
34 changes: 33 additions & 1 deletion app/src/main/java/io/mgba/Data/Database/Cheat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,46 @@ public class Cheat {
@PrimaryKey(autoGenerate = true)
private int id;

@PrimaryKey
@ColumnInfo(name = "idFK")
@NonNull
private File id_FK;

@ColumnInfo(name = "cheatName")
private String value;

@ColumnInfo(name = "codeType")
private int type;

@ColumnInfo(name = "codeState")
private boolean state;

@ColumnInfo(name = "codeName")
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public boolean isState() {
return state;
}

public void setState(boolean state) {
this.state = state;
}

public int getId() {
return id;
}
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/io/mgba/Data/Database/DAOs/CheatDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.mgba.Data.Database.DAOs;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Transaction;
import java.io.File;
import java.util.List;
import io.mgba.Data.Database.Cheat;

@Dao
public interface CheatDAO {

@Query("SELECT * FROM Cheats WHERE idFK = :key")
List<Cheat> getGamesCheats(File key);

@Query("DELETE FROM Cheats WHERE id = :key")
@Transaction
void deleteCheat(int key);

@Insert
@Transaction
void insertCheat(Cheat cheat);

}
2 changes: 0 additions & 2 deletions app/src/main/java/io/mgba/Data/Database/DAOs/GameDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Transaction;
import android.arch.persistence.room.Update;

import java.util.List;

import io.mgba.Data.Database.Game;

@Dao
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/io/mgba/Data/Database/Database.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package io.mgba.Data.Database;


import android.arch.persistence.db.SupportSQLiteDatabase;
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 io.mgba.Data.Database.Converters.GameConverter;
import io.mgba.Data.Database.DAOs.CheatDAO;
import io.mgba.Data.Database.DAOs.GameDAO;

@android.arch.persistence.room.Database(entities = {Game.class}, version = 4)
@android.arch.persistence.room.Database(entities = {Game.class, Cheat.class}, version = 7)
@TypeConverters(GameConverter.class)
public abstract class Database extends RoomDatabase {
private static Database instance;

public abstract GameDAO gameDao();

public abstract CheatDAO cheatDAO();

public static Database getInstance(Context context) {
if(instance == null)
instance = Room.databaseBuilder(context, Database.class, context.getPackageName()).build();
instance = Room.databaseBuilder(context, Database.class, context.getPackageName())
.build();

return instance;
}
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/io/mgba/Data/Database/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public Game[] newArray(int size) {
@ColumnInfo()
private Platform platform;

public Game() {
}

@ColumnInfo()
private String name = null;

Expand All @@ -64,6 +61,9 @@ public Game() {
@ColumnInfo()
private boolean favourite = false;


public Game() { }

@Ignore
public Game(String path, String name, String description, String released, String developer, String genre, String coverURL, String MD5, boolean favourite, Platform platform) {
this.file = new File(path);
Expand Down Expand Up @@ -130,7 +130,6 @@ public String getDeveloper() {
return developer;
}


public void setDeveloper(String developer) {
this.developer = developer;
}
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/io/mgba/Model/IO/LocalDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.content.Context;

import java.io.File;
import java.util.List;

import io.mgba.Data.Database.Cheat;
import io.mgba.Data.Database.Database;
import io.mgba.Data.Database.Game;
import io.mgba.Data.Platform;
Expand Down Expand Up @@ -58,7 +60,25 @@ public List<Game> queryForGames(String query) {

@Override
public List<Game> getGames() {
printLog(TAG, "Getting All Games");
printLog(TAG, "Getting all games");
return db.gameDao().getGames();
}

@Override
public List<Cheat> getGamesCheats(Game key) {
printLog(TAG, "Getting all cheats for " + key.getName());
return db.cheatDAO().getGamesCheats(key.getFile());
}

@Override
public void deleteCheat(Cheat cheat) {
printLog(TAG, "Deleting cheat: " + cheat.getName());
db.cheatDAO().deleteCheat(cheat.getId());
}

@Override
public void insertCheat(Cheat cheat) {
printLog(TAG, "Inserting cheat: " + cheat.getName());
db.cheatDAO().insertCheat(cheat);
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/io/mgba/Model/Interfaces/IDatabase.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package io.mgba.Model.Interfaces;

import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Transaction;

import java.io.File;
import java.util.List;

import io.mgba.Data.Database.Cheat;
import io.mgba.Data.Database.Game;
import io.mgba.Data.Platform;

Expand All @@ -13,4 +19,8 @@ public interface IDatabase {
void delete(Game game);
List<Game> queryForGames(String query);
List<Game> getGames();

List<Cheat> getGamesCheats(Game key);
void deleteCheat(Cheat cheat);
void insertCheat(Cheat cheat);
}
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ org.gradle.jvmargs=-Xmx2048m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableAapt2=false

0 comments on commit 6e72451

Please sign in to comment.