mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge pull request #645 from maskaravivek/overlayMenu
Add popup menu in nearby info dialog
This commit is contained in:
commit
b3215b1e78
8 changed files with 97 additions and 8 deletions
|
|
@ -44,6 +44,7 @@ android {
|
|||
minSdkVersion project.minSdkVersion
|
||||
targetSdkVersion project.targetSdkVersion
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
|
@ -34,10 +37,13 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
@BindView(R.id.link_preview_go_button)
|
||||
TextView goToButton;
|
||||
|
||||
@BindView(R.id.link_preview_overflow_button)
|
||||
ImageView overflowButton;
|
||||
|
||||
private Unbinder unbinder;
|
||||
|
||||
private LatLng location;
|
||||
private Uri articleLink;
|
||||
private Sitelinks sitelinks;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
|
@ -56,15 +62,61 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
}
|
||||
|
||||
private void getArticleLink(Bundle bundle) {
|
||||
Sitelinks sitelinks = bundle.getParcelable(ARG_SITE_LINK);
|
||||
this.sitelinks = bundle.getParcelable(ARG_SITE_LINK);
|
||||
|
||||
if (sitelinks.getWikipediaLink() != null) {
|
||||
this.articleLink = sitelinks.getWikipediaLink();
|
||||
} else {
|
||||
if (sitelinks.getWikipediaLink() == null) {
|
||||
goToButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
overflowButton.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
|
||||
|
||||
overflowButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popupMenuListener();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void popupMenuListener() {
|
||||
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) {
|
||||
NearbyInfoDialog mDialog = new NearbyInfoDialog();
|
||||
Bundle bundle = new Bundle();
|
||||
|
|
@ -96,7 +148,11 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
|
||||
@OnClick(R.id.link_preview_go_button)
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class Sitelinks implements Parcelable {
|
|||
stringUrl = stringUrl
|
||||
.replaceAll("<", "")
|
||||
.replaceAll(">", "")
|
||||
.replaceAll("\n", "");
|
||||
.replaceAll("[\n\r]", "");
|
||||
if (!Utils.isNullOrWhiteSpace(stringUrl) && stringUrl != null) {
|
||||
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_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:orientation="horizontal"
|
||||
android:minHeight="64dp">
|
||||
|
||||
<TextView
|
||||
|
|
@ -52,6 +52,16 @@
|
|||
android:textColor="@android:color/black"
|
||||
android:textSize="20sp"
|
||||
tools:text="Lorem ipsum" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/link_preview_overflow_button"
|
||||
android:layout_width="@dimen/overflow_button_dimen"
|
||||
android:layout_height="@dimen/overflow_button_dimen"
|
||||
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>
|
||||
|
||||
<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>
|
||||
|
|
@ -4,4 +4,5 @@
|
|||
<dimen name="small_margin">8dp</dimen>
|
||||
<dimen name="bottom_peak_height">240dp</dimen>
|
||||
<dimen name="hamburger_menu_item">18sp</dimen>
|
||||
<dimen name="overflow_button_dimen">48dp</dimen>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -179,4 +179,7 @@ Tap this message (or hit back) to skip this step.</string>
|
|||
<string name="navigation_item_settings">Settings</string>
|
||||
<string name="navigation_item_feedback">Feedback</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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue