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. 5
      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'])
}) })
.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.profile = {};
$scope.photo = {}; $scope.photo = {};
@ -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) { .controller('ChangelogModalController', function ($scope, $modal) {

5
app/js/init.js

@ -72,7 +72,7 @@
} }
$(document.body).addClass(classes.join(' ')); $(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], var layout = params[0],
locale = params[1], locale = params[1],
defaultLocale = 'en-us', defaultLocale = 'en-us',
@ -100,7 +100,8 @@
case 'mobile': Config.Mobile = true; break; case 'mobile': Config.Mobile = true; break;
case 'desktop': Config.Mobile = false; break; case 'desktop': Config.Mobile = false; break;
default: default:
Config.Mobile = Config.Navigator.mobile || $(window).width() < 480; var width = $(window).width();
Config.Mobile = Config.Navigator.mobile || width > 10 && width < 480;
break; break;
} }
$('head').append( $('head').append(

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

@ -48,6 +48,7 @@
"settings_modal_enter_send_description_md": "**Enter** - send message, **Shift + Enter** - new line", "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_ctrl_enter_send_description_md": "**Ctrl + Enter** - send message, **Enter** - new line",
"settings_modal_send_on_enter": "Send on Enter", "settings_modal_send_on_enter": "Send on Enter",
"settings_switch_back_to_desktop": "Switch back to Desktop layout",
"settings_modal_about": "About", "settings_modal_about": "About",
"settings_modal_source_code_github": "Source code on GitHub", "settings_modal_source_code_github": "Source code on GitHub",
"settings_modal_follow_us_twitter": "Follow us on Twitter!", "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'])
var confirmShown = false; var confirmShown = false;
function switchLayout(mobile) { function switchLayout(mobile) {
ConfigStorage.noPrefix();
Storage.set({ Storage.set({
current_layout: mobile ? 'mobile' : 'desktop', layout_selected: mobile ? 'mobile' : 'desktop',
layout_confirmed: {width: $(window).width(), mobile: mobile} layout_width: $(window).width()
}).then(function () { }).then(function () {
AppRuntimeManager.reload(); AppRuntimeManager.reload();
}); });
@ -4719,28 +4720,25 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return; return;
} }
var width = $(window).width(); var width = $(window).width();
if (!e && Config.Mobile && width <= 800) { var newMobile = width < 600;
if (!width ||
!e && (Config.Navigator.mobile ? width <= 800 : newMobile)) {
return; return;
} }
var newMobile = width < 600;
if (newMobile != Config.Mobile) { if (newMobile != Config.Mobile) {
Storage.get('layout_confirmed').then(function (result) { ConfigStorage.noPrefix();
if (result && Storage.get('layout_width').then(function (confirmedWidth) {
(result.mobile if (width == confirmedWidth) {
? width == result.width
: width == result.width
)
) {
return false; return false;
} }
confirmShown = true; confirmShown = true;
ErrorService.confirm({ ErrorService.confirm({
type: newMobile ? 'SWITCH_MOBILE_VERSION' : 'SWITCH_DESKTOP_VERSION' type: newMobile ? 'SWITCH_MOBILE_VERSION' : 'SWITCH_DESKTOP_VERSION'
}).then(function () { }).then(function () {
Storage.remove('layout_confirmed');
switchLayout(newMobile); switchLayout(newMobile);
}, function () { }, function () {
Storage.set({layout_confirmed: {width: width, mobile: Config.Mobile}}); ConfigStorage.noPrefix();
Storage.set({layout_width: width});
confirmShown = false; confirmShown = false;
}); });
}); });

6
app/partials/mobile/settings_modal.html

@ -134,6 +134,12 @@
</div> </div>
</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"> <div class="mobile_modal_section">
<h4 class="mobile_modal_section_header" my-i18n="settings_modal_about"></h4> <h4 class="mobile_modal_section_header" my-i18n="settings_modal_about"></h4>
<div class="mobile_modal_section_body settings_about_section_body clearfix"> <div class="mobile_modal_section_body settings_about_section_body clearfix">

Loading…
Cancel
Save