mirror of
https://github.com/LBRYFoundation/lbry-android.git
synced 2025-08-23 17:47:28 +00:00
* simplify code for readability * code-cleanup. Make non-changing variables final * Bump buildToolsVersion 29.0.1 -> 29.0.2 for FDroid build compability * Set gradle version to static 3.6.4 instead of dynamic 3.+ * Use StandardCharsets.UTF_8 instead of string UTF8 * Remove unused imports * Add missing null check Co-authored-by: Patric Karlström <patric@pkcab.eu>
51 lines
No EOL
1.7 KiB
Java
51 lines
No EOL
1.7 KiB
Java
package io.lbry.browser.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import io.lbry.browser.R;
|
|
import io.lbry.browser.model.License;
|
|
import io.lbry.browser.utils.Predefined;
|
|
|
|
public class LicenseSpinnerAdapter extends ArrayAdapter<License> {
|
|
private final int layoutResourceId;
|
|
private final LayoutInflater inflater;
|
|
|
|
public LicenseSpinnerAdapter(Context context, int resource) {
|
|
super(context, resource, 0, Predefined.LICENSES);
|
|
inflater = LayoutInflater.from(context);
|
|
layoutResourceId = resource;
|
|
}
|
|
public int getItemPosition(String name) {
|
|
for (int i = 0; i < Predefined.LICENSES.size(); i++) {
|
|
License lic = Predefined.LICENSES.get(i);
|
|
if (lic.getName().equalsIgnoreCase(name)) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
@Override
|
|
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {
|
|
return createView(position, view, parent);
|
|
}
|
|
@Override
|
|
public View getView(int position, View view, @NonNull ViewGroup parent) {
|
|
return createView(position, view, parent);
|
|
}
|
|
private View createView(int position, View convertView, ViewGroup parent) {
|
|
License item = getItem(position);
|
|
View view = inflater.inflate(layoutResourceId, parent, false);
|
|
TextView label = view.findViewById(R.id.item_display_name);
|
|
label.setText(item != null ? item.getStringResourceId() : 0);
|
|
|
|
return view;
|
|
}
|
|
} |