Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ dependencies {
implementation 'com.google.android.material:material:1.1.0-alpha04'

// Navigation
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-rc02'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-rc02'
implementation "android.arch.navigation:navigation-fragment-ktx:$naviagation_version"
implementation "android.arch.navigation:navigation-ui-ktx:$naviagation_version"

//Firebase Firestore Service
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'

// Timber
implementation 'com.github.ajalt:timberkt:1.5.1'

// Anko
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"

// Koin
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-android-viewmodel:$koin_version"
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".App"
android:theme="@style/AppTheme.SplashTheme">
<activity android:name=".ui.MainActivity">
<intent-filter>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/orionst/notist/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ package com.orionst.notist

import android.app.Application
import com.github.ajalt.timberkt.Timber
import com.orionst.notist.di.appModule
import com.orionst.notist.di.noteListModule
import com.orionst.notist.di.noteModule
import com.orionst.notist.di.splashModule
import org.koin.android.ext.android.startKoin

class App: Application() {
override fun onCreate() {
super.onCreate()
Timber.plant(timber.log.Timber.DebugTree())

startKoin(this, listOf(appModule, splashModule, noteListModule, noteModule))
}
}
29 changes: 29 additions & 0 deletions app/src/main/java/com/orionst/notist/common/NoteColorExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.orionst.notist.common

import android.content.Context
import androidx.core.content.ContextCompat
import com.orionst.notist.R
import com.orionst.notist.data.entity.Note

fun Note.Color.getColorInt(context: Context) =
ContextCompat.getColor(
context, when (this) {
Note.Color.WHITE -> R.color.white
Note.Color.YELLOW -> R.color.yellow
Note.Color.GREEN -> R.color.green
Note.Color.BLUE -> R.color.blue
Note.Color.RED -> R.color.red
Note.Color.VIOLET -> R.color.violet
Note.Color.PINK -> R.color.pink
}
)

fun Note.Color.getColorRes(): Int = when (this) {
Note.Color.WHITE -> R.color.white
Note.Color.VIOLET -> R.color.violet
Note.Color.YELLOW -> R.color.yellow
Note.Color.RED -> R.color.red
Note.Color.PINK -> R.color.pink
Note.Color.GREEN -> R.color.green
Note.Color.BLUE -> R.color.blue
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/orionst/notist/data/NotesRepository.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.orionst.notist.data

import com.orionst.notist.data.entity.Note
import com.orionst.notist.data.provider.FirestoreProvider
import com.orionst.notist.data.provider.RemoteDataProvider

object NotesRepository {
private val remoteDataProvider: RemoteDataProvider = FirestoreProvider()
class NotesRepository(val remoteDataProvider: RemoteDataProvider) {

fun getCurrentUser() = remoteDataProvider.getCurrentUser()

fun getNotes() = remoteDataProvider.subscribeToAllNotes()

fun saveNote(note: Note) = remoteDataProvider.saveNote(note)

fun deleteNote(id: String) = remoteDataProvider.deleteNoteById(id)

fun getNoteById(id: String) = remoteDataProvider.getNoteById(id)
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/orionst/notist/data/entity/Note.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Note(
val id: String = "",
val title: String = "",
val text: String ="",
val color: Color = Color.WHITE,
val lastChanged: Date = Date()
) : Parcelable {

Expand All @@ -23,4 +24,14 @@ class Note(
}

override fun hashCode() = id.hashCode()

enum class Color {
WHITE,
YELLOW,
GREEN,
BLUE,
RED,
VIOLET,
PINK
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@ import com.orionst.notist.data.entity.User
import com.orionst.notist.data.errors.NoAuthException
import com.orionst.notist.model.NoteResult

class FirestoreProvider : RemoteDataProvider {
class FirestoreProvider(private val firebaseAuth: FirebaseAuth, private val store: FirebaseFirestore) : RemoteDataProvider {

private val store by lazy {
FirebaseFirestore.getInstance()
}

private val notesReference by lazy {
store.collection(NOTES_COLLECTION)
}

private val currentUser get() = FirebaseAuth.getInstance().currentUser
private val currentUser get() = firebaseAuth.currentUser

private fun getUserNotesCollection() = currentUser?.let {
store.collection(USERS_COLLECTION).document(it.uid).collection(NOTES_COLLECTION)
Expand Down Expand Up @@ -78,6 +70,16 @@ class FirestoreProvider : RemoteDataProvider {
}
}

override fun deleteNoteById(id: String) = MutableLiveData<NoteResult>().apply {
getUserNotesCollection().document(id).delete()
.addOnSuccessListener {
value = NoteResult.Success(null)
}
.addOnFailureListener {
value = NoteResult.Error(it)
}
}

// Get notes without auth from storage
//
// override fun subscribeToAllNotes() = MutableLiveData<NoteResult>().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ interface RemoteDataProvider {
fun subscribeToAllNotes(): LiveData<NoteResult>
fun getNoteById(id: String): LiveData<NoteResult>
fun saveNote(note: Note): LiveData<NoteResult>
fun deleteNoteById(id: String): LiveData<NoteResult>
fun getCurrentUser(): LiveData<User?>
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/orionst/notist/di/KoinModules.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.orionst.notist.di

import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
import com.orionst.notist.data.NotesRepository
import com.orionst.notist.data.provider.FirestoreProvider
import com.orionst.notist.data.provider.RemoteDataProvider
import com.orionst.notist.ui.screens.note.NoteViewModel
import com.orionst.notist.ui.screens.note_list.NoteListViewModel
import com.orionst.notist.ui.screens.splash.SplashViewModel
import org.koin.android.viewmodel.ext.koin.viewModel
import org.koin.dsl.module.module

val appModule = module {
single { FirebaseAuth.getInstance() }
single { FirebaseFirestore.getInstance() }
single<RemoteDataProvider> { FirestoreProvider(get(), get()) }
single { NotesRepository(get()) }
}

val splashModule = module {
viewModel { SplashViewModel(get()) }
}

val noteListModule = module {
viewModel { NoteListViewModel(get()) }
}

val noteModule = module {
viewModel { NoteViewModel(get()) }
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/orionst/notist/ui/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import com.orionst.notist.data.errors.NoAuthException

abstract class BaseFragment<T, S : BaseViewState<T>> : Fragment() {

abstract val viewModel: BaseViewModel<T, S>
abstract val model: BaseViewModel<T, S>

companion object {
private const val RC_SIGN_IN = 42001
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewModel.getViewState().observe(this, Observer<S> { viewState ->
model.getViewState().observe(this, Observer<S> { viewState ->
viewState?.apply {
data?.let { renderData(it) }
error?.let { renderError(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.orionst.notist.ui.custom_view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.Dimension
import androidx.annotation.Dimension.DP
import androidx.annotation.Dimension.PX
import androidx.core.content.ContextCompat
import com.orionst.notist.R
import org.jetbrains.anko.dip

class ColorCircleView @JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) {

companion object {
@Dimension(unit = DP) private const val defRadiusDp = 16
@Dimension(unit = DP) private const val defStrokeWidthDp = 1
}

private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
}

private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
}

private var center: Pair<Float, Float> = 0f to 0f

@Dimension(unit = PX) var radius: Float = dip(defRadiusDp).toFloat()

@ColorRes var fillColorRes: Int = R.color.white
set(value) {
field = value
fillPaint.color = ContextCompat.getColor(context, value)
}

@ColorRes
var strokeColorRes: Int = R.color.text_secondary
set(value) {
field = value
strokePaint.color = ContextCompat.getColor(context, value)
}

@Dimension(unit = PX) var strokeWidth: Float = dip(defStrokeWidthDp).toFloat()
set(value) {
field = value
strokePaint.strokeWidth = value
}

init {
val a = context.obtainStyledAttributes(attrs, R.styleable.ColorCircleView)

val defRadiusPx = dip(defRadiusDp).toFloat()
radius = a.getDimension(R.styleable.ColorCircleView_circleRadius, defRadiusPx)
fillColorRes = a.getResourceId(R.styleable.ColorCircleView_fillColor, R.color.white)

val defStrokeWidthPx = dip(defStrokeWidthDp).toFloat()
strokeWidth = a.getDimension(R.styleable.ColorCircleView_strokeWidth, defStrokeWidthPx)

strokeColorRes = a.getResourceId(R.styleable.ColorCircleView_strokeColor, R.color.text_secondary)
a.recycle()
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val height = (radius * 2 + paddingTop + paddingBottom).toInt()
val width = (radius * 2 + paddingStart + paddingEnd).toInt()

setMeasuredDimension(width, height)
}

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
center = measuredWidth/2f to measuredHeight/2f
super.onLayout(changed, left, top, right, bottom)
}

override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)

canvas.drawCircle(center.first, center.second, radius, strokePaint)
canvas.drawCircle(center.first, center.second, radius - strokeWidth, fillPaint)
}


}
Loading