From bec51bcfc08bf8e6e33f1d355702aaa75bd461cf Mon Sep 17 00:00:00 2001 From: JanNiklas Grabowski Date: Wed, 5 Apr 2023 06:10:07 +0000 Subject: [PATCH] MESSENGER-4482 fix feature banner link and add navigationbar --- Config/BWIBuildSettings.swift | 22 +++++++++ .../Modules/Settings/SettingsViewController.m | 10 +--- Riot/Modules/TabBar/MasterTabBarController.m | 4 -- bwi/FeatureBanner/FeatureBannerView.swift | 20 ++++---- bwi/Tools/BWINewFeatureHelper.swift | 46 ------------------- 5 files changed, 36 insertions(+), 66 deletions(-) delete mode 100644 bwi/Tools/BWINewFeatureHelper.swift diff --git a/Config/BWIBuildSettings.swift b/Config/BWIBuildSettings.swift index adc8f2d24..9422c753a 100644 --- a/Config/BWIBuildSettings.swift +++ b/Config/BWIBuildSettings.swift @@ -192,6 +192,28 @@ class BWIBuildSettings: NSObject { // replace feature history link variable with the appropiate build setting var bwiFeatureHistoryLink = "https://messenger.bwi.de/bwmessenger#c6110" var bwiReplaceFeatureLink = true + + // feature history file path + var bwiFeatureHistoryFilePath: String { + guard let bundleFileURL = Bundle.main.url(forResource: newFeaturesHTML, withExtension: "html") else {return ""} + + // replace feature link and copy file into document directory + if bwiReplaceFeatureLink { + if var newFileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last { + newFileURL = newFileURL.appendingPathComponent(newFeaturesHTML.appending(".html")) + do { + var text = try String(contentsOf: bundleFileURL, encoding: .utf8) + text = text.replacingOccurrences(of: "$FEATURELINK", with: bwiFeatureHistoryLink) + try text.write(to: newFileURL, atomically: false, encoding: .utf8) + + // return new path + return newFileURL.path + } catch {} + } + } + + return bundleFileURL.path + } // login with matrix id should only be enabled in some configurations var bwiEnableLoginWithMatrixID = true diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index e9b753163..30cf90b59 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -3442,14 +3442,8 @@ ChangePasswordCoordinatorBridgePresenterDelegate> { if (row == SHOW_NEW_FEATURES) { - NSString *htmlFile = [[NSBundle mainBundle] pathForResource:BWIBuildSettings.shared.newFeaturesHTML ofType:@"html" inDirectory:nil]; - // bwi: if enabled replace feature link and use file from document directory - if (BWIBuildSettings.shared.bwiReplaceFeatureLink) { - BwiNewFeatureHelper *featureHelper = [[BwiNewFeatureHelper alloc] init]; - [featureHelper replaceFeatureHistoryLink]; - NSURL *filePath = [featureHelper getDocumentDirectory]; - htmlFile = [filePath path]; - } + // bwi: replace link and show webview + NSString *htmlFile = BWIBuildSettings.shared.bwiFeatureHistoryFilePath; WebViewViewController *webViewViewController = [[WebViewViewController alloc] initWithLocalHTMLFile: htmlFile]; webViewViewController.title = BWIL10n.bwiSettingsNewFeaturesHeader; [self pushViewController:webViewViewController]; diff --git a/Riot/Modules/TabBar/MasterTabBarController.m b/Riot/Modules/TabBar/MasterTabBarController.m index ddb60c185..938107f76 100644 --- a/Riot/Modules/TabBar/MasterTabBarController.m +++ b/Riot/Modules/TabBar/MasterTabBarController.m @@ -114,10 +114,6 @@ [self updateSideMenuNotifcationIcon]; }]; - // replace link - if (BWIBuildSettings.shared.bwiReplaceFeatureLink) { - [[[BwiNewFeatureHelper alloc] init] replaceFeatureHistoryLink]; - } } - (void)userInterfaceThemeDidChange diff --git a/bwi/FeatureBanner/FeatureBannerView.swift b/bwi/FeatureBanner/FeatureBannerView.swift index 38b3556a4..10e07818d 100644 --- a/bwi/FeatureBanner/FeatureBannerView.swift +++ b/bwi/FeatureBanner/FeatureBannerView.swift @@ -27,6 +27,7 @@ protocol FeatureBannerDelegate { @objcMembers class FeatureBannerViewCell: UITableViewCell, FeatureBannerDelegate { private var parentViewController: UIViewController? private let hostingController = UIHostingController(rootView: nil) + private var webViewController: WebViewViewController? override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -89,16 +90,19 @@ protocol FeatureBannerDelegate { } func didPressShowDetails() { - let htmlFile = Bundle.main.path(forResource: BWIBuildSettings.shared.newFeaturesHTML, ofType: "html") - if let webviewController = WebViewViewController(localHTMLFile: htmlFile) { - webviewController.title = BWIL10n.bwiSettingsNewFeaturesHeader - - hostingController.parent?.present(webviewController, animated: true, completion: { () -> Void in - self.hideTopBanner() - }) - } + let htmlFile = BWIBuildSettings.shared.bwiFeatureHistoryFilePath + self.webViewController = WebViewViewController(localHTMLFile: htmlFile) + webViewController?.title = BWIL10n.bwiSettingsNewFeaturesHeader + let navigationBar: UINavigationController = UINavigationController(rootViewController: webViewController!) + webViewController?.navigationItem.setLeftBarButton(UIBarButtonItem(title: VectorL10n.close, style: .plain, target: self, action: #selector(closeModal)), animated: false) + hostingController.parent?.present(navigationBar, animated: true, completion: { () -> Void in + self.hideTopBanner() + }) } + @objc func closeModal() { + webViewController?.dismiss(animated: true) + } } diff --git a/bwi/Tools/BWINewFeatureHelper.swift b/bwi/Tools/BWINewFeatureHelper.swift deleted file mode 100644 index 23b60f1d0..000000000 --- a/bwi/Tools/BWINewFeatureHelper.swift +++ /dev/null @@ -1,46 +0,0 @@ -// -/* - * Copyright (c) 2022 BWI GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Foundation - -@objc class BwiNewFeatureHelper: NSObject { - - @objc func replaceFeatureHistoryLink() { - guard let urlPath = Bundle.main.url(forResource: BWIBuildSettings.shared.newFeaturesHTML, withExtension: "html") else { - return - } - - // files in bundle cannot be edited use document directory - if let filePath = getDocumentDirectory() { - do { - var text = try String(contentsOf: urlPath, encoding: .utf8) - text = text.replacingOccurrences(of: "$FEATURELINK", with: BWIBuildSettings.shared.bwiFeatureHistoryLink) - try text.write(to: filePath, atomically: false, encoding: .utf8) - } - catch {} - } else { return } - } - - @objc func getDocumentDirectory() -> URL? { - if let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last { - return documentDirectory.appendingPathComponent(BWIBuildSettings.shared.newFeaturesHTML.appending(".html")) - } else { - return Bundle.main.url(forResource: BWIBuildSettings.shared.newFeaturesHTML, withExtension: "html") - } - } -} -