package com.base.pdfviewerscannerwhite.utils

import android.content.Context
import android.content.Intent
import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.Build
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.ConstObject
import com.base.pdfviewerscannerwhite.ui.splash.SplashActivity


object ShortcutUtils {


    fun Context.addDeskShortCut() {

        //获取ShortcutManager对象
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            val shortcutManager: ShortcutManager = getSystemService(ShortcutManager::class.java) as ShortcutManager

            val shortcut1 = ShortcutInfo.Builder(this, "11111")
                .setShortLabel("Scan Pdf")
                .setIcon(Icon.createWithResource(this, R.mipmap.saomiao_shortcut))
                .setIntent(Intent(Intent.ACTION_MAIN, null, this, SplashActivity::class.java).apply {
                    putExtra("actionId", ConstObject.SHORTCUT_SCAN_PDF)
                })
                .build()

            val shortcut2 = ShortcutInfo.Builder(this, "22222")
                .setShortLabel("Split Pdf")
                .setIcon(Icon.createWithResource(this, R.mipmap.chaifen_shortcut))
                .setIntent(Intent(Intent.ACTION_MAIN, null, this, SplashActivity::class.java).apply {
                    putExtra("actionId", ConstObject.SHORTCUT_MERGE_PDF)
                })
                .build()

            val shortcut3 = ShortcutInfo.Builder(this, "33333")
                .setShortLabel("Merge Pdf")
                .setIcon(Icon.createWithResource(this, R.mipmap.hebing_shortcut))
                .setIntent(Intent(Intent.ACTION_MAIN, null, this, SplashActivity::class.java).apply {
                    putExtra("actionId", ConstObject.SHORTCUT_MERGE_PDF)
                })
                .build()

            //setDynamicShortcuts()方法来设置快捷方式
            shortcutManager.setDynamicShortcuts(listOf(shortcut1, shortcut2, shortcut3))

        }

    }
}