Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Expose backgroundImage API

  • Loading branch information
Tim Palade authored and mahmoud-adam85 committed May 11, 2018
1 parent 37cfdc8 commit 74d903df9c7ca9b78b5c86b0fc099ac167e4cdfe
@@ -512,6 +512,7 @@
AFA9FB0D208E135E0028CA1B /* ControlCenterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA9FB0C208E135E0028CA1B /* ControlCenterDelegate.swift */; };
AFE484D32056838500554B2E /* CliqzURLBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFE484D22056838500554B2E /* CliqzURLBar.swift */; };
AFF2874E209B54F6001E9B59 /* CliqzHomePanels.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFF2874D209B54F6001E9B59 /* CliqzHomePanels.swift */; };
AFF28766209B5F6E001E9B59 /* ImageExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFF28765209B5F6E001E9B59 /* ImageExtension.swift */; };
C400467C1CF4E43E00B08303 /* BackForwardListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C400467B1CF4E43E00B08303 /* BackForwardListViewController.swift */; };
C40046FA1CF8E0B200B08303 /* BackForwardListAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40046F91CF8E0B200B08303 /* BackForwardListAnimator.swift */; };
C45F44691D087DB600CB7EF0 /* TopTabsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45F44681D087DB600CB7EF0 /* TopTabsViewController.swift */; };
@@ -1977,6 +1978,7 @@
AFE484D22056838500554B2E /* CliqzURLBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CliqzURLBar.swift; sourceTree = "<group>"; };
AFECF63AADEF4013C5D72D77 /* Pods-Client.firefox.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Client.firefox.xcconfig"; path = "Pods/Target Support Files/Pods-Client/Pods-Client.firefox.xcconfig"; sourceTree = "<group>"; };
AFF2874D209B54F6001E9B59 /* CliqzHomePanels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CliqzHomePanels.swift; sourceTree = "<group>"; };
AFF28765209B5F6E001E9B59 /* ImageExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageExtension.swift; sourceTree = "<group>"; };
C400467B1CF4E43E00B08303 /* BackForwardListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackForwardListViewController.swift; sourceTree = "<group>"; };
C40046F91CF8E0B200B08303 /* BackForwardListAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackForwardListAnimator.swift; sourceTree = "<group>"; };
C45F44681D087DB600CB7EF0 /* TopTabsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopTabsViewController.swift; sourceTree = "<group>"; };
@@ -3299,6 +3301,7 @@
AFA9FACB208DFD790028CA1B /* ArrayExtensions.swift */,
AFA9FB0A208E04FA0028CA1B /* DictionaryExtensions.swift */,
AF77B88D209A022A00E7A0C4 /* NSData+GZIP.swift */,
AFF28765209B5F6E001E9B59 /* ImageExtension.swift */,
);
path = Extensions;
sourceTree = "<group>";
4F30F52520517A6B0049E4F6 /* ClickableUITableViewCell.swift in Sources */,
E6CF28E71CB43B7900151AB3 /* SensitiveViewController.swift in Sources */,
1EEA36ED2067DD70003B6AD5 /* VideoDownloader.swift in Sources */,
AFF28766209B5F6E001E9B59 /* ImageExtension.swift in Sources */,
E68E7ADA1CAC207400FDCA76 /* ChangePasscodeViewController.swift in Sources */,
E640E85E1C73A45A00C5F072 /* PasscodeEntryViewController.swift in Sources */,
8D8251811F4DE67F00780643 /* AdvanceAccountSettingViewController.swift in Sources */,
@@ -0,0 +1,34 @@
//
// ImageExtension.swift
// Client
//
// Created by Tim Palade on 5/3/18.
// Copyright © 2018 Cliqz. All rights reserved.
//
import UIKit

extension UIImage {
static func cliqzBackgroundImage() -> UIImage? {

let (device, orientation) = UIDevice.current.getDeviceAndOrientation()

switch device {
case .iPhone:
if orientation == .portrait {
return UIImage(named: "iPhonePortrait")
}
return UIImage(named: "iPhoneLandscape")
case .iPhoneX:
if orientation == .portrait {
return UIImage(named: "iPhoneXPortrait")
}
return UIImage(named: "iPhoneXLandscape")
case .iPad:
if orientation == .portrait {
return UIImage(named: "iPadPortrait")
}
return UIImage(named: "iPadLandscape")
}
}
}
@@ -8,6 +8,17 @@
import Foundation

public enum DeviceType {
case iPhone
case iPhoneX
case iPad
}

public enum DeviceOrientation {
case portrait
case landscape
}

public extension UIDevice {

var modelName: String {
@@ -93,4 +104,29 @@ public extension UIDevice {
return UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height
}
}

func getDeviceAndOrientation() -> (DeviceType, DeviceOrientation) {

let device: DeviceType

if self.isiPad() {
device = .iPad
}
else if self.isiPhoneXDevice() {
device = .iPhoneX
}
else {
device = .iPhone
}

var orientation: DeviceOrientation = .portrait

if let window = UIApplication.shared.delegate?.window as? UIWindow {
if window.frame.height < window.frame.width {
orientation = .landscape
}
}

return (device, orientation)
}
}
@@ -52,17 +52,6 @@ class CliqzHomePanelViewController: UIViewController, UITextFieldDelegate {
fileprivate let segmentedControl: UISegmentedControl
fileprivate let controllerContainerView: UIView = UIView()

enum DeviceType {
case iPhone
case iPhoneX
case iPad
}

enum DeviceOrientation {
case portrait
case landscape
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {

self.panels = CliqzHomePanels().enabledPanels
@@ -124,8 +113,7 @@ class CliqzHomePanelViewController: UIViewController, UITextFieldDelegate {
}

func setBackgroundImage() {
let (device, orientation) = getDeviceAndOrientation()
backgroundView.image = image(device: device, orientation: orientation)
backgroundView.image = UIImage.cliqzBackgroundImage()
}

}
@@ -169,52 +157,6 @@ extension CliqzHomePanelViewController {
@objc func orientationDidChange(_ notification: Notification) {
setBackgroundImage()
}

func getDeviceAndOrientation() -> (DeviceType, DeviceOrientation) {

let device: DeviceType

if UIDevice.current.isiPad() {
device = .iPad
}
else if UIDevice.current.isiPhoneXDevice() {
device = .iPhoneX
}
else {
device = .iPhone
}

let orientation: DeviceOrientation

if view.frame.height > view.frame.width {
orientation = .portrait
}
else {
orientation = .landscape
}

return (device, orientation)
}

func image(device: DeviceType, orientation: DeviceOrientation) -> UIImage? {
switch device {
case .iPhone:
if orientation == .portrait {
return UIImage(named: "iPhonePortrait")
}
return UIImage(named: "iPhoneLandscape")
case .iPhoneX:
if orientation == .portrait {
return UIImage(named: "iPhoneXPortrait")
}
return UIImage(named: "iPhoneXLandscape")
case .iPad:
if orientation == .portrait {
return UIImage(named: "iPadPortrait")
}
return UIImage(named: "iPadLandscape")
}
}
}

extension CliqzHomePanelViewController: HomePanelDelegate {

0 comments on commit 74d903d

Please sign in to comment.