@@ -211,6 +211,7 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded {
211211 getString(R .string.direct_editing_error),
212212 Snackbar .LENGTH_INDEFINITE ,
213213 )
214+
214215 if (note != null ) {
215216 snackbar.setAction(R .string.switch_to_plain_editing) {
216217 changeToEditMode()
@@ -220,38 +221,40 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded {
220221 close()
221222 }
222223 }
224+
223225 snackbar.show()
224226 }
225227
226228 override fun shouldShowToolbar (): Boolean = false
227229
228230 @SuppressLint(" SetJavaScriptEnabled" )
229231 private fun prepareWebView () {
230- val webSettings = binding.noteWebview.settings
231- // enable zoom
232- webSettings.setSupportZoom(true )
233- webSettings.builtInZoomControls = true
234- webSettings.displayZoomControls = false
235-
236- // Non-responsive webs are zoomed out when loaded
237- webSettings.useWideViewPort = true
238- webSettings.loadWithOverviewMode = true
239-
240- // user agent
241- val userAgent =
242- getString(R .string.user_agent, getString(R .string.app_name), BuildConfig .VERSION_NAME )
243- webSettings.userAgentString = userAgent
244-
245- // no private data storing
246- webSettings.savePassword = false
247- webSettings.saveFormData = false
248-
249- // disable local file access
250- webSettings.allowFileAccess = false
251-
252- // enable javascript
253- webSettings.javaScriptEnabled = true
254- webSettings.domStorageEnabled = true
232+ binding.noteWebview.settings.run {
233+ // enable zoom
234+ setSupportZoom(true )
235+ builtInZoomControls = true
236+ displayZoomControls = false
237+
238+ // Non-responsive webs are zoomed out when loaded
239+ useWideViewPort = true
240+ loadWithOverviewMode = true
241+
242+ // user agent
243+ val userAgent =
244+ getString(R .string.user_agent, getString(R .string.app_name), BuildConfig .VERSION_NAME )
245+ userAgentString = userAgent
246+
247+ // no private data storing
248+ savePassword = false
249+ saveFormData = false
250+
251+ // disable local file access
252+ allowFileAccess = false
253+
254+ // enable javascript
255+ javaScriptEnabled = true
256+ domStorageEnabled = true
257+ }
255258
256259 if (BuildConfig .DEBUG ) {
257260 // caching disabled in debug mode
@@ -343,6 +346,11 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded {
343346 }
344347
345348 private fun changeToEditMode () {
349+ if (note == null || note.remoteId == null ) {
350+ Log .d(TAG , " note is null, cant edit" )
351+ return
352+ }
353+
346354 toggleLoadingUI(true )
347355 val updateDisposable = Single .just(note.remoteId)
348356 .map { remoteId ->
@@ -399,21 +407,25 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded {
399407
400408 @JvmStatic
401409 fun newInstance (accountId : Long , noteId : Long ): BaseNoteFragment {
402- val fragment = NoteDirectEditFragment ()
403- val args = Bundle ()
404- args.putLong(PARAM_NOTE_ID , noteId)
405- args.putLong(PARAM_ACCOUNT_ID , accountId)
406- fragment.arguments = args
407- return fragment
410+ val bundle = Bundle ().apply {
411+ putLong(PARAM_NOTE_ID , noteId)
412+ putLong(PARAM_ACCOUNT_ID , accountId)
413+ }
414+
415+ return NoteDirectEditFragment ().apply {
416+ arguments = bundle
417+ }
408418 }
409419
410420 @JvmStatic
411421 fun newInstanceWithNewNote (newNote : Note ? ): BaseNoteFragment {
412- val fragment = NoteDirectEditFragment ()
413- val args = Bundle ()
414- args.putSerializable(PARAM_NEWNOTE , newNote)
415- fragment.arguments = args
416- return fragment
422+ val bundle = Bundle ().apply {
423+ putSerializable(PARAM_NEWNOTE , newNote)
424+ }
425+
426+ return NoteDirectEditFragment ().apply {
427+ arguments = bundle
428+ }
417429 }
418430 }
419431}
0 commit comments