Skip to content

Commit

Permalink
Merge pull request #843 from FabianWessel/fix/scrollBluetoothDevices
Browse files Browse the repository at this point in the history
Fix/scrollBluetoothDevices
  • Loading branch information
SebaDro authored Oct 13, 2021
2 parents 80166ff + e82c61d commit a44c938
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 91 deletions.
155 changes: 89 additions & 66 deletions org.envirocar.app/res/layout/activity_obd_selection_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,96 +19,119 @@
with the enviroCar app. If not, see http://www.gnu.org/licenses/.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/activity_obd_selection_layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:padding="@dimen/spacing_large">

<TextView
android:id="@+id/activity_obd_selection_layout_paired_devices_text"
style="@style/Base.TextAppearance.AppCompat.SearchResult.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/obd_selection_paired_devices"
android:textColor="@color/blue_dark_cario"
android:textSize="14sp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="16dp" />

<ListView
android:id="@+id/activity_obd_selection_layout_paired_devices_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:choiceMode="singleChoice"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintTop_toBottomOf="@+id/activity_obd_selection_layout_paired_devices_text"
tools:layout_editor_absoluteX="16dp" />

<TextView
android:id="@+id/activity_obd_selection_layout_paired_devices_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="@string/obd_selection_no_paired_devices"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintTop_toBottomOf="@+id/activity_obd_selection_layout_paired_devices_text"
tools:layout_editor_absoluteX="26dp" />

<LinearLayout
android:id="@+id/activity_obd_selection_layout_content"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/spacing_large">
android:layout_height="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activity_obd_selection_layout_paired_devices_text"
tools:layout_editor_absoluteX="16dp">

<TextView
android:id="@+id/activity_obd_selection_layout_paired_devices_text"
android:id="@+id/activity_obd_selection_layout_available_devices_text"
style="@style/Base.TextAppearance.AppCompat.SearchResult.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_medium"
android:text="@string/obd_selection_paired_devices"
android:layout_weight="1"
android:text="@string/obd_selection_avaiable_devices"
android:textColor="@color/blue_dark_cario"
android:textSize="14sp"
android:visibility="gone"/>
android:textSize="14sp" />

<ListView
android:id="@+id/activity_obd_selection_layout_paired_devices_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:choiceMode="singleChoice"/>

<LinearLayout
android:layout_width="match_parent"
<ProgressBar
android:id="@+id/activity_obd_selection_layout_search_devices_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp">

<TextView
android:id="@+id/activity_obd_selection_layout_available_devices_text"
style="@style/Base.TextAppearance.AppCompat.SearchResult.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/obd_selection_avaiable_devices"
android:textColor="@color/blue_dark_cario"
android:textSize="14sp"/>

<ProgressBar
android:id="@+id/activity_obd_selection_layout_search_devices_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:maxHeight="20dp"
android:minHeight="10dp"
android:visibility="gone"/>

<ImageView
android:id="@+id/activity_obd_selection_layout_rescan_bluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:src="@drawable/ic_refresh_black_24dp"
android:tint="@color/blue_light_cario"
android:maxHeight="20dp"
android:minHeight="10dp"/>

</LinearLayout>

<ListView
android:id="@+id/activity_obd_selection_layout_available_devices_list"
android:layout_width="match_parent"
android:layout_marginRight="8dp"
android:maxHeight="20dp"
android:minHeight="10dp"
android:visibility="gone" />

<ImageView
android:id="@+id/activity_obd_selection_layout_rescan_bluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"/>
android:layout_marginRight="20dp"
android:maxHeight="20dp"
android:minHeight="10dp"
android:src="@drawable/ic_refresh_black_24dp"
app:tint="@color/blue_light_cario" />

</LinearLayout>

<ListView
android:id="@+id/activity_obd_selection_layout_available_devices_list"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
tools:layout_editor_absoluteX="16dp" />

<TextView
android:id="@+id/activity_obd_selection_layout_available_devices_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
android:text="Kein Bluetooth-Gerät in der Nähe gefunden"/>
android:text="@string/obd_selection_no_available_devices"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
tools:layout_editor_absoluteX="26dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
android:text="@string/obd_selection_bluetooth_disabled"
tools:layout_editor_absoluteX="26dp" />

</LinearLayout>
</LinearLayout>
9 changes: 6 additions & 3 deletions org.envirocar.app/res/values-de/strings_obd_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
<string name="obd_selection_discovery_started">Suche gestartet!</string>
<string name="obd_selection_is_selected_template">%s ausgewählt.</string>

<string name="obd_selection_paired_devices">Gepaarte Geräte</string>
<string name="obd_selection_no_paired_devices">Keine gekoppelten Bluetooth-Geräte.</string>
<string name="obd_selection_no_available_devices">Keine Bluetooth-Geräte gefunden.</string>

<string name="obd_selection_paired_devices">Gekoppelte Geräte</string>
<string name="obd_selection_avaiable_devices">Verfügbare Geräte</string>

<string name="obd_selection_dialog_pairing_title">Mit Gerät koppeln</string>
<string name="obd_selection_dialog_pairing_title">Gerät koppeln</string>
<string name="obd_selection_dialog_pairing_content_template">Möchten Sie ihr Gerät mit %s koppeln?</string>
<string name="obd_selection_dialog_delete_pairing_title">Paarung löschen?</string>
<string name="obd_selection_dialog_delete_pairing_title">Gerät entkoppeln?</string>
<string name="obd_selection_dialog_delete_pairing_content_template">Möchten Sie die Kopplung mit \"%s\" löschen?</string>

