Skip to content

Commit

Permalink
Version bumps and nit cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharkaboi committed Jul 18, 2021
1 parent 33d2807 commit bda296e
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 260 deletions.
43 changes: 16 additions & 27 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'androidx.navigation.safeargs.kotlin'

android {
compileSdkVersion 30
Expand All @@ -12,16 +13,16 @@ android {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.1"
versionName "1.2"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"true"]
"room.schemaLocation" : "$projectDir/schemas".toString(),
"room.incremental" : "true",
"room.expandProjection": "true"]
}
}
}
Expand All @@ -33,9 +34,6 @@ android {
}
}

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -51,40 +49,31 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//core dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation "androidx.multidex:multidex:2.0.1"

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
//lifecycle dependencies
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
//Hilt dependencies
implementation "com.google.dagger:hilt-android:2.35"
kapt "com.google.dagger:hilt-android-compiler:2.35"
implementation 'com.google.dagger:hilt-android:2.37'
kapt 'com.google.dagger:hilt-compiler:2.37'
//jetpack nav dependencies
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
//design dependencies
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//room
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
//glide
implementation 'io.coil-kt:coil:1.2.0'
//api
implementation 'io.coil-kt:coil:1.3.0'
//util
implementation 'com.jakewharton.timber:timber:4.7.1'
//testing dependencies
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

This file was deleted.

10 changes: 9 additions & 1 deletion app/src/main/java/com/cybershark/linkmanager/LinkManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package com.cybershark.linkmanager

import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber

@HiltAndroidApp
class LinkManager : Application()
class LinkManager : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}
9 changes: 3 additions & 6 deletions app/src/main/java/com/cybershark/linkmanager/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.cybershark.linkmanager.di

import android.content.Context
import androidx.room.Room
import com.cybershark.linkmanager.repository.IRepository
import com.cybershark.linkmanager.repository.Repository
import com.cybershark.linkmanager.repository.room.dao.LinkDao
import com.cybershark.linkmanager.repository.room.db.LinksDB
Expand All @@ -26,13 +27,9 @@ object AppModule {

@Singleton
@Provides
fun getRoomDao(linksDB: LinksDB): LinkDao {
return linksDB.getDAO()
}
fun getRoomDao(linksDB: LinksDB): LinkDao = linksDB.getDAO()

@Singleton
@Provides
fun getRepository(linkDao: LinkDao): Repository {
return Repository(linkDao)
}
fun getRepository(linkDao: LinkDao): IRepository = Repository(linkDao)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.cybershark.linkmanager.repository

import androidx.lifecycle.LiveData
import com.cybershark.linkmanager.repository.room.entities.LinkEntity

interface IRepository {
val allLinks: LiveData<List<LinkEntity>>

suspend fun insertLink(linkEntity: LinkEntity): Result<Unit>

suspend fun deleteAllLinks(): Result<Unit>

suspend fun updateLink(linkEntity: LinkEntity): Result<Unit>

suspend fun deleteLinkById(linkId: Int): Result<Unit>

suspend fun getAllLinksAsString(): Result<String>
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,68 @@
package com.cybershark.linkmanager.repository

import androidx.lifecycle.LiveData
import com.cybershark.linkmanager.repository.room.dao.LinkDao
import com.cybershark.linkmanager.repository.room.entities.LinkEntity
import com.cybershark.linkmanager.ui.links.viewmodels.LinksViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class Repository(private val linksDao: LinkDao) {
class Repository(private val linksDao: LinkDao) : IRepository {

val allLinks = linksDao.getAllLinks()
override val allLinks: LiveData<List<LinkEntity>> = linksDao.getAllLinks()

suspend fun insertLink(linkEntity: LinkEntity) = linksDao.insertLink(linkEntity)
override suspend fun insertLink(linkEntity: LinkEntity): Result<Unit> =
withContext(Dispatchers.IO) {
try {
linksDao.insertLink(linkEntity)
return@withContext Result.success(Unit)
} catch (e: Exception) {
return@withContext Result.failure(e)
}
}

suspend fun deleteAllLinks() = linksDao.deleteAllLinks()
override suspend fun deleteAllLinks(): Result<Unit> = withContext(Dispatchers.IO) {
try {
linksDao.deleteAllLinks()
return@withContext Result.success(Unit)
} catch (e: Exception) {
return@withContext Result.failure(e)
}
}

suspend fun updateLink(linkEntity: LinkEntity) = linksDao.updateLink(linkEntity)
override suspend fun updateLink(linkEntity: LinkEntity): Result<Unit> =
withContext(Dispatchers.IO) {
try {
linksDao.updateLink(linkEntity)
return@withContext Result.success(Unit)
} catch (e: Exception) {
return@withContext Result.failure(e)
}
}

suspend fun deleteLinkById(linkId: Int) = linksDao.deleteLinkById(linkId)
override suspend fun deleteLinkById(linkId: Int): Result<Unit> = withContext(Dispatchers.IO) {
try {
linksDao.deleteLinkById(linkId)
return@withContext Result.success(Unit)
} catch (e: Exception) {
return@withContext Result.failure(e)
}
}

override suspend fun getAllLinksAsString(): Result<String> = withContext(Dispatchers.Default) {
try {
if (allLinks.value.isNullOrEmpty()) {
return@withContext Result.failure(Exception("No links added!"))
}
val string = buildString {
append(LinksViewModel.START_MESSAGE)
allLinks.value?.forEach {
append("${it.linkName} - ${it.linkURL}\n")
}
}
return@withContext Result.success(string)
} catch (e: Exception) {
return@withContext Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import com.cybershark.linkmanager.repository.room.entities.LinkEntity

@Database(entities = [LinkEntity::class], exportSchema = true, version = 1)
abstract class LinksDB : RoomDatabase() {

abstract fun getDAO(): LinkDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.room.PrimaryKey
@Entity(tableName = "links")
data class LinkEntity(
@PrimaryKey(autoGenerate = true)
val pk : Int = 0 ,
@ColumnInfo(name = "linkName",defaultValue = "")
val linkName : String,
@ColumnInfo(name = "linkURL",defaultValue = "")
val linkURL : String
val pk: Int = 0,
@ColumnInfo(name = "linkName", defaultValue = "")
val linkName: String,
@ColumnInfo(name = "linkURL", defaultValue = "")
val linkURL: String
)
Loading

0 comments on commit bda296e

Please sign in to comment.