-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement checklist update functionality
- Loading branch information
1 parent
f5d72e8
commit 759643f
Showing
7 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
docpuree/src/main/java/jp/co/tokubai/docpuree/source/CheckListSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
package jp.co.tokubai.docpuree.source | ||
|
||
object CheckListSource { | ||
val checkList = mutableListOf<Class<*>>() | ||
val checkList = mutableListOf<CheckListItem>() | ||
} | ||
|
||
data class CheckListItem( | ||
val clazz: Class<*>, | ||
var isLogged: Boolean, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
docpuree/src/main/java/jp/co/tokubai/docpuree/ui/checklist/CheckListViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
package jp.co.tokubai.docpuree.ui.checklist | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import jp.co.tokubai.docpuree.source.CheckListSource | ||
import jp.co.tokubai.docpuree.source.LogHistorySource | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
class CheckListViewModel : ViewModel() { | ||
init { | ||
observeLoggedClass() | ||
} | ||
|
||
val checkList = CheckListSource.checkList | ||
val latestLog = LogHistorySource.successfullyLoggedJson | ||
|
||
private fun observeLoggedClass() { | ||
LogHistorySource.successfullyLoggedJson.onEach { successfullyLoggedJson -> | ||
val nextCheckListItem = CheckListSource.checkList.firstOrNull { !it.isLogged } | ||
nextCheckListItem?.let { checkItem -> | ||
val isCheckItemIsLogged = | ||
checkItem.clazz.simpleName == LogHistorySource.getClassFromLoggedJson( | ||
successfullyLoggedJson | ||
) | ||
if (isCheckItemIsLogged) { | ||
nextCheckListItem.isLogged = true | ||
Log.d("CheckList", CheckListSource.checkList.toString()) | ||
} | ||
} | ||
}.launchIn(GlobalScope) | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
docpuree/src/main/java/jp/co/tokubai/docpuree/ui/searchlog/SearchLogViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package jp.co.tokubai.docpuree.ui.searchlog | ||
|
||
import androidx.lifecycle.ViewModel | ||
import jp.co.tokubai.docpuree.source.CheckListItem | ||
import jp.co.tokubai.docpuree.source.CheckListSource | ||
|
||
class SearchLogViewModel : ViewModel() { | ||
|
||
fun addLogToCheckList(clazz: Class<*>) { | ||
CheckListSource.checkList.add(clazz) | ||
CheckListSource.checkList.add(CheckListItem(clazz, false)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters