Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a shortcut when creating ChuckerInterceptor #588

Merged
merged 13 commits into from
Mar 26, 2021
21 changes: 21 additions & 0 deletions library/src/main/java/com/chuckerteam/chucker/api/Chucker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package com.chuckerteam.chucker.api

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 android.util.Log
import com.chuckerteam.chucker.R
import com.chuckerteam.chucker.internal.support.Logger
import com.chuckerteam.chucker.internal.support.NotificationHelper
import com.chuckerteam.chucker.internal.ui.MainActivity
Expand Down Expand Up @@ -30,6 +35,22 @@ public object Chucker {
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}

public fun Context.createShortcut() {
MiSikora marked this conversation as resolved.
Show resolved Hide resolved
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
getSystemService(ShortcutManager::class.java)?.let {
val shortcut = ShortcutInfo.Builder(this, "id1")
MiSikora marked this conversation as resolved.
Show resolved Hide resolved
MiSikora marked this conversation as resolved.
Show resolved Hide resolved
.setShortLabel("Open chucker activity")
.setLongLabel("Open chucker activity")
MiSikora marked this conversation as resolved.
Show resolved Hide resolved
.setIcon(Icon.createWithResource(this, R.mipmap.chucker_ic_launcher_round))
Goooler marked this conversation as resolved.
Show resolved Hide resolved
.setIntent(getLaunchIntent(this).setAction(Intent.ACTION_VIEW))
.build()
val allShortcuts = it.dynamicShortcuts.toMutableList()
allShortcuts.add(shortcut)
it.dynamicShortcuts = allShortcuts
MiSikora marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

/**
* Dismisses all previous Chucker notifications.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.chuckerteam.chucker.api

import android.content.Context
import androidx.annotation.VisibleForTesting
import com.chuckerteam.chucker.api.Chucker.createShortcut
import com.chuckerteam.chucker.internal.data.entity.HttpTransaction
import com.chuckerteam.chucker.internal.support.CacheDirectoryProvider
import com.chuckerteam.chucker.internal.support.PlainTextDecoder
Expand Down Expand Up @@ -53,6 +54,10 @@ public class ChuckerInterceptor private constructor(
decoders,
)

init {
builder.context.createShortcut()
MiSikora marked this conversation as resolved.
Show resolved Hide resolved
}

/** Adds [headerName] into [headersToRedact] */
public fun redactHeader(vararg headerName: String) {
headersToRedact.addAll(headerName)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.