@@ -95,20 +95,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
9595 override fun onResume () {
9696 super .onResume()
9797 for (type in types) {
98- val connection = defaultSharedPreferences.getString(" hardware_${type} printer_connection" , " network_printer" )
99-
100- if (! TextUtils .isEmpty(defaultSharedPreferences.getString(" hardware_${type} printer_ip" , " " ))) {
101- val ip = defaultSharedPreferences.getString(" hardware_${type} printer_ip" , " " )
102- val name = defaultSharedPreferences.getString(" hardware_${type} printer_printername" , " " )
103-
104- findPreference<Preference >(" hardware_${type} printer_find" )?.summary = getString(
105- R .string.pref_printer_current, name, ip, getString(resources.getIdentifier(connection, " string" , requireActivity().packageName))
106- )
107- } else if (! TextUtils .isEmpty(defaultSharedPreferences.getString(" hardware_${type} printer_connection" , " " ))) {
108- findPreference<Preference >(" hardware_${type} printer_find" )?.summary = getString(R .string.pref_printer_current_short,
109- getString(resources.getIdentifier(connection, " string" , requireActivity().packageName)))
110- } else {
111- findPreference<Preference >(" hardware_${type} printer_find" )?.summary = " "
98+ val pref = findPreference<Preference >(" hardware_${type} printer_find" )
99+ if (pref != null ) {
100+ if (! TextUtils .isEmpty(defaultSharedPreferences.getString(" hardware_${type} printer_ip" , " " ))) {
101+ pref.summary = printerSummary(type)
102+ } else {
103+ pref.summary = " "
104+ }
112105 }
113106 }
114107
@@ -122,6 +115,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
122115 }
123116 }
124117
118+ private fun printerSummary (type : String ): String {
119+ val ip = defaultSharedPreferences.getString(" hardware_${type} printer_ip" , " " )
120+ val name = defaultSharedPreferences.getString(" hardware_${type} printer_printername" , " " )
121+ val connection = defaultSharedPreferences.getString(" hardware_${type} printer_connection" , " network_printer" )
122+ return getString(R .string.pref_printer_current, name, ip, getString(resources.getIdentifier(connection, " string" , requireActivity().packageName)))
123+ }
124+
125125 private fun asset_dialog (@StringRes title : Int ) {
126126 val webView = WebView (requireActivity())
127127 webView.loadUrl(" file:///android_asset/about.html" )
0 commit comments