mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
code cleanup
This commit is contained in:
parent
1932e87e02
commit
2548091e09
@ -78,9 +78,8 @@ complexity:
|
|||||||
active: true
|
active: true
|
||||||
threshold: 60
|
threshold: 60
|
||||||
LongParameterList:
|
LongParameterList:
|
||||||
active: false
|
active: true
|
||||||
functionThreshold: 9
|
threshold: 6
|
||||||
constructorThreshold: 9
|
|
||||||
ignoreDefaultParameters: false
|
ignoreDefaultParameters: false
|
||||||
MethodOverloading:
|
MethodOverloading:
|
||||||
active: false
|
active: false
|
||||||
|
@ -67,11 +67,10 @@ const val DISABLE_ICON_ITEM_ALPHA = 130
|
|||||||
const val ENABLE_ICON_ITEM_ALPHA = 255
|
const val ENABLE_ICON_ITEM_ALPHA = 255
|
||||||
|
|
||||||
class AddNoteDialog : DialogFragment() {
|
class AddNoteDialog : DialogFragment() {
|
||||||
private var zimId: String? = null
|
private lateinit var zimId: String
|
||||||
private var zimFileName: String? = null
|
private var zimFileName: String? = null
|
||||||
private var zimFileTitle: String? = null
|
private var zimFileTitle: String? = null
|
||||||
private var zimFileUrl: String? = null
|
private lateinit var zimFileUrl: String
|
||||||
private var zimFavicon: String? = null
|
|
||||||
private var articleTitle: String? = null
|
private var articleTitle: String? = null
|
||||||
|
|
||||||
// Corresponds to "ArticleUrl" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt"
|
// Corresponds to "ArticleUrl" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt"
|
||||||
@ -115,16 +114,15 @@ class AddNoteDialog : DialogFragment() {
|
|||||||
zimFileName = zimReaderContainer.zimCanonicalPath
|
zimFileName = zimReaderContainer.zimCanonicalPath
|
||||||
if (zimFileName != null) { // No zim file currently opened
|
if (zimFileName != null) { // No zim file currently opened
|
||||||
zimFileTitle = zimReaderContainer.zimFileTitle
|
zimFileTitle = zimReaderContainer.zimFileTitle
|
||||||
zimFavicon = zimReaderContainer.favicon
|
zimId = zimReaderContainer.id.orEmpty()
|
||||||
zimId = zimReaderContainer.id
|
|
||||||
|
|
||||||
if (arguments != null) {
|
if (arguments != null) {
|
||||||
articleTitle = arguments?.getString(NOTES_TITLE)
|
articleTitle = arguments?.getString(NOTES_TITLE)
|
||||||
zimFileUrl = arguments?.getString(ARTICLE_URL)
|
zimFileUrl = arguments?.getString(ARTICLE_URL).orEmpty()
|
||||||
} else {
|
} else {
|
||||||
val webView = (activity as WebViewProvider?)?.getCurrentWebView()
|
val webView = (activity as WebViewProvider?)?.getCurrentWebView()
|
||||||
articleTitle = webView?.title
|
articleTitle = webView?.title
|
||||||
zimFileUrl = webView?.url
|
zimFileUrl = webView?.url.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Corresponds to "ZimFileName" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt"
|
// Corresponds to "ZimFileName" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt"
|
||||||
@ -157,8 +155,8 @@ 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"
|
||||||
if (arguments != null && arguments?.getString(NOTE_FILE_PATH) != null) {
|
arguments?.getString(NOTE_FILE_PATH)?.let {
|
||||||
return getTextAfterLastSlashWithoutExtension(arguments?.getString(NOTE_FILE_PATH)!!)
|
return@getArticleNoteFileName getTextAfterLastSlashWithoutExtension(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val articleUrl = (activity as WebViewProvider?)?.getCurrentWebView()?.url
|
val articleUrl = (activity as WebViewProvider?)?.getCurrentWebView()?.url
|
||||||
@ -333,12 +331,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?.isNotEmpty() == true) {
|
if (filePath.isNotEmpty() && zimFileUrl.isNotEmpty()) {
|
||||||
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!!,
|
url = zimFileUrl,
|
||||||
noteFilePath = noteFilePath,
|
noteFilePath = noteFilePath,
|
||||||
zimFileReader = zimReader
|
zimFileReader = zimReader
|
||||||
)
|
)
|
||||||
|
@ -24,9 +24,9 @@ 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.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.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.AddNoteDialog.Companion.NOTES_TITLE
|
||||||
|
import org.kiwix.kiwixmobile.core.main.AddNoteDialog.Companion.NOTE_FILE_PATH
|
||||||
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||||
|
|
||||||
class OpenNote(
|
class OpenNote(
|
||||||
@ -40,18 +40,19 @@ class OpenNote(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showAddNoteDialog(activity: AppCompatActivity) {
|
private fun showAddNoteDialog(activity: AppCompatActivity) {
|
||||||
val act: CoreMainActivity = activity as CoreMainActivity
|
val coreMainActivity: CoreMainActivity = activity as CoreMainActivity
|
||||||
val fragmentTransaction: FragmentTransaction =
|
val fragmentTransaction: FragmentTransaction =
|
||||||
act.supportFragmentManager.beginTransaction()
|
coreMainActivity.supportFragmentManager.beginTransaction()
|
||||||
val previousInstance: Fragment? =
|
val previousInstance: Fragment? =
|
||||||
act.supportFragmentManager.findFragmentByTag(AddNoteDialog.TAG)
|
coreMainActivity.supportFragmentManager.findFragmentByTag(AddNoteDialog.TAG)
|
||||||
|
|
||||||
if (previousInstance == null) {
|
if (previousInstance == null) {
|
||||||
val dialogFragment = AddNoteDialog()
|
val dialogFragment = AddNoteDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle().apply {
|
||||||
bundle.putString(NOTE_FILE_PATH, noteFilePath)
|
putString(NOTE_FILE_PATH, noteFilePath)
|
||||||
bundle.putString(ARTICLE_URL, zimFileUrl)
|
putString(ARTICLE_URL, zimFileUrl)
|
||||||
bundle.putString(NOTES_TITLE, title)
|
putString(NOTES_TITLE, title)
|
||||||
|
}
|
||||||
dialogFragment.arguments = bundle
|
dialogFragment.arguments = bundle
|
||||||
dialogFragment.show(fragmentTransaction, AddNoteDialog.TAG)
|
dialogFragment.show(fragmentTransaction, AddNoteDialog.TAG)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user