@@ -16,6 +16,7 @@ import nl.komponents.kovenant.Promise
1616import nl.komponents.kovenant.then
1717import org.joda.time.DateTime
1818import org.readium.lcp.sdk.Lcp
19+ import org.readium.r2.lcp.BuildConfig.DEBUG
1920import org.readium.r2.lcp.license.model.LicenseDocument
2021import org.readium.r2.lcp.license.model.StatusDocument
2122import org.readium.r2.lcp.public.*
@@ -56,7 +57,7 @@ class License(private var documents: ValidatedDocuments,
5657 return charactersLeft
5758 }
5859 } catch (error: Error ) {
59- Timber .e(error)
60+ if ( DEBUG ) Timber .e(error)
6061 }
6162 return null
6263 }
@@ -77,7 +78,7 @@ class License(private var documents: ValidatedDocuments,
7778 charactersLeft = maxOf(0 , charactersLeft - result.length)
7879 licenses.setCopiesLeft(charactersLeft, license.id)
7980 } catch (error: Error ) {
80- Timber .e(error)
81+ if ( DEBUG ) Timber .e(error)
8182 }
8283 return result
8384 }
@@ -90,7 +91,7 @@ class License(private var documents: ValidatedDocuments,
9091 return pagesLeft
9192 }
9293 } catch (error: Error ) {
93- Timber .e(error)
94+ if ( DEBUG ) Timber .e(error)
9495 }
9596 return null
9697 }
@@ -106,7 +107,7 @@ class License(private var documents: ValidatedDocuments,
106107 pagesLeft = maxOf(0 , pagesLeft - pagesCount)
107108 licenses.setPrintsLeft(pagesLeft, license.id)
108109 } catch (error: Error ) {
109- Timber .e(error)
110+ if ( DEBUG ) Timber .e(error)
110111 }
111112 return true
112113 }
@@ -161,7 +162,6 @@ class License(private var documents: ValidatedDocuments,
161162 if (link.type == " text/html" ) {
162163 callHTML(url, params) {
163164 validateStatusDocument(it)
164-
165165 }
166166 } else {
167167 callPUT(url, params) {
@@ -171,7 +171,7 @@ class License(private var documents: ValidatedDocuments,
171171 } catch (e: LCPError ) {
172172 completion(LCPError .wrap(e))
173173 }
174-
174+ completion( null )
175175 }
176176
177177 override val canReturnPublication: Boolean
@@ -197,6 +197,7 @@ class License(private var documents: ValidatedDocuments,
197197 }
198198 completion(null )
199199 }
200+ completion(null )
200201 }
201202
202203 init {
@@ -209,7 +210,7 @@ class License(private var documents: ValidatedDocuments,
209210
210211 fun moveLicense (archivePath : String , licenseData : ByteArray ) {
211212 val pathInZip = " META-INF/license.lcpl"
212- Timber .i(" LCP moveLicense" )
213+ if ( DEBUG ) Timber .i(" LCP moveLicense" )
213214 val source = File (archivePath)
214215 val tmpZip = File (" $archivePath .tmp" )
215216 tmpZip.delete()
@@ -227,16 +228,26 @@ class License(private var documents: ValidatedDocuments,
227228 val title = license.link(LicenseDocument .Rel .publication)?.title
228229 val url = license.url(LicenseDocument .Rel .publication)
229230
230- val rootDir: String = context.getExternalFilesDir(null )?.path + " /"
231+ val properties = Properties ()
232+ val inputStream = context.assets.open(" configs/config.properties" )
233+ properties.load(inputStream)
234+ val useExternalFileDir = properties.getProperty(" useExternalFileDir" , " false" )!! .toBoolean()
235+
236+ val rootDir: String = if (useExternalFileDir) {
237+ context.getExternalFilesDir(null )?.path + " /"
238+ } else {
239+ context.filesDir.path + " /"
240+ }
241+
231242 val fileName = UUID .randomUUID().toString()
232243 return Fuel .download(url.toString()).destination { _, _ ->
233- Timber .i(" LCP destination %s%s" , rootDir, fileName)
244+ if ( DEBUG ) Timber .i(" LCP destination %s%s" , rootDir, fileName)
234245 File (rootDir, fileName)
235246
236247 }.promise() then {
237248 val (_, response, _) = it
238- Timber .i(" LCP destination %s%s" , rootDir, fileName)
239- Timber .i(" LCP then %s" , response.url.toString())
249+ if ( DEBUG ) Timber .i(" LCP destination %s%s" , rootDir, fileName)
250+ if ( DEBUG ) Timber .i(" LCP then %s" , response.url.toString())
240251
241252 rootDir + fileName
242253
0 commit comments