Skip to content

Instantly share code, notes, and snippets.

@illuzor illuzor/WallpaperFragment.kt Secret
Last active Sep 23, 2018

What would you like to do?
package com.illuzor.lesson.wallpapers.screens
import android.os.Bundle
import androidx.lifecycle.ViewModelProviders
import com.illuzor.lesson.wallpapers.R
import com.illuzor.lesson.wallpapers.model.ViewModelWallpaper
import com.illuzor.lesson.wallpapers.model.ViewModelBase.State.*
class WallpaperFragment : AbstractFragment() {
override val layoutId = R.layout.fragment_wallpaper
private var loaded = false
private lateinit var relativeUrl: String
private lateinit var model: ViewModelWallpaper
private lateinit var imageFile: File
private val CACHE_SIZE = 20
override fun onCreate(savedInstanceState: Bundle?) {
model = ViewModelProviders.of(this).get(
val filename = arguments!!.getString("filename", "")
val category = arguments!!.getString("category", "")
relativeUrl = "images/$category/$filename"
private fun createFile(filename: String) {
val subfolder = File(context!!.cacheDir.path + "/wallpapers/")
imageFile = subfolder.resolve(filename)
if (imageFile.exists()) return
if (subfolder.exists() && subfolder.listFiles().size >= CACHE_SIZE) {
subfolder.listFiles().forEach { it.delete() }
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.