Add Translation activity to spinner#802
Conversation
app/src/main/res/menu/home_menu.xml
Outdated
| android:title="@string/menu_jump" | ||
| app:showAsAction="never" /> | ||
| <item | ||
| android:id="@+id/translations" |
There was a problem hiding this comment.
Please do not use hard-coded string literals, use one provided in strings.xml.
There was a problem hiding this comment.
thanks can fix that, there are items in the home_menu which should be converted as well
There was a problem hiding this comment.
Hmm... there should not be. Android Studio shows them as string literals, but actually they are not.
Overall, you will have to redo this patch anyway. Don't put the menu here. "More translations" option should go to translations spinner in translation screen/mode, the one you see at the top when you have more than one translation are installed.
There was a problem hiding this comment.
ah ok, i misunderstood that ignore my bottom comment. I can add it in there. jzk
There was a problem hiding this comment.
hey so ive looked at this a bit, focusing on TranslationsSpinnerAdapter and PagerActivity. I'm running into issues finding a straightforward solution - the translation spinner has a checkbox dropdown item, and implementing another view to the dropdown such as TextView is non-trivial unless both items are added to a parent view. Additionally, since the spinner has checkboxes, an event listener for OnItemSelectedListener isn't being picked up if implemented in PagerActivity. Please let me know if you have some guidance on this. Thank you
There was a problem hiding this comment.
I suppose one will have to build a custom adapter that can hold multiple types of items (checkbox and text, in this case).
There was a problem hiding this comment.
this is where the custom adapter is being made. since SpinnerAdapter is a BaseAdapter, you can just override getViewTypeCount to return 2, and getItemViewType to return 0 except for the last row (the custom row you will add), in which case you'll return 1.
then, in getView, if getItemViewType is 1, show a different xml or just a TextView with "get more translations"
There was a problem hiding this comment.
hmm, it appears Spinners don't allow for setting this on the later APIs. "Spinner overrides getViewTypeCount() on the Adapter associated with this view. Calling getItemViewType(int) on the object returned from getAdapter() will always return 0. Calling getViewTypeCount() will always return 1. On API LOLLIPOP and above, attempting to set an adapter with more than one view type will throw an IllegalArgumentException." -https://developer.android.com/reference/android/widget/Spinner.html#setAdapter(android.widget.SpinnerAdapter) also https://code.google.com/p/android/issues/detail?id=17128. It looks like there can be a workaround using Tags however which I can look at
ahmedre
left a comment
There was a problem hiding this comment.
jazakAllah khairan for doing this - some comments
| // and the String[] constructor makes a new (immutable) List with the items of the array. | ||
| super(context, resource, new ArrayList<>()); | ||
| this.layoutInflater = LayoutInflater.from(context); | ||
| List<String> transList = new ArrayList<String>(Arrays.asList(translationNames)); |
There was a problem hiding this comment.
List<String> transList = Arrays.asList(translationName);
There was a problem hiding this comment.
I tried this, getting java.lang.UnsupportedOperationException on the next line however when trying to add to the list. Is there another way you intended to do this? jzk
There was a problem hiding this comment.
ah, makes sense, because Arrays.asList generates an immutable list.
i'd then replace it with a loop - i.e.
List<String> transList = new ArrayList<>();
for (String translation : translationNames) {
transList.add(translation);
}| super(context, resource, new ArrayList<>()); | ||
| this.layoutInflater = LayoutInflater.from(context); | ||
| List<String> transList = new ArrayList<String>(Arrays.asList(translationNames)); | ||
| transList.add("More Translations"); |
There was a problem hiding this comment.
add to strings.xml and use an R.string value
| this.layoutInflater = LayoutInflater.from(context); | ||
| List<String> transList = new ArrayList<String>(Arrays.asList(translationNames)); | ||
| transList.add("More Translations"); | ||
| translationNames = transList.toArray(new String[transList.size()]); |
There was a problem hiding this comment.
remove it, you don't need it
There was a problem hiding this comment.
I did this initially as translationNames is also used in addAll(translationNames);, should "More translations" not be a part of the underlying array?
There was a problem hiding this comment.
you have two options - one is to add it within the underlying array, and the other is to change the adapter to know that "count is always size + 1," and to know that "once you pass this element, the next element is the more option" - if it's cleaner to add it to the array (i.e. if the array is all Strings, as it seems to be), then it probably makes sense.
There was a problem hiding this comment.
jzk, thanks for the clarification!
| CheckBoxHolder holder; | ||
| if (convertView == null) { | ||
| convertView = layoutInflater.inflate( | ||
| convertView = layoutInflater.inflate( |
There was a problem hiding this comment.
keep wrapped in null check, otherwise, we make a new one every time this is called
| @@ -49,6 +49,10 @@ | |||
| android:id="@+id/jump" | |||
| android:title="@string/menu_jump" | |||
There was a problem hiding this comment.
undo changes to this file, not needed.
| clear(); | ||
| List<String> transList = new ArrayList<String>(Arrays.asList(translationNames)); | ||
| transList.add("More Translations"); | ||
| translationNames = transList.toArray(new String[transList.size()]); |
| jumpToLastPage(); | ||
| return true; | ||
| } | ||
| case R.id.translations: { |
| @Override | ||
| public View getDropDownView(int position, View convertView, ViewGroup parent) { | ||
|
|
||
| int type = super.getItemViewType(position); |
There was a problem hiding this comment.
i think you can probably remove this method altogether
| if (type == 1) { | ||
| LayoutInflater inflater = getLayoutInflater(); | ||
| convertView = inflater.inflate(R.layout.translation_ab_spinner_selected, parent, false); | ||
| }else{ |
| convertView = inflater.inflate(R.layout.translation_ab_spinner_selected, parent, false); | ||
| }else{ | ||
| convertView = super.getView(position, convertView, parent); | ||
| SpinnerHolder holder = (SpinnerHolder) convertView.getTag(); |
There was a problem hiding this comment.
make sure SpinnerHolder lets you get access to the checkbox and then hide/show it
There was a problem hiding this comment.
thanks, could you clarify this, I didn't need to change anything here after implementing your other comments. Jzk
ozbek
left a comment
There was a problem hiding this comment.
Mostly cosmetic, but would love to see the changes.
app/src/main/res/values/strings.xml
Outdated
| <string name="prefs_highlight_bookmarks_summary">Highlight bookmarked ayahs while reading</string> | ||
| <string name="prefs_translation_text_title">Translation text size</string> | ||
| <string name="prefs_translations">Translations</string> | ||
| <string name="prefs_more_translations">More Translations</string> |
There was a problem hiding this comment.
I was basing this off the pattern used for R.string.translations where it referenced <string name="translations">@string/prefs_translations</string>. Otherwise I would've just referenced the string directly. Please let me know if this isn't necessary
There was a problem hiding this comment.
prefs_translations is used in the Settings, prefs_more_translations is not used and not needed. Please remove it.
| } | ||
|
|
||
| public String[] updateTranslationNames(String[] translationNames) { | ||
|
|
There was a problem hiding this comment.
jzk, yea this doesn't match the other methods, removing
|
|
||
| public String[] updateTranslationNames(String[] translationNames) { | ||
|
|
||
| List<String> transList = new ArrayList<>(); |
There was a problem hiding this comment.
Nitpick: I don't like the trans prefix. Can you make it translationsList or (since, it is a local variable) simply list would also work.
There was a problem hiding this comment.
jzk, made into translationsList
| holder.checkBox.setText(translationNames[position]); | ||
| holder.checkBox.setChecked(selectedItems.contains(translations.get(position).filename)); | ||
| holder.checkBox.setOnClickListener(onCheckedChangeListener); | ||
|
|
| holder.checkBox.setButtonDrawable(transparentDrawable); | ||
| holder.checkBox.setText(R.string.more_translations); | ||
| holder.checkBox.setOnClickListener(this.textListener); | ||
|
|
| String desc = QuranInfo.getPageSubtitle(PagerActivity.this, page); | ||
| holder.subtitle.setText(desc); | ||
| holder.subtitle.setVisibility(View.VISIBLE); | ||
|
|
ozbek
left a comment
There was a problem hiding this comment.
JazakAllah khair, looks good to me 👍
| import android.view.ViewGroup; | ||
| import android.view.WindowManager; | ||
| import android.view.LayoutInflater; | ||
| import android.widget.TextView; |
| import com.quran.labs.androidquran.common.LocalTranslation; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; |
| this.textListener = onClickListener; | ||
| } | ||
|
|
||
| public String[] updateTranslationNames(String[] translationNames) { |
| import com.quran.labs.androidquran.model.bookmark.RecentPageModel; | ||
| import com.quran.labs.androidquran.presenter.translation.TranslationManagerPresenter; | ||
| import com.quran.labs.androidquran.service.AudioService; | ||
| import com.quran.labs.androidquran.ui.TranslationManagerActivity; |
| holder = (CheckBoxHolder) convertView.getTag(); | ||
| if (position == translationNames.length - 1) { | ||
| Drawable transparentDrawable = new ColorDrawable(Color.TRANSPARENT); | ||
| holder.checkBox.setButtonDrawable(transparentDrawable); |
There was a problem hiding this comment.
Please remove transparentDrawable and use setButtonDrawable(null) instead.
|
|
||
| public String[] updateTranslationNames(String[] translationNames) { | ||
| List<String> translationsList = new ArrayList<>(); | ||
| for (String translation : translationNames) { |
There was a problem hiding this comment.
Please remove this for loop and use List<String> translationsList = new ArrayList<>(Arrays.asList(translationNames)); instead.
There was a problem hiding this comment.
jzk, I made the change to a loop based on @ahmedre earlier comment "i'd then replace it with a loop - i.e.
List transList = new ArrayList<>();
for (String translation : translationNames) {
transList.add(translation);
}" , Please let me know if the replacement is what we want as a final state. thanks
|
waeyyak. Thanks for all the feedback |
|
|
||
| private String[] updateTranslationNames(String[] translationNames) { | ||
| List<String> translationsList = new ArrayList<>(); | ||
| for (String translation : translationNames) { |
There was a problem hiding this comment.
Please replaced the for loop with the code from previous comment.
There was a problem hiding this comment.
ok sure, i had changed it based on Ahmeds comments but i can revert it to this
There was a problem hiding this comment.
I see. Let's wait for him on this then. I wonder what's his reasoning for using a for loop.
There was a problem hiding this comment.
ok sure thing, my only thought would be readability but ill leave the change out for now
|
hmm, i didn't see that issue in my test, let me add some more translations and check |
|
I didn't see it in my emulator but am seeing it on my phone, the previous commit from two days ago doesn't have the issue so it must be tied to how the views are being re-used in |
| holder.checkBox.setText(R.string.more_translations); | ||
| holder.checkBox.setOnClickListener(this.textListener); | ||
| } else { | ||
| holder.checkBox.setButtonDrawable(R.drawable.abc_btn_check_material); |
There was a problem hiding this comment.
Android Studio is complaining that 'The resource @drawable/abc_btn_check_material is marked as private in com.android.support:appcompat'. Can we change its visibility somehow (instead of setting to null or changing its transparency)?
There was a problem hiding this comment.
hmm, im not sure how this would be done outside of using a drawable, is there a reason other than bloat to bring in the checkbox drawable resource into the project workspace?
|
Do you have any suggestions? We get lots of emails asking things around how
to add translations, and it seems a little unintuitive to force people out
to settings to get a translation.
…On Sun, Mar 5, 2017, 10:05 AM Shuhrat Dehkanov ***@***.***> wrote:
@ahmedre <https://github.com/ahmedre>, is #760
<#760> really needed?
Looking at the changes required, this seems an overkill for a functionality
with so little use...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#802 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC6m7HN0A-8pQOmAC8i6WwdSEzS73Qrks5rivligaJpZM4L4dk9>
.
|
|
Maybe something like this (remove .zip, apply on top of this PR): pr-802.patch.zip? (Does GitHub allow changes on other people's PRs, something like Gerrit?) |
|
@uzairmad what do you think of the last bug and the patch? |
|
sorry just checked, it looks good for me - I still need to test it on API 14 or if you have already, i can push it in this PR if thats ok. jzk |
|
it looks good on api 14, jzk @ozbek , i can push it |
ahmedre
left a comment
There was a problem hiding this comment.
i'll approve this, but if you get around to it, try to merge the two view types together.
| int type = super.getItemViewType(position); | ||
| if (type == 1) { | ||
| LayoutInflater inflater = getLayoutInflater(); | ||
| convertView = inflater.inflate(R.layout.translation_ab_spinner_selected, parent, false); |
There was a problem hiding this comment.
i still wish we'd share the inflation instead of inflating a separate view
|
jazakAllah khairan |
|
waiyyakum jazakallahukhairan for the feedback |
Added link to translations activity from spinner per #760, please review when you have a chance. thanks