Skip to content

Commit

Permalink
Added some animation. Corrected ui.Simple Firebase with Room Sync works.
Browse files Browse the repository at this point in the history
  • Loading branch information
kKrzysciak96 committed Nov 7, 2023
1 parent afe4b4f commit 1ba06d4
Show file tree
Hide file tree
Showing 54 changed files with 1,092 additions and 220 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application

<application
android:name=".app.HiltApp"
tools:replace="android:name"
android:allowBackup="true"
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/eltescode/warhbook/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MainActivity : ComponentActivity() {
content = {
NavHost(
navController = navController,
startDestination = Routes.SPLASH_SCREEN
startDestination = Routes.SIGN_IN
)
{

Expand Down Expand Up @@ -133,8 +133,8 @@ class MainActivity : ComponentActivity() {
"?noteId={noteId}&noteColor={noteColor}",
arguments = listOf(
navArgument(name = "noteId") {
type = NavType.IntType
defaultValue = -1
type = NavType.StringType
defaultValue = "-1"
},
navArgument(name = "noteColor") {
type = NavType.IntType
Expand All @@ -146,7 +146,8 @@ class MainActivity : ComponentActivity() {
snackBarHostState = snackBarHostState,
noteColor = color
) {
navController.navigateUp()
navController.popBackStack(Routes.NOTES, true)
navController.navigate(Routes.NOTES)
}
}
composable(route = Routes.YOUR_SHEETS) {
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/java/DataStore.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object DataStore {
private const val dataStoreVersion = "1.0.0"
const val dataStore = "androidx.datastore:datastore-preferences:$dataStoreVersion"
}
2 changes: 2 additions & 0 deletions core_data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ dependencies {
implementation(Firebase.firebaseAuth)
implementation(Firebase.firebaseFirestore)
implementation(Firebase.firebaseStorage)

implementation(Retrofit.retrofit)
}
4 changes: 3 additions & 1 deletion core_data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.eltescode.core_data.utils.exception

suspend fun <T> callOrThrow(
errorWrapper: ErrorWrapper,
apiCall: suspend () -> T
): T {
return runCatching { apiCall() }.getOrElse { throw errorWrapper.wrap(it) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.eltescode.core_data.utils.exception

interface ErrorWrapper {
fun wrap(throwable: Throwable): Throwable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.eltescode.core_data.utils.exception

import retrofit2.HttpException


class ErrorWrapperImpl : ErrorWrapper {
override fun wrap(throwable: Throwable): Throwable {
return when (throwable) {
is HttpException -> {
wrapServerException(throwable)
}

else -> throwable
}
}

private fun wrapServerException(httpException: HttpException): Throwable {
return with(httpException) {
when (httpException.code()) {
500 -> ServerException.Internal(message)
400 -> ServerException.BadRequest(message)
401 -> ServerException.Unauthorized(message)
402 -> ServerException.PaymentRequired(message)
403 -> ServerException.Forbidden(message)
404 -> ServerException.NotFound(message)
else -> ServerException.Unknown(message)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.eltescode.core_data.utils.exception

sealed class ServerException(message: String?) : Throwable(message) {
class Internal(message: String?) : ServerException(message)
class NotFound(message: String?) : ServerException(message)
class BadRequest(message: String?) : ServerException(message)
class Unauthorized(message: String?) : ServerException(message)
class PaymentRequired(message: String?) : ServerException(message)
class Forbidden(message: String?) : ServerException(message)
class Unknown(message: String?) : ServerException(message)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.eltescode.core_data.utils.network

interface NetworkStateProvider {
fun isNetworkAvailable(): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.eltescode.core_data.utils.network

import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import androidx.annotation.RequiresApi

class NetworkStateProviderImpl(private val connectivityManager: ConnectivityManager) :
NetworkStateProvider {
@RequiresApi(Build.VERSION_CODES.M)
override fun isNetworkAvailable(): Boolean {
val capabilities =
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
?: return false

return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)
|| capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|| capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.ui.graphics.ShaderBrush
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.res.imageResource
import com.eltescode.core_ui.R
import com.eltescode.core_ui.ui.SilverColors.Companion.color979c9f

@Composable
fun backgroundShaderBrush(): ShaderBrush {
Expand All @@ -25,7 +26,7 @@ fun backgroundShaderBrush(): ShaderBrush {
@Composable
fun silverBackgroundBrush(): Brush {
return Brush.linearGradient(
colors = listOf(Color.White, Color(0XFF979c9f)),
colors = listOf(Color.White, color979c9f),
start = Offset.Zero,
end = Offset.Infinite
)
Expand Down
20 changes: 20 additions & 0 deletions core_ui/src/main/java/com/eltescode/core_ui/ui/Colors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,25 @@ class SilverColors {
val color84898b = Color(0XFF84898b)
val color979c9f = Color(0XFF979c9f)
val colorAab0b3 = Color(0XFFaab0b3)
val colorffffff = Color(0XFFffffff)
}
}

class GreenColors {
companion object {

val colorCfea75 = Color(0XFFcfea75)
val color008c15 = Color(0XFF008c15)

}
}

class BlueColors {
companion object {

val color91b1fd = Color(0XFF91b1fd)
val color4e6db1 = Color(0XFF4e6db1)


}
}
2 changes: 2 additions & 0 deletions notes/notes_data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ dependencies {
implementation(Firebase.firebaseAuth)
implementation(Firebase.firebaseFirestore)
implementation(Firebase.firebaseStorage)

implementation(DataStore.dataStore)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package com.eltescode.notes_data.di

import android.app.Application
import android.content.Context
import android.net.ConnectivityManager
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.room.Room
import com.eltescode.core_data.utils.exception.ErrorWrapper
import com.eltescode.core_data.utils.exception.ErrorWrapperImpl
import com.eltescode.core_data.utils.network.NetworkStateProvider
import com.eltescode.core_data.utils.network.NetworkStateProviderImpl
import com.eltescode.notes_data.local.NoteDatabase
import com.eltescode.notes_data.repository.NoteRepositoryImpl
import com.eltescode.notes_data.repository.SyncHelper
import com.eltescode.notes_data.repository.SyncHelperImpl
import com.eltescode.notes_data.utils.CustomPreferences
import com.eltescode.notes_data.utils.CustomPreferencesImpl
import com.eltescode.notes_domain.repository.NoteRepository
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Singleton

@Module
Expand All @@ -27,8 +46,69 @@ object NotesDataModule {

@Provides
@Singleton
fun providesNoteRepository(db: NoteDatabase): NoteRepository {
return NoteRepositoryImpl(db.provideDao())
fun providesConnectivityManager(@ApplicationContext context: Context): ConnectivityManager {
return context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
}

@Provides
@Singleton
fun providesSyncHelper(): SyncHelper {
return SyncHelperImpl
}

@Provides
@Singleton
fun providesNetworkStateProvider(connectivityManager: ConnectivityManager): NetworkStateProvider {
return NetworkStateProviderImpl(connectivityManager)
}


@Provides
@Singleton
fun providesErrorWrapper(): ErrorWrapper {
return ErrorWrapperImpl()
}

@Provides
@Singleton
fun providesErrorCoroutineScope(): CoroutineScope {
return CoroutineScope(SupervisorJob())
}

@Provides
@Singleton
fun providesDataStore(@ApplicationContext context: Context): DataStore<Preferences> {
return PreferenceDataStoreFactory.create { context.preferencesDataStoreFile("data_store_pref") }
}

@Provides
@Singleton
fun providesCustomPreferences(dataStore: DataStore<Preferences>): CustomPreferences {
return CustomPreferencesImpl(dataStore)
}

@Provides
@Singleton
fun providesNoteRepository(
db: NoteDatabase,
auth: FirebaseAuth,
fireStore: FirebaseFirestore,
errorWrapper: ErrorWrapper,
networkStateProvider: NetworkStateProvider,
preferences: CustomPreferences,
syncHelper: SyncHelper,
coroutineScope: CoroutineScope
): NoteRepository {
return NoteRepositoryImpl(
db.provideDao(),
errorWrapper,
auth,
fireStore,
networkStateProvider,
syncHelper,
preferences,
coroutineScope,
)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package com.eltescode.notes_data.local

import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.UUID

@Entity(tableName = "note_table")
data class NoteCached(
@PrimaryKey
val id: Int? = null,
val noteId: UUID,
val title: String,
val content: String,
val timestamp: Long,
val color: Int,
val attachment: String = ""
val attachment: String = "",
val userId: UUID? = null,
) {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ package com.eltescode.notes_data.local

import androidx.room.*
import kotlinx.coroutines.flow.Flow
import java.util.UUID

@Dao
interface NoteDao {

@Query("SELECT * FROM note_table")
fun getAllNotes(): Flow<List<NoteCached>>
fun getAllNotesFlow(): Flow<List<NoteCached>>

@Query("SELECT * FROM note_table WHERE id = :id")
suspend fun getNoteById(id: Int): NoteCached?
@Query("SELECT * FROM note_table")
suspend fun getAllNotes(): List<NoteCached>

@Query("SELECT * FROM note_table WHERE noteId = :id")
suspend fun getNoteById(id: UUID): NoteCached?

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertNote(noteDomain: NoteCached)
suspend fun insertNote(vararg noteDomain: NoteCached)

@Delete
suspend fun deleteNote(noteDomain: NoteCached)

@Query("DELETE FROM note_table")
suspend fun dropDataBase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.eltescode.notes_data.mappers

import com.eltescode.notes_data.local.NoteCached
import com.eltescode.notes_domain.model.Note
import java.util.UUID

fun Note.mapToNoteCached() = NoteCached(
id = id,
noteId = UUID.fromString(noteId),
title = title,
content = content,
timestamp = timestamp,
Expand All @@ -13,7 +14,7 @@ fun Note.mapToNoteCached() = NoteCached(
)

fun NoteCached.mapToNote() = Note(
id = id,
noteId = noteId.toString(),
title = title,
content = content,
timestamp = timestamp,
Expand Down
Loading

0 comments on commit 1ba06d4

Please sign in to comment.