-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
864 additions
and
312 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
part of '../models.dart'; | ||
|
||
/// This object describes the way a background is filled based on the selected colors. | ||
abstract class BackgroundFill { | ||
/// Type of the background fill. | ||
BackgroundFillType get type; | ||
|
||
/// Creates a new [BackgroundFill] object. | ||
/// This method decides which [BackgroundFill] subclass to use based on the [type] field. | ||
factory BackgroundFill.fromJson(Map<String, dynamic> json) { | ||
switch (json['type']) { | ||
case 'solid': | ||
return BackgroundFillSolid.fromJson(json); | ||
case 'gradient': | ||
return BackgroundFillGradient.fromJson(json); | ||
case 'freeform_gradient': | ||
return BackgroundFillFreeformGradient.fromJson(json); | ||
default: | ||
throw ArgumentError('Invalid background fill type'); | ||
} | ||
} | ||
|
||
/// Creates a new [BackgroundFill] object from JSON. | ||
const BackgroundFill(); | ||
|
||
/// Converts a [BackgroundFill] to a [Map] for JSON encoding. | ||
Map<String, dynamic> toJson(); | ||
} |
30 changes: 30 additions & 0 deletions
30
lib/src/telegram/models/abstracts/background_type_fill.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
part of '../models.dart'; | ||
|
||
/// This object describes the type of a background. | ||
abstract class BackgroundType { | ||
/// Type of the background. | ||
BackgroundTypeType get type; | ||
|
||
/// Creates a new [BackgroundType] object. | ||
/// This method decides which [BackgroundType] subclass to use based on the [type] field. | ||
static BackgroundType create(Map<String, dynamic> json) { | ||
switch (json['type']) { | ||
case 'fill': | ||
return BackgroundTypeFill.fromJson(json); | ||
case 'wallpaper': | ||
return BackgroundTypeWallpaper.fromJson(json); | ||
case 'pattern': | ||
return BackgroundTypePattern.fromJson(json); | ||
case 'chat_theme': | ||
return BackgroundTypeChatTheme.fromJson(json); | ||
default: | ||
throw ArgumentError('Invalid background type'); | ||
} | ||
} | ||
|
||
/// Creates a new [BackgroundType] object from JSON. | ||
const BackgroundType(); | ||
|
||
/// Converts a [BackgroundType] to a [Map] for JSON encoding. | ||
Map<String, dynamic> toJson(); | ||
} |
31 changes: 31 additions & 0 deletions
31
lib/src/telegram/models/background_fill_freeform_gradient.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
part of 'models.dart'; | ||
|
||
/// Represents a background fill where the background is a freeform gradient that rotates after every message in the chat. | ||
class BackgroundFillFreeformGradient extends BackgroundFill { | ||
@override | ||
BackgroundFillType get type => BackgroundFillType.freeformGradient; | ||
|
||
/// A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format. | ||
final List<int> colors; | ||
|
||
/// Constructs a [BackgroundFillFreeformGradient] object. | ||
const BackgroundFillFreeformGradient({ | ||
required this.colors, | ||
}); | ||
|
||
/// Creates a [BackgroundFillFreeformGradient] object from JSON. | ||
factory BackgroundFillFreeformGradient.fromJson(Map<String, dynamic> json) { | ||
return BackgroundFillFreeformGradient( | ||
colors: List<int>.from(json['colors']), | ||
); | ||
} | ||
|
||
/// Converts a [BackgroundFillFreeformGradient] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.value, | ||
'colors': colors, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
part of 'models.dart'; | ||
|
||
/// Represents a background fill where the background is a gradient fill. | ||
class BackgroundFillGradient extends BackgroundFill { | ||
@override | ||
BackgroundFillType get type => BackgroundFillType.gradient; | ||
|
||
/// Top color of the gradient in the RGB24 format. | ||
final int topColor; | ||
|
||
/// Bottom color of the gradient in the RGB24 format. | ||
final int bottomColor; | ||
|
||
/// Clockwise rotation angle of the background fill in degrees; 0-359. | ||
final int rotationAngle; | ||
|
||
/// Constructs a [BackgroundFillGradient] object. | ||
const BackgroundFillGradient({ | ||
required this.topColor, | ||
required this.bottomColor, | ||
required this.rotationAngle, | ||
}); | ||
|
||
/// Creates a [BackgroundFillGradient] object from JSON. | ||
factory BackgroundFillGradient.fromJson(Map<String, dynamic> json) { | ||
return BackgroundFillGradient( | ||
topColor: json['top_color'], | ||
bottomColor: json['bottom_color'], | ||
rotationAngle: json['rotation_angle'], | ||
); | ||
} | ||
|
||
/// Converts a [BackgroundFillGradient] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.value, | ||
'top_color': topColor, | ||
'bottom_color': bottomColor, | ||
'rotation_angle': rotationAngle, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
part of 'models.dart'; | ||
|
||
/// Represents a background fill where the background is filled using the selected color. | ||
class BackgroundFillSolid extends BackgroundFill { | ||
@override | ||
BackgroundFillType get type => BackgroundFillType.solid; | ||
|
||
/// The color of the background fill in the RGB24 format. | ||
final int color; | ||
|
||
/// Constructs a [BackgroundFillSolid] object. | ||
const BackgroundFillSolid({ | ||
required this.color, | ||
}); | ||
|
||
/// Creates a [BackgroundFillSolid] object from JSON. | ||
factory BackgroundFillSolid.fromJson(Map<String, dynamic> json) { | ||
return BackgroundFillSolid( | ||
color: json['color'], | ||
); | ||
} | ||
|
||
/// Converts a [BackgroundFillSolid] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.value, | ||
'color': color, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
part of 'models.dart'; | ||
|
||
/// Represents a background type where the background is taken directly from a built-in chat theme. | ||
class BackgroundTypeChatTheme extends BackgroundType { | ||
@override | ||
BackgroundTypeType get type => BackgroundTypeType.chatTheme; | ||
|
||
/// Name of the chat theme, which is usually an emoji. | ||
final String themeName; | ||
|
||
/// Constructs a [BackgroundTypeChatTheme] object. | ||
const BackgroundTypeChatTheme({ | ||
required this.themeName, | ||
}); | ||
|
||
/// Creates a [BackgroundTypeChatTheme] object from JSON. | ||
factory BackgroundTypeChatTheme.fromJson(Map<String, dynamic> json) { | ||
return BackgroundTypeChatTheme( | ||
themeName: json['theme_name'], | ||
); | ||
} | ||
|
||
/// Converts a [BackgroundTypeChatTheme] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.value, | ||
'theme_name': themeName, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
part of 'models.dart'; | ||
|
||
/// Represents a background type where the background is automatically filled based on selected colors. | ||
class BackgroundTypeFill extends BackgroundType { | ||
@override | ||
BackgroundTypeType get type => BackgroundTypeType.fill; | ||
|
||
/// The background fill. | ||
final BackgroundFill fill; | ||
|
||
/// Dimming of the background in dark themes, as a percentage; 0-100. | ||
final int darkThemeDimming; | ||
|
||
/// Constructs a [BackgroundTypeFill] object. | ||
const BackgroundTypeFill({ | ||
required this.fill, | ||
required this.darkThemeDimming, | ||
}); | ||
|
||
/// Creates a [BackgroundTypeFill] object from JSON. | ||
factory BackgroundTypeFill.fromJson(Map<String, dynamic> json) { | ||
return BackgroundTypeFill( | ||
fill: BackgroundFill.fromJson(json['fill']), | ||
darkThemeDimming: json['dark_theme_dimming'], | ||
); | ||
} | ||
|
||
/// Converts a [BackgroundTypeFill] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.value, | ||
'fill': fill.toJson(), | ||
'dark_theme_dimming': darkThemeDimming, | ||
}; | ||
} | ||
} |
Oops, something went wrong.