Commit 7ec79dfe authored by Anon's avatar Anon
Browse files

Merge branch 'destionation-input' into 'master'

Add destination path input field

See merge request card10/companion-app-android!9
parents 077c532c d5f4a948
......@@ -34,7 +34,8 @@ private const val TAG = "FileTransfer"
class FileTransfer(
private val service: LowEffortService,
private val reader: ChunkedReader,
private var listener: FileTransferListener
private var listener: FileTransferListener,
private val destinationPath: String
) : OnPacketReceivedListener {
private var currentState = TransferState.IDLE
......@@ -100,7 +101,7 @@ class FileTransfer(
service.sendPacket(
Packet(
PacketType.START,
"/foo.py".toByteArray(Charset.forName("ASCII"))
destinationPath.toByteArray(Charset.forName("ASCII"))
)
)
currentState = TransferState.START_SENT
......
......@@ -30,6 +30,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.UiThread
......@@ -53,6 +54,7 @@ class FileTransferFragment : Fragment(), GattListener, FileTransferListener{
private lateinit var tvSelected: TextView
private lateinit var tvStatus: TextView
private lateinit var progressBar: ProgressBar
private lateinit var inputDestination: EditText
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.file_transfer_fragment, container, false)
......@@ -62,6 +64,7 @@ class FileTransferFragment : Fragment(), GattListener, FileTransferListener{
tvSelected = view.findViewById(R.id.label_selected)
tvStatus = view.findViewById(R.id.label_status)
progressBar = view.findViewById(R.id.progress)
inputDestination = view.findViewById(R.id.input_destination)
buttonPickFile = view.findViewById(R.id.button_pick_file)
buttonPickFile.setOnClickListener {
......@@ -95,7 +98,7 @@ class FileTransferFragment : Fragment(), GattListener, FileTransferListener{
val reader = ChunkedReader(ctx, uri, ConnectionService.mtu)
val service = ConnectionService.leService ?: throw IllegalStateException()
transfer = FileTransfer(service, reader, this)
transfer = FileTransfer(service, reader, this, inputDestination.text.toString())
} catch (e: Exception) {
Log.e(TAG, "Failed to initialize transfer")
return
......
......@@ -12,7 +12,7 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="@string/file_transfer_button_pick_file" />
android:text="@string/file_transfer_button_pick_file"/>
<TextView
android:id="@+id/label_selected"
......@@ -23,7 +23,24 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_pick_file"
android:text="@string/file_transfer_label_no_file_selected" />
android:text="@string/file_transfer_label_no_file_selected"/>
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/input_destination"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_selected"
android:importantForAutofill="no"
android:hint="@string/file_transfer_hint_destination"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/label_destination_help"
android:text="@string/file_transfer_label_destination_help"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/input_destination"/>
<Button
android:id="@+id/button_start_stop_transfer"
......@@ -32,8 +49,8 @@
android:layout_marginTop="@dimen/send_label_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_selected"
android:text="@string/file_transfer_button_start_transfer" />
app:layout_constraintTop_toBottomOf="@id/label_destination_help"
android:text="@string/file_transfer_button_start_transfer"/>
<TextView
android:id="@+id/label_status"
......@@ -42,7 +59,7 @@
android:layout_marginTop="@dimen/send_label_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_start_stop_transfer" />
app:layout_constraintTop_toBottomOf="@id/button_start_stop_transfer"/>
<ProgressBar
android:id="@+id/progress"
......@@ -53,6 +70,6 @@
android:layout_marginTop="@dimen/send_label_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_status" />
app:layout_constraintTop_toBottomOf="@id/label_status"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -11,11 +11,13 @@
<string name="main_button_mood">Change Mood</string>
<string name="main_button_beautiful">Beautiful</string>
<string name="file_transfer_button_pick_file">Select</string>
<string name="file_transfer_button_pick_file">Select file</string>
<string name="file_transfer_button_start_transfer">Start</string>
<string name="file_transfer_button_stop_transfer">Cancel</string>
<string name="file_transfer_label_no_file_selected">No file selected</string>
<string name="file_transfer_label_selected_file">Selected file:</string>
<string name="file_transfer_hint_destination">Destination path</string>
<string name="file_transfer_label_destination_help">(e.g. /test.py)</string>
<string name="loading_dialog_loading">Loading</string>
<string name="dialog_action_ok">OK</string>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment