Skip to content
3 changes: 3 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"please_enter_the_posting_key": "Please enter the posting key",
"username": "username",
"posting_key": "posting key",
"poll_vote": "Vote",
"poll_voted": "voted",
"poll_revote": "Revote",
"no_threads_found": "No threads found",
"age_limit": "\u2022 Only accounts older than {} days allowed",
"interpretation_token": "\u2022 User HP based vote interpretation",
Expand Down
34 changes: 23 additions & 11 deletions lib/core/locales/locale_text.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import 'package:easy_localization/easy_localization.dart';

class LocaleText {
static String isAddedToYourBookmarks(String content) =>"is_added_to_your_bookmarks".tr(args: [content]);
static String isRemovedToYourBookmarks(String content) => "is_removed_from_your_bookmarks".tr(args: [content]);
static String successfullLoginMessage(String content) => "successfull_login_message".tr(args: [content]);
static String isAddedToYourBookmarks(String content) =>
"is_added_to_your_bookmarks".tr(args: [content]);
static String isRemovedToYourBookmarks(String content) =>
"is_removed_from_your_bookmarks".tr(args: [content]);
static String successfullLoginMessage(String content) =>
"successfull_login_message".tr(args: [content]);
static String get notLoggedIn => "not_logged_in".tr();
static String get pleaseLoginFirst => "please_login_first".tr();
static String get cancel => "cancel".tr();
static const String login = "login";
static const String login = "login";
static String get bookmarks => "bookmarks".tr();
static String get darkMode => "dark_mode".tr();
static String get lightMode => "light_mode".tr();
static String get logOut => "log_out".tr();
static String get scanTapQRCode => "scan_tap_qr_code".tr();
static String get authorizeThisRequestWithKeyChainForHiveApp => "authorize_this_request_with_keychain_for_hive_app".tr();
static String get timeoutTimerForHiveAuthQr => "timeout_timer_for_hiveAuth_qr".tr();
static String get sorryWeAreUnableToReachOurServer => "sorry_we_are_unable_to_reach_our_server".tr();
static String get authorizeThisRequestWithKeyChainForHiveApp =>
"authorize_this_request_with_keychain_for_hive_app".tr();
static String get timeoutTimerForHiveAuthQr =>
"timeout_timer_for_hiveAuth_qr".tr();
static String get sorryWeAreUnableToReachOurServer =>
"sorry_we_are_unable_to_reach_our_server".tr();
static String get tryAgain => "try_again".tr();
static String get replyCannotBeEmpty => "reply_cannot_be_empty".tr();
static String get addAComment => "add_a_comment".tr();
Expand All @@ -31,12 +37,14 @@ class LocaleText {
static String get emHiveAuthTokenMessage => "em_hive_auth_token_message".tr();
static String get emAuthNackMessage => "em_auth_nack_message".tr();
static String get emPostingLoginMessage => "em_posting_login_message".tr();
static String get emCommentDeclineMessage => "em_comment_decline_message".tr();
static String get emCommentDeclineMessage =>
"em_comment_decline_message".tr();
static String get emTimeOutMessage => "em_time_out_message".tr();
static String get emVoteFailureMessage => "em_vote_failure_message".tr();
static String get smHiveAuthLoginMessage => "sm_hive_auth_login_message".tr();
static String get smPostingLoginMessage => "sm_posting_login_message".tr();
static String get smCommentPublishMessage => "sm_comment_publish_message".tr();
static String get smCommentPublishMessage =>
"sm_comment_publish_message".tr();
static String get smVoteSuccessMessage => "sm_vote_success_message".tr();
static String get somethingWentWrong => "something_went_wrong".tr();
static const String loginWithPostingKey = "login_with_posting_key";
Expand All @@ -47,7 +55,11 @@ class LocaleText {
static const String noThreadsFound = "no_threads_found";

//polls realted texts
static String ageLimit (int days) => "age_limit".tr(args: [days.toString()]);
static String ageLimit(int days) => "age_limit".tr(args: [days.toString()]);
static String get interpretationToken => "interpretation_token".tr();
static String maxChoices (int choices) => "max_choices".tr(args: [choices.toString()]);
static String maxChoices(int choices) =>
"max_choices".tr(args: [choices.toString()]);
static String get pollVote => "poll_vote".tr();
static String get pollVoted => "poll_voted".tr();
static String get pollRevote => "poll_revote".tr();
}
12 changes: 12 additions & 0 deletions lib/core/providers/global_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:waves/core/utilities/theme/theme_mode.dart';
import 'package:waves/features/threads/presentation/thread_feed/controller/poll_controller.dart';
import 'package:waves/features/threads/presentation/thread_feed/controller/thread_feed_controller.dart';
import 'package:waves/features/user/presentation/user_profile/controller/user_profile_controller.dart';
import 'package:waves/features/user/view/user_controller.dart';

class GlobalProviders {
Expand All @@ -14,6 +15,17 @@ class GlobalProviders {
lazy: false,
create: (context) => UserController(),
),
ChangeNotifierProxyProvider<UserController, UserProfileController>(
create: (context) => UserProfileController(accountName: null),
update: (context, userController, previousProfileController) {
if (previousProfileController == null) {
return UserProfileController(accountName: userController.userName);
} else {
previousProfileController.updateAccountName(userController.userName);
return previousProfileController;
}
}
),
ChangeNotifierProxyProvider<UserController, ThreadFeedController>(
create: (context) => ThreadFeedController(observer: null),
update: (context, userController, previousThreadFeedController) {
Expand Down
137 changes: 93 additions & 44 deletions lib/core/services/poll_service/poll_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:waves/core/utilities/enum.dart';
import 'package:waves/core/locales/locale_text.dart';

class PollModel {
final String author;
Expand All @@ -10,7 +10,7 @@ class PollModel {
final String parentAuthor;
final double protocolVersion;
final String question;
final String preferredInterpretation;
final PollPreferredInterpretation? preferredInterpretation;
final String? token;
final DateTime endTime;
final String status;
Expand Down Expand Up @@ -55,7 +55,8 @@ class PollModel {
parentAuthor: json['parent_author'],
protocolVersion: json['protocol_version'].toDouble(),
question: json['question'],
preferredInterpretation: json['preferred_interpretation'],
preferredInterpretation: PollPreferredInterpretation.fromString(
json['preferred_interpretation']),
token: json['token'],
endTime: DateTime.parse(json['end_time']),
status: json['status'],
Expand Down Expand Up @@ -97,10 +98,13 @@ class PollModel {
}

double get totalInterpretedVotes {
return pollChoices.fold(0.0, (prev, entry) {
num val = preferredInterpretation == PollPreferredInterpretation.tokens
? entry.votes?.hiveHp ?? 0
: entry.votes?.totalVotes ?? 0;

//TODO: return value based on selected interpretation;
return pollChoices.fold(0, (val, entry) => val + (entry.votes?.totalVotes ?? 0));

return prev + val;
});
}

List<int> userVotedIds(String? username) {
Expand All @@ -113,7 +117,6 @@ class PollModel {
}

void injectPollVoteCache(String username, List<int> selection) {

double userHp = 1; //TOOD: use real user hp

//extract previously votes choices and new choices
Expand Down Expand Up @@ -150,35 +153,35 @@ class PollModel {
pollChoices = [
...notTouchedChoices,
...removedChoices.map((pc) => pc.copyWith(
votes: Votes(
totalVotes: (pc.votes?.totalVotes ?? 0) - 1,
hiveHp: (pc.votes?.hiveHp ?? 0) - userHp,
hiveProxiedHp: 0,
hiveHpInclProxied: (pc.votes?.hiveHpInclProxied ?? 0) - userHp,
splSpsp: 0,
),
)),
votes: Votes(
totalVotes: (pc.votes?.totalVotes ?? 0) - 1,
hiveHp: (pc.votes?.hiveHp ?? 0) - userHp,
hiveProxiedHp: 0,
hiveHpInclProxied: (pc.votes?.hiveHpInclProxied ?? 0) - userHp,
splSpsp: 0,
),
)),
...newChoices.map((pc) => pc.copyWith(
votes: Votes(
totalVotes: (pc.votes?.totalVotes ?? 0) + 1,
hiveHp: (pc.votes?.hiveHp ?? 0) + userHp,
hiveProxiedHp: 0,
hiveHpInclProxied: (pc.votes?.hiveHpInclProxied ?? 0) + userHp,
splSpsp: 0,
),
)),
votes: Votes(
totalVotes: (pc.votes?.totalVotes ?? 0) + 1,
hiveHp: (pc.votes?.hiveHp ?? 0) + userHp,
hiveProxiedHp: 0,
hiveHpInclProxied: (pc.votes?.hiveHpInclProxied ?? 0) + userHp,
splSpsp: 0,
),
)),
]..sort((a, b) => a.choiceNum.compareTo(b.choiceNum));

//update poll voters with updated selection
pollVoters = [
...otherVoters,
PollVoter(
name: username,
choices: selection,
hiveHp: userHp,
splSpsp: 0,
hiveProxiedHp: 0,
hiveHpInclProxied: userHp)
name: username,
choices: selection,
hiveHp: userHp,
splSpsp: 0,
hiveProxiedHp: 0,
hiveHpInclProxied: userHp)
];
}
}
Expand Down Expand Up @@ -224,13 +227,11 @@ class PollChoice {
};
}


PollChoice copyWith({Votes? votes}) {
PollChoice copyWith({Votes? votes}) {
return PollChoice(
choiceNum: choiceNum,
choiceText: choiceText,
votes: votes ?? this.votes
);
choiceNum: choiceNum,
choiceText: choiceText,
votes: votes ?? this.votes);
}
}

Expand Down Expand Up @@ -273,16 +274,25 @@ class Votes {
};
}

Votes copyWith({int? totalVotes, double? hiveHp, double? hiveHpInclProxied}) {
Votes copyWith({int? totalVotes, double? hiveHp, double? hiveHpInclProxied}) {
return Votes(
totalVotes: totalVotes ?? this.totalVotes,
hiveHp: hiveHp ?? this.hiveHp,
hiveProxiedHp: hiveProxiedHp,
hiveHpInclProxied: hiveHpInclProxied ?? this.hiveHpInclProxied,
splSpsp: splSpsp
);


totalVotes: totalVotes ?? this.totalVotes,
hiveHp: hiveHp ?? this.hiveHp,
hiveProxiedHp: hiveProxiedHp,
hiveHpInclProxied: hiveHpInclProxied ?? this.hiveHpInclProxied,
splSpsp: splSpsp);
}

num getInterprettedVotes(PollPreferredInterpretation? interpretation) {
return interpretation == PollPreferredInterpretation.tokens
? hiveHp
: totalVotes;
}

String getInterprettedSymbol(PollPreferredInterpretation? interpretation) {
return interpretation == PollPreferredInterpretation.tokens
? "HP"
: LocaleText.pollVoted;
}
}

Expand Down Expand Up @@ -369,3 +379,42 @@ class PollStats {
};
}
}

enum PollPreferredInterpretation
implements Comparable<PollPreferredInterpretation> {
tokens(value: 'tokens'),
numberOfVotes(value: 'number_of_votes');

const PollPreferredInterpretation({
required this.value,
});

final String value;

// Lookup map to find enum from string
static final Map<String, PollPreferredInterpretation> _valueMap = {
'tokens': PollPreferredInterpretation.tokens,
'number_of_votes': PollPreferredInterpretation.numberOfVotes,
};

// Convert string to enum
static PollPreferredInterpretation? fromString(String? value) {
if (value == null) {
return null;
}

final result = _valueMap[value];
if (result == null) {
throw ArgumentError('Unknown value: $value');
}
return result;
}

// Convert enum to string
String toShortString() {
return value;
}

@override
int compareTo(PollPreferredInterpretation other) => 0;
}
17 changes: 15 additions & 2 deletions lib/core/utilities/theme/theme_mode.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:flutter/material.dart';

class ThemeController extends ChangeNotifier {

final Color _primaryThemeColor = Colors.blue;
final Color _primaryThemeColor = const Color(0xFF357CE5);
final Color _primaryColor = Colors.black;
final Color _primaryColorTwo = const Color.fromARGB(255, 8, 8, 8);
final Color _secondaryColor = Colors.white;
Expand Down Expand Up @@ -178,4 +177,18 @@ class ThemeController extends ChangeNotifier {
),
);
}

