mirror of
https://github.com/gsantner/dandelion
synced 2024-11-15 17:02:10 +01:00
Add an option to open context menu for post links
This commit is contained in:
parent
4e00d54c78
commit
7698f7b724
7 changed files with 49 additions and 0 deletions
|
@ -260,6 +260,10 @@ public class AppSettings {
|
||||||
return getBoolean(prefApp, R.string.pref_key__chrome_custom_tabs_enabled, true);
|
return getBoolean(prefApp, R.string.pref_key__chrome_custom_tabs_enabled, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPostContextMenuEnabled() {
|
||||||
|
return getBoolean(prefApp, R.string.pref_key__post_link_context_menu_enabled, false);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLoggingEnabled() {
|
public boolean isLoggingEnabled() {
|
||||||
return getBoolean(prefApp, R.string.pref_key__logging_enabled, true);
|
return getBoolean(prefApp, R.string.pref_key__logging_enabled, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,11 @@ import android.view.ContextMenu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.github.dfa.diaspora_android.App;
|
||||||
import com.github.dfa.diaspora_android.R;
|
import com.github.dfa.diaspora_android.R;
|
||||||
import com.github.dfa.diaspora_android.activity.MainActivity;
|
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||||
import com.github.dfa.diaspora_android.task.ImageDownloadTask;
|
import com.github.dfa.diaspora_android.task.ImageDownloadTask;
|
||||||
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ public class ContextMenuWebView extends NestedWebView {
|
||||||
public static final int ID_COPY_LINK = 12;
|
public static final int ID_COPY_LINK = 12;
|
||||||
public static final int ID_SHARE_LINK = 13;
|
public static final int ID_SHARE_LINK = 13;
|
||||||
public static final int ID_SHARE_IMAGE = 14;
|
public static final int ID_SHARE_IMAGE = 14;
|
||||||
|
public static final int ID_OPEN_HERE = 15;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Activity parentActivity;
|
private Activity parentActivity;
|
||||||
|
@ -195,6 +198,13 @@ public class ContextMenuWebView extends NestedWebView {
|
||||||
.getText(R.string.context_menu_share_link)));
|
.getText(R.string.context_menu_share_link)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//Open link in the webview
|
||||||
|
case ID_OPEN_HERE:
|
||||||
|
if (url != null) {
|
||||||
|
loadUrlNew(url);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -212,6 +222,10 @@ public class ContextMenuWebView extends NestedWebView {
|
||||||
result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
|
result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
|
||||||
// Menu options for a hyperlink.
|
// Menu options for a hyperlink.
|
||||||
menu.setHeaderTitle(result.getExtra());
|
menu.setHeaderTitle(result.getExtra());
|
||||||
|
String url = result.getExtra();
|
||||||
|
if (url != null && new DiasporaUrlHelper(((App)parentActivity.getApplication()).getSettings()).isPostUrl(url)) {
|
||||||
|
menu.add(0, ID_OPEN_HERE, 0, context.getString(R.string.context_menu_open_here)).setOnMenuItemClickListener(handler);
|
||||||
|
}
|
||||||
menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link)).setOnMenuItemClickListener(handler);
|
menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link)).setOnMenuItemClickListener(handler);
|
||||||
menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link)).setOnMenuItemClickListener(handler);
|
menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link)).setOnMenuItemClickListener(handler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import com.github.dfa.diaspora_android.R;
|
||||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||||
import com.github.dfa.diaspora_android.data.PodAspect;
|
import com.github.dfa.diaspora_android.data.PodAspect;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class that provides easy access to specific urls related to diaspora
|
* Helper class that provides easy access to specific urls related to diaspora
|
||||||
* Created by vanitasvitae on 10.08.16.
|
* Created by vanitasvitae on 10.08.16.
|
||||||
|
@ -51,6 +53,8 @@ public class DiasporaUrlHelper {
|
||||||
public static final String SUBURL_STATISTICS = "/statistics";
|
public static final String SUBURL_STATISTICS = "/statistics";
|
||||||
public static final String URL_BLANK = "about:blank";
|
public static final String URL_BLANK = "about:blank";
|
||||||
|
|
||||||
|
public static final Pattern NUMBERS_ONLY_PATTERN = Pattern.compile("^\\d+$");
|
||||||
|
|
||||||
public DiasporaUrlHelper(AppSettings settings) {
|
public DiasporaUrlHelper(AppSettings settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
@ -237,4 +241,15 @@ public class DiasporaUrlHelper {
|
||||||
}
|
}
|
||||||
return app.getString(R.string.aspects);
|
return app.getString(R.string.aspects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPostUrl(String url) {
|
||||||
|
if (url.startsWith(getPodUrl() + SUBURL_POSTS)) {
|
||||||
|
String path = url.substring((getPodUrl() + SUBURL_POSTS).length());
|
||||||
|
if (NUMBERS_ONLY_PATTERN.matcher(path).matches()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.webkit.WebViewClient;
|
||||||
|
|
||||||
import com.github.dfa.diaspora_android.App;
|
import com.github.dfa.diaspora_android.App;
|
||||||
import com.github.dfa.diaspora_android.activity.MainActivity;
|
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||||
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
|
||||||
public class CustomWebViewClient extends WebViewClient {
|
public class CustomWebViewClient extends WebViewClient {
|
||||||
private final App app;
|
private final App app;
|
||||||
|
@ -44,6 +45,10 @@ public class CustomWebViewClient extends WebViewClient {
|
||||||
i.putExtra(MainActivity.EXTRA_URL, url);
|
i.putExtra(MainActivity.EXTRA_URL, url);
|
||||||
LocalBroadcastManager.getInstance(app.getApplicationContext()).sendBroadcast(i);
|
LocalBroadcastManager.getInstance(app.getApplicationContext()).sendBroadcast(i);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (app.getSettings().isPostContextMenuEnabled()
|
||||||
|
&& new DiasporaUrlHelper(app.getSettings()).isPostUrl(url)) {
|
||||||
|
view.showContextMenu();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
<!-- More -->
|
<!-- More -->
|
||||||
<string name="pref_catkey__category_more" translatable="false">pref_catkey__category_more</string>
|
<string name="pref_catkey__category_more" translatable="false">pref_catkey__category_more</string>
|
||||||
|
<string name="pref_key__post_link_context_menu_enabled" translatable="false">pref_key__post_link_context_menu_enabled</string>
|
||||||
<string name="pref_key__logging_spam_enabled" translatable="false">pref_key__logging_spam_enabled</string>
|
<string name="pref_key__logging_spam_enabled" translatable="false">pref_key__logging_spam_enabled</string>
|
||||||
<string name="pref_key__logging_enabled" translatable="false">pref_key__logging_enabled</string>
|
<string name="pref_key__logging_enabled" translatable="false">pref_key__logging_enabled</string>
|
||||||
|
|
||||||
|
@ -118,6 +119,9 @@
|
||||||
<string name="pref_desc__append_shared_via_app">Append a reference to this app ("shared by…") to shared texts</string>
|
<string name="pref_desc__append_shared_via_app">Append a reference to this app ("shared by…") to shared texts</string>
|
||||||
|
|
||||||
<!-- More -->
|
<!-- More -->
|
||||||
|
<string name="pref_title__post_link_context_menu_enabled">Context menu for post links</string>
|
||||||
|
<string name="pref_desc__post_link_context_menu_enabled">Open context menu for post links with short press</string>
|
||||||
|
|
||||||
<string name="pref_title__sub_logging" translatable="false">@string/about_activity__title_debug_info</string>
|
<string name="pref_title__sub_logging" translatable="false">@string/about_activity__title_debug_info</string>
|
||||||
<string name="pref_desc__sub_logging" translatable="false">@string/fragment_debug__section_log</string>
|
<string name="pref_desc__sub_logging" translatable="false">@string/fragment_debug__section_log</string>
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@
|
||||||
<string name="context_menu_share_image">Share image</string>
|
<string name="context_menu_share_image">Share image</string>
|
||||||
<string name="context_menu_open_external_browser">Open in external browser…</string>
|
<string name="context_menu_open_external_browser">Open in external browser…</string>
|
||||||
<string name="context_menu_copy_link">Copy link address to clipboard</string>
|
<string name="context_menu_copy_link">Copy link address to clipboard</string>
|
||||||
|
<string name="context_menu_open_here">Open link</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- More from MainActivity -->
|
<!-- More from MainActivity -->
|
||||||
|
|
|
@ -152,6 +152,12 @@
|
||||||
android:key="@string/pref_catkey__category_more"
|
android:key="@string/pref_catkey__category_more"
|
||||||
android:title="@string/pref_cat__more">
|
android:title="@string/pref_cat__more">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="@string/pref_key__post_link_context_menu_enabled"
|
||||||
|
android:title="@string/pref_title__post_link_context_menu_enabled"
|
||||||
|
android:summary="@string/pref_desc__post_link_context_menu_enabled"/>
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:summary="@string/pref_desc__sub_logging"
|
android:summary="@string/pref_desc__sub_logging"
|
||||||
android:title="@string/pref_title__sub_logging">
|
android:title="@string/pref_title__sub_logging">
|
||||||
|
|
Loading…
Reference in a new issue