mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-23 11:26:54 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
84 lines
3.9 KiB
Swift
Executable File
84 lines
3.9 KiB
Swift
Executable File
// MARK: Swiftgram – Local stars balance: edit amount
|
||
import Foundation
|
||
import UIKit
|
||
import Display
|
||
import SwiftSignalKit
|
||
import TelegramPresentationData
|
||
import ItemListUI
|
||
import PresentationDataUtils
|
||
import AccountContext
|
||
import SGSimpleSettings
|
||
|
||
private enum FeelRichAmountEntry: ItemListNodeEntry {
|
||
case header(id: Int, text: String)
|
||
case amount(id: Int, text: String, placeholder: String)
|
||
|
||
var id: Int { stableId }
|
||
var section: ItemListSectionId { 0 }
|
||
var stableId: Int {
|
||
switch self {
|
||
case .header(let id, _), .amount(let id, _, _): return id
|
||
}
|
||
}
|
||
static func < (lhs: FeelRichAmountEntry, rhs: FeelRichAmountEntry) -> Bool { lhs.stableId < rhs.stableId }
|
||
static func == (lhs: FeelRichAmountEntry, rhs: FeelRichAmountEntry) -> Bool {
|
||
switch (lhs, rhs) {
|
||
case let (.header(a, t1), .header(b, t2)): return a == b && t1 == t2
|
||
case let (.amount(a, t1, p1), .amount(b, t2, p2)): return a == b && t1 == t2 && p1 == p2
|
||
default: return false
|
||
}
|
||
}
|
||
func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem {
|
||
let theme = presentationData.theme
|
||
let args = arguments as! FeelRichAmountArguments
|
||
switch self {
|
||
case .header(_, let text):
|
||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: section)
|
||
case .amount(_, let text, let placeholder):
|
||
return ItemListSingleLineInputItem(presentationData: presentationData, systemStyle: .glass, title: NSAttributedString(string: (presentationData.strings.baseLanguageCode == "ru" ? "Сумма (звёзды)" : "Amount (stars)"), textColor: theme.list.itemPrimaryTextColor), text: text, placeholder: placeholder, type: .number, clearType: .always, sectionId: section, textUpdated: { args.updateAmount($0) }, action: {})
|
||
}
|
||
}
|
||
}
|
||
|
||
private final class FeelRichAmountArguments {
|
||
let reload: () -> Void
|
||
init(reload: @escaping () -> Void) { self.reload = reload }
|
||
func updateAmount(_ value: String) {
|
||
SGSimpleSettings.shared.feelRichStarsAmount = value
|
||
reload()
|
||
}
|
||
}
|
||
|
||
private func feelRichAmountEntries(presentationData: PresentationData) -> [FeelRichAmountEntry] {
|
||
let lang = presentationData.strings.baseLanguageCode
|
||
var entries: [FeelRichAmountEntry] = []
|
||
var id = 0
|
||
entries.append(.header(id: id, text: lang == "ru" ? "БАЛАНС ЗВЁЗД" : "STARS BALANCE"))
|
||
id += 1
|
||
entries.append(.amount(id: id, text: SGSimpleSettings.shared.feelRichStarsAmount, placeholder: "1000"))
|
||
return entries
|
||
}
|
||
|
||
/// Edit local stars balance amount.
|
||
public func FeelRichAmountController(context: AccountContext, onSave: @escaping () -> Void) -> ViewController {
|
||
let reloadPromise = ValuePromise(true, ignoreRepeated: false)
|
||
let arguments = FeelRichAmountArguments(reload: { reloadPromise.set(true) })
|
||
|
||
let signal = combineLatest(reloadPromise.get(), context.sharedContext.presentationData)
|
||
|> map { _, presentationData -> (ItemListControllerState, (ItemListNodeState, FeelRichAmountArguments)) in
|
||
let lang = presentationData.strings.baseLanguageCode
|
||
let controllerState = ItemListControllerState(
|
||
presentationData: ItemListPresentationData(presentationData),
|
||
title: .text(lang == "ru" ? "Сумма звёзд" : "Stars amount"),
|
||
leftNavigationButton: nil,
|
||
rightNavigationButton: nil,
|
||
backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back)
|
||
)
|
||
let entries = feelRichAmountEntries(presentationData: presentationData)
|
||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: entries, style: .blocks, ensureVisibleItemTag: nil, initialScrollToItem: nil)
|
||
return (controllerState, (listState, arguments))
|
||
}
|
||
|
||
return ItemListController(context: context, state: signal)
|
||
}
|