Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions app/src/main/java/org/fedorahosted/freeotp/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ class MainActivity : AppCompatActivity() {
windowInsets
}

ViewCompat.setOnApplyWindowInsetsListener(binding.addTokenFab) { view, windowInsets ->

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit should have already contained this change 40151ec

val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val marginParams = view.layoutParams as android.view.ViewGroup.MarginLayoutParams
marginParams.bottomMargin = resources.getDimensionPixelSize(R.dimen.space_3) + insets.bottom
if (view.layoutDirection == View.LAYOUT_DIRECTION_RTL) {
marginParams.leftMargin = resources.getDimensionPixelSize(R.dimen.space_3) + insets.left
} else {
marginParams.rightMargin = resources.getDimensionPixelSize(R.dimen.space_3) + insets.right
}
view.layoutParams = marginParams
windowInsets
}


viewModel.migrateOldData()

binding.tokenList.adapter = tokenListAdapter
Expand Down Expand Up @@ -341,13 +355,33 @@ class MainActivity : AppCompatActivity() {

val uri = intent.data
if (uri != null) {
lifecycleScope.launch {
try {
otpTokenDatabase.otpTokenDao().insert(OtpTokenFactory.createFromUri(uri))
} catch (e: Exception) {
Snackbar.make(binding.rootView, R.string.invalid_token_uri_received, Snackbar.LENGTH_SHORT)
.show()
}
val rawPath = uri.path?.trimStart('/') ?: ""

// Account is required; reject the intent silently if absent
val account = rawPath.substringAfter(":", "").ifEmpty { null } ?: return

// Issuer is optional; can be empty
val issuer = uri.getQueryParameter("issuer") ?: rawPath.substringBefore(":")

// Post to ensure the window is attached before showing the dialog.
// onNewIntent may be called from onCreate before setContentView completes.
window.decorView.post {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.add_token_confirmation_title)
.setMessage(getString(R.string.add_token_confirmation_message, issuer, account))
.setIcon(R.drawable.alert)
.setPositiveButton(R.string.ok_text) { _, _ ->
lifecycleScope.launch {
try {
otpTokenDatabase.otpTokenDao().insert(OtpTokenFactory.createFromUri(uri))
} catch (e: Exception) {
Snackbar.make(binding.rootView, R.string.invalid_token_uri_received, Snackbar.LENGTH_SHORT)
.show()
}
}
}
.setNegativeButton(R.string.cancel_text, null)
.show()
}
}
}
Expand Down Expand Up @@ -526,4 +560,4 @@ class MainActivity : AppCompatActivity() {
const val SCREENSHOT_MODE_EXTRA = "screenshot_mode"
const val SHARE_FROM_PACKAGE_NAME_INTENT_EXTRA = "shareFromPackageName"
}
}
}
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<string name="authentication_dialog_title">Authentication required</string>
<string name="authentication_dialog_subtitle">Please use biometric or PIN to authenticate FreeOTP+</string>
<string name="unable_to_authenticate">Unable to authenticate. Do you have screen lock enabled with PIN / biometric enabled?</string>
<string name="add_token_confirmation_title">Add OTP Account?</string>
<string name="add_token_confirmation_message">An external source wants to add an OTP account:\n\nIssuer: %1$s\nAccount: %2$s\n\nOnly proceed if you trust this source.</string>

<string name="five" translatable="false">5</string>
<string name="six" translatable="false">6</string>
Expand All @@ -80,4 +82,4 @@
<string name="category">Category</string>
<string name="all_categories">All categories</string>
<string name="uncategorized">Uncategorized</string>
</resources>
</resources>