@@ -38,6 +38,10 @@ import org.nypl.simplified.accounts.database.api.AccountType
38
38
import org.nypl.simplified.books.api.BookContentProtections
39
39
import org.nypl.simplified.books.api.BookDRMInformation
40
40
import org.nypl.simplified.books.api.BookFormat
41
+ import org.nypl.simplified.books.book_database.api.BookFormats
42
+ import org.nypl.simplified.books.book_database.api.BookFormats.BookFormatDefinition.BOOK_FORMAT_AUDIO
43
+ import org.nypl.simplified.books.book_database.api.BookFormats.BookFormatDefinition.BOOK_FORMAT_EPUB
44
+ import org.nypl.simplified.books.book_database.api.BookFormats.BookFormatDefinition.BOOK_FORMAT_PDF
41
45
import org.nypl.simplified.books.book_registry.BookPreviewRegistryType
42
46
import org.nypl.simplified.books.book_registry.BookPreviewStatus
43
47
import org.nypl.simplified.books.controller.api.BooksPreviewControllerType
@@ -162,11 +166,53 @@ class BookPreviewActivity : AppCompatActivity(R.layout.activity_book_preview) {
162
166
return
163
167
}
164
168
169
+ /*
170
+ * Synthesize a `BookFormat` value for the preview. At the time of writing, we're
171
+ * very lax about exact MIME type values, and we assume no DRM. All of our current
172
+ * preview data seems to be fine with this.
173
+ */
174
+
165
175
try {
176
+ val formatDefinition =
177
+ BookFormats .inferFormat(this .feedEntry.feedEntry)
178
+
166
179
this .bookFormat =
167
- this .account.bookDatabase.entry(this .feedEntry.bookID)
168
- .book
169
- .findPreferredFormat()!!
180
+ when (formatDefinition) {
181
+ BOOK_FORMAT_EPUB -> {
182
+ BookFormat .BookFormatEPUB (
183
+ drmInformation = BookDRMInformation .None ,
184
+ file = null ,
185
+ lastReadLocation = null ,
186
+ bookmarks = listOf (),
187
+ contentType = BookFormats .epubMimeTypes().first()
188
+ )
189
+ }
190
+
191
+ BOOK_FORMAT_AUDIO -> {
192
+ BookFormat .BookFormatAudioBook (
193
+ drmInformation = BookDRMInformation .None ,
194
+ file = null ,
195
+ lastReadLocation = null ,
196
+ bookmarks = listOf (),
197
+ manifest = null ,
198
+ contentType = BookFormats .audioBookGenericMimeTypes().first()
199
+ )
200
+ }
201
+
202
+ BOOK_FORMAT_PDF -> {
203
+ BookFormat .BookFormatPDF (
204
+ drmInformation = BookDRMInformation .None ,
205
+ file = null ,
206
+ lastReadLocation = null ,
207
+ bookmarks = listOf (),
208
+ contentType = BookFormats .pdfMimeTypes().first()
209
+ )
210
+ }
211
+
212
+ null -> {
213
+ throw IllegalStateException (" No recognized preview format." )
214
+ }
215
+ }
170
216
} catch (e: Throwable ) {
171
217
this .logger.debug(" Unable to locate book format: " , e)
172
218
this .finish()
@@ -222,17 +268,21 @@ class BookPreviewActivity : AppCompatActivity(R.layout.activity_book_preview) {
222
268
is SR2ReaderFragment -> {
223
269
super .onBackPressed()
224
270
}
271
+
225
272
is SR2SearchFragment -> {
226
273
this .switchFragment(SR2ReaderFragment ())
227
274
}
275
+
228
276
is SR2TOCFragment -> {
229
277
this .switchFragment(SR2ReaderFragment ())
230
278
}
231
279
}
232
280
}
281
+
233
282
null -> {
234
283
super .onBackPressed()
235
284
}
285
+
236
286
else -> {
237
287
super .onBackPressed()
238
288
}
@@ -247,9 +297,11 @@ class BookPreviewActivity : AppCompatActivity(R.layout.activity_book_preview) {
247
297
is SR2BookLoadingFailed -> {
248
298
this .onBookLoadingFailed(event.exception)
249
299
}
300
+
250
301
is SR2ControllerBecameAvailable -> {
251
302
this .onControllerBecameAvailable()
252
303
}
304
+
253
305
is SR2ControllerBecameUnavailable -> {
254
306
// Nothing to do
255
307
}
@@ -268,15 +320,19 @@ class BookPreviewActivity : AppCompatActivity(R.layout.activity_book_preview) {
268
320
SR2ReaderViewCommand .SR2ReaderViewNavigationReaderClose -> {
269
321
this .finish()
270
322
}
323
+
271
324
SR2ReaderViewCommand .SR2ReaderViewNavigationSearchClose -> {
272
325
this .switchFragment(SR2ReaderFragment ())
273
326
}
327
+
274
328
SR2ReaderViewCommand .SR2ReaderViewNavigationSearchOpen -> {
275
329
this .switchFragment(SR2SearchFragment ())
276
330
}
331
+
277
332
SR2ReaderViewCommand .SR2ReaderViewNavigationTOCClose -> {
278
333
this .switchFragment(SR2ReaderFragment ())
279
334
}
335
+
280
336
SR2ReaderViewCommand .SR2ReaderViewNavigationTOCOpen -> {
281
337
this .switchFragment(SR2TOCFragment ())
282
338
}
0 commit comments