Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve speech profile widget handling #871

Merged
merged 4 commits into from
Sep 17, 2024
Merged

Conversation

mdmohsin7
Copy link
Collaborator

@mdmohsin7 mdmohsin7 commented Sep 17, 2024

  • Speech profile is not being set on first time the app opens, which causes to people with speech profile already and maybe switching phones, to see speech profile in onboarding again but also in home/memories page item asking for speech profile
ScreenRecording_09-17-2024.10-57-33_1.1.mp4

Summary by Entelligence.AI

  • New Feature: Introduced SpeechProfileCardWidget, a new widget for managing speech profiles, enhancing the user interface and experience.
  • Refactor: Optimized the flow of the onboarding process by replacing an animation call with a route navigation to HomePageWrapper.
  • Refactor: Improved initialization in HomePageWrapper and HomePage classes, ensuring smoother setup of speaker profile and user people.
  • Bug Fix: Updated a text string in the UI for better clarity during the voice learning phase.

Copy link

github-actions bot commented Sep 17, 2024

Image description Entelligence.AI

Walkthrough

This update introduces a new widget, SpeechProfileCardWidget, for managing speech profiles and refactors the existing codebase to incorporate it. It also modifies the onboarding process flow and updates the initialization sequence in the home page. Additionally, a minor text string change is made in the UI.

Changes

File(s) Summary
app/lib/pages/capture/_page.dart, app/lib/pages/memories/page.dart, app/lib/pages/capture/widgets/widgets.dart, app/lib/providers/home_provider.dart Introduced SpeechProfileCardWidget and refactored existing code to use this new widget. Added boolean variables hasSpeakerProfile and isLoading with corresponding setters. Adjusted logic in CapturePageState and MemoriesPage classes for conditional rendering based on speaker profile availability.
app/lib/pages/onboarding/wrapper.dart, app/lib/pages/home/page.dart Altered onboarding process flow by replacing an animation call with a route navigation call to HomePageWrapper. Updated initialization process in HomePageWrapper and HomePage classes to ensure proper setup of speaker profile and user people.
app/lib/pages/speech_profile/page.dart Updated a text string in the UI for better user experience.

"With each commit we grow, 🌱
Code refined, like rivers that flow. 🌊
A new widget takes the stage, 🎭
Enhancing our app, page by page. 📄
Onboarding's dance has a new beat, 💃
And initialization follows a new feat. 🏁
Even a string finds its voice anew, 🗣️
Celebrating changes, both old and new!" 🎉


Uplevel your code reviews with Entelligence.AI Pro

Entelligence.AI Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between b7f24b8 and 10ce9df commits.
Files selected (5)
  • app/lib/pages/capture/_page.dart (1)
  • app/lib/pages/capture/widgets/widgets.dart (2)
  • app/lib/pages/memories/page.dart (1)
  • app/lib/pages/onboarding/wrapper.dart (1)
  • app/lib/providers/home_provider.dart (2)
Review comments generated (9)
  • Review: 4
  • LGTM: 5

Tips

Chat with Image description Entelligence.AI Bot (@Entelligence.AI)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @Entelligence.AI in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @Entelligence.AI: ignore anywhere in the PR description to pause further reviews from the bot.

@@ -127,7 +127,7 @@ class _OnboardingWrapperState extends State<OnboardingWrapper> with TickerProvid
SpeechProfileWidget(
goNext: () {
if (context.read<SpeechProfileProvider>().memory == null) {
_controller!.animateTo(_controller!.index + 2);
routeToPage(context, const HomePageWrapper(), replace: true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The change from an animation call to a route navigation call could potentially disrupt the user experience. If the SpeechProfileProvider().memory is null, the user is now taken directly to the HomePageWrapper, skipping any remaining onboarding steps. This might be confusing for users who are expecting a smooth onboarding process. Please ensure that this abrupt transition is intended and does not negatively impact the user experience.

- routeToPage(context, const HomePageWrapper(), replace: true);
+ _controller!.animateTo(_controller!.index + 2);

Comment on lines +211 to +275
class SpeechProfileCardWidget extends StatelessWidget {
const SpeechProfileCardWidget({super.key});

@override
Widget build(BuildContext context) {
return Consumer<HomeProvider>(
builder: (context, provider, child) {
if (provider.isLoading) return const SizedBox();
return provider.hasSpeakerProfile
? const SizedBox()
: Stack(
children: [
GestureDetector(
onTap: () async {
MixpanelManager().pageOpened('Speech Profile Memories');
bool hasSpeakerProfile = SharedPreferencesUtil().hasSpeakerProfile;
await routeToPage(context, const SpeechProfilePage());
if (hasSpeakerProfile != SharedPreferencesUtil().hasSpeakerProfile) {
if (context.mounted) {
// TODO: is the websocket restarting once the user comes back?
context.read<DeviceProvider>().restartWebSocket();
}
}
},
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
borderRadius: const BorderRadius.all(Radius.circular(12)),
),
margin: const EdgeInsets.fromLTRB(16, 0, 16, 16),
padding: const EdgeInsets.all(16),
child: const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.multitrack_audio),
SizedBox(width: 16),
Text(
'Teach Omi your voice',
style: TextStyle(color: Colors.white, fontSize: 16),
Expanded(
child: Row(
children: [
Icon(Icons.multitrack_audio),
SizedBox(width: 16),
Text(
'Teach Omi your voice',
style: TextStyle(color: Colors.white, fontSize: 16),
),
],
),
),
Icon(Icons.arrow_forward_ios)
],
),
),
Icon(Icons.arrow_forward_ios)
],
),
),
),
Positioned(
top: 12,
right: 24,
child: Container(
width: 12,
height: 12,
decoration: const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
),
),
],
)
: const SizedBox(height: 0);
),
Positioned(
top: 12,
right: 24,
child: Container(
width: 12,
height: 12,
decoration: const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
),
),
],
);
},
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The refactoring from a function to a widget is a good step towards better modularity. However, there's a potential issue with the SharedPreferencesUtil().hasSpeakerProfile check. This check is performed twice: once before navigating to the SpeechProfilePage and once after returning from it. If the value of hasSpeakerProfile changes while on the SpeechProfilePage, the second check will not reflect the updated value because SharedPreferencesUtil() might not have the latest data immediately after the change.

To ensure that you always have the most recent value, consider using an async getter method for hasSpeakerProfile in SharedPreferencesUtil and await its result.

- bool hasSpeakerProfile = SharedPreferencesUtil().hasSpeakerProfile;
+ bool hasSpeakerProfile = await SharedPreferencesUtil().getHasSpeakerProfile();

And similarly,

