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

Feature/messaging #143

Open
wants to merge 69 commits into
base: feature/messaging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
b9639dc
implement messaging button on home view
frehelfer Apr 3, 2023
fa96a68
clean up spaces
frehelfer Apr 3, 2023
4076fc2
implement storyboard, view controller and view model to chat list vie…
frehelfer Apr 3, 2023
3ddafdd
implement chat list table view and cell
frehelfer Apr 3, 2023
3cb3d45
implement storyboard, view controller and view model to messages view
frehelfer Apr 3, 2023
eb11464
Merge branch 'Greenstand:main' into feature/messaging
frehelfer Apr 4, 2023
173cf54
implement messagesTableViewCell
frehelfer Apr 4, 2023
b0f4aad
implement messagingService and navigation to messagesView
frehelfer Apr 4, 2023
3f56509
add bell icon and some small refactor
frehelfer Apr 4, 2023
7b4052c
message view with bubbles
frehelfer Apr 5, 2023
f7e19ca
refactoring
frehelfer Apr 5, 2023
6f17a4d
Merge branch 'main'
frehelfer Apr 12, 2023
a03d22e
commented some code on messageTableViewCell
frehelfer Apr 12, 2023
538e01a
refactor: message alert displays numbers
frehelfer Apr 12, 2023
f1b563a
refactor: input text view grows when text get bigger
frehelfer Apr 12, 2023
c6ec76b
some design changes, added backgroundGreen Color
frehelfer Apr 12, 2023
7e791dc
add image to navigation bar
frehelfer Apr 14, 2023
f8284e0
implement UITableView extension to change tableview top bounce color …
frehelfer Apr 19, 2023
3a46f39
fetchMessages from home screen on viewWillAppear. Update and display …
frehelfer Apr 24, 2023
62b9d70
small refactor on home view
frehelfer Apr 26, 2023
6026c83
Add messaging service to ChatList screen. Cell are working with saved…
frehelfer Apr 26, 2023
8ae588a
message view are working with saved messages from core data
frehelfer Apr 26, 2023
238f63b
some refactor on fetching unread messages count
frehelfer Apr 28, 2023
cc25de5
add placeholder to messages screen and fix textview autoresizing
frehelfer Apr 28, 2023
55ad35e
move view when keyboard appears
frehelfer May 1, 2023
7cb96c5
fix navigation bar appearance bug with a custom extension that can be…
frehelfer May 2, 2023
5b6ea03
add method to set unread message variable to false when the user read…
frehelfer May 3, 2023
1bb58f4
refactor preset messages mode using an array of MessageEntity
frehelfer May 3, 2023
3130adf
create new message and save it on core data
frehelfer May 3, 2023
cbe708f
adjust message cell UI
frehelfer May 3, 2023
dd9e063
update logic to display message
frehelfer May 4, 2023
5d925f0
Change messages color
frehelfer May 5, 2023
f9168f2
weak reference to self
frehelfer May 16, 2023
89e0832
new logic to messages screen. MessageViewModel fetch data directly fr…
frehelfer May 17, 2023
e57fc5a
add method to fetch messages with offset. When user scrolls up, it fe…
frehelfer May 18, 2023
1c5bbb9
some cleanup
frehelfer May 19, 2023
3187f8b
tap to hidekeyboard ignores send message uibutton
frehelfer May 19, 2023
6543a7c
fix tableview content up/down following keyboard
frehelfer May 19, 2023
32fe059
small design changes on chat screen
frehelfer May 19, 2023
85a8911
cache row height
frehelfer May 20, 2023
4a03dca
Add no messages view
frehelfer May 31, 2023
273b92a
add announce view
frehelfer May 31, 2023
3fc9a29
announce view
frehelfer Jun 1, 2023
608c667
update syncMessages method. Added recursion to get and post methods.
frehelfer Jun 1, 2023
1766205
implement SurveyView base files
frehelfer Jun 2, 2023
37b7816
add custom button to survey screen
frehelfer Jun 2, 2023
937af08
add survey logic to select a choice
frehelfer Jun 9, 2023
424bb05
added methos to create and save a new survey response
frehelfer Jun 9, 2023
3d3a7bf
adjust some logic to the survey flow
frehelfer Jun 9, 2023
a9bd2f3
add scrollView to announce screen
frehelfer Jun 9, 2023
65f23fe
get unread messages count on home screen
frehelfer Jun 12, 2023
1157540
Change the logic to present a survey view controller
frehelfer Jun 14, 2023
8b1b70c
Add notification center to home screen. Updates unread message count …
frehelfer Jun 14, 2023
04e78e4
add darker backgroundcolor when button is highlighted
frehelfer Jun 14, 2023
af5e736
improve chatlist screen fetch request
frehelfer Jun 15, 2023
fd0c7d4
remove profile image from chatlist screen
frehelfer Jun 15, 2023
e1d5496
remove setupNavigationAppearance and revert to the origin
frehelfer Aug 8, 2023
dafa136
changed some localizable text strings
frehelfer Aug 9, 2023
56d80e1
updated generated strings
frehelfer Aug 9, 2023
203790c
removed all green background color from the project
frehelfer Aug 9, 2023
18e3d18
fix indentation and camel case
frehelfer Aug 10, 2023
1f2eea2
added chatList fallback text to localizable strings
frehelfer Aug 10, 2023
cbb188c
removed duplicated MessageType model
frehelfer Aug 10, 2023
9eb1e4b
added completion handlers for syncMessages method
frehelfer Aug 10, 2023
49d50af
removed notification center
frehelfer Aug 10, 2023
041b880
changed survey index to questionIndex
frehelfer Aug 17, 2023
2851b2f
added syncMessages button to chatListScreen
frehelfer Aug 18, 2023
e339db0
changed some methods name on surveyViewModel
frehelfer Aug 18, 2023
3d3d326
Merge branch 'main' into feature/messaging
frehelfer Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
35,715 changes: 2,023 additions & 33,692 deletions Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

