mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Add overlay menu items and functions
This commit is contained in:
parent
5265ff49c0
commit
7c81873c64
3 changed files with 59 additions and 4 deletions
|
|
@ -6,8 +6,10 @@ import android.os.CountDownTimer;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.transition.TransitionManager;
|
import android.support.transition.TransitionManager;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
|
|
@ -36,9 +38,11 @@ class PlaceRenderer extends Renderer<Place> {
|
||||||
@BindView(R.id.cameraButton) LinearLayout cameraButton;
|
@BindView(R.id.cameraButton) LinearLayout cameraButton;
|
||||||
@BindView(R.id.galeryButton) LinearLayout galeryButton;
|
@BindView(R.id.galeryButton) LinearLayout galeryButton;
|
||||||
@BindView(R.id.directionsButton) LinearLayout directionsButton;
|
@BindView(R.id.directionsButton) LinearLayout directionsButton;
|
||||||
|
@BindView(R.id.iconOverflow) LinearLayout iconOverflow;
|
||||||
|
|
||||||
private View view;
|
private View view;
|
||||||
private static ArrayList<LinearLayout> openedItems;
|
private static ArrayList<LinearLayout> openedItems;
|
||||||
|
private Place place;
|
||||||
|
|
||||||
|
|
||||||
PlaceRenderer(){
|
PlaceRenderer(){
|
||||||
|
|
@ -98,7 +102,7 @@ class PlaceRenderer extends Renderer<Place> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
Place place = getContent();
|
place = getContent();
|
||||||
tvName.setText(place.name);
|
tvName.setText(place.name);
|
||||||
String descriptionText = place.getDescription().getText();
|
String descriptionText = place.getDescription().getText();
|
||||||
if (descriptionText.equals("?")) {
|
if (descriptionText.equals("?")) {
|
||||||
|
|
@ -124,9 +128,56 @@ class PlaceRenderer extends Renderer<Place> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
iconOverflow.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
|
||||||
|
iconOverflow.setOnClickListener(v -> popupMenuListener());
|
||||||
private void startActivity(Intent intent){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void popupMenuListener() {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(view.getContext(), iconOverflow);
|
||||||
|
popupMenu.inflate(R.menu.nearby_info_dialog_options);
|
||||||
|
|
||||||
|
MenuItem commonsArticle = popupMenu.getMenu()
|
||||||
|
.findItem(R.id.nearby_info_menu_commons_article);
|
||||||
|
MenuItem wikiDataArticle = popupMenu.getMenu()
|
||||||
|
.findItem(R.id.nearby_info_menu_wikidata_article);
|
||||||
|
MenuItem wikipediaArticle = popupMenu.getMenu()
|
||||||
|
.findItem(R.id.nearby_info_menu_wikipedia_article);
|
||||||
|
|
||||||
|
commonsArticle.setEnabled(!place.siteLinks.getCommonsLink().equals(Uri.EMPTY));
|
||||||
|
wikiDataArticle.setEnabled(!place.siteLinks.getWikidataLink().equals(Uri.EMPTY));
|
||||||
|
wikipediaArticle.setEnabled(!place.siteLinks.getWikipediaLink().equals(Uri.EMPTY));
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.nearby_info_menu_commons_article:
|
||||||
|
openWebView(place.siteLinks.getCommonsLink());
|
||||||
|
return true;
|
||||||
|
case R.id.nearby_info_menu_wikidata_article:
|
||||||
|
openWebView(place.siteLinks.getWikidataLink());
|
||||||
|
return true;
|
||||||
|
case R.id.nearby_info_menu_wikipedia_article:
|
||||||
|
openWebView(place.siteLinks.getWikipediaLink());
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openWebView(Uri link) {
|
||||||
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, link);
|
||||||
|
view.getContext().startActivity(browserIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean showMenu() {
|
||||||
|
return !place.siteLinks.getCommonsLink().equals(Uri.EMPTY)
|
||||||
|
|| !place.siteLinks.getWikidataLink().equals(Uri.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,4 +6,7 @@
|
||||||
<item android:id="@+id/nearby_info_menu_wikidata_article"
|
<item android:id="@+id/nearby_info_menu_wikidata_article"
|
||||||
android:title="@string/nearby_info_menu_wikidata_article"
|
android:title="@string/nearby_info_menu_wikidata_article"
|
||||||
/>
|
/>
|
||||||
|
<item android:id="@+id/nearby_info_menu_wikipedia_article"
|
||||||
|
android:title="@string/nearby_info_menu_wikipedia_article"
|
||||||
|
/>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
@ -200,6 +200,7 @@
|
||||||
<string name="no_description_found">no description found</string>
|
<string name="no_description_found">no description found</string>
|
||||||
<string name="nearby_info_menu_commons_article">Commons file page</string>
|
<string name="nearby_info_menu_commons_article">Commons file page</string>
|
||||||
<string name="nearby_info_menu_wikidata_article">Wikidata item</string>
|
<string name="nearby_info_menu_wikidata_article">Wikidata item</string>
|
||||||
|
<string name="nearby_info_menu_wikipedia_article">Wikipedia article</string>
|
||||||
<string name="error_while_cache">Error while caching pictures</string>
|
<string name="error_while_cache">Error while caching pictures</string>
|
||||||
<string name="title_info">A unique descriptive title for the file, which will serve as a filename. You may use plain language with spaces. Do not include the file extension</string>
|
<string name="title_info">A unique descriptive title for the file, which will serve as a filename. You may use plain language with spaces. Do not include the file extension</string>
|
||||||
<string name="description_info">Please describe the media as much as possible: Where was it taken? What does it show? What is the context? Please describe the objects or persons. Reveal information that can not be easily guessed, for instance the time of day if it is a landscape. If the media shows something unusual, please explain what makes it unusual.</string>
|
<string name="description_info">Please describe the media as much as possible: Where was it taken? What does it show? What is the context? Please describe the objects or persons. Reveal information that can not be easily guessed, for instance the time of day if it is a landscape. If the media shows something unusual, please explain what makes it unusual.</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue