mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add nearby list adapter
This commit is contained in:
parent
5f843bf366
commit
56334afe03
8 changed files with 141 additions and 24 deletions
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -66,6 +66,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||||
import fr.free.nrw.commons.nearby.Label;
|
import fr.free.nrw.commons.nearby.Label;
|
||||||
import fr.free.nrw.commons.nearby.NearbyController;
|
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.NearbyMarker;
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract;
|
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.container_sheet) FrameLayout frameLayout;
|
||||||
@BindView(R.id.loading_nearby_list) ConstraintLayout loadingNearbyLayout;
|
@BindView(R.id.loading_nearby_list) ConstraintLayout loadingNearbyLayout;
|
||||||
|
|
||||||
@BindView(R.id.choice_chip_exists)
|
@BindView(R.id.choice_chip_exists) Chip chipExists;
|
||||||
Chip chipExists;
|
@BindView(R.id.choice_chip_needs_photo) Chip chipNeedsPhoto;
|
||||||
@BindView(R.id.choice_chip_needs_photo)
|
@BindView(R.id.search_view) SearchView searchView;
|
||||||
Chip chipNeedsPhoto;
|
@BindView(R.id.search_list_view) ListView searchListView;
|
||||||
@BindView(R.id.search_view)
|
@BindView(R.id.nearby_filter_list_layout) LinearLayout nearbyFilterListLayout;
|
||||||
SearchView searchView;
|
|
||||||
@BindView(R.id.search_list_view)
|
|
||||||
ListView searchListView;
|
|
||||||
@BindView(R.id.nearby_filter_list_layout)
|
|
||||||
LinearLayout nearbyFilterListLayout;
|
|
||||||
|
|
||||||
@Inject LocationServiceManager locationManager;
|
@Inject LocationServiceManager locationManager;
|
||||||
@Inject NearbyController nearbyController;
|
@Inject NearbyController nearbyController;
|
||||||
|
|
@ -205,12 +201,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
public void initNearbyFilter() {
|
public void initNearbyFilter() {
|
||||||
|
|
||||||
ArrayList<String> stringArrayList = new ArrayList<>();
|
NearbyFilterSearchListViewAdapter nearbyFilterSearchListViewAdapter
|
||||||
for(Label label : TEXT_TO_DESCRIPTION.values())
|
= new NearbyFilterSearchListViewAdapter(getContext(),new ArrayList<>(TEXT_TO_DESCRIPTION.values()));
|
||||||
stringArrayList.add(label.toString());
|
searchListView.setAdapter(nearbyFilterSearchListViewAdapter);
|
||||||
|
|
||||||
ArrayAdapter adapter = new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,stringArrayList);
|
|
||||||
searchListView.setAdapter(adapter);
|
|
||||||
LayoutUtils.setLayoutHeightAllignedToWidth(1, nearbyFilterListLayout);
|
LayoutUtils.setLayoutHeightAllignedToWidth(1, nearbyFilterListLayout);
|
||||||
|
|
||||||
compositeDisposable.add(RxSearchView.queryTextChanges(searchView)
|
compositeDisposable.add(RxSearchView.queryTextChanges(searchView)
|
||||||
|
|
@ -219,6 +212,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe( query -> {
|
.subscribe( query -> {
|
||||||
Log.d("deneme4","query:"+query);
|
Log.d("deneme4","query:"+query);
|
||||||
|
if (!query.equals("")) {
|
||||||
|
Log.d("deneme4","query if:"+query);
|
||||||
|
nearbyFilterListLayout.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
nearbyFilterListLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,11 @@
|
||||||
layout="@layout/nearby_filter_all_items"
|
layout="@layout/nearby_filter_all_items"
|
||||||
android:id="@+id/nearby_filter"/>
|
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
|
<FrameLayout
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,4 @@
|
||||||
android:background="@color/status_bar_blue">
|
android:background="@color/status_bar_blue">
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<include layout="@layout/nearby_filter_list" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
@ -2,16 +2,15 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/nearby_filter_list_layout"
|
android:id="@+id/nearby_filter_list_layout"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_marginStart="72dp"
|
android:layout_marginStart="72dp"
|
||||||
android:visibility="gone"
|
|
||||||
android:elevation="6dp">
|
android:elevation="6dp">
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/selected_items_list_view"
|
android:id="@+id/selected_items_list_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
@ -22,7 +21,7 @@
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/search_list_view"
|
android:id="@+id/search_list_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
||||||
20
app/src/main/res/layout/nearby_search_list_item.xml
Normal file
20
app/src/main/res/layout/nearby_search_list_item.xml
Normal 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>
|
||||||
|
|
@ -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="notification_mark_read">Notification marked as read</string>
|
||||||
<string name="some_error">There was some error!</string>
|
<string name="some_error">There was some error!</string>
|
||||||
<string name="place_state">Place state:</string>
|
<string name="place_state">Place state:</string>
|
||||||
<string name="place_state_exists">Exists:</string>
|
<string name="place_state_exists">Exists</string>
|
||||||
<string name="place_state_needs_photo">Needs photo:</string>
|
<string name="place_state_needs_photo">Needs photo</string>
|
||||||
<string name="place_type">Place type:</string>
|
<string name="place_type">Place type:</string>
|
||||||
<string name="nearby_search_hint">Bridge, museum, hotel etc.</string>
|
<string name="nearby_search_hint">Bridge, museum, hotel etc.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue