package com.shaarit.service import android.content.Intent import android.os.Build import android.service.quicksettings.Tile import android.service.quicksettings.TileService import androidx.annotation.RequiresApi /** * Quick Settings Tile for quickly adding a new link * * Swipe down from the top of the screen twice to access Quick Settings, * then tap the ShaarIt tile to quickly add a bookmark. */ @RequiresApi(Build.VERSION_CODES.N) class AddLinkTileService : TileService() { override fun onClick() { super.onClick() // Launch MainActivity with the add link deep link val intent = Intent(Intent.ACTION_VIEW).apply { data = android.net.Uri.parse("shaarit://add") flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP `package` = packageName } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { val pendingIntent = android.app.PendingIntent.getActivity( this, 0, intent, android.app.PendingIntent.FLAG_UPDATE_CURRENT or android.app.PendingIntent.FLAG_IMMUTABLE ) startActivityAndCollapse(pendingIntent) } else { @Suppress("DEPRECATION") startActivityAndCollapse(intent) } } override fun onStartListening() { super.onStartListening() updateTile() } private fun updateTile() { qsTile?.apply { state = Tile.STATE_ACTIVE label = "Add Link" contentDescription = "Quickly add a new bookmark to ShaarIt" updateTile() } } }