Skip to content

Commit

Permalink
Replace constructor with static factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
OmGodse committed Jul 21, 2020
1 parent fd7ce50 commit 2d1984c
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/src/main/java/com/omgodse/notally/viewmodels/BaseNoteModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ class BaseNoteModel(app: Application) : AndroidViewModel(app) {
private val archivedObserver: NotallyFileObserver

init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
observer = NotallyFileObserver(notesHelper.getNotePath())
deletedObserver = NotallyFileObserver(notesHelper.getDeletedPath())
archivedObserver = NotallyFileObserver(notesHelper.getArchivedPath())
}
else {
observer = NotallyFileObserver(notesHelper.getNotePath().path)
deletedObserver = NotallyFileObserver(notesHelper.getDeletedPath().path)
archivedObserver = NotallyFileObserver(notesHelper.getArchivedPath().path)
}
observer = NotallyFileObserver.getInstance(notesHelper.getNotePath())
deletedObserver = NotallyFileObserver.getInstance(notesHelper.getDeletedPath())
archivedObserver = NotallyFileObserver.getInstance(notesHelper.getArchivedPath())

observer.onEventCallback = { event, path ->
onEvent(event, path, notes, notesHelper.getNotePath())
Expand Down Expand Up @@ -272,9 +265,9 @@ class BaseNoteModel(app: Application) : AndroidViewModel(app) {
var onEventCallback: ((event: Int, path: String) -> Unit)? = null

@RequiresApi(Build.VERSION_CODES.Q)
constructor(file: File) : super(file, mask)
private constructor(file: File) : super(file, mask)

constructor(filePath: String) : super(filePath, mask)
private constructor(filePath: String) : super(filePath, mask)

override fun onEvent(event: Int, path: String?) {
/*
Expand All @@ -291,6 +284,12 @@ class BaseNoteModel(app: Application) : AndroidViewModel(app) {

companion object {
const val mask = DELETE or CREATE or MODIFY

fun getInstance(file: File) : NotallyFileObserver {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
NotallyFileObserver(file)
} else NotallyFileObserver(file.path)
}
}
}
}

0 comments on commit 2d1984c

Please sign in to comment.