-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Languages order preference #5826 #6059
Open
Adeeth101
wants to merge
7
commits into
commons-app:main
Choose a base branch
from
Adith101:Languages-order-preference-#5826-
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1fbbc07
Draft for MR 1
Adith101 5b778af
Merge pull request #1 from commons-app/main
Adith101 1d479f0
Merge branch 'main' into Languages-order-preference-#5826-
nicolas-raoul 4db8589
Fixing the nearbyController default language
Adith101 d7adc2e
Merge pull request #2 from commons-app/main
Adeeth101 492b097
Update strings.xml
nicolas-raoul c549144
Merge branch 'main' into Languages-order-preference-#5826-
nicolas-raoul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
77 changes: 77 additions & 0 deletions
77
app/src/main/java/fr/free/nrw/commons/recentlanguages/SavedLanguagesAdapter.kt
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,77 @@ | ||
package fr.free.nrw.commons.recentlanguages | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import fr.free.nrw.commons.R | ||
import fr.free.nrw.commons.databinding.RowItemLanguagesSpinnerBinding | ||
import fr.free.nrw.commons.utils.LangCodeUtils | ||
import org.apache.commons.lang3.StringUtils | ||
import java.util.HashMap | ||
|
||
/** | ||
* Array adapter for saved languages | ||
*/ | ||
class SavedLanguagesAdapter constructor( | ||
context: Context, | ||
var savedLanguages: List<Language>, // List of saved languages | ||
private val selectedLanguages: HashMap<*, String>, // Selected languages map | ||
) : ArrayAdapter<String?>(context, R.layout.row_item_languages_spinner) { | ||
/** | ||
* Selected language code in SavedLanguagesAdapter | ||
* Used for marking selected ones | ||
*/ | ||
var selectedLangCode = "" | ||
|
||
override fun isEnabled(position: Int) = | ||
savedLanguages[position].languageCode.let { | ||
it.isNotEmpty() && !selectedLanguages.containsValue(it) && it != selectedLangCode | ||
} | ||
|
||
override fun getCount() = savedLanguages.size | ||
|
||
override fun getView( | ||
position: Int, | ||
convertView: View?, | ||
parent: ViewGroup, | ||
): View { | ||
val binding: RowItemLanguagesSpinnerBinding | ||
var rowView = convertView | ||
|
||
if (rowView == null) { | ||
val layoutInflater = | ||
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater | ||
binding = RowItemLanguagesSpinnerBinding.inflate(layoutInflater, parent, false) | ||
rowView = binding.root | ||
} else { | ||
binding = RowItemLanguagesSpinnerBinding.bind(rowView) | ||
} | ||
|
||
val languageCode = savedLanguages[position].languageCode | ||
val languageName = savedLanguages[position].languageName | ||
binding.tvLanguage.let { | ||
it.isEnabled = isEnabled(position) | ||
if (languageCode.isEmpty()) { | ||
it.text = StringUtils.capitalize(languageName) | ||
it.textAlignment = View.TEXT_ALIGNMENT_CENTER | ||
} else { | ||
it.text = | ||
"${StringUtils.capitalize(languageName)}" + | ||
" [${LangCodeUtils.fixLanguageCode(languageCode)}]" | ||
} | ||
} | ||
return rowView | ||
} | ||
|
||
/** | ||
* Provides code of a language from saved languages for a specific position | ||
*/ | ||
fun getLanguageCode(position: Int): String = savedLanguages[position].languageCode | ||
|
||
/** | ||
* Provides name of a language from saved languages for a specific position | ||
*/ | ||
fun getLanguageName(position: Int): String = savedLanguages[position].languageName | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be great to internationalize this.