Skip to content

Commit

Permalink
Merge pull request #86 from doc-ai/dev
Browse files Browse the repository at this point in the history
Hotfix for crash in play store build but not dev build
  • Loading branch information
RohanJahagirdar authored Jul 30, 2020
2 parents 46ec37f + dd607c9 commit b8d77c7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
14 changes: 9 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "ai.doc.netrunner_android"
minSdkVersion 22
targetSdkVersion 29
versionCode 3
versionName "1.1.1"
versionCode 4
versionName "1.1.2"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

Expand All @@ -17,6 +17,10 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

aaptOptions {
Expand Down Expand Up @@ -54,8 +58,8 @@ allprojects {

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
Expand All @@ -69,8 +73,8 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'

implementation 'com.github.doc-ai.tensorio-android:core:0.9.11'
implementation 'com.github.doc-ai.tensorio-android:tflite:0.9.11'
implementation 'com.github.doc-ai.tensorio-android:core:d22a981feecf08fef5c02324948120626fc8bd04'
implementation 'com.github.doc-ai.tensorio-android:tflite:d22a981feecf08fef5c02324948120626fc8bd04'

testImplementation 'junit:junit:4.13'

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/ai/doc/netrunner/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ai.doc.netrunner.utilities.*
import ai.doc.netrunner.viewmodels.MainViewModel
import ai.doc.netrunner.viewmodels.ModelBundlesViewModel
import ai.doc.tensorio.core.modelbundle.ModelBundle
import ai.doc.tensorio.core.modelbundle.ModelBundleManager
import ai.doc.tensorio.core.modelbundle.ModelBundlesManager
import ai.doc.tensorio.tflite.model.TFLiteModel

import android.app.Activity
Expand Down Expand Up @@ -125,8 +125,8 @@ class MainActivity : AppCompatActivity(), WelcomeFragment.Callbacks {
// Load the Model

modelBundlesViewModel.setBundleManagers(
ModelBundleManager(applicationContext, ""),
ModelBundleManager(ModelManagerUtilities.getModelFilesDir(this)))
ModelBundlesManager.managerWithAssets(applicationContext, ""),
ModelBundlesManager.managerWithFiles(ModelManagerUtilities.getModelFilesDir(this)))

try {
val bundle = modelBundlesViewModel.bundleWithId(selectedModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import ai.doc.netrunner.fragments.ModelBundleFragment
import ai.doc.netrunner.fragments.ModelBundleJsonFragment
import ai.doc.netrunner.fragments.ModelBundleListFragment
import ai.doc.netrunner.utilities.ModelManagerUtilities
import ai.doc.tensorio.core.modelbundle.FileModelBundle
import ai.doc.tensorio.core.modelbundle.ModelBundle
import ai.doc.tensorio.core.modelbundle.ModelBundleManager
import ai.doc.tensorio.core.modelbundle.ModelBundlesManager
import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -34,8 +35,8 @@ class ModelManagerActivity : AppCompatActivity(), ModelBundleListFragment.Callba
setContentView(R.layout.activity_model_manager)

modelBundlesViewModel.setBundleManagers(
ModelBundleManager(applicationContext, ""),
ModelBundleManager(ModelManagerUtilities.getModelFilesDir(this)))
ModelBundlesManager.managerWithAssets(applicationContext, ""),
ModelBundlesManager.managerWithFiles(ModelManagerUtilities.getModelFilesDir(this)))

setSupportActionBar(findViewById<Toolbar>(R.id.toolbar))
supportActionBar?.setHomeButtonEnabled(true)
Expand Down Expand Up @@ -85,7 +86,7 @@ class ModelManagerActivity : AppCompatActivity(), ModelBundleListFragment.Callba
override fun onDeleteModelSelected(modelBundle: ModelBundle) {
supportFragmentManager.popBackStack()

ModelManagerUtilities.deleteModelBundle(modelBundle)
ModelManagerUtilities.deleteModelBundle(modelBundle as FileModelBundle)
modelBundlesViewModel.reloadManagers()
setDidUpdateModels()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ class ImportModelBundleFragment : DialogFragment() {
val modelBundleDir = unzip(fileDestination)

// Validate Model Bundle

val validator = ModelBundleValidator(requireContext(), modelBundleDir)

validator.validate() {_, json ->
// Reject models with non-unique identifiers, TODO: and non-unique filenames, currently fails on copy
!modelBundlesViewModel.modelIds.contains(json.getString("id"))
}
// Disabled until fix is found, see #83

// val validator = ModelBundleValidator.validatorWithFile(requireContext(), modelBundleDir)
//
// validator.validate() {_, json ->
// // Reject models with non-unique identifiers, TODO: and non-unique filenames, currently fails on copy
// !modelBundlesViewModel.modelIds.contains(json.getString("id"))
// }

// Copy To Models Dir

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ai.doc.netrunner.utilities

import ai.doc.netrunner.BuildConfig
import ai.doc.tensorio.core.modelbundle.ModelBundle
import ai.doc.tensorio.core.modelbundle.FileModelBundle
import android.content.Context
import java.io.File
import java.io.IOException
Expand All @@ -23,11 +22,7 @@ object ModelManagerUtilities {

/** Deletes the model bundle represented by a File */

fun deleteModelBundle(modelBundle: ModelBundle) {
if (BuildConfig.DEBUG && modelBundle.file == null) {
error("Only file model bundles can ever be deleted")
}

fun deleteModelBundle(modelBundle: FileModelBundle) {
val file = modelBundle.file ?: return
file.deleteRecursively()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ai.doc.netrunner.viewmodels

import ai.doc.tensorio.core.modelbundle.ModelBundle
import ai.doc.tensorio.core.modelbundle.ModelBundleManager
import ai.doc.tensorio.core.modelbundle.ModelBundlesManager
import androidx.lifecycle.ViewModel

class ModelBundlesViewModel : ViewModel() {

private lateinit var assetsManager: ModelBundleManager
private lateinit var filesManager: ModelBundleManager
private lateinit var assetsManager: ModelBundlesManager
private lateinit var filesManager: ModelBundlesManager

lateinit var modelIds: List<String>
private set
Expand All @@ -17,7 +17,7 @@ class ModelBundlesViewModel : ViewModel() {

/** You must provide the view model with an assetsManager and a filesManager prior to using it */

fun setBundleManagers(assetsManager: ModelBundleManager, filesManager: ModelBundleManager) {
fun setBundleManagers(assetsManager: ModelBundlesManager, filesManager: ModelBundlesManager) {
this.assetsManager = assetsManager
this.filesManager = filesManager
loadIdsAndBundles()
Expand Down

0 comments on commit b8d77c7

Please sign in to comment.