Skip to content

Commit

Permalink
Move out getActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Nov 21, 2023
1 parent c9b435b commit a0f8f7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.mullvad.mullvadvpn.compose.component.MullvadCircularProgressIndicator
import net.mullvad.mullvadvpn.lib.payment.model.ProductId
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.color.AlphaDescription
import net.mullvad.mullvadvpn.ui.extension.getActivity
import net.mullvad.mullvadvpn.viewmodel.PaymentUiSideEffect
import net.mullvad.mullvadvpn.viewmodel.PaymentViewModel
import org.koin.androidx.compose.koinViewModel
Expand Down Expand Up @@ -222,11 +223,3 @@ fun PaymentDialog(
}
)
}

private fun Context.getActivity(): Activity? {
return when (this) {
is Activity -> this
is ContextWrapper -> this.baseContext.getActivity()
else -> null
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package net.mullvad.mullvadvpn.ui.extension

import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.ContextWrapper

fun Context.copyToClipboard(content: String, clipboardLabel: String) {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(clipboardLabel, content)
clipboard.setPrimaryClip(clipData)
}

fun Context.getActivity(): Activity? {
return when (this) {
is Activity -> this
is ContextWrapper -> this.baseContext.getActivity()
else -> null
}
}

0 comments on commit a0f8f7b

Please sign in to comment.