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