mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Change BiMap to HashMap (#3572)
* Change BiMap to HashMap * Change containsKey to containsValue and delete BiMap.java
This commit is contained in:
parent
630f0a1dff
commit
839a61bba4
3 changed files with 6 additions and 48 deletions
|
|
@ -18,13 +18,13 @@ import androidx.appcompat.widget.AppCompatSpinner;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.utils.AbstractTextWatcher;
|
||||
import fr.free.nrw.commons.utils.BiMap;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class DescriptionsAdapter extends RecyclerView.Adapter<DescriptionsAdapter.ViewHolder> {
|
||||
|
|
@ -32,12 +32,12 @@ public class DescriptionsAdapter extends RecyclerView.Adapter<DescriptionsAdapte
|
|||
private List<Description> descriptions;
|
||||
private Callback callback;
|
||||
|
||||
private BiMap<AdapterView, String> selectedLanguages;
|
||||
private HashMap<AdapterView, String> selectedLanguages;
|
||||
private String savedLanguageValue;
|
||||
|
||||
public DescriptionsAdapter(String savedLanguageValue) {
|
||||
descriptions = new ArrayList<>();
|
||||
selectedLanguages = new BiMap<>();
|
||||
selectedLanguages = new HashMap<>();
|
||||
this.savedLanguageValue = savedLanguageValue;
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class DescriptionsAdapter extends RecyclerView.Adapter<DescriptionsAdapte
|
|||
|
||||
public void setItems(List<Description> descriptions) {
|
||||
this.descriptions = descriptions;
|
||||
selectedLanguages = new BiMap<>();
|
||||
selectedLanguages = new HashMap<>();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import android.widget.ArrayAdapter
|
|||
import androidx.annotation.LayoutRes
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.utils.BiMap
|
||||
import fr.free.nrw.commons.utils.LangCodeUtils
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.row_item_languages_spinner.*
|
||||
|
|
@ -24,7 +23,7 @@ import java.util.*
|
|||
*/
|
||||
class SpinnerLanguagesAdapter constructor(
|
||||
context: Context,
|
||||
private val selectedLanguages: BiMap<*, String>
|
||||
private val selectedLanguages: HashMap<*, String>
|
||||
) : ArrayAdapter<Any?>(context, -1) {
|
||||
|
||||
private val languageNamesList: List<String>
|
||||
|
|
@ -41,7 +40,7 @@ class SpinnerLanguagesAdapter constructor(
|
|||
var selectedLangCode = ""
|
||||
|
||||
override fun isEnabled(position: Int) = languageCodesList[position].let {
|
||||
it.isNotEmpty() && !selectedLanguages.containsKey(it) && it != selectedLangCode
|
||||
it.isNotEmpty() && !selectedLanguages.containsValue(it) && it != selectedLangCode
|
||||
}
|
||||
|
||||
override fun getCount() = languageNamesList.size
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* HashMap that can be searched in both the forward and reverse directions.
|
||||
*/
|
||||
public class BiMap<K, V> {
|
||||
|
||||
private HashMap<K, V> map = new HashMap<>();
|
||||
private HashMap<V, K> inversedMap = new HashMap<>();
|
||||
|
||||
public void put(K k, V v) {
|
||||
map.put(k, v);
|
||||
inversedMap.put(v, k);
|
||||
}
|
||||
|
||||
public V get(K k) {
|
||||
return map.get(k);
|
||||
}
|
||||
|
||||
public K getKey(V v) {
|
||||
return inversedMap.get(v);
|
||||
}
|
||||
|
||||
public Set<V> getEntrySet(){
|
||||
return inversedMap.keySet();
|
||||
}
|
||||
|
||||
public void remove(K k){
|
||||
inversedMap.remove(map.remove(k));
|
||||
}
|
||||
|
||||
|
||||
public boolean containsKey(V v){
|
||||
return inversedMap.containsKey(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue