mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 12:45:20 +00:00
Remove "street" location channel; add coverage + names; style mesh
- Drop GeohashChannelLevel.street and update mappings/tests\n- Map geohash lengths >=8 to Block in teleport, no Street\n- Show ~distance coverage (mi/km via Locale.measurementSystem) next to each #geohash\n- Add reverse geocoding to display coarse names (country/region/city/neighborhood) per level\n- Style "#mesh" row title with toolbar blue\n- Fix iOS 16 deprecation: use Locale.measurementSystem
This commit is contained in:
@@ -93,7 +93,7 @@ struct LocationChannelsSheet: View {
|
||||
private var channelList: some View {
|
||||
List {
|
||||
// Mesh option first
|
||||
channelRow(title: meshTitleWithCount(), subtitle: "#bluetooth", isSelected: isMeshSelected) {
|
||||
channelRow(title: meshTitleWithCount(), subtitle: "#bluetooth", isSelected: isMeshSelected, titleColor: standardBlue) {
|
||||
manager.select(ChannelID.mesh)
|
||||
isPresented = false
|
||||
}
|
||||
@@ -101,7 +101,11 @@ struct LocationChannelsSheet: View {
|
||||
// Nearby options
|
||||
if !manager.availableChannels.isEmpty {
|
||||
ForEach(manager.availableChannels) { channel in
|
||||
channelRow(title: geohashTitleWithCount(for: channel), subtitle: "#\(channel.geohash)", isSelected: isSelected(channel)) {
|
||||
let coverage = coverageString(forPrecision: channel.geohash.count)
|
||||
let name = locationName(for: channel.level)
|
||||
let namePart = name.map { formattedNamePrefix(for: channel.level) + $0 }
|
||||
let subtitle = ["#\(channel.geohash)", coverage, namePart].compactMap { $0 }.joined(separator: " • ")
|
||||
channelRow(title: geohashTitleWithCount(for: channel), subtitle: subtitle, isSelected: isSelected(channel)) {
|
||||
manager.select(ChannelID.location(channel))
|
||||
isPresented = false
|
||||
}
|
||||
@@ -198,7 +202,7 @@ struct LocationChannelsSheet: View {
|
||||
return false
|
||||
}
|
||||
|
||||
private func channelRow(title: String, subtitle: String, isSelected: Bool, action: @escaping () -> Void) -> some View {
|
||||
private func channelRow(title: String, subtitle: String, isSelected: Bool, titleColor: Color? = nil, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
@@ -207,6 +211,7 @@ struct LocationChannelsSheet: View {
|
||||
HStack(spacing: 4) {
|
||||
Text(parts.base)
|
||||
.font(.system(size: 14, design: .monospaced))
|
||||
.foregroundColor(titleColor ?? Color.primary)
|
||||
if let count = parts.countSuffix, !count.isEmpty {
|
||||
Text(count)
|
||||
.font(.system(size: 11, design: .monospaced))
|
||||
@@ -270,7 +275,7 @@ struct LocationChannelsSheet: View {
|
||||
case 5: return .city
|
||||
case 6: return .neighborhood
|
||||
case 7: return .block
|
||||
default: return .street
|
||||
default: return .block
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -280,6 +285,69 @@ extension LocationChannelsSheet {
|
||||
private var standardGreen: Color {
|
||||
(colorScheme == .dark) ? Color.green : Color(red: 0, green: 0.5, blue: 0)
|
||||
}
|
||||
private var standardBlue: Color {
|
||||
Color(red: 0.0, green: 0.478, blue: 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Coverage helpers
|
||||
extension LocationChannelsSheet {
|
||||
private func coverageString(forPrecision len: Int) -> String {
|
||||
// Approximate max cell dimension at equator for a given geohash length.
|
||||
// Values sourced from common geohash dimension tables.
|
||||
let maxMeters: Double = {
|
||||
switch len {
|
||||
case 2: return 1_250_000
|
||||
case 3: return 156_000
|
||||
case 4: return 39_100
|
||||
case 5: return 4_890
|
||||
case 6: return 1_220
|
||||
case 7: return 153
|
||||
case 8: return 38.2
|
||||
case 9: return 4.77
|
||||
case 10: return 1.19
|
||||
default:
|
||||
if len <= 1 { return 5_000_000 }
|
||||
// For >10, scale down conservatively by ~1/4 each char
|
||||
let over = len - 10
|
||||
return 1.19 * pow(0.25, Double(over))
|
||||
}
|
||||
}()
|
||||
|
||||
let usesMetric: Bool = {
|
||||
if #available(iOS 16.0, *) {
|
||||
return Locale.current.measurementSystem == .metric
|
||||
} else {
|
||||
return Locale.current.usesMetricSystem
|
||||
}
|
||||
}()
|
||||
if usesMetric {
|
||||
let km = maxMeters / 1000.0
|
||||
return "~\(formatDistance(km)) km"
|
||||
} else {
|
||||
let miles = maxMeters / 1609.344
|
||||
return "~\(formatDistance(miles)) mi"
|
||||
}
|
||||
}
|
||||
|
||||
private func formatDistance(_ value: Double) -> String {
|
||||
if value >= 100 { return String(format: "%.0f", value.rounded()) }
|
||||
if value >= 10 { return String(format: "%.1f", value) }
|
||||
return String(format: "%.1f", value)
|
||||
}
|
||||
|
||||
private func locationName(for level: GeohashChannelLevel) -> String? {
|
||||
manager.locationNames[level]
|
||||
}
|
||||
|
||||
private func formattedNamePrefix(for level: GeohashChannelLevel) -> String {
|
||||
switch level {
|
||||
case .country:
|
||||
return ""
|
||||
default:
|
||||
return "around "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user