Last active
February 13, 2026 07:10
-
-
Save kustraslawomir/8a7ef7472090c870e2e7432cbd78a9b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SuppressLint("Range") | |
| public ArrayList<EquipmentModel> getRoomEquipmentByType(String whereQuery, String roomId) { | |
| ArrayList<EquipmentModel> equipmentList = new ArrayList<>(); | |
| SQLiteDatabase readableDatabase = getDatabase().getReadableDatabase(); | |
| String query = "SELECT * FROM " + RoomEquipmentTable.TABLE_NAME + | |
| " WHERE " + RoomEquipmentTable.ROOM_ID + " = '" + roomId + "' AND " + whereQuery + | |
| " ORDER BY " + RoomEquipmentTable.PRIORITY + " DESC"; | |
| try (Cursor cursor = readableDatabase.rawQuery(query, null)) { | |
| if (cursor.getCount() > 0) { | |
| while (cursor.moveToNext()) { | |
| String deviceType = cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.DEVICE)); | |
| String description = cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.DESCRIPTION)); | |
| if ("hangings".equals(deviceType)) { | |
| if (description == null || !description.toLowerCase().contains("zasłon")) { | |
| Log.d("EquipmentModule", "Skipping 'hangings' device, it's not a curtain (zasłona). Name: " + description); | |
| continue; | |
| } | |
| } | |
| EquipmentModel equipmentModel = new EquipmentModel(); | |
| equipmentModel.setId(cursor.getInt(cursor.getColumnIndex(RoomEquipmentTable.ID))); | |
| equipmentModel.setManufacturer(cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.MANUFACTURER))); | |
| equipmentModel.setDevice(deviceType); | |
| equipmentModel.setIp(cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.IP))); | |
| equipmentModel.setPort(cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.PORT))); | |
| equipmentModel.setAddress(cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.ADDRESS))); | |
| equipmentModel.setSlot(cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.SLOT))); | |
| equipmentModel.setRange(cursor.getString(cursor.getColumnIndex(RoomEquipmentTable.RANGE))); | |
| equipmentModel.setDescription(description); | |
| equipmentModel.setRefreshTime(cursor.getInt(cursor.getColumnIndex(RoomEquipmentTable.REFRESH_TIME))); | |
| equipmentModel.setNotifyTargetGroup(cursor.getInt(cursor.getColumnIndex(RoomEquipmentTable.NOTIFY_TARGET_GROUP))); | |
| equipmentModel.setGroupId(cursor.getInt(cursor.getColumnIndex(RoomEquipmentTable.GROUP_ID))); | |
| equipmentModel.setPriority(cursor.getInt(cursor.getColumnIndex(RoomEquipmentTable.PRIORITY))); | |
| equipmentList.add(equipmentModel); | |
| } | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| return equipmentList; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment