@@ -14,6 +14,7 @@ import androidx.appcompat.app.AlertDialog
1414import androidx.preference.Preference
1515import com.osfans.trime.R
1616import com.osfans.trime.databinding.FolderPickerDialogBinding
17+ import com.osfans.trime.util.getFileFromUri
1718import com.osfans.trime.util.getUriForFile
1819import java.io.File
1920
@@ -25,11 +26,12 @@ class FolderPickerPreference
2526 defStyleAttr: Int = androidx.preference.R .attr.preferenceStyle,
2627 ) : Preference (context, attrs, defStyleAttr) {
2728 private var value = " "
28- lateinit var documentTreeLauncher: ActivityResultLauncher <Uri ?>
29- lateinit var dialogView: FolderPickerDialogBinding
29+ private lateinit var dialogView: FolderPickerDialogBinding
3030
3131 var default = " "
3232
33+ var documentTreeLauncher: ActivityResultLauncher <Uri ?>? = null
34+
3335 init {
3436 context.theme.obtainStyledAttributes(attrs, R .styleable.FolderPickerPreferenceAttrs , 0 , 0 ).run {
3537 try {
@@ -68,7 +70,7 @@ class FolderPickerPreference
6870 dialogView = FolderPickerDialogBinding .inflate(LayoutInflater .from(context))
6971 dialogView.editText.setText(initValue)
7072 dialogView.button.setOnClickListener {
71- documentTreeLauncher.launch(context.getUriForFile(File (initValue)))
73+ documentTreeLauncher? .launch(context.getUriForFile(File (initValue)))
7274 }
7375 AlertDialog
7476 .Builder (context)
@@ -89,4 +91,8 @@ class FolderPickerPreference
8991 notifyChanged()
9092 }
9193 }
94+
95+ fun onResult (result : Uri ) {
96+ dialogView.editText.setText(context.getFileFromUri(result)?.absolutePath)
97+ }
9298 }
0 commit comments