WIP list context menu

This commit is contained in:
Daniele 2021-09-07 08:57:56 +02:00
parent e89ce8e7da
commit bac3639c3f
4 changed files with 29 additions and 5 deletions

View File

@ -23,7 +23,9 @@ package it.danieleverducci.nextcloudmaps.activity.main;
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filter;
@ -141,7 +143,7 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
}
};
class GeofavoriteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
class GeofavoriteViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener {
TextView tv_title, tv_content;
ImageView bt_context_menu;
ImageView bt_share;
@ -178,6 +180,12 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
itemClickListener.onItemClick(view, getAdapterPosition());
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
MenuInflater menuInflater = new MenuInflater(context);
menuInflater.inflate(R.menu.list_context_menu, menu);
}
}
private void performSort() {
@ -189,6 +197,7 @@ public class GeofavoriteAdapter extends RecyclerView.Adapter<GeofavoriteAdapter.
}
private void openContextMenu(View v) {
v.showContextMenu();
//.showContextMenuForChild(v);
}

View File

@ -82,7 +82,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
private MainPresenter presenter;
private GeofavoriteAdapter geofavoriteAdapter;
private ItemClickListener itemClickListener;
private ItemClickListener rvItemClickListener;
NavigationAdapter navigationCommonAdapter;
@ -104,7 +104,7 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
presenter = new MainPresenter(this);
itemClickListener = new ItemClickListener() {
rvItemClickListener = new ItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Geofavorite geofavorite = geofavoriteAdapter.get(position);
@ -127,11 +127,12 @@ public class MainActivity extends AppCompatActivity implements MainView, OnSorti
}
};
geofavoriteAdapter = new GeofavoriteAdapter(getApplicationContext(), itemClickListener);
geofavoriteAdapter = new GeofavoriteAdapter(getApplicationContext(), rvItemClickListener);
recyclerView.setAdapter(geofavoriteAdapter);
geofavoriteAdapter.setSortRule(sortRule);
registerForContextMenu(recyclerView);
swipeRefresh = findViewById(R.id.swipe_refresh);
swipeRefresh.setOnRefreshListener(() -> presenter.getGeofavorites());

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Detail button -->
<item
android:id="@+id/list_context_menu_detail"
android:title="@string/list_context_menu_detail"/>
<!-- Delete button -->
<item
android:id="@+id/list_context_menu_delete"
android:title="@string/list_context_menu_delete"/>
</menu>

View File

@ -31,6 +31,8 @@
<string name="search_in_all">Search by name</string>
<string name="share_via">Share via</string>
<string name="share_message">Check out this place: {lat}°N, {lng}°E</string>
<string name="list_context_menu_detail">Details</string>
<string name="list_context_menu_delete">Delete</string>
<!-- Sort dialog -->
<string name="sort_by">Sort by</string>