1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-09-13 20:29:42 +02:00
This commit is contained in:
Dmitriy Bogdanov 2016-10-03 09:20:00 +00:00 committed by GitHub
commit eef410ceb7
8 changed files with 54 additions and 2 deletions

View file

@ -94,8 +94,7 @@ public class SettingsActivity extends AppCompatActivity {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updatePreference(findPreference(key));
if (key != null && isAdded() && (key.equals(getString(R.string.pref_key__clear_cache)) ||
key.equals(getString(R.string.pref_key__font_size)) ||
if (key != null && isAdded() && (key.equals(getString(R.string.pref_key__font_size)) ||
key.equals(getString(R.string.pref_key__load_images)) ||
key.equals(getString(R.string.pref_key__intellihide_toolbars)) ||
key.equals(getString(R.string.pref_key__proxy_enabled)) ||
@ -158,6 +157,10 @@ public class SettingsActivity extends AppCompatActivity {
.show();
return true;
}
case R.string.pref_title__clear_cache: {
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
break;
}
default: {
intent = null;

View file

@ -260,6 +260,10 @@ public class AppSettings {
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() {
return getBoolean(prefApp, R.string.pref_key__logging_enabled, true);
}

View file

@ -37,9 +37,11 @@ import android.view.ContextMenu;
import android.view.MenuItem;
import android.widget.Toast;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.task.ImageDownloadTask;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
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_SHARE_LINK = 13;
public static final int ID_SHARE_IMAGE = 14;
public static final int ID_OPEN_HERE = 15;
private final Context context;
private Activity parentActivity;
@ -195,6 +198,13 @@ public class ContextMenuWebView extends NestedWebView {
.getText(R.string.context_menu_share_link)));
}
break;
//Open link in the webview
case ID_OPEN_HERE:
if (url != null) {
loadUrlNew(url);
}
break;
}
return true;
}
@ -212,6 +222,10 @@ public class ContextMenuWebView extends NestedWebView {
result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
// Menu options for a hyperlink.
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_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link)).setOnMenuItemClickListener(handler);
}

View file

@ -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.PodAspect;
import java.util.regex.Pattern;
/**
* Helper class that provides easy access to specific urls related to diaspora
* 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 URL_BLANK = "about:blank";
public static final Pattern NUMBERS_ONLY_PATTERN = Pattern.compile("^\\d+$");
public DiasporaUrlHelper(AppSettings settings) {
this.settings = settings;
}
@ -237,4 +241,15 @@ public class DiasporaUrlHelper {
}
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;
}
}

View file

@ -27,6 +27,7 @@ import android.webkit.WebViewClient;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
public class CustomWebViewClient extends WebViewClient {
private final App app;
@ -44,6 +45,10 @@ public class CustomWebViewClient extends WebViewClient {
i.putExtra(MainActivity.EXTRA_URL, url);
LocalBroadcastManager.getInstance(app.getApplicationContext()).sendBroadcast(i);
return true;
} else if (app.getSettings().isPostContextMenuEnabled()
&& new DiasporaUrlHelper(app.getSettings()).isPostUrl(url)) {
view.showContextMenu();
return true;
}
return false;
}

View file

@ -46,6 +46,7 @@
<!-- More -->
<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_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>
<!-- 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_desc__sub_logging" translatable="false">@string/fragment_debug__section_log</string>

View file

@ -85,6 +85,7 @@
<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_copy_link">Copy link address to clipboard</string>
<string name="context_menu_open_here">Open link</string>
<!-- More from MainActivity -->

View file

@ -152,6 +152,12 @@
android:key="@string/pref_catkey__category_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
android:summary="@string/pref_desc__sub_logging"
android:title="@string/pref_title__sub_logging">