-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced Glide integration with RecyclerView
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../main/java/com/owncloud/android/presentation/ui/transfers/TransferPreloadModelProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.owncloud.android.presentation.ui.transfers | ||
|
||
import android.content.Context | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.ListPreloader | ||
import com.bumptech.glide.RequestBuilder | ||
import com.bumptech.glide.load.engine.DiskCacheStrategy | ||
import com.owncloud.android.domain.transfers.model.OCTransfer | ||
import com.owncloud.android.utils.MimetypeIconUtil | ||
import java.io.File | ||
import java.util.Collections | ||
|
||
class TransferPreloadModelProvider( | ||
val transfers: List<OCTransfer>, | ||
val context: Context | ||
) : ListPreloader.PreloadModelProvider<Any> { | ||
|
||
override fun getPreloadItems(position: Int): MutableList<Any> { | ||
val localPath = transfers[position].localPath | ||
return if (localPath.isEmpty()) { | ||
Collections.emptyList() | ||
} else { | ||
Collections.singletonList(localPath) | ||
} | ||
} | ||
|
||
override fun getPreloadRequestBuilder(transfer: Any): RequestBuilder<*> { | ||
val ocTransfer = transfer as OCTransfer | ||
val remoteFile = File(ocTransfer.remotePath) | ||
var fileName = remoteFile.name | ||
if (fileName.isEmpty()) { | ||
fileName = File.separator | ||
} | ||
return Glide.with(context) | ||
.load(ocTransfer.localPath) | ||
.diskCacheStrategy(DiskCacheStrategy.ALL) | ||
.placeholder(MimetypeIconUtil.getFileTypeIconId(MimetypeIconUtil.getBestMimeTypeByFilename(ocTransfer.localPath), fileName)) | ||
} | ||
} |