- if (hasSpeakerProfile != SharedPreferencesUtil().hasSpeakerProfile) {
+ if (hasSpeakerProfile != await SharedPreferencesUtil().getHasSpeakerProfile()) {

This way, you're sure to get the most recent value from shared preferences.

Comment on lines +37 to +39
void setSpeakerProfile(bool? value) {
hasSpeakerProfile = value ?? SharedPreferencesUtil().hasSpeakerProfile;
notifyListeners();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The setSpeakerProfile method is using a default value from SharedPreferencesUtil().hasSpeakerProfile if the provided value is null. This could lead to unexpected behavior if the shared preferences value hasn't been initialized yet. It would be better to explicitly handle the null case.

-    hasSpeakerProfile = value ?? SharedPreferencesUtil().hasSpeakerProfile;
+    if (value != null) {
+        hasSpeakerProfile = value;
+    }

Comment on lines 42 to +49
Future setupHasSpeakerProfile() async {
SharedPreferencesUtil().hasSpeakerProfile = await userHasSpeakerProfile();
setIsLoading(true);
var res = await userHasSpeakerProfile();
setSpeakerProfile(res);
SharedPreferencesUtil().hasSpeakerProfile = res;
debugPrint('_setupHasSpeakerProfile: ${SharedPreferencesUtil().hasSpeakerProfile}');
MixpanelManager().setUserProperty('Speaker Profile', SharedPreferencesUtil().hasSpeakerProfile);
setIsLoading(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The setupHasSpeakerProfile method is setting isLoading to true at the start and false at the end, but there's no error handling in case userHasSpeakerProfile() throws an exception. This could leave isLoading set to true indefinitely. Consider adding a try-catch block to ensure isLoading is set to false even when an error occurs.

-    setIsLoading(true);
-    var res = await userHasSpeakerProfile();
-    setSpeakerProfile(res);
-    SharedPreferencesUtil().hasSpeakerProfile = res;
-    debugPrint('_setupHasSpeakerProfile: ${SharedPreferencesUtil().hasSpeakerProfile}');
-    MixpanelManager().setUserProperty('Speaker Profile', SharedPreferencesUtil().hasSpeakerProfile);
-    setIsLoading(false);
+    try {
+        setIsLoading(true);
+        var res = await userHasSpeakerProfile();
+        setSpeakerProfile(res);
+        SharedPreferencesUtil().hasSpeakerProfile = res;
+        debugPrint('_setupHasSpeakerProfile: ${SharedPreferencesUtil().hasSpeakerProfile}');
+        MixpanelManager().setUserProperty('Speaker Profile', SharedPreferencesUtil().hasSpeakerProfile);
+    } catch (e) {
+        // Handle or log the error as needed
+    } finally {
+        setIsLoading(false);
+    }

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between 10ce9df and 9166b51 commits.
Files selected (1)
  • app/lib/pages/home/page.dart (2)
Review comments generated (2)
  • Review: 2
  • LGTM: 0

Tips

Chat with Image description Entelligence.AI Bot (@Entelligence.AI)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @Entelligence.AI in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @Entelligence.AI: ignore anywhere in the PR description to pause further reviews from the bot.

@@ -53,6 +53,7 @@ class _HomePageWrapperState extends State<HomePageWrapper> {
context.read<DeviceProvider>().periodicConnect('coming from HomePageWrapper');
await context.read<mp.MemoryProvider>().getInitialMemories();
context.read<PluginProvider>().setSelectedChatPluginId(null);
await context.read<HomeProvider>().setupHasSpeakerProfile();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The setupHasSpeakerProfile function is now being called in the initState method. This is a good change as it ensures that the speaker profile setup is done as soon as the widget is initialized. However, please ensure that any potential exceptions thrown by setupHasSpeakerProfile are properly handled to prevent the app from crashing during initialization.

      await context.read<HomeProvider>().setupHasSpeakerProfile();
+        .catchError((error) {
+          // Handle error appropriately
+        });

if (mounted) {
await context.read<HomeProvider>().setUserPeople();
}
await context.read<HomeProvider>().setUserPeople();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The call to setUserPeople has been moved outside of the nested if (mounted) check and is now directly under the first if (mounted) check. This is a good change as it simplifies the code and reduces unnecessary nesting. However, similar to the previous comment, please ensure that any potential exceptions thrown by setUserPeople are properly handled.

        await context.read<HomeProvider>().setUserPeople();
+            .catchError((error) {
+              // Handle error appropriately
+            });

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between 9166b51 and 9e5581c commits.
Files selected (1)
  • app/lib/pages/speech_profile/page.dart (1)
Review comments generated (1)
  • Review: 0
  • LGTM: 1

Tips

Chat with Image description Entelligence.AI Bot (@Entelligence.AI)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @Entelligence.AI in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @Entelligence.AI: ignore anywhere in the PR description to pause further reviews from the bot.

@beastoin beastoin merged commit 327aef7 into main Sep 17, 2024
1 check passed
@beastoin beastoin deleted the speech-profile-widget branch September 17, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants