Skip to content

Commit 498d640

Browse files
committed
Rewrite demo app with Kotlin, Compose and Clean Architecture
1 parent 6d86851 commit 498d640

38 files changed

+1449
-723
lines changed

app/build.gradle

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,69 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'org.jetbrains.kotlin.android'
3+
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
24

35
android {
4-
compileSdkVersion 34
6+
compileSdk 35
57
namespace = "com.tomclaw.cache.demo"
8+
69
defaultConfig {
710
applicationId "com.tomclaw.cache.demo"
8-
minSdkVersion 21
9-
targetSdkVersion 34
10-
versionCode 1
11-
versionName "1.1"
11+
minSdk 21
12+
targetSdk 35
13+
versionCode 2
14+
versionName "2.0"
1215
}
16+
1317
buildTypes {
1418
release {
1519
minifyEnabled false
1620
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1721
}
1822
}
23+
1924
compileOptions {
2025
sourceCompatibility JavaVersion.VERSION_17
2126
targetCompatibility JavaVersion.VERSION_17
2227
}
28+
29+
kotlinOptions {
30+
jvmTarget = '17'
31+
}
32+
33+
buildFeatures {
34+
compose true
35+
}
2336
}
2437

2538
dependencies {
26-
implementation 'androidx.appcompat:appcompat:1.7.0'
27-
implementation 'com.google.android.material:material:1.12.0'
28-
implementation 'androidx.recyclerview:recyclerview:1.3.2'
39+
// Compose BOM
40+
def composeBom = platform('androidx.compose:compose-bom:2024.12.01')
41+
implementation composeBom
42+
43+
// Compose
44+
implementation 'androidx.compose.ui:ui'
45+
implementation 'androidx.compose.ui:ui-graphics'
46+
implementation 'androidx.compose.ui:ui-tooling-preview'
47+
implementation 'androidx.compose.material3:material3'
48+
implementation 'androidx.compose.material:material-icons-extended'
49+
50+
// Activity Compose
51+
implementation 'androidx.activity:activity-compose:1.9.3'
52+
53+
// Lifecycle + ViewModel
54+
implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.8.7'
55+
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.7'
56+
57+
// Coroutines
58+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0'
59+
60+
// Core
61+
implementation 'androidx.core:core-ktx:1.15.0'
62+
63+
// Cache library
2964
implementation project(path: ':cache')
65+
66+
// Debug
67+
debugImplementation 'androidx.compose.ui:ui-tooling'
68+
debugImplementation 'androidx.compose.ui:ui-test-manifest'
3069
}

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.tomclaw.cache.demo">
3+
xmlns:tools="http://schemas.android.com/tools">
54

65
<application
76
android:name=".App"
@@ -10,17 +9,17 @@
109
android:label="@string/app_name"
1110
android:roundIcon="@mipmap/ic_launcher_round"
1211
android:supportsRtl="true"
13-
android:theme="@style/AppTheme"
12+
android:theme="@android:style/Theme.Material.Light.NoActionBar"
1413
tools:ignore="GoogleAppIndexingWarning">
1514
<activity
1615
android:name=".MainActivity"
17-
android:exported="true">
16+
android:exported="true"
17+
android:theme="@android:style/Theme.Material.Light.NoActionBar">
1818
<intent-filter>
1919
<action android:name="android.intent.action.MAIN" />
20-
2120
<category android:name="android.intent.category.LAUNCHER" />
2221
</intent-filter>
2322
</activity>
2423
</application>
2524

26-
</manifest>
25+
</manifest>

app/src/main/java/com/tomclaw/cache/demo/App.java

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.tomclaw.cache.demo
2+
3+
import android.app.Application
4+
import com.tomclaw.cache.DiskLruCache
5+
import com.tomclaw.cache.demo.data.CacheRepositoryImpl
6+
import com.tomclaw.cache.demo.domain.repository.CacheRepository
7+
import com.tomclaw.cache.demo.domain.usecase.AccessFileUseCase
8+
import com.tomclaw.cache.demo.domain.usecase.AddFileUseCase
9+
import com.tomclaw.cache.demo.domain.usecase.ClearCacheUseCase
10+
import com.tomclaw.cache.demo.domain.usecase.DeleteFileUseCase
11+
import com.tomclaw.cache.demo.domain.usecase.ObserveCacheUseCase
12+
import com.tomclaw.cache.demo.presentation.ViewModelFactory
13+
import java.io.File
14+
import java.io.IOException
15+
16+
class App : Application() {
17+
18+
lateinit var viewModelFactory: ViewModelFactory
19+
private set
20+
21+
override fun onCreate() {
22+
super.onCreate()
23+
24+
val cacheDir = File(filesDir, "lru_cache")
25+
val tempDir = cacheDir
26+
27+
val cache = try {
28+
DiskLruCache.create(cacheDir, CACHE_SIZE)
29+
} catch (e: IOException) {
30+
throw RuntimeException("Failed to create cache", e)
31+
}
32+
33+
val repository: CacheRepository = CacheRepositoryImpl(cache, tempDir)
34+
35+
val observeCacheUseCase = ObserveCacheUseCase(repository)
36+
val addFileUseCase = AddFileUseCase(repository)
37+
val accessFileUseCase = AccessFileUseCase(repository)
38+
val deleteFileUseCase = DeleteFileUseCase(repository)
39+
val clearCacheUseCase = ClearCacheUseCase(repository)
40+
41+
viewModelFactory = ViewModelFactory(
42+
observeCacheUseCase = observeCacheUseCase,
43+
addFileUseCase = addFileUseCase,
44+
accessFileUseCase = accessFileUseCase,
45+
deleteFileUseCase = deleteFileUseCase,
46+
clearCacheUseCase = clearCacheUseCase
47+
)
48+
}
49+
50+
companion object {
51+
private const val CACHE_SIZE = 500L * 1024 // 500 KB
52+
}
53+
}

app/src/main/java/com/tomclaw/cache/demo/CacheAdapter.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

app/src/main/java/com/tomclaw/cache/demo/MainActivity.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)