Skip to content

Commit

Permalink
likes now persist also i added library page (nonfunctional)
Browse files Browse the repository at this point in the history
  • Loading branch information
llsc12 committed Mar 14, 2022
1 parent 9ec880d commit 48c31f5
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 135 deletions.
120 changes: 106 additions & 14 deletions WatchTube WatchKit App/Base.lproj/Interface.storyboard
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="20037" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
<device id="watch40"/>
<device id="watch45"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="20006"/>
Expand Down Expand Up @@ -133,12 +133,81 @@
<outlet property="input" destination="1zg-ds-dvO" id="RNJ-wO-ogg"/>
<outlet property="searchTermsTableRow" destination="gHE-tu-0fR" id="8B7-45-kiL"/>
<outlet property="tableLabel" destination="tgW-SH-kLJ" id="yG8-8z-ENY"/>
<segue destination="BVh-TY-jCX" kind="relationship" relationship="nextPage" id="5PW-4x-gfP"/>
<segue destination="YgX-XY-IDf" kind="relationship" relationship="nextPage" id="2Ev-rO-A12"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="-490" y="-620"/>
</scene>
<!--Library-->
<scene sceneID="bkw-8H-NO2">
<objects>
<controller identifier="LibraryInterfaceController" title="Library" id="YgX-XY-IDf" customClass="LibraryInterfaceController" customModule="WatchTube_WatchKit_Extension">
<items>
<button alignment="left" id="mGh-sP-0ge" userLabel="history">
<group key="contentGroup" width="1" height="40" alignment="left" id="SFH-vU-2ML">
<items>
<imageView alignment="left" verticalAlignment="center" image="clock.arrow.circlepath" catalog="system" id="5hr-8E-Vgq"/>
<label alignment="center" verticalAlignment="center" text="History" id="4vy-DY-J0s"/>
</items>
<color key="backgroundColor" red="0.1333208978" green="0.1332592964" blue="0.13741382960000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<edgeInsets key="margins" left="15" right="0.0" top="0.0" bottom="0.0"/>
<variation key="device=watch38mm" height="35"/>
</group>
<connections>
<action selector="history" destination="YgX-XY-IDf" id="9zB-vJ-HNv"/>
</connections>
</button>
<button alignment="left" id="T36-6Y-9Vf" userLabel="likes">
<group key="contentGroup" width="1" height="40" alignment="left" id="NHZ-vx-UMu">
<items>
<imageView alignment="left" verticalAlignment="center" image="hand.thumbsup.circle.fill" catalog="system" id="AiE-u6-4IS"/>
<label alignment="center" verticalAlignment="center" text="Likes" id="k27-7D-Fdy"/>
</items>
<color key="backgroundColor" red="0.1333208978" green="0.1332592964" blue="0.13741382960000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<edgeInsets key="margins" left="15" right="0.0" top="0.0" bottom="0.0"/>
<variation key="device=watch38mm" height="35"/>
</group>
<connections>
<action selector="likes" destination="YgX-XY-IDf" id="m1U-nY-gbK"/>
</connections>
</button>
<button alignment="left" id="mHg-es-pn2" userLabel="collections">
<group key="contentGroup" width="1" height="40" alignment="left" id="LTd-Pk-iRp">
<items>
<imageView alignment="left" verticalAlignment="center" image="rectangle.stack" catalog="system" id="XCQ-o2-pgz"/>
<label alignment="center" verticalAlignment="center" text="Collections" id="NGd-Mb-jng"/>
</items>
<color key="backgroundColor" red="0.1333208978" green="0.1332592964" blue="0.13741382960000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<edgeInsets key="margins" left="15" right="0.0" top="0.0" bottom="0.0"/>
<variation key="device=watch38mm" height="35"/>
</group>
<connections>
<action selector="collections" destination="YgX-XY-IDf" id="TNd-6g-5gg"/>
</connections>
</button>
<button alignment="left" id="sED-we-qzW" userLabel="subscriptions">
<group key="contentGroup" width="1" height="40" alignment="left" id="HS4-3a-Bcp">
<items>
<imageView alignment="left" verticalAlignment="center" image="rectangle.stack.badge.play.fill" catalog="system" id="o3n-kb-nEL"/>
<label alignment="center" verticalAlignment="center" text="Subscriptions" id="Ed1-ST-9Wl"/>
</items>
<color key="backgroundColor" red="0.1333208978" green="0.1332592964" blue="0.13741382960000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<edgeInsets key="margins" left="15" right="0.0" top="0.0" bottom="0.0"/>
<variation key="device=watch38mm" height="35"/>
</group>
<connections>
<action selector="subscriptions" destination="YgX-XY-IDf" id="AOJ-5M-lFB"/>
</connections>
</button>
</items>
<connections>
<segue destination="BVh-TY-jCX" kind="relationship" relationship="nextPage" id="YGs-DF-AKS"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="-282" y="-620"/>
</scene>
<!--Profile-->
<scene sceneID="an7-zY-X1X">
<objects>
Expand Down Expand Up @@ -481,6 +550,34 @@
</objects>
<point key="canvasLocation" x="-490" y="318"/>
</scene>
<!--History-->
<scene sceneID="JwL-VH-gCO">
<objects>
<controller identifier="HistoryInterfaceController" title="History" id="OQr-ks-5sg"/>
</objects>
<point key="canvasLocation" x="-168" y="455"/>
</scene>
<!--Liked Videos-->
<scene sceneID="3a3-oh-jQH">
<objects>
<controller identifier="LikesInterfaceController" title="Liked Videos" id="lFQ-Fi-GNq"/>
</objects>
<point key="canvasLocation" x="14" y="455"/>
</scene>
<!--Collections-->
<scene sceneID="JYk-sp-tFa">
<objects>
<controller identifier="CollectionsInterfaceController" title="Collections" id="bEr-Un-O7R"/>
</objects>
<point key="canvasLocation" x="196" y="455"/>
</scene>
<!--Subscriptions-->
<scene sceneID="yCJ-F0-2vn">
<objects>
<controller identifier="SubscriptionsInterfaceController" title="Subscriptions" id="nAc-yA-hpO"/>
</objects>
<point key="canvasLocation" x="376" y="455"/>
</scene>
<!--About-->
<scene sceneID="Gcs-lM-aa6">
<objects>
Expand Down Expand Up @@ -863,18 +960,9 @@
<button alignment="left" title="About WatchTube" id="4tg-ZH-j2u">
<group key="contentGroup" width="1" height="40" alignment="left" id="KH7-HE-53b">
<items>
<separator alignment="left" id="42C-mQ-0Ik">
<color key="color" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</separator>
<separator alignment="left" id="mlH-j2-vjX">
<color key="color" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</separator>
<separator alignment="left" id="ycE-se-gWi">
<color key="color" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</separator>
<group alignment="left" verticalAlignment="center" radius="17" id="geY-WJ-aO3">
<group alignment="left" verticalAlignment="center" radius="16" id="geY-WJ-aO3">
<items>
<imageView width="35" height="35" alignment="left" verticalAlignment="center" image="WatchTubeDark" contentMode="scaleAspectFit" id="MZf-AX-cKO">
<imageView width="30" height="29" alignment="left" verticalAlignment="center" image="WatchTubeDark" contentMode="scaleAspectFit" id="MZf-AX-cKO">
<variation key="device=watch38mm" height="20" width="20"/>
</imageView>
</items>
Expand All @@ -888,6 +976,7 @@
</label>
</items>
<color key="backgroundColor" name="buttons"/>
<edgeInsets key="margins" left="15" right="0.0" top="0.0" bottom="0.0"/>
<variation key="device=watch38mm" height="35"/>
</group>
<connections>
Expand Down Expand Up @@ -929,7 +1018,7 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="-67" y="-453"/>
<point key="canvasLocation" x="14" y="-453"/>
</scene>
<!--Information-->
<scene sceneID="aTa-mC-Wbf">
Expand Down Expand Up @@ -1637,6 +1726,7 @@
<image name="arrow.up.circle.fill" catalog="system" width="128" height="121"/>
<image name="channelbanner" width="2176" height="360"/>
<image name="channelview" width="396" height="484"/>
<image name="clock.arrow.circlepath" catalog="system" width="128" height="112"/>
<image name="clock.circle.fill" catalog="system" width="128" height="121"/>
<image name="discord" width="556" height="556"/>
<image name="eye.circle.fill" catalog="system" width="128" height="121"/>
Expand All @@ -1654,6 +1744,8 @@
<image name="pfp" width="512" height="512"/>
<image name="play.circle" catalog="system" width="128" height="121"/>
<image name="playlistview" width="396" height="484"/>
<image name="rectangle.stack" catalog="system" width="128" height="121"/>
<image name="rectangle.stack.badge.play.fill" catalog="system" width="128" height="116"/>
<image name="searchrecents" width="396" height="484"/>
<image name="searchresults" width="396" height="484"/>
<image name="settingspage" width="396" height="484"/>
Expand Down
4 changes: 2 additions & 2 deletions WatchTube WatchKit Extension/Models/Classes/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class liked {
}
}

