Rework archived conversations mode of home view.

This commit is contained in:
Matthew Chen 2018-04-23 13:49:11 -04:00
parent 9c7e9b795a
commit fe9a61117c
8 changed files with 103 additions and 43 deletions

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "DisclosureIndicatorRTL@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "DisclosureIndicatorRTL@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "DisclosureIndicatorRTL@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -182,25 +182,21 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
// TODO: Remove this.
[SignalApp.sharedApp setHomeViewController:self];
ReminderView *archiveReminderView = [ReminderView new];
archiveReminderView.text = NSLocalizedString(
@"INBOX_VIEW_ARCHIVE_MODE_REMINDER", @"Label reminding the user that they are in archive mode.");
__weak HomeViewController *weakSelf = self;
archiveReminderView.tapAction = ^{
[weakSelf showInboxGrouping];
};
ReminderView *archiveReminderView =
[ReminderView explanationWithText:NSLocalizedString(@"INBOX_VIEW_ARCHIVE_MODE_REMINDER",
@"Label reminding the user that they are in archive mode.")];
[self.view addSubview:archiveReminderView];
[archiveReminderView autoPinWidthToSuperview];
[archiveReminderView autoPinToTopLayoutGuideOfViewController:self withInset:0];
self.hideArchiveReminderViewConstraint = [archiveReminderView autoSetDimension:ALDimensionHeight toSize:0];
self.hideArchiveReminderViewConstraint.priority = UILayoutPriorityRequired;
ReminderView *missingContactsPermissionView = [ReminderView new];
missingContactsPermissionView.text = NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION",
@"Multi-line label explaining how to show names instead of phone numbers in your inbox");
missingContactsPermissionView.tapAction = ^{
[[UIApplication sharedApplication] openSystemSettings];
};
ReminderView *missingContactsPermissionView = [ReminderView
nagWithText:NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION",
@"Multi-line label explaining how to show names instead of phone numbers in your inbox")
tapAction:^{
[[UIApplication sharedApplication] openSystemSettings];
}];
[self.view addSubview:missingContactsPermissionView];
[missingContactsPermissionView autoPinWidthToSuperview];
[missingContactsPermissionView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:archiveReminderView];
@ -1056,6 +1052,10 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.self.threadMappings updateWithTransaction:transaction];
}];
[self checkIfEmptyView];
self.threadMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ self.currentGrouping ]
view:TSThreadDatabaseViewExtensionName];
return;
}
@ -1141,17 +1141,27 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
- (void)checkIfEmptyView
{
[_tableView setHidden:NO];
[_emptyBoxLabel setHidden:NO];
if (self.homeViewMode == HomeViewMode_Inbox && [self.threadMappings numberOfItemsInGroup:TSInboxGroup] == 0) {
// We need to consult the db view, not the mapping since the mapping only knows about
// the current group.
__block NSUInteger inboxCount;
__block NSUInteger archiveCount;
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSThreadDatabaseViewExtensionName];
inboxCount = [viewTransaction numberOfItemsInGroup:TSInboxGroup];
archiveCount = [viewTransaction numberOfItemsInGroup:TSArchiveGroup];
}];
if (self.homeViewMode == HomeViewMode_Inbox && inboxCount == 0 && archiveCount == 0) {
[self setEmptyBoxText];
[_tableView setHidden:YES];
} else if (self.homeViewMode == HomeViewMode_Archive &&
[self.threadMappings numberOfItemsInGroup:TSArchiveGroup] == 0) {
[_emptyBoxLabel setHidden:NO];
} else if (self.homeViewMode == HomeViewMode_Archive && archiveCount == 0) {
[self setEmptyBoxText];
[_tableView setHidden:YES];
[_emptyBoxLabel setHidden:NO];
} else {
[_emptyBoxLabel setHidden:YES];
[_tableView setHidden:NO];
}
}

View File

@ -82,12 +82,12 @@ NS_ASSUME_NONNULL_BEGIN
_nonContactAccountSet = [NSMutableSet set];
_collation = [UILocalizedIndexedCollation currentCollation];
ReminderView *contactsPermissionReminderView = [[ReminderView alloc]
initWithText:NSLocalizedString(@"COMPOSE_SCREEN_MISSING_CONTACTS_PERMISSION",
@"Multi-line label explaining why compose-screen contact picker is empty.")
tapAction:^{
[[UIApplication sharedApplication] openSystemSettings];
}];
ReminderView *contactsPermissionReminderView =
[ReminderView nagWithText:NSLocalizedString(@"COMPOSE_SCREEN_MISSING_CONTACTS_PERMISSION",
@"Multi-line label explaining why compose-screen contact picker is empty.")
tapAction:^{
[[UIApplication sharedApplication] openSystemSettings];
}];
[self.view addSubview:contactsPermissionReminderView];
[contactsPermissionReminderView autoPinWidthToSuperview];
[contactsPermissionReminderView autoPinEdgeToSuperviewMargin:ALEdgeTop];

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -9,7 +9,7 @@ class ReminderView: UIView {
let TAG = "[ReminderView]"
let label = UILabel()
let defaultTapAction = {
static let defaultTapAction = {
Logger.debug("[ReminderView] tapped.")
}
@ -25,30 +25,51 @@ class ReminderView: UIView {
}
}
required init?(coder: NSCoder) {
self.tapAction = defaultTapAction
enum ReminderViewMode {
// Nags are urgent interactive prompts, bidding for the user's attention.
case nag
// Explanations are not interactive or urgent.
case explanation
}
let mode: ReminderViewMode
super.init(coder: coder)
setupSubviews()
@available(*, unavailable, message:"use other constructor instead.")
required init?(coder aDecoder: NSCoder) {
fatalError("\(#function) is unimplemented.")
}
@available(*, unavailable, message:"use other constructor instead.")
override init(frame: CGRect) {
self.tapAction = defaultTapAction
fatalError("\(#function) is unimplemented.")
}
super.init(frame: frame)
private init(mode: ReminderViewMode,
text: String, tapAction: @escaping () -> Void) {
self.mode = mode
self.tapAction = tapAction
super.init(frame: .zero)
self.text = text
setupSubviews()
}
convenience init(text: String, tapAction: @escaping () -> Void) {
self.init(frame: .zero)
self.text = text
self.tapAction = tapAction
@objc public class func nag(text: String, tapAction: @escaping () -> Void) -> ReminderView {
return ReminderView(mode: .nag, text: text, tapAction: tapAction)
}
@objc public class func explanation(text: String) -> ReminderView {
return ReminderView(mode: .explanation, text: text, tapAction: ReminderView.defaultTapAction)
}
func setupSubviews() {
self.backgroundColor = UIColor.ows_reminderYellow
switch (mode) {
case .nag:
self.backgroundColor = UIColor.ows_reminderYellow
case .explanation:
self.backgroundColor = UIColor(rgbHex: 0xf5f5f5)
}
self.clipsToBounds = true
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(gestureRecognizer:)))
@ -66,19 +87,25 @@ class ReminderView: UIView {
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
label.autoPinEdge(toSuperviewEdge: .top)
label.autoPinEdge(toSuperviewEdge: .left)
label.autoPinLeadingToSuperviewMargin()
label.autoPinEdge(toSuperviewEdge: .bottom)
label.textColor = UIColor.black.withAlphaComponent(0.9)
guard mode == .nag else {
label.autoPinTrailingToSuperviewMargin()
return
}
// Icon
let iconImage = #imageLiteral(resourceName: "system_disclosure_indicator").withRenderingMode(.alwaysTemplate)
let iconName = (self.isRTL() ? "system_disclosure_indicator_rtl" : "system_disclosure_indicator")
let iconImage = UIImage(named: iconName)?.withRenderingMode(.alwaysTemplate)
let iconView = UIImageView(image: iconImage)
iconView.contentMode = .scaleAspectFit
iconView.tintColor = UIColor.black.withAlphaComponent(0.6)
container.addSubview(iconView)
iconView.autoPinEdge(toSuperviewEdge: .right)
iconView.autoPinEdge(.left, to: .right, of: label, withOffset: 28)
iconView.autoPinLeading(toTrailingEdgeOf: label, offset: 28)
iconView.autoPinTrailingToSuperviewMargin()
iconView.autoVCenterInSuperview()
iconView.autoSetDimension(.width, toSize: 13)
}

View File

@ -894,7 +894,7 @@
"IN_CALL_TERMINATED" = "Call Ended.";
/* Label reminding the user that they are in archive mode. */
"INBOX_VIEW_ARCHIVE_MODE_REMINDER" = "You are viewing your archived messages. Tap to return to your Inbox.";
"INBOX_VIEW_ARCHIVE_MODE_REMINDER" = "These conversations are archived. They will appear in the inbox if new messages are received.";
/* Multi-line label explaining how to show names instead of phone numbers in your inbox */
"INBOX_VIEW_MISSING_CONTACTS_PERMISSION" = "To see the names of your contacts, update your system settings to allow contact access.";