diff --git a/.gitignore b/.gitignore index 949085d..6dfad4e 100644 --- a/.gitignore +++ b/.gitignore @@ -163,8 +163,11 @@ fabric.properties ### Java ### # Compiled class file -./filepicker/build -./filepicker/build/* +filepicker/build +filepicker/build/* + +twoway-view/build +twoway-view/build/* # Log file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index e86a16a..3226e40 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 57856af..b6bd9b7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,7 +40,6 @@ android { dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation fileTree(include: ['*.jar'], dir: 'libs') - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.github.hotchemi:permissionsdispatcher:3.0.1' implementation ('com.mikepenz:aboutlibraries:6.0.6@aar') { transitive = true } implementation "com.android.support:appcompat-v7:" + project.ext.AppCompatVersion @@ -65,17 +64,23 @@ dependencies { implementation 'com.annimon:stream:1.1.9' implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1' implementation "android.arch.persistence.room:runtime:1.0.0" - - // Test helpers for Room - testImplementation "android.arch.persistence.room:testing:1.0.0" implementation "com.android.support:preference-v7:" + project.ext.AppCompatVersion implementation "com.android.support:preference-v14:" + project.ext.AppCompatVersion + + //Tests + androidTestImplementation 'org.mockito:mockito-core:1.10.19' + testImplementation "android.arch.persistence.room:testing:1.0.0" testImplementation 'junit:junit:4.12' + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) + + //Annotations annotationProcessor "android.arch.persistence.room:compiler:1.0.0" annotationProcessor 'com.google.dagger:dagger-compiler:2.11' annotationProcessor 'com.google.dagger:dagger-android-processor:2.11' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:3.0.1' + + //third-party implementation project(':filepicker') implementation project(':floatingsearchview') implementation project(':twoway-view') diff --git a/app/src/androidTest/java/io/mgba/DatabaseTests.java b/app/src/androidTest/java/io/mgba/DatabaseTests.java index 5063b1d..cfc4a9d 100644 --- a/app/src/androidTest/java/io/mgba/DatabaseTests.java +++ b/app/src/androidTest/java/io/mgba/DatabaseTests.java @@ -12,8 +12,6 @@ import org.junit.runner.RunWith; import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import io.mgba.Data.Database.Database; diff --git a/app/src/androidTest/java/io/mgba/LibraryTests.java b/app/src/androidTest/java/io/mgba/LibraryTests.java new file mode 100644 index 0000000..ea9fd4c --- /dev/null +++ b/app/src/androidTest/java/io/mgba/LibraryTests.java @@ -0,0 +1,29 @@ +package io.mgba; + +import android.app.Application; +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import io.mgba.Model.Interfaces.ILibrary; +import io.mgba.Model.Library; +import io.mgba.Utils.TestsDB; +import io.mgba.Utils.TestsFLM; + +@RunWith(AndroidJUnit4.class) +public class LibraryTests { + + private ILibrary library; + + @Before + public void init() { + Context ctx = InstrumentationRegistry.getTargetContext(); + library = new Library(((mgba)ctx.getApplicationContext()), new TestsDB(), new TestsFLM()); + } + +} diff --git a/app/src/androidTest/java/io/mgba/Utils/TestsDB.java b/app/src/androidTest/java/io/mgba/Utils/TestsDB.java new file mode 100644 index 0000000..c7d00c1 --- /dev/null +++ b/app/src/androidTest/java/io/mgba/Utils/TestsDB.java @@ -0,0 +1,61 @@ +package io.mgba.Utils; + +import org.junit.BeforeClass; + +import java.util.LinkedList; +import java.util.List; + +import io.mgba.Data.Database.Game; +import io.mgba.Data.Platform; +import io.mgba.Model.Interfaces.IDatabase; + +public class TestsDB implements IDatabase{ + private static List games; + + @BeforeClass + public static void init() { + games = new LinkedList<>(); + games.add(new Game("/a.gba", "Pokemon", "Some desc", "2000", "I", "", "", "AAA", false, Platform.GBA)); + games.add(new Game("/b.gba", "Metroid", "Some desc", "2000", "I", "", "", "AAA", true, Platform.GBA)); + games.add(new Game("/c.gba", "Zelda", "Some desc", "2000", "I", "", "", "AAA", true, Platform.GBC)); + games.add(new Game("/d.gba", "Mario", "Some desc", "2000", "I", "", "", "AAA", false, Platform.GBC)); + + } + + @Override + public List getGamesForPlatform(Platform platform) { + return games; + } + + @Override + public List getFavouritesGames() { + return games; + } + + @Override + public void insert(Game... games) { + + } + + @Override + public void delete() { + + } + + @Override + public void delete(Game game) { + System.out.println(""); + + + } + + @Override + public List queryForGames(String query) { + return null; + } + + @Override + public List getGames() { + return null; + } +} diff --git a/app/src/androidTest/java/io/mgba/Utils/TestsFLM.java b/app/src/androidTest/java/io/mgba/Utils/TestsFLM.java new file mode 100644 index 0000000..444e923 --- /dev/null +++ b/app/src/androidTest/java/io/mgba/Utils/TestsFLM.java @@ -0,0 +1,45 @@ +package io.mgba.Utils; + +import com.google.common.base.Predicate; + +import org.junit.BeforeClass; + +import java.io.File; +import java.util.LinkedList; +import java.util.List; +import io.mgba.Model.Interfaces.IFilesManager; + +public class TestsFLM implements IFilesManager { + private static List files; + + private String dir = ""; + + @BeforeClass + public static void init() { + files = new LinkedList<>(); + files.add(new File("/a.b")); + files.add(new File("/c.d")); + files.add(new File("/e.f")); + files.add(new File("/g.h")); + } + + @Override + public List getGameList(Predicate predicate) { + return files; + } + + @Override + public List getGameList() { + return files; + } + + @Override + public String getCurrentDirectory() { + return dir; + } + + @Override + public void setCurrentDirectory(String directory) { + dir = directory; + } +} diff --git a/app/src/main/java/io/mgba/Model/IO/FilesManager.java b/app/src/main/java/io/mgba/Model/IO/FilesManager.java index e2a30dd..ac2d033 100644 --- a/app/src/main/java/io/mgba/Model/IO/FilesManager.java +++ b/app/src/main/java/io/mgba/Model/IO/FilesManager.java @@ -45,7 +45,12 @@ public FilesManager(String directory) { * @return the file's extension */ public static String getFileExtension(File file){ - return file.getName() + String name = file.getName(); + + if(!name.contains(".")) + return name.substring(name.length() - 3); + + return name .substring(file.getName().lastIndexOf(".")) .substring(1) .toLowerCase(); diff --git a/app/src/main/java/io/mgba/Model/Library.java b/app/src/main/java/io/mgba/Model/Library.java index ae66000..a04fff5 100644 --- a/app/src/main/java/io/mgba/Model/Library.java +++ b/app/src/main/java/io/mgba/Model/Library.java @@ -32,9 +32,16 @@ public Library(mgba application) { application.inject(this); } + public Library(mgba application, IDatabase database, IFilesManager filesService) { + this.application = application; + this.database = database; + this.filesService = filesService; + } + + @Override public Single> prepareGames(Platform platform) { - return Single.create(subscriber -> { + Single> ret = Single.create(subscriber -> { if(platform == null){ subscriber.onSuccess(new LinkedList<>()); @@ -45,11 +52,13 @@ public Single> prepareGames(Platform platform) { subscriber.onSuccess(games); }); + + return ret.doOnError(mgba::report); } @Override public Single> query(String query) { - return Single.create(subscriber -> { + Single> ret = Single.create(subscriber -> { if(query == null || query.length() == 0){ subscriber.onSuccess(new LinkedList<>()); @@ -60,11 +69,13 @@ public Single> query(String query) { subscriber.onSuccess(games); }); + + return ret.doOnError(mgba::report); } @Override public Single> reloadGames(Platform... platform) { - return Single.create(subscriber -> { + Single> ret = Single.create(subscriber -> { //clean up possible removed files from content provider List games = database.getGames(); @@ -75,9 +86,11 @@ public Single> reloadGames(Platform... platform) { games.addAll(updatedList); Collections.sort(games, (o1, o2) -> o1.getName().compareTo(o2.getName())); - subscriber.onSuccess(filter(Arrays.asList(platform), games)); }); + + return ret.doOnError(mgba::report); + } @Override @@ -98,8 +111,9 @@ private void removeGamesFromDatabase(List games){ private List processNewGames(List games){ return Stream.of(filesService.getGameList()) .map(f -> new Game(f.getAbsolutePath(), getPlatform(f))) - .filter(f -> games.size() == 0 || - Stream.of(games).anyMatch(g -> g.getFile().equals(f.getFile()) && g.needsUpdate())) + .filter(f -> games.size() == 0 + || Stream.of(games).anyMatch(g -> g.getFile().equals(f.getFile()) + && g.needsUpdate())) .map(g -> { Stream.of(games).filter(g1 -> g1.equals(g)).forEach(games::remove); diff --git a/app/src/main/java/io/mgba/Presenter/GamesPresenter.java b/app/src/main/java/io/mgba/Presenter/GamesPresenter.java index fc81e27..383d676 100644 --- a/app/src/main/java/io/mgba/Presenter/GamesPresenter.java +++ b/app/src/main/java/io/mgba/Presenter/GamesPresenter.java @@ -11,6 +11,7 @@ import io.mgba.Data.Database.Game; import io.mgba.Data.Platform; import io.mgba.R; +import io.mgba.mgba; import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; @@ -57,7 +58,8 @@ public void loadGames(io.mgba.UI.Activities.Interfaces.ILibrary databaseHelper, // A do nothing kinda of method just so I can update UI. // On a rx thread that need to be non UI. private Single updateView(){ - return Single.create(s -> s.onSuccess(true)); + Single ret = Single.create(s -> s.onSuccess(true)); + return ret.doOnError(mgba::report); } @Override diff --git a/app/src/main/java/io/mgba/mgba.java b/app/src/main/java/io/mgba/mgba.java index 685f0de..b292b01 100644 --- a/app/src/main/java/io/mgba/mgba.java +++ b/app/src/main/java/io/mgba/mgba.java @@ -44,11 +44,6 @@ private ModelComponent initModelComponent_Dagger(mgba application){ .build(); } - public static void printLog(String tag, String message){ - if(BuildConfig.DEBUG) - Log.v(tag, message); - } - public void savePreference(String key, String value) { preparePreferencesController(); preferencesController.save(key, value); @@ -136,4 +131,21 @@ public void inject(MainPresenter target) { public void inject(Library library) { modelComponent.inject(library); } + + public static void report(Throwable error) { + if(BuildConfig.DEBUG) { + + Log.e(" --- An error occurred:", error.getMessage()); + Log.e(" --- StackTrace:", error.getStackTrace().toString()); + + } + + } + + public static void printLog(String tag, String message){ + if(BuildConfig.DEBUG) + Log.v(tag, message); + } + + } diff --git a/app/src/test/java/io/mgba/FileManagerTests.java b/app/src/test/java/io/mgba/FileManagerTests.java new file mode 100644 index 0000000..99f8240 --- /dev/null +++ b/app/src/test/java/io/mgba/FileManagerTests.java @@ -0,0 +1,29 @@ +package io.mgba; + +import org.junit.Test; + +import java.io.File; +import io.mgba.Model.IO.FilesManager; + +import static org.junit.Assert.assertEquals; + +public class FileManagerTests { + + @Test + public void getExtensionOnFileWithExtension(){ + assertEquals("test", FilesManager.getFileExtension(new File("/something.test"))); + } + + + @Test + public void getExtensionOnFileWithoutExtension(){ + assertEquals("est", FilesManager.getFileExtension(new File("/somethingtest"))); + } + + @Test + public void getFilenameWithoutExtension(){ + assertEquals("something", FilesManager.getFileWithoutExtension(new File("/something.test"))); + } + + +}