Add nearby list adapter

This commit is contained in:
neslihanturan 2019-10-09 13:03:26 +03:00
parent 5f843bf366
commit 56334afe03
8 changed files with 141 additions and 24 deletions

View file

@ -0,0 +1,75 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.graphics.drawable.Icon;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import fr.free.nrw.commons.R;
public class NearbyFilterSearchListViewAdapter extends ArrayAdapter<Label> {
private final LayoutInflater inflater;
private ViewHolder viewHolder;
private final ArrayList<Label> labels;
public NearbyFilterSearchListViewAdapter(Context context, ArrayList<Label> labels) {
super(context,0, labels);
this.labels = labels;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return labels.size();
}
@Override
public Label getItem(int position) {
return labels.get(position);
}
@Override
public long getItemId(int position) {
return labels.get(position).hashCode();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.nearby_search_list_item, null);
viewHolder = new ViewHolder();
viewHolder.placeLabel = convertView.findViewById(R.id.place_text);
viewHolder.placeIcon = convertView.findViewById(R.id.place_icon);
convertView.setTag(viewHolder);
}
else{
//Get viewholder we already created
viewHolder = (ViewHolder)convertView.getTag();
}
Label label = labels.get(position);
if(label != null){
viewHolder.placeIcon.setImageResource(label.getIcon());
viewHolder.placeLabel.setText(label.toString());
}
return convertView;
}
//View Holder Pattern for better performance
private static class ViewHolder {
TextView placeLabel;
ImageView placeIcon;
}
}

View file

@ -0,0 +1,21 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class NearbyfilterSearchListView extends ListView {
public NearbyfilterSearchListView(Context context) {
super(context);
}
public NearbyfilterSearchListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NearbyfilterSearchListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}

View file

@ -66,6 +66,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.NearbyFilterSearchListViewAdapter;
import fr.free.nrw.commons.nearby.NearbyMarker;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
@ -119,16 +120,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@BindView(R.id.container_sheet) FrameLayout frameLayout;
@BindView(R.id.loading_nearby_list) ConstraintLayout loadingNearbyLayout;
@BindView(R.id.choice_chip_exists)
Chip chipExists;
@BindView(R.id.choice_chip_needs_photo)
Chip chipNeedsPhoto;
@BindView(R.id.search_view)
SearchView searchView;
@BindView(R.id.search_list_view)
ListView searchListView;
@BindView(R.id.nearby_filter_list_layout)
LinearLayout nearbyFilterListLayout;
@BindView(R.id.choice_chip_exists) Chip chipExists;
@BindView(R.id.choice_chip_needs_photo) Chip chipNeedsPhoto;
@BindView(R.id.search_view) SearchView searchView;
@BindView(R.id.search_list_view) ListView searchListView;
@BindView(R.id.nearby_filter_list_layout) LinearLayout nearbyFilterListLayout;
@Inject LocationServiceManager locationManager;
@Inject NearbyController nearbyController;
@ -205,12 +201,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
public void initNearbyFilter() {
ArrayList<String> stringArrayList = new ArrayList<>();
for(Label label : TEXT_TO_DESCRIPTION.values())
stringArrayList.add(label.toString());
ArrayAdapter adapter = new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,stringArrayList);
searchListView.setAdapter(adapter);
NearbyFilterSearchListViewAdapter nearbyFilterSearchListViewAdapter
= new NearbyFilterSearchListViewAdapter(getContext(),new ArrayList<>(TEXT_TO_DESCRIPTION.values()));
searchListView.setAdapter(nearbyFilterSearchListViewAdapter);
LayoutUtils.setLayoutHeightAllignedToWidth(1, nearbyFilterListLayout);
compositeDisposable.add(RxSearchView.queryTextChanges(searchView)
@ -219,6 +212,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
.observeOn(AndroidSchedulers.mainThread())
.subscribe( query -> {
Log.d("deneme4","query:"+query);
if (!query.equals("")) {
Log.d("deneme4","query if:"+query);
nearbyFilterListLayout.setVisibility(View.VISIBLE);
} else {
nearbyFilterListLayout.setVisibility(View.GONE);
}
}
));
}

View file

@ -15,6 +15,11 @@
layout="@layout/nearby_filter_all_items"
android:id="@+id/nearby_filter"/>
<include layout="@layout/nearby_filter_list"
android:layout_below="@id/nearby_filter"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"

View file

@ -19,6 +19,4 @@
android:background="@color/status_bar_blue">
</RelativeLayout>
<include layout="@layout/nearby_filter_list" />
</LinearLayout>

View file

@ -2,16 +2,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nearby_filter_list_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginStart="72dp"
android:visibility="gone"
android:elevation="6dp">
<ListView
android:id="@+id/selected_items_list_view"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
@ -22,7 +21,7 @@
<ListView
android:id="@+id/search_list_view"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/place_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="@+id/place_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>

View file

@ -582,8 +582,8 @@ Upload your first media by tapping on the add button.</string>
<string name="notification_mark_read">Notification marked as read</string>
<string name="some_error">There was some error!</string>
<string name="place_state">Place state:</string>
<string name="place_state_exists">Exists:</string>
<string name="place_state_needs_photo">Needs photo:</string>
<string name="place_state_exists">Exists</string>
<string name="place_state_needs_photo">Needs photo</string>
<string name="place_type">Place type:</string>
<string name="nearby_search_hint">Bridge, museum, hotel etc.</string>
</resources>