-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove txt pages from the database and only save the URI - text conte…
…nt can be extracted from URI by the reader. This fixes crashes where database would not be able to handle large text pages;
- Loading branch information
1 parent
e971cce
commit 8ab7c7e
Showing
7 changed files
with
78 additions
and
29 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
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
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
43 changes: 43 additions & 0 deletions
43
domain/src/main/java/org/kafka/domain/observers/ObserveTxtPages.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.kafka.domain.observers | ||
|
||
import androidx.core.net.toUri | ||
import com.kafka.data.dao.FileDao | ||
import com.kafka.data.dao.RecentTextDao | ||
import com.kafka.data.entities.RecentTextItem | ||
import com.kafka.data.entities.isTxt | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import org.kafka.base.domain.SubjectInteractor | ||
import org.kafka.domain.interactors.ReadTextFromUri | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Observe recent text file and extract pages using the local uri. | ||
* */ | ||
class ObserveTxtPages @Inject constructor( | ||
private val fileDao: FileDao, | ||
private val recentTextDao: RecentTextDao, | ||
private val readTextFromUri: ReadTextFromUri | ||
) : SubjectInteractor<ObserveTxtPages.Params, List<RecentTextItem.Page>>() { | ||
|
||
override fun createObservable(params: Params): Flow<List<RecentTextItem.Page>> { | ||
return combine( | ||
recentTextDao.observe(params.fileId), | ||
fileDao.observe(params.fileId) | ||
) { recentText, file -> | ||
if (file != null) { | ||
val pages = if (file.isTxt()) { | ||
readTextFromUri(recentText.localUri.toUri()).getOrElse { emptyList() } | ||
} else { | ||
emptyList() | ||
} | ||
|
||
pages.mapIndexed { index, s -> RecentTextItem.Page(index + 1, s) } | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
} | ||
|
||
data class Params(val fileId: String) | ||
} |
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