Skip to content

Commit 8eb447e

Browse files
committed
Initial Commit
0 parents  commit 8eb447e

File tree

73 files changed

+1820
-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.

73 files changed

+1820
-0
lines changed

.gitignore

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Built application files
2+
*.apk
3+
*.aar
4+
*.ap_
5+
*.aab
6+
7+
# Files for the ART/Dalvik VM
8+
*.dex
9+
10+
# Java class files
11+
*.class
12+
13+
# Generated files
14+
bin/
15+
gen/
16+
out/
17+
# Uncomment the following line in case you need and you don't have the release build type files in your app
18+
# release/
19+
20+
# Gradle files
21+
.gradle/
22+
build/
23+
24+
# Local configuration file (sdk path, etc)
25+
local.properties
26+
27+
# Proguard folder generated by Eclipse
28+
proguard/
29+
30+
# Log Files
31+
*.log
32+
33+
# Android Studio Navigation editor temp files
34+
.navigation/
35+
36+
# Android Studio captures folder
37+
captures/
38+
39+
# IntelliJ
40+
*.iml
41+
.idea/workspace.xml
42+
.idea/tasks.xml
43+
.idea/gradle.xml
44+
.idea/assetWizardSettings.xml
45+
.idea/dictionaries
46+
.idea/libraries
47+
# Android Studio 3 in .gitignore file.
48+
.idea/caches
49+
.idea/modules.xml
50+
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
51+
.idea/navEditor.xml
52+
53+
# Keystore files
54+
# Uncomment the following lines if you do not want to check your keystore files in.

.idea/.gitignore

Whitespace-only changes.

.idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Readme.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Demo Internet Access App - Bookshelf App
2+
3+
Simple app to demonstrate internet access.
4+
The App display asynchronously downloaded images of the books along with their titles in a vertical grid.
5+
In Addition it lets the user Search for Books
6+
7+
Some goals
8+
- Use repository
9+
- Use Dependency Injection Container
10+
- use viewmodel
11+
- use uiState
12+
- use allow user to search
13+
14+
15+
16+
### ScreenShots
17+
![|100](screenshot_01.png) ![|100](screenshot_02.png) ![|100](screenshot_03.png)
18+
<p style=float:left">
19+
<img src="screenshot_01.png" width="200" />
20+
<img src="screenshot_02.png" width="200" />
21+
<img src="screenshot_03.png" width="200" />
22+
</p>
23+
<p style=float:left">
24+
<img src="screenshot_04.png" width="200" />
25+
<img src="screenshot_05.png" width="200" />
26+
<img src="screenshot_06.png" width="200" />
27+
</p>
28+
---
29+
30+
31+
ref: demo-internet-access-bookshelf-app-android-kotlin-compose

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.20'
5+
}
6+
7+
android {
8+
namespace 'com.example.bookshelf'
9+
compileSdk 33
10+
11+
defaultConfig {
12+
applicationId "com.example.bookshelf"
13+
minSdk 26
14+
targetSdk 33
15+
versionCode 1
16+
versionName "1.0"
17+
18+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19+
vectorDrawables {
20+
useSupportLibrary true
21+
}
22+
}
23+
24+
buildTypes {
25+
release {
26+
minifyEnabled false
27+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility JavaVersion.VERSION_1_8
32+
targetCompatibility JavaVersion.VERSION_1_8
33+
}
34+
kotlinOptions {
35+
jvmTarget = '1.8'
36+
}
37+
buildFeatures {
38+
compose true
39+
}
40+
composeOptions {
41+
kotlinCompilerExtensionVersion '1.2.0'
42+
}
43+
packagingOptions {
44+
resources {
45+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
46+
}
47+
}
48+
}
49+
50+
dependencies {
51+
52+
implementation 'androidx.core:core-ktx:1.9.0'
53+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
54+
implementation 'androidx.activity:activity-compose:1.6.1'
55+
implementation "androidx.compose.ui:ui:$compose_ui_version"
56+
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
57+
implementation 'androidx.compose.material:material:1.3.1'
58+
testImplementation 'junit:junit:4.13.2'
59+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
60+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
61+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
62+
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
63+
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
64+
65+
66+
// viewmodel
67+
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
68+
// retrofit
69+
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
70+
implementation "com.squareup.retrofit2:retrofit:2.9.0"
71+
// json file
72+
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
73+
// images in json
74+
implementation "io.coil-kt:coil-compose:2.2.2"
75+
//Navigation
76+
implementation "androidx.navigation:navigation-compose:2.5.3"
77+
}

app/proguard-rules.pro

+21
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.bookshelf
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.bookshelf", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+32
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+
<application
7+
android:name=".BookshelfApplication"
8+
9+
android:usesCleartextTraffic="true"
10+
11+
android:allowBackup="true"
12+
android:dataExtractionRules="@xml/data_extraction_rules"
13+
android:fullBackupContent="@xml/backup_rules"
14+
android:icon="@mipmap/ic_launcher"
15+
android:label="@string/app_name"
16+
android:supportsRtl="true"
17+
android:theme="@style/Theme.Bookshelf"
18+
tools:targetApi="31">
19+
<activity
20+
android:name=".MainActivity"
21+
android:exported="true"
22+
android:label="@string/app_name"
23+
android:theme="@style/Theme.Bookshelf">
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN" />
26+
27+
<category android:name="android.intent.category.LAUNCHER" />
28+
</intent-filter>
29+
</activity>
30+
</application>
31+
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.bookshelf
2+
3+
import android.app.Application
4+
import com.example.bookshelf.di.AppContainer
5+
import com.example.bookshelf.di.DefaultAppContainer
6+
7+
class BookshelfApplication: Application() {
8+
/** AppContainer instance used by the rest of classes to obtain dependencies */
9+
lateinit var container: AppContainer
10+
override fun onCreate() {
11+
super.onCreate()
12+
container = DefaultAppContainer()
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.bookshelf
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.lifecycle.viewmodel.compose.viewModel
7+
import com.example.bookshelf.ui.BookshelfApp
8+
import com.example.bookshelf.ui.screens.home_screen.BookshelfViewModel
9+
import com.example.bookshelf.ui.theme.BookshelfTheme
10+
11+
class MainActivity : ComponentActivity() {
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
setContent {
15+
BookshelfTheme {
16+
val viewModel : BookshelfViewModel = viewModel(factory = BookshelfViewModel.Factory)
17+
BookshelfApp(viewModel)
18+
}
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.bookshelf.data
2+
3+
import com.example.bookshelf.model.Book
4+
5+
/**
6+
* Repository retrieves volume data from underlying data source.
7+
*/
8+
interface BookshelfRepository {
9+
/** Retrieves list of books from underlying data source */
10+
// Notes: List<Book>? NULLABLE
11+
suspend fun getBooks(query: String): List<Book>?
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.example.bookshelf.data
2+
3+
import com.example.bookshelf.model.Book
4+
import com.example.bookshelf.network.BookshelfApiService
5+
6+
/**
7+
* Default Implementation of repository that retrieves volumes data from underlying data source.
8+
*/
9+
class DefaultBookshelfRepository(
10+
private val bookshelfApiService: BookshelfApiService
11+
) : BookshelfRepository {
12+
/** Retrieves list of Volumes from underlying data source */
13+
// Notes: List<Book>? NULLABLE
14+
override suspend fun getBooks(query: String): List<Book>? {
15+
return try {
16+
val res = bookshelfApiService.getBooks(query)
17+
if (res.isSuccessful) {
18+
res.body()?.items ?: emptyList()
19+
} else {
20+
emptyList()
21+
}
22+
} catch (e: Exception) {
23+
e.printStackTrace()
24+
null
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.bookshelf.di
2+
3+
import com.example.bookshelf.data.BookshelfRepository
4+
import com.example.bookshelf.network.BookshelfApiService
5+
6+
/**
7+
* Dependency Injection container at the application level.
8+
*/
9+
interface AppContainer {
10+
val bookshelfApiService: BookshelfApiService
11+
val bookshelfRepository: BookshelfRepository
12+
}

0 commit comments

Comments
 (0)