Skip to content

Commit c419f77

Browse files
committed
Initial commit
0 parents  commit c419f77

File tree

65 files changed

+1643
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1643
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'kotlin-kapt'
5+
id 'com.google.dagger.hilt.android'
6+
id 'androidx.navigation.safeargs'
7+
}
8+
9+
android {
10+
namespace 'com.example.imagelrucache'
11+
compileSdk 33
12+
13+
defaultConfig {
14+
applicationId "com.example.imagelrucache"
15+
minSdk 21
16+
targetSdk 33
17+
versionCode 1
18+
versionName "1.0"
19+
20+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21+
}
22+
23+
buildTypes {
24+
release {
25+
minifyEnabled false
26+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_1_8
31+
targetCompatibility JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = '1.8'
35+
}
36+
viewBinding{
37+
enabled true
38+
}
39+
}
40+
41+
dependencies {
42+
43+
implementation 'androidx.core:core-ktx:1.7.0'
44+
implementation 'androidx.appcompat:appcompat:1.6.1'
45+
implementation 'com.google.android.material:material:1.8.0'
46+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
47+
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
48+
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
49+
testImplementation 'junit:junit:4.13.2'
50+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
51+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
52+
53+
//Dagger-Hilt
54+
implementation "com.google.dagger:hilt-android:2.44"
55+
kapt "com.google.dagger:hilt-compiler:2.44"
56+
57+
//Retrofit
58+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
59+
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
60+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.imagelrucache
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.imagelrucache", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
7+
<application
8+
android:name=".DocImageApplication"
9+
android:allowBackup="true"
10+
android:dataExtractionRules="@xml/data_extraction_rules"
11+
android:fullBackupContent="@xml/backup_rules"
12+
android:icon="@mipmap/ic_launcher"
13+
android:label="@string/app_name"
14+
android:roundIcon="@mipmap/ic_launcher_round"
15+
android:supportsRtl="true"
16+
android:theme="@style/Theme.ImageLruCache"
17+
android:requestLegacyExternalStorage="true"
18+
tools:targetApi="31">
19+
<activity
20+
android:name=".ui.MainActivity"
21+
android:exported="true">
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
28+
29+
</activity>
30+
</application>
31+
32+
</manifest>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.example.imagelrucache
2+
3+
import android.app.Application
4+
import dagger.hilt.android.HiltAndroidApp
5+
6+
@HiltAndroidApp
7+
class DocImageApplication: Application() {
8+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.example.imagelrucache.adapter
2+
3+
import android.graphics.Bitmap
4+
import android.view.LayoutInflater
5+
import android.view.ViewGroup
6+
import androidx.recyclerview.widget.RecyclerView
7+
import com.example.imagelrucache.databinding.ItemDogBinding
8+
9+
class RecentDogAdapter: RecyclerView.Adapter<RecentDogAdapter.DogViewHolder>() {
10+
11+
private val dogs = mutableListOf<Bitmap>()
12+
13+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)=
14+
DogViewHolder(ItemDogBinding.inflate(LayoutInflater.from(parent.context),parent,false))
15+
16+
override fun onBindViewHolder(holder: DogViewHolder, position: Int) {
17+
holder.onBind(dogs[position])
18+
}
19+
20+
override fun getItemCount() = dogs.size
21+
22+
fun addDogs(dogs:List<Bitmap>){
23+
this.dogs.clear()
24+
this.dogs.addAll(dogs)
25+
notifyDataSetChanged()
26+
}
27+
28+
class DogViewHolder(private val binding:ItemDogBinding):RecyclerView.ViewHolder(binding.root) {
29+
fun onBind(dogBitmap: Bitmap) {
30+
binding.ivDog.setImageBitmap(dogBitmap)
31+
}
32+
33+
}
34+
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.imagelrucache.cache
2+
3+
import android.graphics.Bitmap
4+
5+
interface DogImageCache {
6+
7+
fun putImageToCache(url:String,image:Bitmap)
8+
suspend fun getAllDogImage():List<Bitmap>
9+
fun clearDogImageCache()
10+
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.imagelrucache.cache
2+
3+
import android.graphics.Bitmap
4+
import com.example.imagelrucache.cache.lrudisk.LruDiskCache
5+
import javax.inject.Inject
6+
7+
class DogImageCacheImpl @Inject constructor(private val lruDiskCache: LruDiskCache):DogImageCache {
8+
9+
override fun putImageToCache(url: String, image: Bitmap) {
10+
lruDiskCache.putImage(url,image)
11+
}
12+
13+
override suspend fun getAllDogImage(): List<Bitmap> {
14+
return lruDiskCache.getAllImages()
15+
}
16+
17+
override fun clearDogImageCache() {
18+
return lruDiskCache.clearCache()
19+
}
20+
}

0 commit comments

Comments
 (0)