mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Add file import functionality to PolycentricImportProfileActivity
- Add 'Import from File' button to the import profile UI - Add file picker launcher using ActivityResultContracts.GetContent() - Support importing Polycentric profiles from text files - Read file content and pass it to the existing import method - Add string resource for 'Import from File' button text - Update layout to include file import button between QR scan and manual entry This allows users to import Polycentric profiles from files exported by the backup functionality, completing the export/import workflow.
This commit is contained in:
+20
@@ -34,6 +34,7 @@ import userpackage.Protocol.ExportBundle
|
||||
class PolycentricImportProfileActivity : AppCompatActivity() {
|
||||
private lateinit var _buttonHelp: ImageButton;
|
||||
private lateinit var _buttonScanProfile: LinearLayout;
|
||||
private lateinit var _buttonImportFile: LinearLayout;
|
||||
private lateinit var _buttonImportProfile: LinearLayout;
|
||||
private lateinit var _editProfile: EditText;
|
||||
private lateinit var _loaderOverlay: LoaderOverlay;
|
||||
@@ -48,6 +49,20 @@ class PolycentricImportProfileActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private val _filePickerLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||
uri?.let { fileUri ->
|
||||
try {
|
||||
val content = contentResolver.openInputStream(fileUri)?.bufferedReader()?.readText()
|
||||
content?.let { fileContent ->
|
||||
import(fileContent.trim())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.e(TAG, "Failed to read file", e)
|
||||
UIDialogs.toast(this, "Failed to read file: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun attachBaseContext(newBase: Context?) {
|
||||
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||
}
|
||||
@@ -59,6 +74,7 @@ class PolycentricImportProfileActivity : AppCompatActivity() {
|
||||
|
||||
_buttonHelp = findViewById(R.id.button_help);
|
||||
_buttonScanProfile = findViewById(R.id.button_scan_profile);
|
||||
_buttonImportFile = findViewById(R.id.button_import_file);
|
||||
_buttonImportProfile = findViewById(R.id.button_import_profile);
|
||||
_loaderOverlay = findViewById(R.id.loader_overlay);
|
||||
_editProfile = findViewById(R.id.edit_profile);
|
||||
@@ -82,6 +98,10 @@ class PolycentricImportProfileActivity : AppCompatActivity() {
|
||||
_qrCodeResultLauncher.launch(integrator.createScanIntent())
|
||||
};
|
||||
|
||||
_buttonImportFile.setOnClickListener {
|
||||
_filePickerLauncher.launch("text/plain")
|
||||
};
|
||||
|
||||
_buttonImportProfile.setOnClickListener {
|
||||
if (_editProfile.text.isEmpty()) {
|
||||
UIDialogs.toast(this, getString(R.string.text_field_does_not_contain_any_data));
|
||||
|
||||
@@ -47,6 +47,28 @@
|
||||
android:text="@string/scan_qr" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/button_import_file"
|
||||
android:layout_width="140dp"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/background_button_primary_round"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/button_scan_profile">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/inter_light"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16dp"
|
||||
android:text="@string/import_from_file" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_or"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -55,7 +77,7 @@
|
||||
android:fontFamily="@font/inter_light"
|
||||
android:textSize="28dp"
|
||||
android:layout_marginTop="30dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/button_scan_profile"
|
||||
app:layout_constraintTop_toBottomOf="@id/button_import_file"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent" />
|
||||
|
||||
|
||||
@@ -646,6 +646,7 @@
|
||||
<string name="tap_qr_code_for_fullscreen">Tap QR code for fullscreen view</string>
|
||||
<string name="export_to_file">Export to File</string>
|
||||
<string name="save_profile_to_file_for_sharing">Save profile to file for sharing</string>
|
||||
<string name="import_from_file">Import from File</string>
|
||||
<string name="authority">com.futo.platformplayer.fileprovider</string>
|
||||
<string name="share_text">Share Text</string>
|
||||
<string name="copied_text">Copied Text</string>
|
||||
|
||||
Reference in New Issue
Block a user