Skip to content

Commit

Permalink
Add ability to copy network signature in clipboard (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-BaptisteC authored Jan 14, 2024
1 parent 5d0ecfb commit ec154f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.noties.markwon.Markwon
import org.eu.exodus_privacy.exodusprivacy.R
import org.eu.exodus_privacy.exodusprivacy.databinding.FragmentTrackerDetailBinding
import org.eu.exodus_privacy.exodusprivacy.fragments.apps.model.AppsRVAdapter
import org.eu.exodus_privacy.exodusprivacy.utils.copyToClipboard
import org.eu.exodus_privacy.exodusprivacy.utils.openURL
import javax.inject.Inject

Expand Down Expand Up @@ -116,6 +117,12 @@ class TrackerDetailFragment : Fragment(R.layout.fragment_tracker_detail) {
codeSignTV.text = tracker.code_signature
if (tracker.network_signature.isNotEmpty()) {
networkSignTV.text = tracker.network_signature
networkSignTV.setOnLongClickListener {
copyToClipboard(
requireContext(),
networkSignTV.text.toString(),
)
}
networkDetectTV.visibility = View.VISIBLE
networkSignTV.visibility = View.VISIBLE
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.eu.exodus_privacy.exodusprivacy.utils

import android.content.ClipData.newPlainText
import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.os.Build
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.google.android.material.chip.Chip
import org.eu.exodus_privacy.exodusprivacy.R
Expand Down Expand Up @@ -68,3 +72,12 @@ fun PackageManager.getSource(packageName: String): String? {
this.getInstallerPackageName(packageName)
}
}

fun copyToClipboard(context: Context, string: String): Boolean {
val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboardManager.setPrimaryClip(newPlainText("", string))
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(context, "Copied", Toast.LENGTH_SHORT).show()
}
return true
}

0 comments on commit ec154f5

Please sign in to comment.