mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 03:16:27 -04:00
note save and title: fixes
This commit is contained in:
parent
eec576c3d0
commit
b2f2735c8c
@ -28,9 +28,11 @@ import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
||||
import javax.inject.Inject
|
||||
|
||||
class NewNoteDao @Inject constructor(val box: Box<NotesEntity>) : PageDao {
|
||||
fun notes(): Flowable<List<Page>> = box.asFlowable(box.query {
|
||||
fun notes(): Flowable<List<Page>> = box.asFlowable(
|
||||
box.query {
|
||||
order(NotesEntity_.noteTitle)
|
||||
}).map { it.map(::NoteListItem) }
|
||||
}
|
||||
).map { it.map(::NoteListItem) }
|
||||
|
||||
override fun pages(): Flowable<List<Page>> = notes()
|
||||
|
||||
|
@ -118,9 +118,14 @@ class AddNoteDialog : DialogFragment() {
|
||||
zimFavicon = zimReaderContainer.favicon
|
||||
zimId = zimReaderContainer.id
|
||||
|
||||
if (arguments != null) {
|
||||
articleTitle = arguments?.getString(NOTES_TITLE)
|
||||
zimFileUrl = arguments?.getString(ARTICLE_URL)
|
||||
} else {
|
||||
val webView = (activity as WebViewProvider?)?.getCurrentWebView()
|
||||
articleTitle = webView?.title
|
||||
zimFileUrl = webView?.url
|
||||
}
|
||||
|
||||
// Corresponds to "ZimFileName" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt"
|
||||
articleNoteFileName = getArticleNoteFileName()
|
||||
@ -152,18 +157,18 @@ class AddNoteDialog : DialogFragment() {
|
||||
|
||||
private fun getArticleNoteFileName(): String {
|
||||
// Returns url of the form: "content://org.kiwix.kiwixmobile.zim.base/A/Main_Page.html"
|
||||
val articleUrl = if (arguments != null) {
|
||||
arguments?.getString(ARTICLE_URL)
|
||||
} else {
|
||||
(activity as WebViewProvider?)?.getCurrentWebView()?.url
|
||||
if (arguments != null && arguments?.getString(NOTE_FILE_PATH) != null) {
|
||||
return getTextAfterLastSlashWithoutExtension(arguments?.getString(NOTE_FILE_PATH)!!)
|
||||
}
|
||||
|
||||
val articleUrl = (activity as WebViewProvider?)?.getCurrentWebView()?.url
|
||||
var noteFileName = ""
|
||||
if (articleUrl == null) {
|
||||
onFailureToCreateAddNoteDialog()
|
||||
} else {
|
||||
noteFileName = getTextAfterLastSlashWithoutExtension(articleUrl)
|
||||
}
|
||||
return (if (noteFileName.isNotEmpty()) noteFileName else articleTitle) ?: ""
|
||||
return (noteFileName.ifEmpty { articleTitle }) ?: ""
|
||||
}
|
||||
|
||||
/* From ".../Kiwix/granbluefantasy_en_all_all_nopic_2018-10.zim", returns "granbluefantasy_en_all_all_nopic_2018-10"
|
||||
@ -312,7 +317,7 @@ class AddNoteDialog : DialogFragment() {
|
||||
noteEdited = false // As no unsaved changes remain
|
||||
enableDeleteNoteMenuItem()
|
||||
// adding only if saving file is success
|
||||
addNoteToDao(noteFile.canonicalPath, zimFileTitle.orEmpty())
|
||||
addNoteToDao(noteFile.canonicalPath, "${zimFileTitle.orEmpty()}: $articleTitle")
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
.also { context.toast(R.string.note_save_unsuccessful, Toast.LENGTH_LONG) }
|
||||
@ -328,12 +333,12 @@ class AddNoteDialog : DialogFragment() {
|
||||
|
||||
private fun addNoteToDao(noteFilePath: String?, title: String) {
|
||||
noteFilePath?.let { filePath ->
|
||||
if (filePath.isNotEmpty() && zimFileUrl.orEmpty().isNotEmpty()) {
|
||||
if (filePath.isNotEmpty() && zimFileUrl?.isNotEmpty() == true) {
|
||||
val zimReader = zimReaderContainer.zimFileReader
|
||||
if (zimReader != null) {
|
||||
val noteToSave = NoteListItem(
|
||||
title = title,
|
||||
url = zimFileUrl.orEmpty(),
|
||||
url = zimFileUrl!!,
|
||||
noteFilePath = noteFilePath,
|
||||
zimFileReader = zimReader
|
||||
)
|
||||
@ -367,19 +372,9 @@ class AddNoteDialog : DialogFragment() {
|
||||
* is displayed in the EditText field (note content area)
|
||||
*/
|
||||
private fun displayNote() {
|
||||
var noteFilePath: String? = ""
|
||||
noteFilePath = if (arguments != null) {
|
||||
arguments?.getString(NOTE_FILE_PATH)
|
||||
} else {
|
||||
"$zimNotesDirectory$articleNoteFileName.txt"
|
||||
}
|
||||
if (noteFilePath != null && noteFilePath.isNotEmpty()) {
|
||||
val noteFile = File(noteFilePath)
|
||||
val noteFile = File("$zimNotesDirectory$articleNoteFileName.txt")
|
||||
if (noteFile.exists()) {
|
||||
readNoteFromFile(noteFile)
|
||||
} else {
|
||||
onFailureToCreateAddNoteDialog()
|
||||
}
|
||||
}
|
||||
|
||||
// No action in case the note file for the currently open article doesn't exist
|
||||
@ -451,5 +446,6 @@ class AddNoteDialog : DialogFragment() {
|
||||
const val TAG = "AddNoteDialog"
|
||||
const val NOTE_FILE_PATH = "NoteFilePath"
|
||||
const val ARTICLE_URL = "ArticleUrl"
|
||||
const val NOTES_TITLE = "NotesTitle"
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ data class ShowDeleteNotesDialog(
|
||||
if (state.isInSelectionState) DeleteSelectedNotes else DeleteAllNotes,
|
||||
{
|
||||
effects.offer(DeletePageItems(state, pageDao))
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ data class ShowOpenNoteDialog(
|
||||
val item = page as NoteListItem
|
||||
val file = File(item.zimFilePath.orEmpty())
|
||||
zimReaderContainer.setZimFile(file)
|
||||
effects.offer(OpenNote(item.noteFilePath, item.zimUrl))
|
||||
effects.offer(OpenNote(item.noteFilePath, item.zimUrl, item.title))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.popNavigationBackstack
|
||||
import org.kiwix.kiwixmobile.core.main.AddNoteDialog
|
||||
import org.kiwix.kiwixmobile.core.main.AddNoteDialog.Companion.NOTE_FILE_PATH
|
||||
import org.kiwix.kiwixmobile.core.main.AddNoteDialog.Companion.ARTICLE_URL
|
||||
import org.kiwix.kiwixmobile.core.main.AddNoteDialog.Companion.NOTES_TITLE
|
||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
|
||||
class OpenNote(
|
||||
private val noteFilePath: String,
|
||||
private val zimFileUrl: String
|
||||
private val zimFileUrl: String,
|
||||
private val title: String,
|
||||
) : SideEffect<Unit> {
|
||||
override fun invokeWith(activity: AppCompatActivity) {
|
||||
activity as CoreMainActivity
|
||||
activity.popNavigationBackstack()
|
||||
showAddNoteDialog(activity)
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ class OpenNote(
|
||||
val bundle = Bundle()
|
||||
bundle.putString(NOTE_FILE_PATH, noteFilePath)
|
||||
bundle.putString(ARTICLE_URL, zimFileUrl)
|
||||
bundle.putString(NOTES_TITLE, title)
|
||||
dialogFragment.arguments = bundle
|
||||
dialogFragment.show(fragmentTransaction, AddNoteDialog.TAG)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:showIn="@layout/fragment_help">
|
||||
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
@ -40,7 +39,6 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/app_bar" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
tools:listitem="@layout/item_bookmark_history"
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
@ -48,6 +46,7 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/app_bar" />
|
||||
app:layout_constraintTop_toBottomOf="@id/app_bar"
|
||||
tools:listitem="@layout/item_bookmark_history" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user