generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into item-long-press-delete
# Conflicts: # app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingScreen.kt # app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingViewModel.kt # app/src/main/kotlin/com/x8bit/bitwarden/authenticator/ui/authenticator/feature/itemlisting/VaultVerificationCodeItem.kt # app/src/main/res/values/strings.xml
- Loading branch information
Showing
7 changed files
with
160 additions
and
18 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...8bit/bitwarden/authenticator/data/platform/manager/clipboard/BitwardenClipboardManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.x8bit.bitwarden.authenticator.data.platform.manager.clipboard | ||
|
||
import androidx.compose.ui.text.AnnotatedString | ||
import com.x8bit.bitwarden.authenticator.ui.platform.base.util.Text | ||
|
||
/** | ||
* Wrapper class for using the clipboard. | ||
*/ | ||
interface BitwardenClipboardManager { | ||
|
||
/** | ||
* Places the given [text] into the device's clipboard. Setting the data to [isSensitive] will | ||
* obfuscate the displayed data on the default popup (true by default). A toast will be | ||
* displayed on devices that do not have a default popup (pre-API 32) and will not be displayed | ||
* on newer APIs. If a toast is displayed, it will be formatted as "[text] copied" or if a | ||
* [toastDescriptorOverride] is provided, it will be formatted as | ||
* "[toastDescriptorOverride] copied". | ||
*/ | ||
fun setText( | ||
text: AnnotatedString, | ||
isSensitive: Boolean = true, | ||
toastDescriptorOverride: String? = null, | ||
) | ||
|
||
/** | ||
* See [setText] for more details. | ||
*/ | ||
fun setText( | ||
text: String, | ||
isSensitive: Boolean = true, | ||
toastDescriptorOverride: String? = null, | ||
) | ||
|
||
/** | ||
* See [setText] for more details. | ||
*/ | ||
fun setText( | ||
text: Text, | ||
isSensitive: Boolean = true, | ||
toastDescriptorOverride: String? = null, | ||
) | ||
} |
71 changes: 71 additions & 0 deletions
71
.../bitwarden/authenticator/data/platform/manager/clipboard/BitwardenClipboardManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.x8bit.bitwarden.authenticator.data.platform.manager.clipboard | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.os.Build | ||
import android.widget.Toast | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.core.content.getSystemService | ||
import androidx.core.os.persistableBundleOf | ||
import androidx.work.ExistingWorkPolicy | ||
import androidx.work.OneTimeWorkRequest | ||
import androidx.work.WorkManager | ||
import com.x8bit.bitwarden.authenticator.R | ||
import com.x8bit.bitwarden.authenticator.ui.platform.base.util.Text | ||
import com.x8bit.bitwarden.authenticator.ui.platform.base.util.toAnnotatedString | ||
import com.x8bit.bitwarden.data.platform.manager.clipboard.ClearClipboardWorker | ||
|
||
/** | ||
* Default implementation of the [BitwardenClipboardManager] interface. | ||
*/ | ||
class BitwardenClipboardManagerImpl( | ||
private val context: Context, | ||
) : BitwardenClipboardManager { | ||
private val clipboardManager: ClipboardManager = requireNotNull(context.getSystemService()) | ||
|
||
override fun setText( | ||
text: AnnotatedString, | ||
isSensitive: Boolean, | ||
toastDescriptorOverride: String?, | ||
) { | ||
clipboardManager.setPrimaryClip( | ||
ClipData | ||
.newPlainText("", text) | ||
.apply { | ||
description.extras = persistableBundleOf( | ||
"android.content.extra.IS_SENSITIVE" to isSensitive, | ||
) | ||
}, | ||
) | ||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) { | ||
val descriptor = toastDescriptorOverride ?: text | ||
Toast | ||
.makeText( | ||
context, | ||
context.resources.getString(R.string.value_has_been_copied, descriptor), | ||
Toast.LENGTH_SHORT, | ||
) | ||
.show() | ||
} | ||
|
||
val clearClipboardRequest: OneTimeWorkRequest = | ||
OneTimeWorkRequest | ||
.Builder(ClearClipboardWorker::class.java) | ||
.build() | ||
|
||
WorkManager.getInstance(context).enqueueUniqueWork( | ||
"ClearClipboard", | ||
ExistingWorkPolicy.REPLACE, | ||
clearClipboardRequest, | ||
) | ||
} | ||
|
||
override fun setText(text: String, isSensitive: Boolean, toastDescriptorOverride: String?) { | ||
setText(text.toAnnotatedString(), isSensitive, toastDescriptorOverride) | ||
} | ||
|
||
override fun setText(text: Text, isSensitive: Boolean, toastDescriptorOverride: String?) { | ||
setText(text.toString(context.resources), isSensitive, toastDescriptorOverride) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...com/x8bit/bitwarden/authenticator/data/platform/manager/clipboard/ClearClipboardWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.x8bit.bitwarden.data.platform.manager.clipboard | ||
|
||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.content.Context.CLIPBOARD_SERVICE | ||
import androidx.work.Worker | ||
import androidx.work.WorkerParameters | ||
|
||
/** | ||
* A worker to clear the clipboard manager. | ||
*/ | ||
class ClearClipboardWorker(appContext: Context, workerParams: WorkerParameters) : | ||
Worker(appContext, workerParams) { | ||
|
||
private val clipboardManager = | ||
appContext.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager | ||
|
||
override fun doWork(): Result { | ||
clipboardManager.clearPrimaryClip() | ||
return Result.success() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters