Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the Settings view in SwiftUI #1317

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

lissine0
Copy link
Member

@lissine0 lissine0 commented Nov 30, 2024

I was going to link the UIKit AccountEdit view from the SwiftUI settings, so alpha users can use this PR, but it turned out to be ugly:

AccountEdit.mp4

As a result, the UIKit views rewritten in this PR are still being used. This should be the case until the account settings are in SwiftUI.
In order to test this PR, you need to revert lissine0@60839b8c

Notes:

  • The UIKit version of the settings is presented in a split view on iPads: the settings view on the left and the currently selected subview on the right. I didn't port that behavior. It currently looks on iPads like it does on macOS.
  • The UIKit version of the settings has in-app modals for accessing the mail app and the app store. I didn't port that behavior, and relied instead on normal links (mailto: and itms-apps://) which should open the relevant apps externally (I did not test this because it's not possible on the Simulator, but it should work).

Please indicate if you want these things added to the SwiftUI rewrite. I think the second one makes sense, as the modal is nicer than opening an app externally, but I'm not sure about the split view.

@tmolitor-stud-tu
Copy link
Member

That's really ugly and quite strange. I'd be curious what causes this distortion.

As for your PR itself: I just tried it and I'm okay with the mailto: and itms-apps://, but the split-view is broken now: opening the settings on ipad or iphone big enough to be in split-view will open the settings but don't show any back button or other means to close the settings again.

Even though I liked to have a split-view for our settings, I'm okay with removing that and only having a single-view in that case. But closing the settings should always be possible, split-view or not.

This fixes the back button being missing on big-screen iPhones
in landscape mode.

For more information, see the following commit messages:
8183703 and 009becf
@lissine0
Copy link
Member Author

lissine0 commented Dec 1, 2024

opening the settings on ipad or iphone big enough to be in split-view will open the settings but don't show any back button or other means to close the settings again.

On iPads (at least on the iPad 6th generation simulator), you can close the modal by clicking the area outside it, or by swiping it down.
On big-screen iPhones, this problem exists when in landscape mode;
It turns out that this was happening for all views using AddTopLevelNavigation.
I pushed a commit that fixes it.

@tmolitor-stud-tu
Copy link
Member

I don't like it if swiping down/tapping outside is the only method to close things. there should always be a button to do the same.

Copy link
Member

@tmolitor-stud-tu tmolitor-stud-tu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main point is: I'd like the xmpp class to be a data model just like the MLContact class is and then be used in conjunction with the ObservableKVOWrapper to get an auto-updating ui.

return MLXMPPManager.sharedInstance().connectedTime(for: self.accountID)
}
var avatar: UIImage {
return MLImageManager.sharedInstance().getIconFor(MLContact.createContact(fromJid: self.jid, andAccountID: self.accountID)) ?? UIImage(named: "noicon")!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the avatar property of MLContact to get auto-updates (wrap the MLContact in ObservableKVOWrapper.

Text(account.jid)
.frame(maxWidth: .infinity, alignment: .leading)

Text(self.connectionStatusString)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

uptimeFormatter.doesRelativeDateFormatting = true
}

var connectionStatusString: String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the accountState of our xmpp object (in a ObservableKVOWrapper) and a switch statement to stringify the values of the xmppState enum.

return MLXMPPManager.sharedInstance().isAccount(forIdConnected: self.accountID)
}
var connectedTime: Date {
return MLXMPPManager.sharedInstance().connectedTime(for: self.accountID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use connectedTime property of our xmpp class, wrapped by a ObservableKVOWrapper.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the connectedTimeFor: method of MLXMPPManager can even be removed afterwards (no other code is using it if I don't miss something).

#endif
}
Section(header: Text("App")) {
NavigationLink(destination: LazyClosureView(GeneralSettings())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general settings should now be embedded in this settings rather than being a submenu (I only used a submenu because the settings weren't yet ported to swiftui).

UIPasteboard.general.setValue(HelperTools.appBuildVersionInfo(for: MLVersionType.IQ), forPasteboardType: UTType.utf8PlainText.identifier)
#if !DEBUG
tappedVersionInfo += 1
if tappedVersionInfo > 16 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if tappedVersionInfo > 16 {
if tappedVersionInfo >= 16 {


struct Settings: View {
@State private var tappedVersionInfo = 0
@State private var showDebugEntry = HelperTools.defaultsDB().bool(forKey: "showLogInSettings")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a new class with @defaultsDB annotated properties to hold and autoupdate these settings, see the implementation of GeneralSettingsDefaultsDB in GeneralSettings.swift

#if !DEBUG
tappedVersionInfo += 1
if tappedVersionInfo > 16 {
HelperTools.defaultsDB().set(true, forKey: "showLogInSettings")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this, if you use the @defaultsDB annotation (see comment above).

@@ -811,6 +810,15 @@ class SwiftuiInterface : NSObject {
return host
}

@objc
func makeSettingsView() -> UIViewController {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since makeSettingsView does not need any special argument, you should add the settings view to our makeView function below.

}
}
}
.onReceive(NotificationCenter.default.publisher(for: NSNotification.Name(kMonalAccountStatusChanged)).receive(on: RunLoop.main)) { notification in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be needed anymore, once the xmpp class is a proper data model class used in conjunction with the ObservableKVOWrapper.

@tmolitor-stud-tu tmolitor-stud-tu force-pushed the develop branch 10 times, most recently from 622ff1d to 7b95939 Compare December 29, 2024 09:43
@tmolitor-stud-tu tmolitor-stud-tu force-pushed the develop branch 9 times, most recently from b1bf422 to 3c4d40b Compare January 3, 2025 17:42
@tmolitor-stud-tu tmolitor-stud-tu force-pushed the develop branch 14 times, most recently from bae7dea to e32cbe3 Compare January 4, 2025 22:39
@tmolitor-stud-tu
Copy link
Member

username/domain are part of the connectionProperties property and can be used with the KVO wrapper: xmppAccount.connectionProperties.identity.user and xmppAccount.connectionProperties.identity.domain

enabled is not, that's right, but I'd like to make the xmpp class a observable data model just like MLContact is...so we should add an enabled property to the xmpp class and rewrite our code so that every other code in monal uses that property instead of asking the database directly and changing that property gets written to our database automatically...
--> half done in lissine0@5828f36d9

to properly implement the enable property, the semantics/code of MLXMPPManager functions like connectAccountWithDictionary etc. must be changed...

@tmolitor-stud-tu tmolitor-stud-tu force-pushed the develop branch 3 times, most recently from fefe9af to b78a732 Compare February 10, 2025 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants