Browse Source

Improved layout switching

Closes #619
Closes #710
master
Igor Zhukov 10 years ago
parent
commit
64248e2938
  1. 7
      app/js/controllers.js
  2. 7
      app/js/init.js
  3. 1
      app/js/locales/en-us.json
  4. 24
      app/js/services.js
  5. 6
      app/partials/mobile/settings_modal.html

7
app/js/controllers.js

@ -2517,7 +2517,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2517,7 +2517,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
})
.controller('SettingsModalController', function ($rootScope, $scope, $timeout, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, Storage, NotificationsManager, MtpApiFileManager, ApiUpdatesManager, ChangelogNotifyService, AppRuntimeManager, ErrorService, _) {
.controller('SettingsModalController', function ($rootScope, $scope, $timeout, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, Storage, NotificationsManager, MtpApiFileManager, ApiUpdatesManager, ChangelogNotifyService, LayoutSwitchService, AppRuntimeManager, ErrorService, _) {
$scope.profile = {};
$scope.photo = {};
@ -2718,6 +2718,11 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2718,6 +2718,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
});
})
};
$scope.switchBackToDesktop = Config.Mobile && !Config.Navigator.mobile;
$scope.switchToDesktop = function () {
LayoutSwitchService.switchLayout(false);
};
})
.controller('ChangelogModalController', function ($scope, $modal) {

7
app/js/init.js

@ -72,7 +72,7 @@ @@ -72,7 +72,7 @@
}
$(document.body).addClass(classes.join(' '));
ConfigStorage.get('current_layout', 'i18n_locale', function (params) {
ConfigStorage.get('layout_selected', 'i18n_locale', function (params) {
var layout = params[0],
locale = params[1],
defaultLocale = 'en-us',
@ -91,7 +91,7 @@ @@ -91,7 +91,7 @@
}
}
if (ready) {
bootReady.boot = false;
bootReady.boot = false;
angular.bootstrap(document, ['myApp']);
}
};
@ -100,7 +100,8 @@ @@ -100,7 +100,8 @@
case 'mobile': Config.Mobile = true; break;
case 'desktop': Config.Mobile = false; break;
default:
Config.Mobile = Config.Navigator.mobile || $(window).width() < 480;
var width = $(window).width();
Config.Mobile = Config.Navigator.mobile || width > 10 && width < 480;
break;
}
$('head').append(

1
app/js/locales/en-us.json

@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
"settings_modal_enter_send_description_md": "**Enter** - send message, **Shift + Enter** - new line",
"settings_modal_ctrl_enter_send_description_md": "**Ctrl + Enter** - send message, **Enter** - new line",
"settings_modal_send_on_enter": "Send on Enter",
"settings_switch_back_to_desktop": "Switch back to Desktop layout",
"settings_modal_about": "About",
"settings_modal_source_code_github": "Source code on GitHub",
"settings_modal_follow_us_twitter": "Follow us on Twitter!",

24
app/js/services.js

@ -4706,9 +4706,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4706,9 +4706,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var confirmShown = false;
function switchLayout(mobile) {
ConfigStorage.noPrefix();
Storage.set({
current_layout: mobile ? 'mobile' : 'desktop',
layout_confirmed: {width: $(window).width(), mobile: mobile}
layout_selected: mobile ? 'mobile' : 'desktop',
layout_width: $(window).width()
}).then(function () {
AppRuntimeManager.reload();
});
@ -4719,28 +4720,25 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4719,28 +4720,25 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return;
}
var width = $(window).width();
if (!e && Config.Mobile && width <= 800) {
var newMobile = width < 600;
if (!width ||
!e && (Config.Navigator.mobile ? width <= 800 : newMobile)) {
return;
}
var newMobile = width < 600;
if (newMobile != Config.Mobile) {
Storage.get('layout_confirmed').then(function (result) {
if (result &&
(result.mobile
? width == result.width
: width == result.width
)
) {
ConfigStorage.noPrefix();
Storage.get('layout_width').then(function (confirmedWidth) {
if (width == confirmedWidth) {
return false;
}
confirmShown = true;
ErrorService.confirm({
type: newMobile ? 'SWITCH_MOBILE_VERSION' : 'SWITCH_DESKTOP_VERSION'
}).then(function () {
Storage.remove('layout_confirmed');
switchLayout(newMobile);
}, function () {
Storage.set({layout_confirmed: {width: width, mobile: Config.Mobile}});
ConfigStorage.noPrefix();
Storage.set({layout_width: width});
confirmShown = false;
});
});

6
app/partials/mobile/settings_modal.html

@ -134,6 +134,12 @@ @@ -134,6 +134,12 @@
</div>
</div>
<div class="mobile_modal_section" ng-if="switchBackToDesktop">
<div class="mobile_modal_section_value">
<a href="" ng-click="switchToDesktop()" my-i18n="settings_switch_back_to_desktop"></a>
</div>
</div>
<div class="mobile_modal_section">
<h4 class="mobile_modal_section_header" my-i18n="settings_modal_about"></h4>
<div class="mobile_modal_section_body settings_about_section_body clearfix">

Loading…
Cancel
Save