How khushpanchal/ketch works
Project Type and Purpose
• Ketch is an Android library written in Kotlin that provides file downloading functionality.
• Its core purpose is to facilitate downloads (of various file types) using WorkManager, with built-in options for pause, resume, cancel, and notification support.
• The project comprises two main modules: a sample “app” module for demonstration and a “ketch” module which contains the library’s core implementation.
File Structure
• The top-level directories include:
• “app”: A sample Android application demonstrating integration and usage of the Ketch library.
• “ketch”: The actual library module that implements the download functionality.
• Inside the “ketch” module, notice directories and packages that indicate specific architectural concerns:
• Internal modules: “internal/database” (database access, DAO, entity, database instance), “internal/download” (download manager, download task, request, response headers), “internal/network” (Retrofit instance and download service), “internal/notification” (notification manager, broadcast receiver), “internal/utils” (helpers and constants), and “internal/worker” (WorkManager worker implementation).
Key Components
a. Sample Application (App Module):
• Represents the user interface that interacts with the Ketch library.
• Components such as MainActivity, MainFragment, and other UI layouts.
b. Ketch Library (Library Module):
• Download Manager:
• Entry point for initiating downloads (Ketch.kt).
• Manages requests (DownloadRequest.kt) and tasks (DownloadTask.kt).
• Internal Download Subsystem:
• Download Manager (DownloadManager.kt) coordinating download operations.
• WorkManager integration through DownloadWorker.kt for background execution.
• Database Layer:
• Manages local persistence: DownloadDatabase.kt, DownloadDao.kt, DownloadEntity.kt, DatabaseInstance.kt.
• Network Layer:
• Handles network operations using Retrofit: RetrofitInstance.kt and DownloadService.kt.
• Notification Manager:
• Provides download notifications via DownloadNotificationManager.kt and NotificationReceiver.kt.
• Utility and Constants:
• Helpers and constants located in DownloadConst.kt, DownloadLogger.kt, ExceptionConst.kt, FileUtil.kt, MapperUtil.kt, etc.
• Customization & Config:
• Classes like DownloadConfig, NotificationConfig, and associated configuration logic.
Relationships and Interactions
• The Sample Application calls into the Ketch singleton instance, initiating downloads.
• The Download Manager internally organizes a download request, creating tasks and scheduling them via WorkManager (via DownloadWorker).
• The Worker interacts with the Network Layer (Retrofit and OkHttp client) to download the file.
• Download progress and results are recorded in the local Database (via DAO and Entities) so that they can be observed as a Flow.
• Notification Manager listens to progress updates and triggers notifications that indicate download status.
• Utility classes support operations across these components.
Architectural Patterns and Technologies
• WorkManager for reliable background tasks.
• Repository-like pattern for saving and updating download data in a SQLite database (using Room-like DAO interfaces).
• Usage of Retrofit for network communication and OkHttp for HTTP client configuration.
• Notification architecture to communicate download progress.
• Kotlin language paradigms with Coroutines and Flows for asynchronous operations.
Elements to Incorporate
• Initiation of download requests,
• Background processing via WorkManager,
• Updates to the database,
• Propagation of progress notifications to the user interface.