Sirop4ik
Sirop4ik

Reputation: 5273

How to wrap a line in kotlin?

For example I have such java method

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if (hasFocus) {
        // Standard Android full-screen functionality.
        // Use for hide status bar and navigation buttons
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        );

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
}

All conditions are visiable and easy to read, but there is a kotlin implementation

override fun onWindowFocusChanged(hasFocus: Boolean) {
             super.onWindowFocusChanged(hasFocus)
             if (hasFocus) {
                 // Standard Android full-screen functionality.
                 // Use for hide status bar and navigation buttons
                 window.decorView.systemUiVisibility =
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                 window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
             }
         }

You have just one long long line and it is completely not easy to read. If you try to wrap this line like in java you get an error...

So, is there a way how to make it more suitable?

Upvotes: 1

Views: 341

Answers (1)

Animesh Sahu
Animesh Sahu

Reputation: 8106

You could however write or call before the end of line:

window.decorView.systemUiVisibility =
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
    View.SYSTEM_UI_FLAG_FULLSCREEN or
    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

Another way of the workaround could be to use non-infix call:

window.decorView.systemUiVisibility =
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    .or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
    .or(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
    .or(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
    .or(View.SYSTEM_UI_FLAG_FULLSCREEN)
    .or(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)

Upvotes: 1

Related Questions