/*
 *  Copyright (c) 2016 Touch Instinct
 *
 *  This file is part of RoboSwag library.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package ru.touchin.templates;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.view.View;

import ru.touchin.roboswag.components.navigation.activities.ViewControllerActivity;
import ru.touchin.roboswag.components.utils.Logic;
import ru.touchin.roboswag.components.utils.UiUtils;

/**
 * Created by Gavriil Sitnikov on 11/03/16.
 * TODO: description
 */
public abstract class TouchinActivity<TLogic extends Logic> extends ViewControllerActivity<TLogic> {

    protected TouchinActivity() {
        super();
    }

    @Override
    protected void onPostCreate(@Nullable final Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        makeActivityFullScreen();
    }

    private void makeActivityFullScreen() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (isActivityUnderNavigationBar() || isActivityUnderStatusBar())) {
            final View activityView = findViewById(getContainerId());
            int topPadding = activityView.getPaddingTop();
            int bottomPadding = activityView.getPaddingBottom();
            if (isActivityUnderStatusBar()) {
                topPadding += UiUtils.getStatusBarHeight(this);
            }
            if (UiUtils.hasSoftKeys(this)) {
                getWindow().getDecorView()
                        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
                if (isActivityUnderNavigationBar()) {
                    bottomPadding += UiUtils.getNavigationBarHeight(this);
                }
            } else {
                getWindow().getDecorView()
                        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            }
            activityView.setPadding(activityView.getPaddingLeft(),
                    topPadding,
                    activityView.getPaddingRight(),
                    bottomPadding);

        }
    }

    protected boolean isActivityUnderStatusBar() {
        return false;
    }

    protected boolean isActivityUnderNavigationBar() {
        return false;
    }

    @IdRes
    protected abstract int getContainerId();

}

@@ -701,127 +701,354 @@
 oid.
-os.Build;%0Aimport android.os.Bundle;%0Aimport android.support.annotation.IdRes;%0Aimport android.support.annotation.Nullable
+app.ActivityManager;%0Aimport android.graphics.drawable.BitmapDrawable;%0Aimport android.os.Build;%0Aimport android.os.Bundle;%0Aimport android.support.annotation.ColorRes;%0Aimport android.support.annotation.DrawableRes;%0Aimport android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0Aimport android.support.v4.content.ContextCompat
 ;%0Aim
@@ -1440,66 +1440,8 @@
  %7B%0A%0A
-    protected TouchinActivity() %7B%0A        super();%0A    %7D%0A%0A
     
@@ -1583,19 +1583,26 @@
         
-mak
+onConfigur
 eActivit
@@ -1594,36 +1594,32 @@
 onfigureActivity
-Full
 Screen();%0A    %7D%0A
@@ -1640,11 +1640,18 @@
 oid 
-mak
+onConfigur
 eAct
@@ -1659,12 +1659,8 @@
 vity
-Full
 Scre
@@ -1678,16 +1678,48 @@
     if (
+isActivitySizeConfigurable() && 
 Build.VE
@@ -1767,395 +1767,11 @@
 IPOP
- && (isActivityUnderNavigationBar() %7C%7C isActivityUnderStatusBar())) %7B%0A            final View activityView = findViewById(getContainerId());%0A            int topPadding = activityView.getPaddingTop();%0A            int bottomPadding = activityView.getPaddingBottom();%0A            if (isActivityUnderStatusBar()) %7B%0A                topPadding += UiUtils.getStatusBarHeight(this);%0A            %7D
+) %7B
 %0A   
@@ -2091,155 +2091,8 @@
 N);%0A
-                if (isActivityUnderNavigationBar()) %7B%0A                    bottomPadding += UiUtils.getNavigationBarHeight(this);%0A                %7D%0A
     
@@ -2304,183 +2304,494 @@
     
-activityView.setPadding(activityView.getPaddingLeft(),%0A                    topPadding,%0A                    activityView.getPaddingRight(),%0A                    bottomPadding);%0A
+configureActivitySize();%0A        %7D%0A    %7D%0A%0A    protected abstract void configureActivitySize();%0A%0A    protected void setupTaskDescriptor(@NonNull final String label, @DrawableRes int icon, @ColorRes int primaryColor) %7B%0A        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.LOLLIPOP) %7B%0A            final ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(label,%0A                    ((BitmapDrawable) ContextCompat.getDrawable(this, icon)).getBitmap(),
 %0A   
@@ -2799,89 +2799,123 @@
     
-%7D%0A
     
-%7D%0A%0A
     
-protected boolean isActivityUnderStatusBar() %7B%0A        return false;
+    ContextCompat.getColor(this, primaryColor));%0A            setTaskDescription(taskDescription);%0A        %7D
 %0A   
@@ -2923,24 +2923,21 @@
 %7D%0A%0A    p
-rotected
+ublic
  boolean
@@ -2951,26 +2951,24 @@
 vity
-UnderNavigationBar
+SizeConfigurable
 () %7B
@@ -3000,64 +3000,6 @@
   %7D%0A
-%0A    @IdRes%0A    protected abstract int getContainerId();%0A%0A
 %7D%0A

refactor the code