Skip to content

Commit a45edea

Browse files
committed
Minor fixes :)
1 parent d85096b commit a45edea

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

data/src/main/java/org/cryptomator/data/cloud/crypto/CryptoImplDecorator.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ abstract class CryptoImplDecorator(
121121
CloudType.WEBDAV -> LruFileCacheUtil.Cache.WEBDAV
122122
CloudType.S3 -> LruFileCacheUtil.Cache.S3
123123
CloudType.LOCAL -> LruFileCacheUtil.Cache.LOCAL
124-
else -> throw IllegalStateException()
124+
else -> throw IllegalStateException("Unexpected CloudType: $type")
125125
}
126126
}
127127

@@ -458,6 +458,11 @@ abstract class CryptoImplDecorator(
458458
val thumbnailBitmap: Bitmap?
459459
options.inSampleSize = 4 // pixel number reduced by a factor of 1/16
460460
val bitmap = BitmapFactory.decodeStream(thumbnailReader, null, options)
461+
if (bitmap == null) {
462+
closeQuietly(thumbnailReader)
463+
return@submit
464+
}
465+
461466
val thumbnailWidth = 100
462467
val thumbnailHeight = 100
463468
thumbnailBitmap = ThumbnailUtils.extractThumbnail(bitmap, thumbnailWidth, thumbnailHeight)
@@ -468,7 +473,7 @@ abstract class CryptoImplDecorator(
468473

469474
cryptoFile.thumbnail = diskCache[cacheKey]
470475
} catch (e: Exception) {
471-
Timber.e("Bitmap generation crashed")
476+
Timber.e(e, "Bitmap generation crashed")
472477
}
473478
}
474479
}
@@ -511,7 +516,7 @@ abstract class CryptoImplDecorator(
511516
}
512517
Timber.tag("THUMBNAIL").i("[AssociateThumbnails] associated:${associated} files, elapsed:${elapsed}ms")
513518
}
514-
519+
515520
private fun isGenerateThumbnailsEnabled(): Boolean {
516521
return sharedPreferencesHandler.useLruCache() && sharedPreferencesHandler.generateThumbnails() != ThumbnailsOption.NEVER
517522
}

presentation/src/main/java/org/cryptomator/presentation/presenter/BrowseFilesPresenter.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,19 @@ class BrowseFilesPresenter @Inject constructor( //
293293
}
294294
associateThumbnailsUseCase.withList(cloudNodes)
295295
.run(object : DefaultProgressAwareResultHandler<Void, FileTransferState>() {
296-
@Override
297296
override fun onProgress(progress: Progress<FileTransferState>) {
298297
val state = progress.state()
299298
state?.let { state ->
300299
view?.addOrUpdateCloudNode(cloudFileModelMapper.toModel(state.file()))
301300
}
302301
}
303302

304-
@Override
305303
override fun onFinished() {
306304
val images = view?.renderedCloudNodes()?.filterIsInstance<CloudFileModel>()?.filter { file -> isImageMediaType(file.name) } ?: return
307-
val firstImages = images.subList(0, 10)
308-
val noThumbnailImages = firstImages.filter { img -> img.thumbnail == null }
309-
if (noThumbnailImages.isNotEmpty()) {
310-
thumbnailsForVisibleNodes(noThumbnailImages)
305+
images.take(10).filter { img -> img.thumbnail == null }.let { firstImagesWithoutThumbnails ->
306+
if (firstImagesWithoutThumbnails.isNotEmpty()) {
307+
thumbnailsForVisibleNodes(firstImagesWithoutThumbnails)
308+
}
311309
}
312310
}
313311
})

presentation/src/main/java/org/cryptomator/presentation/ui/fragment/BrowseFilesFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import android.util.TypedValue
66
import android.view.View
77
import android.view.View.GONE
88
import android.view.View.VISIBLE
9-
import android.widget.AbsListView.OnScrollListener.SCROLL_STATE_IDLE
109
import android.widget.RelativeLayout
1110
import androidx.core.content.ContextCompat
1211
import androidx.recyclerview.widget.LinearLayoutManager
1312
import androidx.recyclerview.widget.RecyclerView
13+
import androidx.recyclerview.widget.RecyclerView.NO_POSITION
14+
import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE
1415
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1516
import com.simplecityapps.recyclerview_fastscroll.interfaces.OnFastScrollStateChangeListener
1617
import org.cryptomator.domain.CloudNode
@@ -144,6 +145,9 @@ class BrowseFilesFragment : BaseFragment<FragmentBrowseFilesBinding>(FragmentBro
144145
val layoutManager = binding.recyclerViewLayout.recyclerView.layoutManager as LinearLayoutManager
145146
val first = layoutManager.findFirstVisibleItemPosition()
146147
val last = layoutManager.findLastVisibleItemPosition()
148+
if (first == NO_POSITION || last == NO_POSITION) {
149+
return
150+
}
147151
val visibleCloudNodes = cloudNodesAdapter.renderedCloudNodes().subList(first, last + 1)
148152
if (!binding.swipeRefreshLayout.isRefreshing) {
149153
browseFilesPresenter.thumbnailsForVisibleNodes(visibleCloudNodes)

0 commit comments

Comments
 (0)