Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Support dark mode for settings view
Browse files Browse the repository at this point in the history
  • Loading branch information
haoict committed Apr 26, 2020
1 parent d95cf2e commit 0008c66
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 28 deletions.
5 changes: 3 additions & 2 deletions control
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ Package: com.haoict.messengernoads-beta
Name: Messenger No Ads Beta
Depends: mobilesubstrate, firmware (>= 10)
Conflicts: com.haoict.messengernoads
Version: 3.0.0~b1
Version: 3.0.0~b3
Architecture: iphoneos-arm
Description: The best tweak for Messenger app.
The best tweak for Messenger app.
* Tap on your profile picture on top right of the screen to access settings
Features:
- Hide Ads on Messenger app
- Disable Read Receipt (Support Control Center to quick turn on/off)
- Disable Read Receipt
- Disable Typing Indicator
- Disable Story Seen Receipt
- Can Save Friend's Story
Expand Down
Binary file not shown.
Binary file not shown.
13 changes: 7 additions & 6 deletions settingsview/MNASettingsViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "MNASettingsViewController.h"

#define TABLE_BACKGROUND_COLOR "#EFEFF4"
#define TABLE_BACKGROUND_COLOR_DARKMODE "#000000"

@implementation MNASettingsViewController
- (id)init {
Expand Down Expand Up @@ -43,11 +44,11 @@ - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// set switches color
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
self.view.tintColor = kTintColor;
keyWindow.tintColor = kTintColor;
[UISwitch appearanceWhenContainedInInstancesOfClasses:@[self.class]].onTintColor = kTintColor;
self.view.tintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
keyWindow.tintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
[UISwitch appearanceWhenContainedInInstancesOfClasses:@[self.class]].onTintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
// set navigation bar color
self.navigationController.navigationBar.barTintColor = kTintColor;
self.navigationController.navigationBar.barTintColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @KTINT_COLOR_DARKMODE : @KTINT_COLOR];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar setShadowImage: [UIImage new]];
self.navigationController.navigationController.navigationBar.translucent = NO;
Expand All @@ -59,7 +60,7 @@ - (void)viewWillAppear:(BOOL)animated {
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
keyWindow.tintColor = [UIColor blackColor]; // should be nil for default, but Messenger uses black
keyWindow.tintColor = [MNAUtil isDarkMode] ? [UIColor whiteColor] : [UIColor blackColor]; // should be nil for default, but Messenger uses black/white
self.navigationController.navigationBar.barTintColor = nil;
self.navigationController.navigationBar.tintColor = nil;
[self.navigationController.navigationBar setShadowImage:nil];
Expand All @@ -81,7 +82,7 @@ - (void)viewDidLoad {
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.alwaysBounceVertical = NO;
_tableView.backgroundColor = [MNAUtil colorFromHex:@TABLE_BACKGROUND_COLOR];
_tableView.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @TABLE_BACKGROUND_COLOR_DARKMODE : @TABLE_BACKGROUND_COLOR];
[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.view addSubview:_tableView];

Expand Down
39 changes: 20 additions & 19 deletions settingsview/MNATableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#define LABEL_COLOR "#333333"
#define SUBTITLE_COLOR "#828282"
#define STATIC_BACKGROUND_COLOR "#EFEFF4"
#define CELL_BACKGROUND_COLOR "#FFFFFF"

#define LABEL_COLOR_DARKMODE "#F2F2F2"
#define SUBTITLE_COLOR_DARKMODE "#888888"
#define STATIC_BACKGROUND_COLOR_DARKMODE "#000000"
#define CELL_BACKGROUND_COLOR_DARKMODE "#1C1C1C"

#define STATIC_FONT_SIZE 13.0

@implementation MNATableViewCell
Expand All @@ -14,10 +21,10 @@ - (id)initWithData:(MNACellModel *)cellData reuseIdentifier:(NSString *)reuseIde

if (self) {
self.textLabel.text = cellData.label;
self.textLabel.textColor = [MNAUtil colorFromHex:@LABEL_COLOR];
self.textLabel.textColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @LABEL_COLOR_DARKMODE : @LABEL_COLOR];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.detailTextLabel.text = cellData.subtitle;
self.detailTextLabel.textColor = [MNAUtil colorFromHex:@SUBTITLE_COLOR];
self.detailTextLabel.textColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @SUBTITLE_COLOR_DARKMODE : @SUBTITLE_COLOR];
if (cellData.disabled) {
self.userInteractionEnabled = NO;
self.textLabel.enabled = NO;
Expand All @@ -38,7 +45,7 @@ - (id)initWithData:(MNACellModel *)cellData reuseIdentifier:(NSString *)reuseIde

case StaticText: {
self.textLabel.font=[UIFont systemFontOfSize:STATIC_FONT_SIZE];
self.contentView.backgroundColor = [MNAUtil colorFromHex:@STATIC_BACKGROUND_COLOR];
self.contentView.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @STATIC_BACKGROUND_COLOR_DARKMODE : @STATIC_BACKGROUND_COLOR];
break;
}