<string name="obd_selection_device_unpaired_template">%s wurde entkoppelt.</string>
Expand Down
7 changes: 5 additions & 2 deletions org.envirocar.app/res/values/strings_obd_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
<string name="obd_selection_discovery_started">Bluetooth discovery started.</string>
<string name="obd_selection_is_selected_template">%s selected.</string>

<string name="obd_selection_no_paired_devices">No paired Bluetooth devices</string>
<string name="obd_selection_no_available_devices">No Bluetooth devices found</string>

<string name="obd_selection_paired_devices">Paired Devices</string>
<string name="obd_selection_avaiable_devices">Available</string>
<string name="obd_selection_avaiable_devices">Available Devices</string>

<string name="obd_selection_dialog_pairing_title">Pair Device</string>
<string name="obd_selection_dialog_pairing_content_template">Do you want to pair with %s?</string>
<string name="obd_selection_dialog_delete_pairing_title">Delete Pairing?</string>
<string name="obd_selection_dialog_delete_pairing_title">Unpair device?</string>
<string name="obd_selection_dialog_delete_pairing_content_template">Do you want to remove the pairing with "%s"?</string>

<string name="obd_selection_device_unpaired_template">%s has been unpaired.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public interface ShowSnackbarListener {
@BindView(R.id.activity_obd_selection_layout_rescan_bluetooth)
protected ImageView mRescanImageView;

@BindView(R.id.activity_obd_selection_layout_paired_devices_info)
protected TextView mPairedDevicesInfoTextView;
@BindView(R.id.activity_obd_selection_layout_available_devices_info)
protected TextView mNewDevicesInfoTextView;

Expand Down Expand Up @@ -180,7 +182,6 @@ private void updateContentView() {
mContentView.setVisibility(View.GONE);
mNewDevicesArrayAdapter.clear();
mPairedDevicesAdapter.clear();
mNewDevicesInfoTextView.setText(R.string.obd_selection_bluetooth_disabled);
} else {
// Bluetooth is enabled. Show the content view, update the list, and start the
// discovery of Bluetooth devices.
Expand Down Expand Up @@ -318,9 +319,6 @@ public void onStart() {
mProgressBar.setVisibility(View.VISIBLE);
mRescanImageView.setVisibility(View.GONE);

// Set info view to "searching...".
mNewDevicesInfoTextView.setText(R.string
.bluetooth_pairing_preference_info_searching_devices);
showSnackbar(getString(R.string.obd_selection_discovery_started));

// Set timer for 15sec
Expand All @@ -346,20 +344,10 @@ public void onComplete() {
mProgressBar.setVisibility(View.GONE);
mRescanImageView.setVisibility(View.VISIBLE);
showSnackbar("Discovery Finished!");

// If no devices found, set the corresponding textview to visibile.
if (mNewDevicesArrayAdapter.isEmpty()) {
mNewDevicesInfoTextView.setText(R.string
.select_bluetooth_preference_info_no_device_found);
} else if (mNewDevicesArrayAdapter.getCount() == 1) {
mNewDevicesInfoTextView.setText(R.string
.bluetooth_pairing_preference_info_device_found);
} else {
String string = getString(R.string
.bluetooth_pairing_preference_info_devices_found);
mNewDevicesInfoTextView.setText(String.format(string,
Integer.toString(mNewDevicesArrayAdapter.getCount())));
if(mNewDevicesArrayAdapter.isEmpty()){
mNewDevicesInfoTextView.setVisibility(View.VISIBLE);
}

}

@Override
Expand All @@ -377,6 +365,7 @@ public void onNext(BluetoothDevice device) {
// add it to the list and add an entry to the array adapter.
if (!mPairedDevicesAdapter.contains(device) &&
!mNewDevicesArrayAdapter.contains(device)) {
mNewDevicesInfoTextView.setVisibility(View.GONE);
mNewDevicesArrayAdapter.add(device);
}
}
Expand Down Expand Up @@ -460,7 +449,8 @@ public void onDeviceUnpaired(BluetoothDevice device) {
device.getName() + " (" + device.getAddress() + ")"));
mPairedDevicesAdapter.remove(device);
if (mPairedDevicesAdapter.getCount() == 0 ){
mPairedDevicesTextView.setVisibility(View.GONE);
mPairedDevicesInfoTextView.setVisibility(View.VISIBLE);
//mPairedDevicesTextView.setVisibility(View.GONE);
}
updatePairedDevicesList();
}
Expand Down Expand Up @@ -489,7 +479,8 @@ private void updatePairedDevicesList() {

// Make the paired devices textview visible if there are paired devices
if (!pairedDevices.isEmpty()) {
mPairedDevicesTextView.setVisibility(View.VISIBLE);
mPairedDevicesInfoTextView.setVisibility(View.GONE);
//mPairedDevicesTextView.setVisibility(View.VISIBLE);
}
}

Expand Down Expand Up @@ -534,7 +525,8 @@ public void onDevicePaired(BluetoothDevice device) {
device.getName()));
mNewDevicesArrayAdapter.remove(device);
mPairedDevicesAdapter.add(device);
mPairedDevicesTextView.setVisibility(View.VISIBLE);
mPairedDevicesInfoTextView.setVisibility(View.GONE);
//mPairedDevicesTextView.setVisibility(View.VISIBLE);

// Post an event to all registered handlers.
mBus.post(new BluetoothPairingChangedEvent(device, true));
Expand Down

0 comments on commit a44c938

Please sign in to comment.