get pollThemeData => isLightTheme()
? getLightTheme().copyWith(
colorScheme: const ColorScheme.light(
brightness: Brightness.light,
primary: Color(0xFF90B5EB),
secondary: Color(0xFFC0C5C7),
surface: Color(0xFFF6F6F6)))
: getDarkTheme().copyWith(
colorScheme: const ColorScheme.dark(
brightness: Brightness.light,
primary: Color(0xff254C87),
secondary: Color(0xff526D91),
surface: Color(0xff2e3d51)));
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:waves/core/services/poll_service/poll_model.dart';
import 'package:waves/core/utilities/save_convert.dart';
import 'package:waves/features/threads/models/thread_feeds/thread_json_meta_data/thread_json_meta_data_video.dart';

Expand All @@ -15,45 +16,7 @@ enum ContentType implements Comparable<ContentType> {
int compareTo(ContentType other) => 0;
}

enum PollPreferredInterpretation
implements Comparable<PollPreferredInterpretation> {
tokens(value: 'tokens'),
numberOfVotes(value: 'number_of_votes');

const PollPreferredInterpretation({
required this.value,
});

final String value;

// Lookup map to find enum from string
static final Map<String, PollPreferredInterpretation> _valueMap = {
'tokens': PollPreferredInterpretation.tokens,
'number_of_votes': PollPreferredInterpretation.numberOfVotes,
};

// Convert string to enum
static PollPreferredInterpretation? fromString(String? value) {

if(value == null){
return null;
}

final result = _valueMap[value];
if (result == null) {
throw ArgumentError('Unknown value: $value');
}
return result;
}

// Convert enum to string
String toShortString() {
return value;
}

@override
int compareTo(PollPreferredInterpretation other) => 0;
}

class PollFilters {
final int accountAge;
Expand Down
Loading