164 changes: 164 additions & 0 deletions TreeTracker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions TreeTracker/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Home.UploadTreesButton.Title.Start" = "START UPLOAD";
"Home.UploadTreesButton.Title.Stop" = "STOP UPLOAD";
"Home.MyTreesButton.Title" = "MY TREES";
"Home.MessagingButton.Title" = "MESSAGES";

//Add Tree Screen
"AddTree.Title" = "Add Tree";
Expand Down Expand Up @@ -99,3 +100,25 @@
"Settings.PhotoQuality.Option.Medium.Info" = "Medium resolution, medium data usage.";
"Settings.PhotoQuality.Option.High.Title" = "High";
"Settings.PhotoQuality.Option.High.Info" = "High resolution, high data usage.";

//ChatList Screen
"ChatList.SyncMessages.normal.Title" = "Sync Messages";
"ChatList.SyncMessages.loading.Title" = "Loading...";
"ChatList.LastSyncLabel.WithouDate.Text" = "Please, tap the button above to sync messages.";
"ChatList.LastSyncLabel.WithDate.Text" = "Last sync time:";
"ChatList.NoMessagesLabel.Text" = "No messages";
"ChatList.MessageChatCell.FallbackTitle" = "Admin";
"ChatList.DefaultCell.FallbackTitle" = "";

//Messages Screen
"Messages.Title" = "Admin";
"Messages.InputTextView.PlaceHolder" = "Click to write a message";

//Announce Screen
"Announce.Title" = "Announcement";

//Survey Screen
"Survey.Title.Question" = "Question";
"Survey.Title.Response" = "Response";
"Survey.ActionButton.Title.Next" = "Next";
"Survey.ActionButton.Title.Finish" = "Finish";
20 changes: 20 additions & 0 deletions TreeTracker/SwiftGen/StoryboardScenes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ internal enum StoryboardScene {

internal static let initialScene = InitialSceneType<TreeTracker.AddTreeViewController>(storyboard: AddTree.self)
}
internal enum Announce: StoryboardType {
internal static let storyboardName = "Announce"

internal static let initialScene = InitialSceneType<TreeTracker.AnnounceViewController>(storyboard: Announce.self)
}
internal enum ChatList: StoryboardType {
internal static let storyboardName = "ChatList"

internal static let initialScene = InitialSceneType<TreeTracker.ChatListViewController>(storyboard: ChatList.self)
}
internal enum Home: StoryboardType {
internal static let storyboardName = "Home"

Expand All @@ -33,6 +43,11 @@ internal enum StoryboardScene {

internal static let initialScene = InitialSceneType<TreeTracker.LoadingViewController>(storyboard: Loading.self)
}
internal enum Messages: StoryboardType {
internal static let storyboardName = "Messages"

internal static let initialScene = InitialSceneType<TreeTracker.MessagesViewController>(storyboard: Messages.self)
}
internal enum Notes: StoryboardType {
internal static let storyboardName = "Notes"

Expand Down Expand Up @@ -63,6 +78,11 @@ internal enum StoryboardScene {

internal static let initialScene = InitialSceneType<TreeTracker.SignUpViewController>(storyboard: SignUp.self)
}
internal enum Survey: StoryboardType {
internal static let storyboardName = "Survey"

internal static let initialScene = InitialSceneType<TreeTracker.SurveyViewController>(storyboard: Survey.self)
}
internal enum Terms: StoryboardType {
internal static let storyboardName = "Terms"

Expand Down
66 changes: 66 additions & 0 deletions TreeTracker/SwiftGen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ internal enum L10n {
internal static let error = L10n.tr("Localizable", "Alert.Title.Error", fallback: "Error")
}
}
internal enum Announce {
/// Announcement
internal static let title = L10n.tr("Localizable", "Announce.Title", fallback: "Announcement")
}
internal enum App {
/// Localizable.strings
/// TreeTracker
Expand All @@ -48,6 +52,40 @@ internal enum L10n {
/// Copyright © 2020 Greenstand. All rights reserved.
internal static let title = L10n.tr("Localizable", "App.Title", fallback: "Greenstand Treetracker")
}
internal enum ChatList {
internal enum DefaultCell {
///
internal static let fallbackTitle = L10n.tr("Localizable", "ChatList.DefaultCell.FallbackTitle", fallback: "")
}
internal enum LastSyncLabel {
internal enum WithDate {
/// Last sync time:
internal static let text = L10n.tr("Localizable", "ChatList.LastSyncLabel.WithDate.Text", fallback: "Last sync time:")
}
internal enum WithouDate {
/// Please, tap the button above to sync messages.
internal static let text = L10n.tr("Localizable", "ChatList.LastSyncLabel.WithouDate.Text", fallback: "Please, tap the button above to sync messages.")
}
}
internal enum MessageChatCell {
/// Admin
internal static let fallbackTitle = L10n.tr("Localizable", "ChatList.MessageChatCell.FallbackTitle", fallback: "Admin")
}
internal enum NoMessagesLabel {
/// No messages
internal static let text = L10n.tr("Localizable", "ChatList.NoMessagesLabel.Text", fallback: "No messages")
}
internal enum SyncMessages {
internal enum Loading {
/// Loading...
internal static let title = L10n.tr("Localizable", "ChatList.SyncMessages.loading.Title", fallback: "Loading...")
}
internal enum Normal {
/// Sync Messages
internal static let title = L10n.tr("Localizable", "ChatList.SyncMessages.normal.Title", fallback: "Sync Messages")
}
}
}
internal enum DeleteAccountConfirmation {
/// Are you sure you want to delete tour account? All your trees on this device will be lost.
internal static let message = L10n.tr("Localizable", "DeleteAccountConfirmation.Message", fallback: "Are you sure you want to delete tour account? All your trees on this device will be lost.")
Expand Down Expand Up @@ -95,6 +133,10 @@ internal enum L10n {
/// Change User
internal static let title = L10n.tr("Localizable", "Home.LogoutButton.Title", fallback: "Change User")
}
internal enum MessagingButton {
/// MESSAGES
internal static let title = L10n.tr("Localizable", "Home.MessagingButton.Title", fallback: "MESSAGES")
}
internal enum MyTreesButton {
/// MY TREES
internal static let title = L10n.tr("Localizable", "Home.MyTreesButton.Title", fallback: "MY TREES")
Expand Down Expand Up @@ -130,6 +172,14 @@ internal enum L10n {
internal static let title = L10n.tr("Localizable", "LogOutConfirmation.LogOutButton.Title", fallback: "Log Out")
}
}
internal enum Messages {
/// Admin
internal static let title = L10n.tr("Localizable", "Messages.Title", fallback: "Admin")
internal enum InputTextView {
/// Click to write a message
internal static let placeHolder = L10n.tr("Localizable", "Messages.InputTextView.PlaceHolder", fallback: "Click to write a message")
}
}
internal enum Notes {
/// Add tree notes here.
internal static let placeholder = L10n.tr("Localizable", "Notes.Placeholder", fallback: "Add tree notes here.")
Expand Down Expand Up @@ -254,6 +304,22 @@ internal enum L10n {
}
}
}
internal enum Survey {
internal enum ActionButton {
internal enum Title {
/// Finish
internal static let finish = L10n.tr("Localizable", "Survey.ActionButton.Title.Finish", fallback: "Finish")
/// Next
internal static let next = L10n.tr("Localizable", "Survey.ActionButton.Title.Next", fallback: "Next")
}
}
internal enum Title {
/// Question
internal static let question = L10n.tr("Localizable", "Survey.Title.Question", fallback: "Question")
/// Response
internal static let response = L10n.tr("Localizable", "Survey.Title.Response", fallback: "Response")
}
}
internal enum Terms {
/// Terms & Conditions
internal static let title = L10n.tr("Localizable", "Terms.Title", fallback: "Terms & Conditions")
Expand Down
128 changes: 124 additions & 4 deletions TreeTracker/UI/Navigation/Home/HomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ private extension HomeCoordinator {
)
}

func showChatList(planter: Planter) {
configuration.navigationController.pushViewController(
chatListViewController(planter: planter),
animated: true
)
}

func showMessages(planter: Planter) {
configuration.navigationController.pushViewController(
messagesViewController(planter: planter),
animated: true
)
}

func showAnnounce(chat: ChatListViewModel.Chat) {
configuration.navigationController.pushViewController(
announceViewController(chat: chat),
animated: true
)
}

func showSurvey(planter: Planter, survey: SurveyViewModel.Survey, questionIndex: Int = 0) {
configuration.navigationController.pushViewController(
surveyViewController(planter: planter, survey: survey, questionIndex: questionIndex),
animated: true
)
}

func showNotes(note: String?) {
configuration.navigationController.pushViewController(
notesViewController(note: note),
Expand Down Expand Up @@ -99,7 +127,8 @@ private extension HomeCoordinator {
planter: planter,
treeMonitoringService: self.treetrackerSDK.treeMonitoringService,
selfieService: self.treetrackerSDK.selfieService,
uploadManager: self.treetrackerSDK.uploadManager
uploadManager: self.treetrackerSDK.uploadManager,
messagingService: self.treetrackerSDK.messagingService
)
viewModel.coordinatorDelegate = self
return viewModel
Expand All @@ -115,8 +144,8 @@ private extension HomeCoordinator {
}

func addTreeViewController(planter: Planter) -> UIViewController {
let viewcontroller = StoryboardScene.AddTree.initialScene.instantiate()
viewcontroller.viewModel = {
let viewController = StoryboardScene.AddTree.initialScene.instantiate()
viewController.viewModel = {
let viewModel = AddTreeViewModel(
locationProvider: self.treetrackerSDK.locationService,
treeService: self.treetrackerSDK.treeService,
Expand All @@ -127,7 +156,59 @@ private extension HomeCoordinator {
viewModel.coordinatorDelegate = self
return viewModel
}()
return viewcontroller
return viewController
}

func chatListViewController(planter: Planter) -> UIViewController {
let viewController = StoryboardScene.ChatList.initialScene.instantiate()
viewController.viewModel = {
let viewModel = ChatListViewModel(
planter: planter,
selfieService: self.treetrackerSDK.selfieService,
messagingService: self.treetrackerSDK.messagingService
)
viewModel.coordinatorDelegate = self
return viewModel
}()
return viewController
}

func messagesViewController(planter: Planter) -> UIViewController {
let viewController = StoryboardScene.Messages.initialScene.instantiate()
viewController.viewModel = {
let viewModel = MessagesViewModel(
planter: planter,
messagingService: treetrackerSDK.messagingService
)
return viewModel
}()
return viewController
}

func announceViewController(chat: ChatListViewModel.Chat) -> UIViewController {
let viewController = StoryboardScene.Announce.initialScene.instantiate()
viewController.viewModel = {
let viewModel = AnnounceViewModel(
chat: chat
)
return viewModel
}()
return viewController
}

func surveyViewController(planter: Planter, survey: SurveyViewModel.Survey, questionIndex: Int) -> UIViewController {
let viewController = StoryboardScene.Survey.initialScene.instantiate()
viewController.viewModel = {
let viewModel = SurveyViewModel(
planter: planter,
survey: survey,
messagingService: self.treetrackerSDK.messagingService,
questionIndex: questionIndex
)
viewModel.coordinatorDelegate = self
return viewModel
}()
return viewController
}

func notesViewController(note: String?) -> UIViewController {
Expand All @@ -139,6 +220,7 @@ private extension HomeCoordinator {
}()
return viewController
}

func profileViewController(planter: Planter) -> UIViewController {
let viewController = StoryboardScene.Profile.initialScene.instantiate()
viewController.viewModel = {
Expand Down Expand Up @@ -195,6 +277,10 @@ extension HomeCoordinator: HomeViewModelCoordinatorDelegate {
showUploadList(planter: planter)
}

func homeViewModel(_ homeViewModel: HomeViewModel, didSelectViewChatListForPlanter planter: Planter) {
showChatList(planter: planter)
}

func homeViewModel(_ homeViewModel: HomeViewModel, didSelectViewProfileForPlanter planter: Planter) {
showPlanterProfile(planter: planter)
}
Expand Down Expand Up @@ -232,6 +318,7 @@ extension HomeCoordinator: AddTreeViewModelCoordinatorDelegate {
}
}

// MARK: - NotesViewModelCoordinatorDelegate
extension HomeCoordinator: NotesViewModelCoordinatorDelegate {

func notesViewModel(_ notesViewModel: NotesViewModel, didAddNote note: String) {
Expand All @@ -241,3 +328,36 @@ extension HomeCoordinator: NotesViewModelCoordinatorDelegate {
}
}
}

// MARK: - ChatListViewModelCoordinatorDelegate
extension HomeCoordinator: ChatListViewModelCoordinatorDelegate {

func chatListViewModel(_ chatListViewModel: ChatListViewModel, didSelectMessages planter: Planter) {
showMessages(planter: planter)
}

func chatListViewModel(_ chatListViewModel: ChatListViewModel, didSelectAnnounce chat: ChatListViewModel.Chat) {
showAnnounce(chat: chat)
}

func chatListViewModel(_ chatListViewModel: ChatListViewModel, didSelectSurvey survey: SurveyViewModel.Survey, planter: Planter) {
showSurvey(planter: planter, survey: survey)
}

}

// MARK: - SurveyViewModelCoordinatorDelegate
extension HomeCoordinator: SurveyViewModelCoordinatorDelegate {

func surveyViewModel(_ surveyViewModel: SurveyViewModel, showNextQuestion survey: SurveyViewModel.Survey, planter: Planter, questionIndex: Int) {
showSurvey(planter: planter, survey: survey, questionIndex: questionIndex)
}

func surveyViewModel(_ surveyViewModel: SurveyViewModel, didFinishSurvey survey: SurveyViewModel.Survey) {
if let chatListViewController = configuration.navigationController.viewControllers.first(where: { $0 is ChatListViewController }) as? ChatListViewController {
configuration.navigationController.popToViewController(chatListViewController, animated: true)
} else {
configuration.navigationController.popToRootViewController(animated: true)
}
}
}
14 changes: 14 additions & 0 deletions TreeTracker/UI/Views/Home/Components/AddTreeButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class AddTreeButton: UIButton {
super.init(coder: coder)
commonInit()
}

override var isHighlighted: Bool {
didSet {
updateState()
}
}
}

// MARK: - Private
Expand All @@ -32,6 +38,14 @@ private extension AddTreeButton {
setAttributedTitle(attributedTitle, for: .normal)
}

func updateState() {
if isHighlighted {
backgroundColor = Asset.Colors.secondaryGreen.color
} else {
backgroundColor = Asset.Colors.primaryGreen.color
}
}

var attributedTitle: NSAttributedString {
let attributedString = NSMutableAttributedString()
attributedString.append(NSAttributedString(attachment: treeIconTextAttachment))
Expand Down
Loading