|
|
@@ -24,6 +24,11 @@ class LNGameMateListView: UIView {
|
|
|
private let tableView = UITableView()
|
|
|
private var loading = false
|
|
|
|
|
|
+ private let bannerIndex = 1
|
|
|
+ private var bannerList: [LNBannerInfoVO] = []
|
|
|
+ private var bannerLoading = false
|
|
|
+ private var bannerLoaded = false
|
|
|
+
|
|
|
override init(frame: CGRect) {
|
|
|
super.init(frame: frame)
|
|
|
|
|
|
@@ -40,6 +45,7 @@ class LNGameMateListView: UIView {
|
|
|
topCategory = newTopCategory
|
|
|
category = newCategory
|
|
|
self.filter = filter
|
|
|
+ bannerLoaded = false
|
|
|
|
|
|
tableView.mj_header?.beginRefreshing()
|
|
|
}
|
|
|
@@ -50,6 +56,21 @@ class LNGameMateListView: UIView {
|
|
|
}
|
|
|
|
|
|
extension LNGameMateListView {
|
|
|
+ private var shouldShowBannerCell: Bool {
|
|
|
+ viewController is LNHomeViewController && curMateList.count > 1 && !bannerList.isEmpty
|
|
|
+ }
|
|
|
+
|
|
|
+ private func isBannerRow(_ row: Int) -> Bool {
|
|
|
+ shouldShowBannerCell && row == bannerIndex
|
|
|
+ }
|
|
|
+
|
|
|
+ private func mateIndex(for row: Int) -> Int {
|
|
|
+ if shouldShowBannerCell && row > bannerIndex {
|
|
|
+ return row - 1
|
|
|
+ }
|
|
|
+ return row
|
|
|
+ }
|
|
|
+
|
|
|
private func loadList() {
|
|
|
guard !loading else { return }
|
|
|
loading = true
|
|
|
@@ -66,6 +87,7 @@ extension LNGameMateListView {
|
|
|
}
|
|
|
curMateList.append(contentsOf: list)
|
|
|
self.nextTag = nextTag
|
|
|
+ loadBannerIfNeed(force: curNext.isEmpty)
|
|
|
tableView.reloadData()
|
|
|
|
|
|
if curMateList.isEmpty {
|
|
|
@@ -87,6 +109,32 @@ extension LNGameMateListView {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private func loadBannerIfNeed(force: Bool = false) {
|
|
|
+ guard viewController is LNHomeViewController, curMateList.count > 1 else {
|
|
|
+ if !bannerList.isEmpty {
|
|
|
+ bannerList.removeAll()
|
|
|
+ tableView.reloadData()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if bannerLoading {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if bannerLoaded && !force {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ bannerLoading = true
|
|
|
+ LNConfigManager.shared.getBannerList(adSlot: 1) { [weak self] list in
|
|
|
+ guard let self else { return }
|
|
|
+ bannerLoading = false
|
|
|
+ bannerLoaded = true
|
|
|
+ bannerList = list ?? []
|
|
|
+ tableView.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
func reportExposure() {
|
|
|
let frame = convert(bounds, to: nil)
|
|
|
@@ -102,7 +150,16 @@ extension LNGameMateListView {
|
|
|
|
|
|
var items = Set<String>()
|
|
|
for index in indexs {
|
|
|
- items.insert(curMateList[index.row].userNo)
|
|
|
+ if isBannerRow(index.row) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ let mateIdx = mateIndex(for: index.row)
|
|
|
+ guard mateIdx >= 0, mateIdx < curMateList.count else { continue }
|
|
|
+ items.insert(curMateList[mateIdx].userNo)
|
|
|
+ }
|
|
|
+
|
|
|
+ if items.isEmpty {
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
LNStatisticManager.shared.reportExposure(uids: Array(items)) { _ in }
|
|
|
@@ -141,17 +198,30 @@ extension LNGameMateListView: LNGameMateListMenuViewDelegate {
|
|
|
|
|
|
extension LNGameMateListView: UITableViewDataSource, UITableViewDelegate {
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
- curMateList.count
|
|
|
+ curMateList.count + (shouldShowBannerCell ? 1 : 0)
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
+ if isBannerRow(indexPath.row) {
|
|
|
+ let cell = tableView.dequeueReusableCell(withIdentifier: LNMateAdBannerCell.className, for: indexPath) as! LNMateAdBannerCell
|
|
|
+ cell.update(items: bannerList)
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: LNGameMateListCell.className, for: indexPath) as! LNGameMateListCell
|
|
|
-
|
|
|
- let data = curMateList[indexPath.row]
|
|
|
+
|
|
|
+ let data = curMateList[mateIndex(for: indexPath.row)]
|
|
|
cell.update(data)
|
|
|
|
|
|
return cell
|
|
|
}
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
+ if isBannerRow(indexPath.row) {
|
|
|
+ return 82
|
|
|
+ }
|
|
|
+ return UITableView.automaticDimension
|
|
|
+ }
|
|
|
|
|
|
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
|
|
|
reportExposure()
|
|
|
@@ -220,11 +290,13 @@ extension LNGameMateListView {
|
|
|
tableView.mj_footer = footer
|
|
|
|
|
|
tableView.register(LNGameMateListCell.self, forCellReuseIdentifier: LNGameMateListCell.className)
|
|
|
+ tableView.register(LNMateAdBannerCell.self, forCellReuseIdentifier: LNMateAdBannerCell.className)
|
|
|
tableView.dataSource = self
|
|
|
tableView.delegate = self
|
|
|
tableView.allowsSelection = false
|
|
|
tableView.separatorStyle = .none
|
|
|
tableView.backgroundColor = .clear
|
|
|
+ tableView.rowHeight = UITableView.automaticDimension
|
|
|
|
|
|
tableView.addSubview(emptyView)
|
|
|
emptyView.snp.makeConstraints { make in
|
|
|
@@ -261,4 +333,3 @@ struct LNGameMateListViewPreview: UIViewRepresentable {
|
|
|
LNGameMateListViewPreview()
|
|
|
})
|
|
|
#endif
|
|
|
-
|