package com.base.pdfreaderallpdfreader.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.pdfreaderallpdfreader.R
import com.base.pdfreaderallpdfreader.bean.ConstObject
import com.base.pdfreaderallpdfreader.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.pdf_scan_short))
                .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.pdf_split_short))
                .setIntent(Intent(Intent.ACTION_MAIN, null, this, SplashActivity::class.java).apply {
                    putExtra("actionId", ConstObject.SHORTCUT_SPLIT_PDF)
                })
                .build()

            val shortcut3 = ShortcutInfo.Builder(this, "33333")
                .setShortLabel("Merge Pdf")
                .setIcon(Icon.createWithResource(this, R.mipmap.pdf_merge_short))
                .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))

        }

    }
}