Expand All @@ -64,23 +71,23 @@ - (void)prepareForReuse {

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
if (self.selectionStyle != UITableViewCellSelectionStyleNone) {
if (highlighted) {
self.contentView.superview.backgroundColor = [kTintColor colorWithAlphaComponent:0.3];
} else {
self.contentView.superview.backgroundColor = [UIColor whiteColor];
if (highlighted) {
if (self.selectionStyle != UITableViewCellSelectionStyleNone) {
self.contentView.superview.backgroundColor = [[MNAUtil colorFromHex:@KTINT_COLOR] colorWithAlphaComponent:0.3];
}
} else {
self.contentView.superview.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @CELL_BACKGROUND_COLOR_DARKMODE : @CELL_BACKGROUND_COLOR];
}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (self.selectionStyle != UITableViewCellSelectionStyleNone) {
if (selected) {
self.contentView.superview.backgroundColor = [kTintColor colorWithAlphaComponent:0.3];
} else {
self.contentView.superview.backgroundColor = [UIColor whiteColor];
if (selected) {
if (self.selectionStyle != UITableViewCellSelectionStyleNone) {
self.contentView.superview.backgroundColor = [[MNAUtil colorFromHex:@KTINT_COLOR] colorWithAlphaComponent:0.3];
}
} else {
self.contentView.superview.backgroundColor = [MNAUtil colorFromHex:[MNAUtil isDarkMode] ? @CELL_BACKGROUND_COLOR_DARKMODE : @CELL_BACKGROUND_COLOR];
}
}

Expand Down Expand Up @@ -125,10 +132,4 @@ - (void)loadSwitcher {
switchView.enabled = NO;
}
}

// - (void)resetSettings:(id)sender {
// [@{} writeToFile:@PLIST_PATH atomically:YES];
// [self reloadSpecifiers];
// notify_post(PREF_CHANGED_NOTIF);
// }
@end
5 changes: 4 additions & 1 deletion settingsview/MNAUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define PREF_BUNDLE_PATH "/Library/Application Support/MessengerNoAds.bundle"
#define PLIST_FILENAME "com.haoict.messengernoadspref.plist"
#define PREF_CHANGED_NOTIF "com.haoict.messengernoadspref/PrefChanged"
#define kTintColor [UIColor colorWithRed:0.72 green:0.53 blue:1.00 alpha:1.00]
#define KTINT_COLOR "#B787FF" // [UIColor colorWithRed:0.72 green:0.53 blue:1.00 alpha:1.00]
#define KTINT_COLOR_DARKMODE "#B787FF" // don't know what looks good, better let it be the same with white mode

@interface NSTask : NSObject
@property (copy) NSArray *arguments;
Expand All @@ -29,4 +30,6 @@
+ (NSString *)localizedItem:(NSString *)key;
+ (UIColor *)colorFromHex:(NSString *)hexString;
+ (void)showAlertMessage:(NSString *)message title:(NSString *)title viewController:(id)vc;
+ (BOOL)isDarkMode;
+ (BOOL)isiPad;
@end
15 changes: 15 additions & 0 deletions settingsview/MNAUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,19 @@ + (void)showAlertMessage:(NSString *)message title:(NSString *)title viewControl
[vc presentViewController:alert animated:YES completion:nil];
}
}

+ (BOOL)isDarkMode {
if (@available(iOS 12.0, *)) {
if(UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark){
return TRUE;
}else{
return FALSE;
}
}
return FALSE;
}

+ (BOOL)isiPad {
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
}
@end

0 comments on commit 0008c66

Please sign in to comment.