From 992c456af550a596b2f3f6a171019fad7b103d03 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Sun, 10 Dec 2017 11:48:16 +0100 Subject: [PATCH] Some more improvements, while I'm learning more and more about Kotlin. ;-) --- .../AbstractMediaFileManager.kt | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt index 177b2d6..591987e 100644 --- a/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt +++ b/src/main/kotlin/de/fabianonline/telegram_backup/mediafilemanager/AbstractMediaFileManager.kt @@ -48,23 +48,30 @@ abstract class AbstractMediaFileManager(protected var message: TLMessage, protec abstract val size: Int abstract val extension: String - fun isDownloaded() { return File(targetPathAndFilename).isFile() } - fun isDownloading() {return File(targetPathAndFilename + ".downloading").isFile() } - fun getTargetPath() { - val path = user.getFileBase() + Config.FILE_FILES_BASE + File.separatorChar - File(path).mkdirs() - return path - } - fun getTargetFilename() { - val message_id = message.getId() - if (message.getToId() is TLPeerChannel) { - val channel_id = message.getToId().getChannelId() - return "channel_${channel_id}_${message_id}.$extension" - } else return "${message_id}.$extension" - } - val getTargetPathAndFilename() { - return getTargetPath() + getTargetFilename() - } + val downloaded: Boolean + get() = File(targetPathAndFilename).isFile() + + val downloading: Boolean + get() = File("${targetPathAndFilename}.downloading").isFile() + + val targetPath: String + get() { + val path = user.getFileBase() + Config.FILE_FILES_BASE + File.separatorChar + File(path).mkdirs() + return path + } + + val targetFilename: String + get() { + val message_id = message.getId() + if (message.getToId() is TLPeerChannel) { + val channel_id = message.getToId().getChannelId() + return "channel_${channel_id}_${message_id}.$extension" + } else return "${message_id}.$extension" + } + + val targetPathAndFilenam: String + get() = targetPath + targetFilename abstract val letter: String abstract val name: String