-
Notifications
You must be signed in to change notification settings - Fork 892
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
Adding Voice Commands Feature #897
base: main
Are you sure you want to change the base?
Conversation
Many people have complained about not being to import. This patch adds an actual import preference, which just fires off an ACTION_GET_CONTENT intent. On Kitkat and above, the Storage Access Framework gives people the option to import from applications that are document providers (ex Dropbox, Google Drive, etc). On older devices, this usually offers a file picker as an option. Fixes quran#634.
Make the headers for "Current Page", "Page Bookmarks", and "Not Tagged" not clickable (since they do nothing when clicked or long clicked). Clean up some code.
Most of these LTR hardcodes are needed for supporting pre-api 17. To fix this, split out layout-ar and layout-ar-v17, with the latter being an exact copy of the respective files from layout. Some of the other cases (the various ViewPager indicators) actually always receive data in the correct order, so they need to be LTR. These cases have been placed in the code instead. It should be possible to remove some of these explicit layout direction attributes in the future after some additional work.
In cases when the calculated dropdown width is less than the width of the actual spinner, use that width as the dropdown width. This stops certain sura names from being cut off.
adding an .editorconfig file to the repo so that new contributors will automatically have their formatting setup correctly. It's built into Android Studio. Settings->Editor->Code Style then Check "Enable EditorConfig".
The .editorconfig used to adress .java and .sh solely. Since the code style guide says that 2 spaces is used throughout the project. I've changed .editorconfig to use 2 spaces throughout the project.
This also makes "missing translations" a warning instead of an error.
.editorconfig
This is supported by Android Studio and IntelliJ and is important for keeping consistency with the existing code style.
This implements recent pages for Quran (using similar behavior to Quran for iOS). A table of recent pages now exists within the bookmarks database. Whenever a Quran page is selected, it is added to the table. When the page changes, the new page replaces the old one in recents. The recents table currently maintains a maximum of 3 items. Fixes quran#691.
RxPreferences was used for listening to changes on the last page. Now that this code has changes, this is no longer needed. Will consider adding it back in the future if needed insha'Allah.
…and clean up all calsses
This removes the 150 search limit when doing a search (though the limit intentionally remains for suggestions). Fixes quran#791.
The api contains a languageCode as of version 4. Store this in the database as it can help optimize search queries.
Since we know when a query is or isn't Arabic, we can use this information to skip databases that are Arabic when the query isn't Arabic (or that aren't Arabic when the query is Arabic).
This patch returns results from the first database that has results. This is done for performance and to avoid having to sort the results.
In translation mode, long pressing an ayah now shows a toolbar (similar to the one in the images screen), but with the share menu. Choosing to copy or share will copy the verse in Arabic (if it is not disabled in the settings) followed by all currently enabled translations as text, and then copy or share.
Many people complain that they are asked to redownload images on every start of the app. This adds some logging to help identify the problem.
To account for the arabic database, i starts at -1 if it's present. Consequently, there shouldn't be an additional 1 added to the total count, because that results in a clear out of bounds case.
May Allah reward brother Mohamed Omar for preparing these 4 sets. These are sets for sheikh Saad al Ghamidi, sheikh Bandar Baleela, sheikh Mahmoud Ali al Bana, and sheikh Abdulrahman Al Shahat.
These changes are adding voice commands button to the app. Current commands are found under voice_commands.xml. This can be expanded to add commands to audio control or change settings as well.
Adding microphone icon to fix the error
To fix the error
@@ -21,7 +22,12 @@ | |||
import android.view.Menu; | |||
import android.view.MenuInflater; | |||
import android.view.MenuItem; | |||
|
|||
///////////////////////////////////////////// | |||
//voice commands imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment
@@ -65,6 +71,12 @@ | |||
R.string.quran_juz2, | |||
R.string.quran_sura }; | |||
|
|||
/////////////////////////////////////////////////// | |||
//Used for Voice Commands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment
else { | ||
CharSequence text = ""; | ||
if(language.equals("ar-SA")) | ||
text = " لا يوجد الامر " + S + " الرجاء الاعادة "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not use hard coded text, use text from strings.xml
Modified the code to include recommended changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, "voice commands" looks immature and not suitable for production in its current logic and implementation. You may need to put more thought on its core logic.
@@ -22,6 +23,10 @@ | |||
import android.view.MenuInflater; | |||
import android.view.MenuItem; | |||
|
|||
import android.speech.RecognizerIntent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please organize imports. Current order is alphabetic.
private static final int SPEECH_REQUEST_CODE = 0; | ||
private VoiceCommandsUtil voiceCom; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant empty line, please remove.
@@ -118,6 +127,10 @@ public void onCreate(Bundle savedInstanceState) { | |||
(SlidingTabLayout) findViewById(R.id.indicator); | |||
indicator.setViewPager(pager); | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@@ -118,6 +127,10 @@ public void onCreate(Bundle savedInstanceState) { | |||
(SlidingTabLayout) findViewById(R.id.indicator); | |||
indicator.setViewPager(pager); | |||
|
|||
|
|||
voiceCom = new VoiceCommandsUtil(QuranActivity.this); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@@ -265,7 +283,34 @@ protected void onSaveInstanceState(Bundle outState) { | |||
super.onSaveInstanceState(outState); | |||
} | |||
|
|||
private void jumpToLastPage() { | |||
public void startVoiceRecognition() { | |||
final String language = QuranSettings.getInstance(this).isArabicNames() ? "ar-SA" : "en-US"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are essentially limiting voice recognition to Arabic and US English. Both Google voice recognition and the Qur'an app supports more locales. Please consider taking that into account.
myContext.startActivity(i); | ||
return true; | ||
case 5: | ||
sura = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am having hard time understanding the logic here. Why are we jumping to Surah Baqarah here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The voice command is to go to Sura Al-Bagarah. However, I missed adding it in the english xml file. It is in the arabic file. The intention is to make it easy for the user to jump to the required Sura through voice instead of having to type the name in the "Jump" option or scroll to it.
@@ -286,4 +286,7 @@ | |||
</plurals> | |||
<string name="undo">تراجع</string> | |||
|
|||
<!-- voice Commands strings --> | |||
<string name="commandNotFound">جرب مرة أخرى. الأمر التالي غير موجود = </string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<string name="command_not_found">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WailB naming convention of string
@@ -0,0 +1,12 @@ | |||
<?xml version='1.0' encoding='utf-8'?> | |||
<resources> | |||
<string name="vChoice">اذكر الامر المطلوب</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vChoice
<--- please make it more descriptive.
<?xml version='1.0' encoding='utf-8'?> | ||
<resources> | ||
<string name="vChoice">اذكر الامر المطلوب</string> | ||
<string-array name="voiceCommandsList"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<string-array name="voice_commands_list">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using camel case in the markup attributes, 'voiceCommandsList' should be 'voice_commands_list'.
build.gradle
Outdated
@@ -5,7 +5,7 @@ buildscript { | |||
} | |||
|
|||
dependencies { | |||
classpath 'com.android.tools.build:gradle:2.3.0' | |||
classpath 'com.android.tools.build:gradle:2.3.3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest you make an independent PR for the changes in build.gradle
Thank you for your comments. I just want to clarify, this is just a basic code just to show that it works. The core code is there, all is needed is to add "features" to it by adding to the case function in VoiceCommandsUtil.java. I might eluded in my previous posts and probably can be seen in my slow progress, I don't have that much time to work on this to make it a full fledged feature. I am hoping that with this code someone can work on it to add more features to it to make it useful for people. If not, I'll keep working on it as time permits until it is completed. Also, I will make the code cleaner with more descriptive comments. But you have raised a very good issue, its hard for someone new like myself to read the master code and understand the different functions since there is almost no comments or explanations. Even the order of imports being alphabetical is not clear. So, I suggest an effort to be made to add comments to help new collaborators hit the ground running. |
This is a major overhaul of the code to comply with comments received and add additional features such as going to specific pages both in arabic and english. Currently this codes allows to go to suras in arabic and english (only english translated names, also 2 suras are not currently working Qaf and Jinn). You can change the voice commands language as well.
returning gradle build to 2.3.0 as per ozbek comment
Please let me know if there are any additional comments or feel free to work on the code yourself. Just a few items to clarify:
|
Made some optimization to the code to make it cleaner and added arabic root word code to help make the commands more flexible. For example, the user can say ذهب او اذهب او ذهاب as a command to go to a sura.
acf48be
to
f4d3065
Compare
@ahmedre what is the update on this PR? |
These changes are adding voice commands button to the app. Current
commands are found under voice_commands.xml. This can be expanded to add
commands to audio control or change settings as well. A microphone button can be found on top of the main screen.