mirror of
https://github.com/gsantner/dandelion
synced 2024-11-25 22:02:08 +01:00
Update sharing functionality
This commit is contained in:
parent
8f2a01ca73
commit
fb4baa6481
5 changed files with 191 additions and 137 deletions
|
@ -48,7 +48,6 @@ import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.app.NotificationCompat;
|
|
||||||
import android.support.v7.widget.ActionMenuView;
|
import android.support.v7.widget.ActionMenuView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
@ -85,6 +84,7 @@ import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
||||||
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
||||||
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
||||||
import com.github.dfa.diaspora_android.util.Helpers;
|
import com.github.dfa.diaspora_android.util.Helpers;
|
||||||
|
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
.setAction(android.R.string.yes, new View.OnClickListener() {
|
.setAction(android.R.string.yes, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/notifications");
|
webView.loadUrl("https://" + podDomain + "/notifications");
|
||||||
} else {
|
} else {
|
||||||
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||||
|
@ -238,7 +238,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
String url = "https://" + podDomain;
|
String url = "https://" + podDomain;
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadData("", "text/html", null);
|
webView.loadData("", "text/html", null);
|
||||||
webView.loadUrl(url);
|
webView.loadUrl(url);
|
||||||
} else {
|
} else {
|
||||||
|
@ -296,7 +296,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.reload();
|
webView.reload();
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -314,12 +314,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
progressBar.setProgress(progress);
|
progressBar.setProgress(progress);
|
||||||
|
|
||||||
if (progress > 0 && progress <= 60) {
|
if (progress > 0 && progress <= 60) {
|
||||||
Helpers.getUserProfile(wv);
|
WebHelper.getUserProfile(wv);
|
||||||
Helpers.optimizeMobileSiteLayout(wv);
|
WebHelper.optimizeMobileSiteLayout(wv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progress > 60) {
|
if (progress > 60) {
|
||||||
Helpers.optimizeMobileSiteLayout(wv);
|
WebHelper.optimizeMobileSiteLayout(wv);
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
|
progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
|
||||||
|
@ -618,7 +618,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_notifications: {
|
case R.id.action_notifications: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/notifications");
|
webView.loadUrl("https://" + podDomain + "/notifications");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -628,7 +628,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
case R.id.action_conversations: {
|
case R.id.action_conversations: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/conversations");
|
webView.loadUrl("https://" + podDomain + "/conversations");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -649,7 +649,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
case R.id.action_compose: {
|
case R.id.action_compose: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/status_messages/new");
|
webView.loadUrl("https://" + podDomain + "/status_messages/new");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -685,7 +685,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
case R.id.action_search: {
|
case R.id.action_search: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
LinearLayout layout = new LinearLayout(this);
|
LinearLayout layout = new LinearLayout(this);
|
||||||
layout.setOrientation(LinearLayout.VERTICAL);
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
@ -844,12 +844,13 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
void handleSendText(Intent intent) {
|
void handleSendText(Intent intent) {
|
||||||
webView.loadUrl("https://"+podDomain+"/status_messages/new");
|
webView.loadUrl("https://"+podDomain+"/status_messages/new");
|
||||||
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||||
if(appSettings.isAppendSharedViaApp()) {
|
if(appSettings.isAppendSharedViaApp()) {
|
||||||
//TODO: Make \n work
|
// = \n
|
||||||
content = content + " \n" +getString(R.string.shared_by_diaspora_android);
|
content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
||||||
}
|
}
|
||||||
final String sharedText = content;
|
|
||||||
|
final String sharedText = WebHelper.escapeHtmlText(content);
|
||||||
if (sharedText != null) {
|
if (sharedText != null) {
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
|
@ -876,20 +877,24 @@ public class MainActivity extends AppCompatActivity
|
||||||
*/
|
*/
|
||||||
void handleSendSubject(Intent intent) {
|
void handleSendSubject(Intent intent) {
|
||||||
webView.loadUrl("https://"+podDomain+"/status_messages/new");
|
webView.loadUrl("https://"+podDomain+"/status_messages/new");
|
||||||
String content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||||
final String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
String subject = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_SUBJECT));
|
||||||
|
|
||||||
if (appSettings.isAppendSharedViaApp()) {
|
if (appSettings.isAppendSharedViaApp()) {
|
||||||
//TODO: Make \n work
|
// = \n
|
||||||
content = content + " \n" + getString(R.string.shared_by_diaspora_android);
|
content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
||||||
}
|
}
|
||||||
final String sharedText = content;
|
|
||||||
if (sharedSubject != null) {
|
final String sharedSubject = WebHelper.escapeHtmlText(subject);
|
||||||
|
final String sharedContent = WebHelper.escapeHtmlText(content);
|
||||||
|
|
||||||
|
if (subject != null) {
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
|
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
webView.loadUrl("javascript:(function() { " +
|
webView.loadUrl("javascript:(function() { " +
|
||||||
"document.getElementsByTagName('textarea')[0].style.height='110px'; " +
|
"document.getElementsByTagName('textarea')[0].style.height='110px'; " +
|
||||||
"document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedText + "'; " +
|
"document.getElementsByTagName('textarea')[0].innerHTML = '**" + sharedSubject + "** " + sharedContent + "'; " +
|
||||||
" if(document.getElementById(\"main_nav\")) {" +
|
" if(document.getElementById(\"main_nav\")) {" +
|
||||||
" document.getElementById(\"main_nav\").parentNode.removeChild(" +
|
" document.getElementById(\"main_nav\").parentNode.removeChild(" +
|
||||||
" document.getElementById(\"main_nav\"));" +
|
" document.getElementById(\"main_nav\"));" +
|
||||||
|
@ -952,7 +957,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
// Handle navigation view item clicks here.
|
// Handle navigation view item clicks here.
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.nav_stream: {
|
case R.id.nav_stream: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/stream");
|
webView.loadUrl("https://" + podDomain + "/stream");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -961,7 +966,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_profile: {
|
case R.id.nav_profile: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/people/" + appSettings.getProfileId());
|
webView.loadUrl("https://" + podDomain + "/people/" + appSettings.getProfileId());
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -970,9 +975,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_followed_tags: {
|
case R.id.nav_followed_tags: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
// webView.loadUrl("https://" + podDomain + "/followed_tags");
|
// webView.loadUrl("https://" + podDomain + "/followed_tags");
|
||||||
Helpers.showFollowedTagsList(webView, app);
|
WebHelper.showFollowedTagsList(webView, app);
|
||||||
setTitle(R.string.nav_followed_tags);
|
setTitle(R.string.nav_followed_tags);
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -981,9 +986,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_aspects: {
|
case R.id.nav_aspects: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
// webView.loadUrl("https://" + podDomain + "/aspects");
|
// webView.loadUrl("https://" + podDomain + "/aspects");
|
||||||
Helpers.showAspectList(webView, app);
|
WebHelper.showAspectList(webView, app);
|
||||||
setTitle(R.string.aspects);
|
setTitle(R.string.aspects);
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -992,7 +997,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_activities: {
|
case R.id.nav_activities: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/activity");
|
webView.loadUrl("https://" + podDomain + "/activity");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -1001,7 +1006,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_liked: {
|
case R.id.nav_liked: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/liked");
|
webView.loadUrl("https://" + podDomain + "/liked");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -1010,7 +1015,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_commented: {
|
case R.id.nav_commented: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/commented");
|
webView.loadUrl("https://" + podDomain + "/commented");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -1019,7 +1024,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_mentions: {
|
case R.id.nav_mentions: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/mentions");
|
webView.loadUrl("https://" + podDomain + "/mentions");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
@ -1028,7 +1033,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
case R.id.nav_public: {
|
case R.id.nav_public: {
|
||||||
if (Helpers.isOnline(MainActivity.this)) {
|
if (WebHelper.isOnline(MainActivity.this)) {
|
||||||
webView.loadUrl("https://" + podDomain + "/public");
|
webView.loadUrl("https://" + podDomain + "/public");
|
||||||
} else {
|
} else {
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
|
|
|
@ -46,6 +46,7 @@ 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.task.GetPodsService;
|
import com.github.dfa.diaspora_android.task.GetPodsService;
|
||||||
import com.github.dfa.diaspora_android.util.Helpers;
|
import com.github.dfa.diaspora_android.util.Helpers;
|
||||||
|
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
setListedPods(app.getSettings().getPreviousPodlist());
|
setListedPods(app.getSettings().getPreviousPodlist());
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
|
LocalBroadcastManager.getInstance(this).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
|
||||||
|
|
||||||
if (!Helpers.isOnline(PodSelectionActivity.this)) {
|
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +165,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
Linkify.addLinks(dialogMessage, Linkify.ALL);
|
Linkify.addLinks(dialogMessage, Linkify.ALL);
|
||||||
|
|
||||||
// Check if online
|
// Check if online
|
||||||
if (!Helpers.isOnline(PodSelectionActivity.this)) {
|
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||||
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +233,7 @@ public class PodSelectionActivity extends AppCompatActivity {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_reload: {
|
case R.id.action_reload: {
|
||||||
if (Helpers.isOnline(PodSelectionActivity.this)) {
|
if (WebHelper.isOnline(PodSelectionActivity.this)) {
|
||||||
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
|
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
|
||||||
startService(i);
|
startService(i);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import android.widget.ImageView;
|
||||||
import com.github.dfa.diaspora_android.App;
|
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.util.Helpers;
|
import com.github.dfa.diaspora_android.util.Helpers;
|
||||||
|
import com.github.dfa.diaspora_android.util.WebHelper;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
|
@ -16,33 +16,15 @@
|
||||||
|
|
||||||
If not, see <http://www.gnu.org/licenses/>.
|
If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.dfa.diaspora_android.util;
|
package com.github.dfa.diaspora_android.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
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.data.AppSettings;
|
|
||||||
import com.github.dfa.diaspora_android.data.PodAspect;
|
|
||||||
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class Helpers {
|
public class Helpers {
|
||||||
|
|
||||||
public static boolean isOnline(Context context) {
|
|
||||||
ConnectivityManager cnm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo ni = cnm.getActiveNetworkInfo();
|
|
||||||
return ni != null && ni.isConnectedOrConnecting();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) {
|
public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) {
|
||||||
Intent intent = new Intent(from, to);
|
Intent intent = new Intent(from, to);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||||
|
@ -52,87 +34,4 @@ public class Helpers {
|
||||||
from.finish();
|
from.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void optimizeMobileSiteLayout(final WebView wv) {
|
|
||||||
wv.loadUrl("javascript: ( function() {" +
|
|
||||||
" if (document.documentElement == null || document.documentElement.style == null) { return; }" +
|
|
||||||
" document.documentElement.style.paddingBottom = '260px';" +
|
|
||||||
" document.getElementById('main').style.paddingTop = '5px';" +
|
|
||||||
" if(document.getElementById('main_nav')) {" +
|
|
||||||
" document.getElementById('main_nav').parentNode.removeChild(" +
|
|
||||||
" document.getElementById('main_nav'));" +
|
|
||||||
" } else if (document.getElementById('main-nav')) {" +
|
|
||||||
" document.getElementById('main-nav').parentNode.removeChild(" +
|
|
||||||
" document.getElementById('main-nav'));" +
|
|
||||||
" }" +
|
|
||||||
"})();");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void getUserProfile(final WebView wv) {
|
|
||||||
// aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
|
|
||||||
wv.loadUrl("javascript: ( function() {" +
|
|
||||||
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" +
|
|
||||||
" var followed_tags = document.getElementById(\"followed_tags\");" +
|
|
||||||
" if(followed_tags != null) {" +
|
|
||||||
" try {" +
|
|
||||||
" var links = followed_tags.nextElementSibling.children[0].children;" +
|
|
||||||
" var tags = [];" +
|
|
||||||
" for(var i = 0; i < links.length - 1; i++) {" + // the last element is "Manage followed tags" link
|
|
||||||
" tags.push(links[i].innerText.substring(1));" +
|
|
||||||
" }" +
|
|
||||||
" gon.user[\"android_app.followed_tags\"] = tags;" +
|
|
||||||
" } catch(e) {}" +
|
|
||||||
" }" +
|
|
||||||
" var userProfile = JSON.stringify(gon.user);" +
|
|
||||||
" AndroidBridge.setUserProfile(userProfile.toString());" +
|
|
||||||
" } " +
|
|
||||||
"})();");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showAspectList(final WebView wv, final App app) {
|
|
||||||
wv.stopLoading();
|
|
||||||
PodUserProfile profile = app.getPodUserProfile();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
|
||||||
|
|
||||||
// Content
|
|
||||||
for (PodAspect aspect : profile.getAspects()) {
|
|
||||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
|
||||||
sb.append(aspect.toHtmlLink(app));
|
|
||||||
sb.append("<hr style='height:5px;' />");
|
|
||||||
}
|
|
||||||
|
|
||||||
// End
|
|
||||||
sb.append("</body></html>");
|
|
||||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showFollowedTagsList(final WebView wv, final App app) {
|
|
||||||
wv.stopLoading();
|
|
||||||
PodUserProfile profile = app.getPodUserProfile();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
|
||||||
|
|
||||||
// Content
|
|
||||||
AppSettings appSettings = app.getSettings();
|
|
||||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
|
||||||
sb.append(String.format(Locale.getDefault(),
|
|
||||||
"<a href='https://%s/followed_tags' style='color: #000000; text-decoration: none;'><b>%s</b></a>",
|
|
||||||
appSettings.getPodDomain(), app.getString(R.string.all_tags)));
|
|
||||||
sb.append("<hr style='height:5px;' />");
|
|
||||||
for (String tag: profile.getFollowedTags()) {
|
|
||||||
sb.append("<span style='margin-left: 30px; '></span>» ");
|
|
||||||
sb.append(String.format(Locale.getDefault(),
|
|
||||||
"<a href='https://%s/tags/%s' style='color: #000000; text-decoration: none;'>#%s</a>",
|
|
||||||
appSettings.getPodDomain(), tag, tag));
|
|
||||||
sb.append("<hr style='height:5px;' />");
|
|
||||||
}
|
|
||||||
|
|
||||||
// End
|
|
||||||
sb.append("</body></html>");
|
|
||||||
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
/*
|
||||||
|
This file is part of the Diaspora for Android.
|
||||||
|
|
||||||
|
Diaspora for Android is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Diaspora for Android is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with the Diaspora for Android.
|
||||||
|
|
||||||
|
If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.dfa.diaspora_android.util;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import com.github.dfa.diaspora_android.App;
|
||||||
|
import com.github.dfa.diaspora_android.R;
|
||||||
|
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||||
|
import com.github.dfa.diaspora_android.data.PodAspect;
|
||||||
|
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Gregor Santner on 07.08.16.
|
||||||
|
* https://gsantner.github.io
|
||||||
|
*/
|
||||||
|
public class WebHelper {
|
||||||
|
|
||||||
|
public static boolean isOnline(Context context) {
|
||||||
|
ConnectivityManager cnm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo ni = cnm.getActiveNetworkInfo();
|
||||||
|
return ni != null && ni.isConnectedOrConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceUrlWithMarkdown(String url){
|
||||||
|
if( url != null && URLUtil.isHttpUrl(url) || URLUtil.isHttpsUrl(url)){
|
||||||
|
return "<" + url + ">";
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String escapeHtmlText(String text){
|
||||||
|
text = Html.escapeHtml(text);;
|
||||||
|
text = text.replace("\n", " ");
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void optimizeMobileSiteLayout(final WebView wv) {
|
||||||
|
wv.loadUrl("javascript: ( function() {" +
|
||||||
|
" if (document.documentElement == null || document.documentElement.style == null) { return; }" +
|
||||||
|
" document.documentElement.style.paddingBottom = '260px';" +
|
||||||
|
" document.getElementById('main').style.paddingTop = '5px';" +
|
||||||
|
" if(document.getElementById('main_nav')) {" +
|
||||||
|
" document.getElementById('main_nav').parentNode.removeChild(" +
|
||||||
|
" document.getElementById('main_nav'));" +
|
||||||
|
" } else if (document.getElementById('main-nav')) {" +
|
||||||
|
" document.getElementById('main-nav').parentNode.removeChild(" +
|
||||||
|
" document.getElementById('main-nav'));" +
|
||||||
|
" }" +
|
||||||
|
"})();");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getUserProfile(final WebView wv) {
|
||||||
|
// aspects":[{"id":124934,"name":"Friends","selected":true},{"id":124937,"name":"Liked me","selected":false},{"id":124938,"name":"Follow","selected":false},{"id":128327,"name":"Nur ich","selected":false}]
|
||||||
|
wv.loadUrl("javascript: ( function() {" +
|
||||||
|
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" +
|
||||||
|
" var followed_tags = document.getElementById(\"followed_tags\");" +
|
||||||
|
" if(followed_tags != null) {" +
|
||||||
|
" try {" +
|
||||||
|
" var links = followed_tags.nextElementSibling.children[0].children;" +
|
||||||
|
" var tags = [];" +
|
||||||
|
" for(var i = 0; i < links.length - 1; i++) {" + // the last element is "Manage followed tags" link
|
||||||
|
" tags.push(links[i].innerText.substring(1));" +
|
||||||
|
" }" +
|
||||||
|
" gon.user[\"android_app.followed_tags\"] = tags;" +
|
||||||
|
" } catch(e) {}" +
|
||||||
|
" }" +
|
||||||
|
" var userProfile = JSON.stringify(gon.user);" +
|
||||||
|
" AndroidBridge.setUserProfile(userProfile.toString());" +
|
||||||
|
" } " +
|
||||||
|
"})();");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showAspectList(final WebView wv, final App app) {
|
||||||
|
wv.stopLoading();
|
||||||
|
PodUserProfile profile = app.getPodUserProfile();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
||||||
|
|
||||||
|
// Content
|
||||||
|
for (PodAspect aspect : profile.getAspects()) {
|
||||||
|
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||||
|
sb.append(aspect.toHtmlLink(app));
|
||||||
|
sb.append("<hr style='height:5px;' />");
|
||||||
|
}
|
||||||
|
|
||||||
|
// End
|
||||||
|
sb.append("</body></html>");
|
||||||
|
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showFollowedTagsList(final WebView wv, final App app) {
|
||||||
|
wv.stopLoading();
|
||||||
|
PodUserProfile profile = app.getPodUserProfile();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("<html><body style='margin-top: 25px; margin-left:auto;margin-right:auto; font-size: 400%;'>");
|
||||||
|
|
||||||
|
// Content
|
||||||
|
AppSettings appSettings = app.getSettings();
|
||||||
|
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||||
|
sb.append(String.format(Locale.getDefault(),
|
||||||
|
"<a href='https://%s/followed_tags' style='color: #000000; text-decoration: none;'><b>%s</b></a>",
|
||||||
|
appSettings.getPodDomain(), app.getString(R.string.all_tags)));
|
||||||
|
sb.append("<hr style='height:5px;' />");
|
||||||
|
for (String tag: profile.getFollowedTags()) {
|
||||||
|
sb.append("<span style='margin-left: 30px; '></span>» ");
|
||||||
|
sb.append(String.format(Locale.getDefault(),
|
||||||
|
"<a href='https://%s/tags/%s' style='color: #000000; text-decoration: none;'>#%s</a>",
|
||||||
|
appSettings.getPodDomain(), tag, tag));
|
||||||
|
sb.append("<hr style='height:5px;' />");
|
||||||
|
}
|
||||||
|
|
||||||
|
// End
|
||||||
|
sb.append("</body></html>");
|
||||||
|
wv.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-16", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue