Commit cb73a2cb authored by Anthony Léonard's avatar Anthony Léonard Committed by Kateryna Kostiuk

hide list type selector when no requests in list

The whole selector is hidden when no requests are pending for a given
account. In this case, only conversation list is displayed.

When it needs to be visible again, we re-add it to the view with its
constraints.

Also diminish potential number of data reloads in smartview by moving
some code.

Change-Id: Ib00aa8b59a70e65015f9c28402278054b591522d
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent d00cd180
/*
* Copyright (C) 2015-2016 Savoir-faire Linux Inc.
* Copyright (C) 2015-2018 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
......@@ -53,7 +53,8 @@
//UI elements
__unsafe_unretained IBOutlet RingTableView* smartView;
__unsafe_unretained IBOutlet NSSearchField* searchField;
__unsafe_unretained IBOutlet NSSegmentedControl *listTypeSelector;
__strong IBOutlet NSSegmentedControl *listTypeSelector;
bool selectorIsPresent;
QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_;
......@@ -107,6 +108,7 @@ NSInteger const REQUEST_SEG = 1;
[searchField.layer setBackgroundColor:[NSColor colorWithCalibratedRed:0.949 green:0.949 blue:0.949 alpha:0.9].CGColor];
currentFilterType = lrc::api::profile::Type::RING;
selectorIsPresent = true;
}
- (void)placeCall:(id)sender
......@@ -126,17 +128,40 @@ NSInteger const REQUEST_SEG = 1;
-(void) reloadData
{
[smartView deselectAll:nil];
[smartView reloadData];
if (!model_->owner.contactModel->hasPendingRequests()) {
if (currentFilterType == lrc::api::profile::Type::PENDING) {
[self selectConversationList];
}
[listTypeSelector setEnabled:NO forSegment:REQUEST_SEG];
if (selectorIsPresent) {
[listTypeSelector removeFromSuperview];
selectorIsPresent = false;
}
} else {
[listTypeSelector setEnabled:YES forSegment:REQUEST_SEG];
if (!selectorIsPresent) {
// First we restore the selector with selection on "Conversations"
[self.view addSubview:listTypeSelector];
[listTypeSelector setSelected:YES forSegment:CONVERSATION_SEG];
// Then constraints are recreated (as these are lost when calling removeFromSuperview)
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[searchField]-8-[listTypeSelector]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(searchField, listTypeSelector)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[listTypeSelector]-8-[tabbar]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(listTypeSelector, tabbar)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[listTypeSelector]-20-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(listTypeSelector)]];
selectorIsPresent = true;
}
}
[smartView reloadData];
if (!selectedUid_.empty() && model_ != nil) {
auto it = getConversationFromUid(selectedUid_, *model_);
if (it != model_->allFilteredConversations().end()) {
......@@ -155,11 +180,11 @@ NSInteger const REQUEST_SEG = 1;
if (model_ != conversationModel) {
model_ = conversationModel;
selectedUid_.clear(); // Clear selected conversation as the selected account is being changed
[self reloadData];
QObject::disconnect(modelSortedConnection_);
QObject::disconnect(filterChangedConnection_);
QObject::disconnect(newConversationConnection_);
QObject::disconnect(conversationRemovedConnection_);
[self reloadData];
if (model_ != nil) {
modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted,
[self] (){
......
......@@ -286,6 +286,9 @@
</tabView>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3Nq-Rz-Etg">
<rect key="frame" x="19" y="593" width="286" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="18" id="OFJ-Ud-WD3"/>
</constraints>
<segmentedCell key="cell" borderStyle="border" alignment="left" segmentDistribution="fillEqually" style="roundRect" trackingMode="selectOne" id="6T7-ip-Pun">
<font key="font" metaFont="cellTitle"/>
<segments>
......@@ -312,6 +315,7 @@
<constraints>
<constraint firstAttribute="trailing" secondItem="PoQ-x4-ES3" secondAttribute="trailing" constant="20" id="4sB-9A-dhz"/>
<constraint firstItem="PoQ-x4-ES3" firstAttribute="leading" secondItem="YgH-CN-tkB" secondAttribute="leading" constant="20" id="9e0-oX-skE"/>
<constraint firstItem="xXW-iq-GcP" firstAttribute="top" secondItem="PoQ-x4-ES3" secondAttribute="bottom" priority="900" constant="8" id="ESF-pw-bYW"/>
<constraint firstItem="3Nq-Rz-Etg" firstAttribute="leading" secondItem="YgH-CN-tkB" secondAttribute="leading" constant="20" id="ETk-YV-FSi"/>
<constraint firstAttribute="bottom" secondItem="xXW-iq-GcP" secondAttribute="bottom" id="MYN-Zf-Bvk"/>
<constraint firstAttribute="trailing" secondItem="xXW-iq-GcP" secondAttribute="trailing" id="TXC-lN-yL8"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment