Skip to content

Commit

Permalink
Merge pull request #1 from mateusz-bak/wip-first-release
Browse files Browse the repository at this point in the history
Version 0.0.1
  • Loading branch information
mateusz-bak committed Apr 23, 2021
2 parents 1b4b606 + 3cfa736 commit 93eb232
Show file tree
Hide file tree
Showing 76 changed files with 1,541 additions and 8 deletions.
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/
app/release/*

# Gradle files
.gradle/
Expand All @@ -38,12 +39,7 @@ captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
Expand Down Expand Up @@ -83,3 +79,9 @@ lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

# OSX files
.DS_Store
lint/outputs/
lint/tmp/
# lint/reports/
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# myBooks-android
An Android app for keeping tracks of books you have read.

# myBooks-android
An Android app written in Kotlin for keeping tracks of books you have read.

## Screenshots

### List of your books:
<img src="doc/images/screenshot-list.png" alt="drawing" width="300"/>

### Adding a book:
<img src="doc/images/screenshot-adder.png" alt="drawing" width="300"/>

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.amorgos"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "0.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

def room_version= "2.3.0"
def kodein_version="6.4.0"
def lifecycle_version="2.2.0"

// ROOM AND ARCHITECTURAL COMPONENTS
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation "androidx.room:room-ktx:2.2.6"
kapt "androidx.room:room-compiler:2.2.6"

// COROUTINES
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3"

// NEW MATERIAL DESIGN
implementation "com.google.android.material:material:1.3.0"

// VIEWMODEL
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

// KODEIN
implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
implementation "org.kodein.di:kodein-di-framework-android-x:$kodein_version"
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.mybooks

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.mybooks", appContext.packageName)
}
}
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mybooks">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_green_book"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_green_book_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyBooks">
<activity
android:name=".ui.bookslist.ListActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.bookslist.AdderActivity"/>
<activity android:name=".ui.bookslist.AboutActivity"/>
</application>

</manifest>
Binary file added app/src/main/ic_green_book-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions app/src/main/java/com/example/mybooks/data/db/BooksDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.mybooks.data.db

import androidx.lifecycle.LiveData
import androidx.room.*
import com.example.mybooks.data.db.entities.ListElement

@Dao
interface BooksDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsert(item: ListElement)

@Delete
suspend fun delete(item: ListElement)

@Query("SELECT * FROM read_books")
fun getAllListElements(): LiveData<List<ListElement>>
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/example/mybooks/data/db/BooksDatabase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.mybooks.data.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.mybooks.data.db.entities.ListElement

@Database(
entities = [ListElement::class],
version = 1
)
abstract class BooksDatabase: RoomDatabase() {

abstract fun getBooksDao(): BooksDao

companion object {
@Volatile
private var instance: BooksDatabase? = null
private val LOCK = Any()

operator fun invoke(context: Context) = instance ?: synchronized(LOCK) {
instance ?: createDatabase(context).also { instance = it }
}

private fun createDatabase(context: Context) =
Room.databaseBuilder(context.applicationContext,
BooksDatabase::class.java, "BooksDB.db").build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.mybooks.data.db.entities

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "read_books")
data class ListElement (
@ColumnInfo(name = "item_bookTitle")
var bookTitle: String,
@ColumnInfo(name = "item_bookAuthor")
var bookAuthor: String,
@ColumnInfo(name = "item_bookRating")
var bookRating: Float
){
@PrimaryKey(autoGenerate = true)
var id: Int? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.mybooks.data.repositories

import com.example.mybooks.data.db.BooksDatabase
import com.example.mybooks.data.db.entities.ListElement

class BooksRepository (
private val db: BooksDatabase
) {
suspend fun upsert(item: ListElement) = db.getBooksDao().upsert(item)

suspend fun delete(item: ListElement) = db.getBooksDao().delete(item)

fun getAllListElements() = db.getBooksDao().getAllListElements()
}
47 changes: 47 additions & 0 deletions app/src/main/java/com/example/mybooks/other/ListElementAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.mybooks.other

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.mybooks.R
import com.example.mybooks.data.db.entities.ListElement
import com.example.mybooks.ui.bookslist.BooksViewModel
import kotlinx.android.synthetic.main.item_list_element.view.*

class ListElementAdapter(

var books: List<ListElement>,
private val viewModel: BooksViewModel

) : RecyclerView.Adapter<ListElementAdapter.ListElementViewHolder>() {

inner class ListElementViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListElementViewHolder {
return ListElementViewHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.item_list_element,
parent,
false
)
)
}

override fun onBindViewHolder(holder: ListElementViewHolder, position: Int) {
val curBook = books[position]
holder.itemView.apply {
tvBookTitle.text = curBook.bookTitle
tvBookAuthor.text = curBook.bookAuthor
rbRatingIndicator.rating = curBook.bookRating
}

holder.itemView.ivDeleteBook.setOnClickListener{
viewModel.delete(curBook)
}
}

override fun getItemCount(): Int {
return books.size
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.mybooks.ui.bookslist

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.mybooks.R

class AboutActivity: AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
}
}
Loading

0 comments on commit 93eb232

Please sign in to comment.