getChannelReplacementList

fun getChannelReplacementList(new: List<ChannelSettings>, currentSettings: List<ChannelSettings>, minimumSlotCount: Int = 0, maximumSlotCount: Int = Int.MAX_VALUE): List<Channel>(source)

Builds an authoritative Channel list for a full REPLACE import. Every position in new is emitted (PRIMARY at index 0, SECONDARY for 1..new.lastIndex) and any trailing positions beyond new's range are emitted as DISABLED so the radio stops using them.

Unlike getChannelList, this does NOT skip positions where currentSettings[i] == new[i]: the imported set is authoritative, the local cache must not gate the writes, and silent diff-skips during REPLACE were the source of stale channels.

currentSettings is consulted only for its size (to determine trailing DISABLED writes); its values are never compared against new. Callers should read it from radioConfigRepository.channelSetFlow.first().settings, not from a stateInWhileSubscribed StateFlow's .value — the StateFlow placeholder window can return an empty list and suppress trailing DISABLED writes.

Edge case: if new is empty, every emitted slot (including index 0) is DISABLED rather than wrongly promoting an empty ChannelSettings to PRIMARY.

Return

A Channel list covering every slot the radio needs written to materialize new and clear leftover slots.

Parameters

new

The imported ChannelSettings list. Every index becomes a write to the radio.

currentSettings

The current ChannelSettings list. Only its size is used; trailing indices past new become DISABLED writes so leftover slots are cleared.

minimumSlotCount

The minimum slot count to emit. Full replacement callers can use this to disable firmware slots even when the local cache is stale or shorter than the radio's actual channel list.

maximumSlotCount

The maximum slot count to emit. Full replacement callers use this to avoid unsupported firmware channel indices even if an imported or cached list is longer than expected.