class func unsubscribe(id: String) {
class func unlike(id: String) {
if FileManager.default.fileExists(atPath: NSHomeDirectory()+"/Documents/likes.json") == false {return}
if let array = NSArray(contentsOf: URL(fileURLWithPath: NSHomeDirectory()+"/Documents/likes.json")) {
var mutable = array as! Array<String>
Expand All @@ -151,7 +151,7 @@ class liked {
}
}

class func subscribe(id: String) {
class func like(id: String) {
if FileManager.default.fileExists(atPath: NSHomeDirectory()+"/Documents/likes.json") == false {
NSArray(array: []).write(to: URL(fileURLWithPath: NSHomeDirectory()+"/Documents/likes.json"), atomically: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ class ChannelViewInterfaceController: WKInterfaceController {
case true:
subscriptions.subscribe(udid: udid)
case false:
subscriptions.unsubscribe(udid: udid)
isSubscribed.toggle()
let unsub = WKAlertAction(title: "Unsubscribe", style: .destructive) {
self.isSubscribed.toggle()
subscriptions.unsubscribe(udid: self.udid)
self.updateSubscribeButton(instant: false)
}
let cancel = WKAlertAction(title: "Cancel", style: .cancel) {
//do nothing
self.updateSubscribeButton(instant: false)
}
self.presentAlert(withTitle: "Unsubscribe?", message: "Unsubscribe from \(meta.getChannelInfo(udid: self.udid, key: "name"))?", preferredStyle: .sideBySideButtonsAlert, actions: [cancel, unsub])
}
updateSubscribeButton(instant: false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Foundation
import Alamofire

class InfoInterfaceController: WKInterfaceController {

var isLiked: Bool = false

@IBOutlet weak var viewsIcon: WKInterfaceImage!
@IBOutlet weak var likesIcon: WKInterfaceImage!
@IBOutlet weak var authorIcon: WKInterfaceImage!
Expand All @@ -33,19 +36,25 @@ class InfoInterfaceController: WKInterfaceController {
var videoDetails: Dictionary<String, Any> = [:]
override func awake(withContext context: Any?) {
super.awake(withContext: context)

let data = context as! Dictionary<String, String>
videoId = data["id"]!
quality = data["quality"]!
udid = meta.getVideoInfo(id: videoId, key: "channelId") as! String

if liked.getLikes().contains(videoId) {
isLiked = true
} else {
isLiked = false
}

self.showDescriptionButton.setEnabled(false)
self.likesLabel.setText("Loading Likes")
self.viewsLabel.setText("Loading Views")
self.dateLabel.setText("Loading Date")
self.authorLabel.setText("Loading Channel")

let likes = (meta.getVideoInfo(id: videoId, key: "likes") as! Double).abbreviated
let likes = (meta.getVideoInfo(id: videoId, key: "likes") as! Double + (isLiked ? 1 : 0)).abbreviated
let views = (meta.getVideoInfo(id: videoId, key: "views") as! Double).abbreviated
self.likesLabel.setText("\(likes) Likes")
self.viewsLabel.setText("\(views) Views")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class InterfaceController: WKInterfaceController {
Video.getTrending() { videos in // get trending videos
if videos.count == 0 { // show that there are no videos on trending, also means no internet
// wait for the day when youtube gets rid of trending, then you can change this :)
self.internetLabel.setAlpha(0)
self.reloadButton.setAlpha(0)
self.loader.setAlpha(1)
self.animate(withDuration: 0.3) {
self.internetLabel.setAlpha(1)
self.reloadButton.setAlpha(1)
self.loader.setAlpha(0)
}
self.internetLabel.setHidden(false)
self.reloadButton.setHidden(false)
self.loader.setHidden(true) // hide the spinner
Expand Down Expand Up @@ -97,7 +105,7 @@ class InterfaceController: WKInterfaceController {
// }
// }
// }

func setupTable() -> Void {
TrendingTableRow.setNumberOfRows(videos.count, withRowType: "TrendingRow")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// LibraryInterfaceController.swift
// WatchTube WatchKit Extension
//
// Created by llsc12 on 14/03/2022.
//

import WatchKit
import Foundation


class LibraryInterfaceController: WKInterfaceController {

override func awake(withContext context: Any?) {
super.awake(withContext: context)

// Configure interface objects here.
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

@IBAction func history() {
}
@IBAction func likes() {
}
@IBAction func collections() {
}
@IBAction func subscriptions() {
}
}
Loading

0 comments on commit 48c31f5

Please sign in to comment.