Skip to content

Commit

Permalink
Merge pull request #190 from sparcs-kaist/bug@annoying-channeltalk-fl…
Browse files Browse the repository at this point in the history
…oating-button

Resolve #187, implement buttonOptions
  • Loading branch information
happycastle114 authored Sep 13, 2024
2 parents 7e18694 + 127f809 commit 7c9b56d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 29 deletions.
5 changes: 3 additions & 2 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"throw_test": "Throw Test Exception",
"throw_test_desc": "for testing firebase crashlytics",
"about": "About",
"view_licenses": "View Licenses"
"view_licenses": "View Licenses",
"show_channel_talk_button": "Show Channel Talk Button"
},
"department": {
"department": "Dept.",
Expand Down Expand Up @@ -230,4 +231,4 @@
"dont_show_again": "Don't Show Again",
"join_the_event": "Join the Event"
}
}
}
5 changes: 3 additions & 2 deletions assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"throw_test": "테스트 오류 발생",
"throw_test_desc": "Firebase crashlytics 테스트용",
"about": "정보",
"view_licenses": "라이선스 보기"
"view_licenses": "라이선스 보기",
"show_channel_talk_button": "채널톡 버튼 표시하기"
},
"department": {
"department": "학과",
Expand Down Expand Up @@ -231,4 +232,4 @@
"dont_show_again": "다시 보지 않기",
"join_the_event": "이벤트 참여하러 가기"
}
}
}
14 changes: 0 additions & 14 deletions ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved

This file was deleted.

6 changes: 3 additions & 3 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import ChannelIOFront
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ChannelIO.initialize(application)
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
ChannelIO.initialize(application)
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
11 changes: 6 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ void main() {
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;

await ChannelTalk.boot(
pluginKey: '0abc4b50-9e66-4b45-b910-eb654a481f08', // Required
memberHash: token,
language: Language.korean,
appearance: Appearance.light,
);
pluginKey: '0abc4b50-9e66-4b45-b910-eb654a481f08', // Required
memberHash: token,
language: Language.korean,
appearance: Appearance.light,
channelButtonOption: ChannelButtonOption(
position: ChannelButtonPosition.right, xMargin: 16, yMargin: 130));

await ChannelTalk.initPushToken(deviceToken: token ?? "");

Expand Down
20 changes: 20 additions & 0 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:easy_localization/easy_localization.dart';
import 'package:channel_talk_flutter/channel_talk_flutter.dart';

class SettingsPage extends StatelessWidget {
@override
Expand Down Expand Up @@ -107,6 +108,25 @@ class SettingsPage extends StatelessWidget {
),
),
),
_buildListTile(
title: "settings.show_channel_talk_button".tr(),
trailing: CupertinoSwitch(
value: context
.watch<SettingsModel>()
.getShowsChannelTalkButton(),
onChanged: (value) {
context
.read<SettingsModel>()
.setShowsChannelTalkButton(value);

if (!value) {
ChannelTalk.hideChannelButton();
} else {
ChannelTalk.showChannelButton();
}
},
),
),
Visibility(
visible: kDebugMode,
child: _buildListTile(
Expand Down
13 changes: 13 additions & 0 deletions lib/providers/settings_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'package:shared_preferences/shared_preferences.dart';

final _kSendCrashlytics = 'sendCrashlytics';
final _kSendCrashlyticsAnonymously = 'sendCrashlyticsAnonymously';
final _kShowsChannelTalkButton = 'showsChannelTalkButton';

class SettingsModel extends ChangeNotifier {
late bool _sendCrashlytics;
late bool _sendCrashlyticsAnonymously;
late bool _showsChannelTalkButton;

bool getSendCrashlytics() => _sendCrashlytics;
void setSendCrashlytics(bool newValue) {
Expand All @@ -24,6 +26,14 @@ class SettingsModel extends ChangeNotifier {
(instance) => instance.setBool(_kSendCrashlyticsAnonymously, newValue));
}

bool getShowsChannelTalkButton() => _showsChannelTalkButton;
void setShowsChannelTalkButton(bool newValue) {
_showsChannelTalkButton = newValue;
notifyListeners();
SharedPreferences.getInstance().then(
(instance) => instance.setBool(_kShowsChannelTalkButton, newValue));
}

SettingsModel({bool forTest = false}) {
SharedPreferences.getInstance().then((instance) {
getAllValues(instance);
Expand All @@ -32,13 +42,16 @@ class SettingsModel extends ChangeNotifier {
if (forTest) {
_sendCrashlytics = true;
_sendCrashlyticsAnonymously = false;
_showsChannelTalkButton = true;
}
}

getAllValues(SharedPreferences instance) {
_sendCrashlytics = instance.getBool(_kSendCrashlytics) ?? true;
_sendCrashlyticsAnonymously =
instance.getBool(_kSendCrashlyticsAnonymously) ?? false;
_showsChannelTalkButton =
instance.getBool(_kShowsChannelTalkButton) ?? true;
notifyListeners();
}

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ packages:
description:
path: "."
ref: main
resolved-ref: d90abf1380f5d61ae035ca63f53421a640fa4498
url: "https://github.com/happycastle114/channel_talk_flutter.git"
resolved-ref: "6090bc7f6b2ca047b69a85b213e9a81004e2c923"
url: "https://github.com/happycastle114/channel_talk_flutter"
source: git
version: "3.1.3"
characters:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies:
firebase_crashlytics: ^4.0.4
channel_talk_flutter:
git:
url: https://github.com/happycastle114/channel_talk_flutter.git
url: https://github.com/happycastle114/channel_talk_flutter
ref: main

firebase_messaging: ^15.0.4
Expand Down

0 comments on commit 7c9b56d

Please sign in to comment.