package com.dm.wallpaper.board.helpers;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Handler;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.danimahardhika.android.helpers.core.ColorHelper;
import com.dm.wallpaper.board.R;
import com.dm.wallpaper.board.preferences.Preferences;
import com.dm.wallpaper.board.utils.LogUtil;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

import butterknife.ButterKnife;

/*
 * Wallpaper Board
 *
 * Copyright (c) 2017 Dani Mahardhika
 *
 * 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.
 */

public class TapIntroHelper {

    public static void showWallpaperPreviewIntro(@NonNull Context context, @ColorInt int color) {
        if (Preferences.get(context).isTimeToShowWallpaperPreviewIntro()) {
            AppCompatActivity activity = (AppCompatActivity) context;

            RelativeLayout rootView = (RelativeLayout) activity.findViewById(R.id.bottom_panel);
            if (rootView == null) return;

            new Handler().postDelayed(() -> {
                try {
                    int baseColor = color;
                    if (baseColor == 0) {
                        baseColor = ColorHelper.getAttributeColor(context, R.attr.colorAccent);
                    }

                    int primary = ColorHelper.getTitleTextColor(baseColor);
                    int secondary = ColorHelper.setColorAlpha(primary, 0.7f);

                    TapTargetSequence tapTargetSequence = new TapTargetSequence(activity);
                    tapTargetSequence.continueOnCancel(true);

                    Typeface title = TypefaceHelper.getMedium(context);
                    Typeface description = TypefaceHelper.getRegular(context);

                    ImageView apply = ButterKnife.findById(rootView, R.id.menu_apply);
                    ImageView save = ButterKnife.findById(rootView, R.id.menu_save);
                    ImageView preview = ButterKnife.findById(rootView, R.id.menu_preview);

                    TapTarget tapTarget = TapTarget.forView(apply,
                            context.getResources().getString(R.string.tap_intro_wallpaper_preview_apply),
                            context.getResources().getString(R.string.tap_intro_wallpaper_preview_apply_desc))
                            .titleTextColorInt(primary)
                            .descriptionTextColorInt(secondary)
                            .targetCircleColorInt(primary)
                            .outerCircleColorInt(baseColor)
                            .drawShadow(true);

                    TapTarget tapTarget1 = TapTarget.forView(save,
                            context.getResources().getString(R.string.tap_intro_wallpaper_preview_save),
                            context.getResources().getString(R.string.tap_intro_wallpaper_preview_save_desc))
                            .titleTextColorInt(primary)
                            .descriptionTextColorInt(secondary)
                            .targetCircleColorInt(primary)
                            .outerCircleColorInt(baseColor)
                            .drawShadow(true);

                    TapTarget tapTarget2 = TapTarget.forView(preview,
                            context.getResources().getString(R.string.tap_intro_wallpaper_preview_full),
                            context.getResources().getString(R.string.tap_intro_wallpaper_preview_full_desc))
                            .titleTextColorInt(primary)
                            .descriptionTextColorInt(secondary)
                            .targetCircleColorInt(primary)
                            .outerCircleColorInt(baseColor)
                            .drawShadow(true);

                    if (title != null) {
                        tapTarget.titleTypeface(title);
                        tapTarget1.titleTypeface(title);
                        tapTarget2.titleTypeface(title);
                    }

                    if (description != null) {
                        tapTarget.descriptionTypeface(description);
                        tapTarget1.descriptionTypeface(description);
                        tapTarget2.descriptionTypeface(description);
                    }

                    tapTargetSequence.target(tapTarget);
                    if (context.getResources().getBoolean(R.bool.enable_wallpaper_download)) {
                        tapTargetSequence.target(tapTarget1);
                    }
                    tapTargetSequence.target(tapTarget2);

                    tapTargetSequence.listener(new TapTargetSequence.Listener() {
                        @Override
                        public void onSequenceFinish() {
                            Preferences.get(context).setTimeToShowWallpaperPreviewIntro(false);

                            SlidingUpPanelLayout panelLayout = ButterKnife.findById(activity, R.id.sliding_layout);
                            if (panelLayout != null) {
                                new Handler().postDelayed(() -> panelLayout.setPanelState(
                                        SlidingUpPanelLayout.PanelState.EXPANDED), 300);
                            }
                        }

                        @Override
                        public void onSequenceStep(TapTarget tapTarget, boolean b) {

                        }

                        @Override
                        public void onSequenceCanceled(TapTarget tapTarget) {

                        }
                    });
                    tapTargetSequence.start();
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                }
            }, 100);
        }
    }
}

@@ -2518,32 +2518,63 @@
                 
+//Todo:%0D%0A                    //
 Typeface descrip
@@ -4684,32 +4684,67 @@
                 
+//Todo:%0D%0A                        //
 tapTarget.titleT
@@ -4776,32 +4776,34 @@
                 
+//
 tapTarget1.title
@@ -4836,32 +4836,34 @@
                 
+//
 tapTarget2.title
@@ -4872,32 +4872,202 @@
 peface(title);%0D%0A
+                        tapTarget.textTypeface(title);%0D%0A                        tapTarget1.textTypeface(title);%0D%0A                        tapTarget2.textTypeface(title);%0D%0A
                 
@@ -5091,24 +5091,26 @@
             
+//
 if (descript
@@ -5141,32 +5141,67 @@
                 
+//Todo:%0D%0A                        //
 tapTarget.descri
@@ -5245,32 +5245,34 @@
                 
+//
 tapTarget1.descr
@@ -5317,32 +5317,34 @@
                 
+//
 tapTarget2.descr
@@ -5385,32 +5385,34 @@
                 
+//
 %7D%0D%0A%0D%0A           

Update TapIntroHelper.java