grandcentrix-AndroidCodeStyle icon indicating copy to clipboard operation
grandcentrix-AndroidCodeStyle copied to clipboard

Add android-extension generated imports as star

Open StefMa opened this issue 7 years ago • 2 comments

If we use the kotlin android-extension we have something like that in our imports:

import kotlinx.android.synthetic.main.fragment_settings.app_info_text
import kotlinx.android.synthetic.main.fragment_settings.fingerprint_switch
import kotlinx.android.synthetic.main.fragment_settings.global_access_right
import kotlinx.android.synthetic.main.fragment_settings.global_access_right_switch
import kotlinx.android.synthetic.main.fragment_settings.icon_global_access_right_help
import kotlinx.android.synthetic.main.fragment_settings.login_data
import kotlinx.android.synthetic.main.fragment_settings.login_data_header
import kotlinx.android.synthetic.main.fragment_settings.password_edit
import kotlinx.android.synthetic.main.fragment_settings.security_settings_section
import kotlinx.android.synthetic.main.fragment_settings.set_up_settings_security
import kotlinx.android.synthetic.main.fragment_settings.set_up_super_pin
import kotlinx.android.synthetic.main.fragment_settings.settings_content
import kotlinx.android.synthetic.main.fragment_settings.settings_security_text_layout
import kotlinx.android.synthetic.main.fragment_settings.settings_super_pin_text_layout
import kotlinx.android.synthetic.main.fragment_settings.start_tutorial
import kotlinx.android.synthetic.main.fragment_settings.tracking_layout
import kotlinx.android.synthetic.main.fragment_settings.tracking_switch
import kotlinx.android.synthetic.main.fragment_settings.tutorial_layout
import kotlinx.android.synthetic.main.fragment_settings.username_edit

From my point of view that can be easly added as star imports. There is no need to use them as a single import...

StefMa avatar Apr 16 '18 13:04 StefMa

If you have

import kotlinx.android.synthetic.main.fragment_settings.*
import kotlinx.android.synthetic.main.fragment_login.*

How do you know where username_edit comes from?

Would the star import improve autocompletion?

passsy avatar Apr 17 '18 08:04 passsy

In which situation do you have such a import? With fragments_ and acitvities_ it should be the problem. Because it should only import one file. If it's import "more" with fragment_ or activtiy_ syntax you use a wrong id ;)

But you are right with layouts (or generics). Like generic_loader_black.xml and generic_placeholder.xml (for example). If we use that in a layout like fragment_login like:

<include layout="@layout/generic_loader_black"/>
<include layout="@layout/generic_placeholder"/>

then we would have such a import you describe:

import kotlinx.android.synthetic.main.generic_loader_black.*
import kotlinx.android.synthetic.main.generic_placerholder.*

Then we don't know where a import like spinner came from. From the placeholder or the loader... Am I right here? 🤔

On the other hand. I'm a friend of don't use the same ID anywhere in the app. So a simple click on it will redirect us to the file. And we see directly where we use it. Additionally: This "pattern" is way more common than taking a look to the imports :D

StefMa avatar Apr 17 '18 08:04 StefMa