mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add popup menu in nearby info dialog
This commit is contained in:
parent
95ecfbd3c2
commit
4823486139
7 changed files with 95 additions and 8 deletions
|
|
@ -44,6 +44,7 @@ android {
|
||||||
minSdkVersion project.minSdkVersion
|
minSdkVersion project.minSdkVersion
|
||||||
targetSdkVersion project.targetSdkVersion
|
targetSdkVersion project.targetSdkVersion
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,12 @@ import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v7.widget.PopupMenu;
|
||||||
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.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
|
|
@ -34,10 +37,13 @@ public class NearbyInfoDialog extends OverlayDialog {
|
||||||
@BindView(R.id.link_preview_go_button)
|
@BindView(R.id.link_preview_go_button)
|
||||||
TextView goToButton;
|
TextView goToButton;
|
||||||
|
|
||||||
|
@BindView(R.id.link_preview_overflow_button)
|
||||||
|
ImageView overflowButton;
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
|
||||||
private LatLng location;
|
private LatLng location;
|
||||||
private Uri articleLink;
|
private Sitelinks sitelinks;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
@ -56,15 +62,60 @@ public class NearbyInfoDialog extends OverlayDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getArticleLink(Bundle bundle) {
|
private void getArticleLink(Bundle bundle) {
|
||||||
Sitelinks sitelinks = bundle.getParcelable(ARG_SITE_LINK);
|
this.sitelinks = bundle.getParcelable(ARG_SITE_LINK);
|
||||||
|
|
||||||
if (sitelinks.getWikipediaLink() != null) {
|
if (sitelinks.getWikipediaLink() == null) {
|
||||||
this.articleLink = sitelinks.getWikipediaLink();
|
|
||||||
} else {
|
|
||||||
goToButton.setVisibility(View.GONE);
|
goToButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
overflowButton.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
overflowButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
popupMenuListener(v);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void popupMenuListener(View v) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(getActivity(), overflowButton);
|
||||||
|
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);
|
||||||
|
|
||||||
|
commonsArticle.setEnabled(sitelinks.getCommonsLink() != null);
|
||||||
|
wikiDataArticle.setEnabled(sitelinks.getWikidataLink() != null);
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(menuListener);
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean showMenu() {
|
||||||
|
return sitelinks.getCommonsLink() != null ||
|
||||||
|
sitelinks.getWikidataLink() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PopupMenu.OnMenuItemClickListener menuListener = new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.nearby_info_menu_commons_article:
|
||||||
|
openWebView(sitelinks.getCommonsLink());
|
||||||
|
return true;
|
||||||
|
case R.id.nearby_info_menu_wikidata_article:
|
||||||
|
openWebView(sitelinks.getWikidataLink());
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static void showYourself(FragmentActivity fragmentActivity, Place place) {
|
public static void showYourself(FragmentActivity fragmentActivity, Place place) {
|
||||||
NearbyInfoDialog mDialog = new NearbyInfoDialog();
|
NearbyInfoDialog mDialog = new NearbyInfoDialog();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
@ -96,7 +147,11 @@ public class NearbyInfoDialog extends OverlayDialog {
|
||||||
|
|
||||||
@OnClick(R.id.link_preview_go_button)
|
@OnClick(R.id.link_preview_go_button)
|
||||||
void onReadArticleClick() {
|
void onReadArticleClick() {
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, articleLink);
|
openWebView(sitelinks.getWikipediaLink());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openWebView(Uri link) {
|
||||||
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, link);
|
||||||
startActivity(browserIntent);
|
startActivity(browserIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class Sitelinks implements Parcelable {
|
||||||
stringUrl = stringUrl
|
stringUrl = stringUrl
|
||||||
.replaceAll("<", "")
|
.replaceAll("<", "")
|
||||||
.replaceAll(">", "")
|
.replaceAll(">", "")
|
||||||
.replaceAll("\n", "");
|
.replaceAll("[\n\r]", "");
|
||||||
if (!Utils.isNullOrWhiteSpace(stringUrl) && stringUrl != null) {
|
if (!Utils.isNullOrWhiteSpace(stringUrl) && stringUrl != null) {
|
||||||
return Uri.parse(stringUrl);
|
return Uri.parse(stringUrl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
app/src/main/res/drawable/ic_more_vert_white_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_more_vert_white_24dp.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#000000"
|
||||||
|
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
|
||||||
|
</vector>
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:orientation="horizontal"
|
||||||
android:minHeight="64dp">
|
android:minHeight="64dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
@ -52,6 +52,16 @@
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
tools:text="Lorem ipsum" />
|
tools:text="Lorem ipsum" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/link_preview_overflow_button"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:contentDescription="@string/abc_action_menu_overflow_description"
|
||||||
|
app:srcCompat="@drawable/ic_more_vert_white_24dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
|
|
||||||
9
app/src/main/res/menu/nearby_info_dialog_options.xml
Normal file
9
app/src/main/res/menu/nearby_info_dialog_options.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@+id/nearby_info_menu_commons_article"
|
||||||
|
android:title="@string/nearby_info_menu_commons_article"
|
||||||
|
/>
|
||||||
|
<item android:id="@+id/nearby_info_menu_wikidata_article"
|
||||||
|
android:title="@string/nearby_info_menu_wikidata_article"
|
||||||
|
/>
|
||||||
|
</menu>
|
||||||
|
|
@ -195,4 +195,7 @@ Tap this message (or hit back) to skip this step.</string>
|
||||||
<string name="navigation_item_settings">Settings</string>
|
<string name="navigation_item_settings">Settings</string>
|
||||||
<string name="navigation_item_feedback">Feedback</string>
|
<string name="navigation_item_feedback">Feedback</string>
|
||||||
<string name="navigation_item_logout">Logout</string>
|
<string name="navigation_item_logout">Logout</string>
|
||||||
|
|
||||||
|
<string name="nearby_info_menu_commons_article">Commons Article</string>
|
||||||
|
<string name="nearby_info_menu_wikidata_article">WikiData Article</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue