mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Convert CaptionListViewAdapter to kotlin
This commit is contained in:
parent
afd12549ce
commit
1483e87331
2 changed files with 43 additions and 67 deletions
|
|
@ -1,67 +0,0 @@
|
|||
package fr.free.nrw.commons.media;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
import fr.free.nrw.commons.R;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Adapter for Caption Listview
|
||||
*/
|
||||
public class CaptionListViewAdapter extends BaseAdapter {
|
||||
|
||||
List<Caption> captions;
|
||||
|
||||
public CaptionListViewAdapter(final List<Caption> captions) {
|
||||
this.captions = captions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return size of captions list
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return captions.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Object at position i
|
||||
*/
|
||||
@Override
|
||||
public Object getItem(final int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return id for current item
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(final int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* inflate the view and bind data with UI
|
||||
*/
|
||||
@Override
|
||||
public View getView(final int i, final View view, final ViewGroup viewGroup) {
|
||||
final TextView captionLanguageTextView;
|
||||
final TextView captionTextView;
|
||||
final View captionLayout = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.caption_item, null);
|
||||
captionLanguageTextView = captionLayout.findViewById(R.id.caption_language_textview);
|
||||
captionTextView = captionLayout.findViewById(R.id.caption_text);
|
||||
if (captions.size() == 1 && captions.get(0).getValue().equals("No Caption")) {
|
||||
captionLanguageTextView.setText(captions.get(i).getLanguage());
|
||||
captionTextView.setText(captions.get(i).getValue());
|
||||
} else {
|
||||
captionLanguageTextView.setText(captions.get(i).getLanguage() + ":");
|
||||
captionTextView.setText(captions.get(i).getValue());
|
||||
}
|
||||
|
||||
return captionLayout;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package fr.free.nrw.commons.media
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.TextView
|
||||
import fr.free.nrw.commons.R
|
||||
|
||||
/**
|
||||
* Adapter for Caption Listview
|
||||
*/
|
||||
class CaptionListViewAdapter(var captions: List<Caption>) : BaseAdapter() {
|
||||
override fun getCount(): Int {
|
||||
return captions.size
|
||||
}
|
||||
|
||||
override fun getItem(i: Int): Any? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getItemId(i: Int): Long {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getView(i: Int, view: View, viewGroup: ViewGroup): View {
|
||||
val captionLanguageTextView: TextView
|
||||
val captionTextView: TextView
|
||||
val captionLayout = LayoutInflater.from(viewGroup.context)
|
||||
.inflate(R.layout.caption_item, null)
|
||||
captionLanguageTextView = captionLayout.findViewById(R.id.caption_language_textview)
|
||||
captionTextView = captionLayout.findViewById(R.id.caption_text)
|
||||
if (captions.size == 1 && captions[0].value == "No Caption") {
|
||||
captionLanguageTextView.text = captions[i].language
|
||||
captionTextView.text = captions[i].value
|
||||
} else {
|
||||
captionLanguageTextView.text = captions[i].language + ":"
|
||||
captionTextView.text = captions[i].value
|
||||
}
|
||||
|
||||
return captionLayout
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue