mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-15 22:42:51 +00:00
Merge pull request #1045 from Toadsta/copyURI
Copy URI to clipboard when using transfer entries
This commit is contained in:
commit
927a27943b
6 changed files with 55 additions and 5 deletions
|
@ -1,15 +1,22 @@
|
|||
package com.beemdevelopment.aegis.ui;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipDescription;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
|
||||
|
@ -34,6 +41,7 @@ public class TransferEntriesActivity extends AegisActivity {
|
|||
private TextView _entriesCount;
|
||||
private Button _nextButton;
|
||||
private Button _previousButton;
|
||||
private Button _copyButton;
|
||||
private int _currentEntryCount = 1;
|
||||
|
||||
@Override
|
||||
|
@ -52,6 +60,7 @@ public class TransferEntriesActivity extends AegisActivity {
|
|||
_entriesCount = findViewById(R.id.tvEntriesCount);
|
||||
_nextButton = findViewById(R.id.btnNext);
|
||||
_previousButton = findViewById(R.id.btnPrevious);
|
||||
_copyButton = findViewById(R.id.btnCopyClipboard);
|
||||
|
||||
if (getSupportActionBar() != null){
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
@ -90,6 +99,30 @@ public class TransferEntriesActivity extends AegisActivity {
|
|||
}
|
||||
});
|
||||
|
||||
if (_authInfos.get(0) instanceof GoogleAuthInfo) {
|
||||
_copyButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
_copyButton.setOnClickListener(v -> {
|
||||
Transferable selectedEntry = _authInfos.get(_currentEntryCount - 1);
|
||||
try {
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("text/plain", selectedEntry.getUri().toString());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
extras.putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true);
|
||||
clip.getDescription().setExtras(extras);
|
||||
}
|
||||
if (clipboard != null) {
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
Toast.makeText(this,R.string.uri_copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
|
||||
} catch (GoogleAuthInfoException e) {
|
||||
Dialogs.showErrorDialog(this, R.string.unable_to_copy_uri_to_clipboard, e);
|
||||
}
|
||||
});
|
||||
|
||||
generateQR();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue