1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-12-15 00:31:11 +01:00

Merged master

This commit is contained in:
vanitasvitae 2016-10-10 15:07:30 +02:00
commit c09618f191
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
62 changed files with 1943 additions and 1101 deletions

View file

@ -62,10 +62,10 @@ public class AboutActivity extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@BindView(R.id.toolbar)
@BindView(R.id.main__topbar)
protected Toolbar toolbar;
@BindView(R.id.linearlayout)
@BindView(R.id.appbar_linear_layout)
protected LinearLayout linearLayout;
@Override

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__http_proxy_enabled)) ||
@ -162,11 +161,17 @@ public class SettingsActivity extends AppCompatActivity {
return true;
}
case R.string.pref_title__http_proxy_load_tor_preset: {
((EditTextPreference)findPreference(getString(R.string.pref_key__http_proxy_host))).setText("127.0.0.1");
((EditTextPreference)findPreference(getString(R.string.pref_key__http_proxy_port))).setText("8118");
((EditTextPreference) findPreference(getString(R.string.pref_key__http_proxy_host))).setText("127.0.0.1");
((EditTextPreference) findPreference(getString(R.string.pref_key__http_proxy_port))).setText("8118");
return true;
}
case R.string.pref_title__clear_cache:
{
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
break;
}
default: {
intent = null;
break;

View file

@ -1,56 +0,0 @@
/*
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.activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.util.Helpers;
import butterknife.ButterKnife;
public class SplashActivity extends AppCompatActivity {
private App app;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash__activity);
ButterKnife.bind(this);
app = (App) getApplication();
int delay = getResources().getInteger(R.integer.splash_delay);
new Handler().postDelayed(startActivityRunnable, delay);
}
private final Runnable startActivityRunnable = new Runnable() {
public void run() {
boolean hasPodDomain = app.getSettings().hasPodDomain();
Helpers.animateToActivity(SplashActivity.this,
hasPodDomain ? MainActivity.class : PodSelectionActivity.class,
true
);
}
};
}

View file

@ -0,0 +1,371 @@
/*
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.fragment;
import android.Manifest;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;
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.data.AppSettings;
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
import com.github.dfa.diaspora_android.webview.CustomWebViewClient;
import com.github.dfa.diaspora_android.webview.ProgressBarWebChromeClient;
import com.github.dfa.diaspora_android.util.AppLog;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import info.guardianproject.netcipher.NetCipher;
import info.guardianproject.netcipher.webkit.WebkitProxy;
/**
* Fragment with a webView and a ProgressBar.
* This Fragment retains its instance.
* Created by vanitas on 26.09.16.
*/
public class BrowserFragment extends CustomFragment {
public static final String TAG = "com.github.dfa.diaspora_android.BrowserFragment";
protected View rootLayout;
protected ContextMenuWebView webView;
protected ProgressBar progressBar;
protected AppSettings appSettings;
protected CustomWebViewClient webViewClient;
protected WebSettings webSettings;
protected String pendingUrl;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
AppLog.d(this, "onCreateView()");
if(rootLayout == null) {
rootLayout = inflater.inflate(R.layout.browser__fragment, container, false);
}
return rootLayout;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
AppLog.d(this, "onViewCreated()");
super.onViewCreated(view, savedInstanceState);
if(this.appSettings == null) {
this.appSettings = ((App) getActivity().getApplication()).getSettings();
}
if(this.webView == null) {
this.webView = (ContextMenuWebView) view.findViewById(R.id.webView);
this.applyWebViewSettings();
}
if(this.progressBar == null) {
this.progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
}
if (appSettings.isProxyEnabled()) {
if (!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
AppLog.e(this, "Could not enable Proxy");
Toast.makeText(getContext(), R.string.toast_set_proxy_failed, Toast.LENGTH_SHORT).show();
}
} else if (appSettings.wasProxyEnabled()) {
resetProxy();
}
if(pendingUrl != null) {
loadUrl(pendingUrl);
pendingUrl = null;
}
webView.setParentActivity(getActivity());
this.setRetainInstance(true);
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (getRetainInstance() && rootLayout.getParent() instanceof ViewGroup) {
((ViewGroup) rootLayout.getParent()).removeView(rootLayout);
}
}
private void applyWebViewSettings() {
this.webSettings = webView.getSettings();
webSettings.setAllowFileAccess(false);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDomStorageEnabled(true);
webSettings.setMinimumFontSize(appSettings.getMinimumFontSize());
webSettings.setLoadsImagesAutomatically(appSettings.isLoadImages());
webSettings.setAppCacheEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= 21) {
WebView.enableSlowWholeDocumentDraw();
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
this.registerForContextMenu(webView);
//webView.setParentActivity(this);
webView.setOverScrollMode(WebView.OVER_SCROLL_ALWAYS);
this.webViewClient = new CustomWebViewClient((App) getActivity().getApplication(), webView);
webView.setWebViewClient(webViewClient);
webView.setWebChromeClient(new ProgressBarWebChromeClient(webView, progressBar));
}
/**
* Set proxy according to arguments. host must not be "" or null, port must be positive.
* Return true on success and update appSettings' proxy related values.
*
* @param host proxy host (eg. localhost or 127.0.0.1)
* @param port proxy port (eg. 8118)
* @return success
* @throws IllegalArgumentException if arguments do not fit specifications above
*/
private boolean setProxy(final String host, final int port) {
AppLog.i(this, "StreamFragment.setProxy()");
if (host != null && !host.equals("") && port >= 0) {
AppLog.i(this, "Set proxy to "+host+":"+port);
//Temporary change thread policy
AppLog.v(this, "Set temporary ThreadPolicy");
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
AppLog.v(this, "Apply NetCipher proxy settings");
NetCipher.setProxy(host, port); //Proxy for HttpsUrlConnections
try {
//Proxy for the webview
AppLog.v(this, "Apply Webkit proxy settings");
WebkitProxy.setProxy(MainActivity.class.getName(), getContext().getApplicationContext(), null, host, port);
} catch (Exception e) {
AppLog.e(this, "Could not apply WebKit proxy settings:\n"+e.toString());
}
AppLog.v(this, "Save changes in appSettings");
appSettings.setProxyEnabled(true);
appSettings.setProxyWasEnabled(true);
AppLog.v(this, "Reset old ThreadPolicy");
StrictMode.setThreadPolicy(old);
AppLog.i(this, "Success! Reload WebView");
webView.reload();
return true;
} else {
AppLog.e(this, "Invalid proxy configuration. Host: "+host+" Port: "+port+"\nRefuse to set proxy");
return false;
}
}
@SuppressWarnings("unused")
private boolean setProxy() {
return setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
}
private void resetProxy() {
AppLog.i(this, "StreamFragment.resetProxy()");
AppLog.v(this, "write changes to appSettings");
appSettings.setProxyEnabled(false);
appSettings.setProxyWasEnabled(false);
//Temporary change thread policy
AppLog.v(this, "Set temporary ThreadPolicy");
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
AppLog.v(this, "clear NetCipher proxy");
NetCipher.clearProxy();
try {
AppLog.v(this, "clear WebKit proxy");
WebkitProxy.resetProxy(MainActivity.class.getName(), getContext());
} catch (Exception e) {
AppLog.e(this, "Could not clear WebKit proxy:\n"+e.toString());
}
AppLog.v(this, "Reset old ThreadPolicy");
StrictMode.setThreadPolicy(old);
//Restart app
AppLog.i(this, "Success! Restart app due to proxy reset");
Intent restartActivity = new Intent(getContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
System.exit(0);
}
@SuppressWarnings("ResultOfMethodCallIgnored")
protected boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
AppLog.i(this, "StreamFragment.makeScreenshotOfWebView()");
if (android.os.Build.VERSION.SDK_INT >= 23) {
int hasWRITE_EXTERNAL_STORAGE = getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
new AlertDialog.Builder(getContext())
.setMessage(R.string.permissions_screenshot)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (android.os.Build.VERSION.SDK_INT >= 23)
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE_ASK_PERMISSIONS);
}
})
.show();
return false;
}
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE_ASK_PERMISSIONS);
return false;
}
}
Date dateNow = new Date();
DateFormat dateFormat = new SimpleDateFormat("yy_MM_dd--HH_mm_ss", Locale.getDefault());
File fileSaveDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Diaspora");
String fileSaveName = hasToShareScreenshot ? ".DfA_share.jpg" : String.format("DfA_%s.jpg", dateFormat.format(dateNow));
if (!fileSaveDirectory.exists()) {
if(!fileSaveDirectory.mkdirs()) {
AppLog.w(this, "Could not mkdir "+fileSaveDirectory.getAbsolutePath());
}
}
if (!hasToShareScreenshot) {
Snackbar.make(webView, getString(R.string.share__toast_screenshot) + " " + fileSaveName, Snackbar.LENGTH_LONG).show();
}
Bitmap bitmap;
webView.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(webView.getDrawingCache());
webView.setDrawingCacheEnabled(false);
OutputStream bitmapWriter = null;
try {
bitmapWriter = new FileOutputStream(new File(fileSaveDirectory, fileSaveName));
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, bitmapWriter);
bitmapWriter.flush();
bitmap.recycle();
} catch (Exception e) {
return false;
} finally {
if (bitmapWriter != null) {
try {
bitmapWriter.close();
} catch (IOException _ignSaveored) {/* Nothing */}
}
}
// Only show share intent when Action Share Screenshot was selected
if (hasToShareScreenshot) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, webView.getTitle());
sharingIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
Uri bmpUri = Uri.fromFile(new File(fileSaveDirectory, fileSaveName));
sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
startActivity(Intent.createChooser(sharingIntent, getString(R.string.action_share_dotdotdot)));
} else {
// Broadcast that this file is indexable
File file = new File(fileSaveDirectory, fileSaveName);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
getActivity().sendBroadcast(intent);
}
return true;
}
@Override
public String getFragmentTag() {
return TAG;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do here */
}
public boolean onBackPressed() {
if(webView.canGoBack()) {
webView.goBack();
return true;
}
return false;
}
public void loadUrl(String url) {
if(getWebView() != null) {
AppLog.v(this, "loadUrl(): load "+url);
getWebView().loadUrlNew(url);
} else {
AppLog.v(this, "loadUrl(): WebView null: Set pending url to "+url);
pendingUrl = url;
}
}
public String getUrl() {
if(getWebView() != null) {
return getWebView().getUrl();
} else {
return pendingUrl;
}
}
public void reloadUrl() {
AppLog.v(this, "reloadUrl()");
if(getWebView() != null) {
getWebView().reload();
}
}
public ContextMenuWebView getWebView() {
return this.webView;
}
}

View file

@ -0,0 +1,65 @@
/*
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.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Menu;
import android.view.MenuInflater;
/**
* Customized abstract Fragment class with some useful methods
* Created by vanitas on 21.09.16.
*/
public abstract class CustomFragment extends Fragment {
public static final String TAG = "com.github.dfa.diaspora_android.CustomFragment";
/**
* We have an optionsMenu
* @param savedInstanceState state
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
/**
* Return the tag used to identify the Fragment.
* @return tag
*/
public abstract String getFragmentTag();
/**
* Add fragment-dependent options to the bottom options toolbar
* @param menu bottom menu
* @param inflater inflater
*/
public abstract void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater);
/**
* Return true if the fragment reacted to a back button press, false else.
* In case the fragment returned false, the parent activity should handle the backPress.
* @return did we react to the back press?
*/
public abstract boolean onBackPressed();
}

View file

@ -0,0 +1,345 @@
/*
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.fragment;
import android.Manifest;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
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.data.PodUserProfile;
import com.github.dfa.diaspora_android.webview.DiasporaStreamWebChromeClient;
import com.github.dfa.diaspora_android.webview.FileUploadWebChromeClient;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.WebHelper;
import org.json.JSONException;
import java.io.File;
import java.io.IOException;
/**
* Fragment that displays the Stream of the diaspora* user
* Created by vanitas on 26.09.16.
*/
public class DiasporaStreamFragment extends BrowserFragment {
public static final String TAG = "com.github.dfa.diaspora_android.StreamFragment";
protected DiasporaUrlHelper urls;
private ValueCallback<Uri[]> imageUploadFilePathCallbackNew;
private ValueCallback<Uri> imageUploadFilePathCallbackOld;
private String mCameraPhotoPath;
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.urls = new DiasporaUrlHelper(appSettings);
webView.setWebChromeClient(new DiasporaStreamWebChromeClient(webView, progressBar, fileUploadCallback, sharedTextCallback));
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
if(((MainActivity)getActivity()).getTextToBeShared() != null) {
loadUrl(urls.getNewPostUrl());
} else if(webView.getUrl() == null) {
loadUrl(urls.getStreamUrl());
}
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_top, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_bottom, menu);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
AppLog.d(this, "onActivityResult(): "+requestCode);
switch (requestCode) {
case MainActivity.INPUT_FILE_REQUEST_CODE_NEW:
case MainActivity.INPUT_FILE_REQUEST_CODE_OLD:
AppLog.v(this, "INPUT_FILE_REQUEST_CODE: "+requestCode);
onImageUploadResult(requestCode, resultCode, data);
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
AppLog.d(this, "StreamFragment.onOptionsItemSelected()");
switch (item.getItemId()) {
case R.id.action_reload: {
if(WebHelper.isOnline(getContext())) {
reloadUrl();
return true;
} else {
return false;
}
}
case R.id.action_toggle_desktop_page: {
loadUrl(urls.getToggleMobileUrl());
return true;
}
case R.id.action_go_to_top: {
ObjectAnimator anim = ObjectAnimator.ofInt(webView, "scrollY", webView.getScrollY(), 0);
anim.setDuration(400);
anim.start();
return true;
}
case R.id.action_share_link: {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, webView.getTitle());
sharingIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.action_share_dotdotdot)));
return true;
}
case R.id.action_take_screenshot: {
makeScreenshotOfWebView(false);
return true;
}
case R.id.action_share_screenshot: {
makeScreenshotOfWebView(true);
return true;
}
}
return super.onOptionsItemSelected(item);
}
public void onImageUploadResult(int requestCode, int resultCode, Intent data) {
AppLog.d(this, "onImageUploadResult");
switch (requestCode) {
case MainActivity.INPUT_FILE_REQUEST_CODE_NEW: {
AppLog.v(this, "Upload image using recent method (Lollipop+)");
if (imageUploadFilePathCallbackNew == null || resultCode != Activity.RESULT_OK) {
AppLog.e(this, "Callback is null: " + (imageUploadFilePathCallbackNew == null)
+ " resultCode: " + resultCode);
if (imageUploadFilePathCallbackNew != null)
imageUploadFilePathCallbackNew.onReceiveValue(new Uri[]{});
return;
}
Uri[] results = null;
if (data == null) {
if (mCameraPhotoPath != null) {
AppLog.v(this, "Intent data is null. Try to parse cameraPhotoPath");
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
} else {
AppLog.w(this, "Intent data is null and cameraPhotoPath is null");
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
AppLog.v(this, "Intent has data. Try to parse dataString");
results = new Uri[]{Uri.parse(dataString)};
} else {
AppLog.w(this, "dataString is null");
}
}
AppLog.v(this, "handle received result over to callback");
imageUploadFilePathCallbackNew.onReceiveValue(results);
imageUploadFilePathCallbackNew = null;
return;
}
case MainActivity.INPUT_FILE_REQUEST_CODE_OLD: {
AppLog.v(this, "Upload image using legacy method (Jelly Bean, Kitkat)");
if (imageUploadFilePathCallbackOld == null || resultCode != Activity.RESULT_OK) {
AppLog.e(this, "Callback is null: " + (imageUploadFilePathCallbackOld == null)
+ " resultCode: " + resultCode);
if (imageUploadFilePathCallbackOld != null)
imageUploadFilePathCallbackOld.onReceiveValue(null);
return;
}
Uri results = null;
if (data == null) {
if (mCameraPhotoPath != null) {
AppLog.v(this, "Intent has no data. Try to parse cameraPhotoPath");
results = Uri.parse(mCameraPhotoPath);
} else {
AppLog.w(this, "Intent has no data and cameraPhotoPath is null");
}
} else {
String dataString = data.getDataString();
if (dataString != null) {
AppLog.v(this, "Intent has data. Try to parse dataString");
results = Uri.parse(dataString);
} else {
AppLog.w(this, "dataString is null");
}
}
AppLog.v(this, "handle received result over to callback");
imageUploadFilePathCallbackOld.onReceiveValue(results);
imageUploadFilePathCallbackOld = null;
}
}
}
protected DiasporaStreamWebChromeClient.SharedTextCallback sharedTextCallback = new DiasporaStreamWebChromeClient.SharedTextCallback() {
@Override
public String getSharedText() {
return ((MainActivity)getActivity()).getTextToBeShared();
}
@Override
public void setSharedText(String shared) {
((MainActivity)getActivity()).setTextToBeShared(shared);
}
};
protected FileUploadWebChromeClient.FileUploadCallback fileUploadCallback = new FileUploadWebChromeClient.FileUploadCallback() {
@Override
public boolean imageUpload(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
if(Build.VERSION.SDK_INT >= 23) {
int hasWRITE_EXTERNAL_STORAGE = getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
new AlertDialog.Builder(getContext())
.setMessage(R.string.permissions_image)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (android.os.Build.VERSION.SDK_INT >= 23)
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE_ASK_PERMISSIONS);
}
})
.show();
return false;
}
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE_ASK_PERMISSIONS);
return false;
}
}
AppLog.v(this, "onOpenFileChooser");
if (imageUploadFilePathCallbackNew != null) imageUploadFilePathCallbackNew.onReceiveValue(null);
imageUploadFilePathCallbackNew = filePathCallback;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile;
try {
photoFile = Helpers.createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
AppLog.e(this, "ERROR creating temp file: "+ ex.toString());
// Error occurred while creating the File
Snackbar.make(webView, R.string.unable_to_load_image, Snackbar.LENGTH_LONG).show();
return false;
}
// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
} else {
takePictureIntent = null;
}
}
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("image/*");
Intent[] intentArray;
if (takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else {
intentArray = new Intent[0];
}
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
AppLog.d(this, "startActivityForResult");
startActivityForResult(chooserIntent, MainActivity.INPUT_FILE_REQUEST_CODE_NEW);
return true;
}
@Override
public void legacyImageUpload(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
AppLog.v(this, "openFileChooser(ValCallback<Uri>, String, String");
imageUploadFilePathCallbackOld = uploadMsg;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
AppLog.v(this, "startActivityForResult");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), MainActivity.INPUT_FILE_REQUEST_CODE_OLD);
}
};
private class JavaScriptInterface {
@SuppressWarnings("unused")
@JavascriptInterface
public void setUserProfile(final String webMessage) throws JSONException {
PodUserProfile pup = ((App)getActivity().getApplication()).getPodUserProfile();
AppLog.v(this, "StreamFragment.JavaScriptInterface.setUserProfile()");
if (pup.isRefreshNeeded()) {
AppLog.v(this, "PodUserProfile needs refresh; Try to parse JSON");
pup.parseJson(webMessage);
} else {
AppLog.v(this, "No PodUserProfile refresh needed");
}
}
@SuppressWarnings("unused")
@JavascriptInterface
public void contentHasBeenShared() {
((MainActivity)getActivity()).setTextToBeShared(null);
}
}
@Override
public String getFragmentTag() {
return TAG;
}
}

View file

@ -0,0 +1,146 @@
/*
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.fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
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.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
/**
* Fragment that shows a list of the Hashtags the user follows
* Created by vanitas on 29.09.16.
*/
public class HashtagListFragment extends CustomFragment {
public static final String TAG = "com.github.dfa.diaspora_android.HashtagListFragment";
protected RecyclerView followedTagsRecyclerView;
protected String[] followedTags;
protected App app;
protected DiasporaUrlHelper urls;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
AppLog.d(this, "onCreateView()");
return inflater.inflate(R.layout.hashtag_list__fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.followedTagsRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_followed_tags__recycler_view);
this.app = (App) getActivity().getApplication();
this.urls = new DiasporaUrlHelper(app.getSettings());
followedTags = app.getPodUserProfile().getFollowedTags();
followedTagsRecyclerView.setHasFixedSize(true);
followedTagsRecyclerView.setNestedScrollingEnabled(false);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getContext());
followedTagsRecyclerView.setLayoutManager(layoutManager);
final FollowedTagsAdapter adapter = new FollowedTagsAdapter(followedTags, onHashtagClickListener);
followedTagsRecyclerView.setAdapter(adapter);
//Set window title
getActivity().setTitle(R.string.nav_followed_tags);
}
@Override
public String getFragmentTag() {
return TAG;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override
public boolean onBackPressed() {
return false;
}
protected View.OnClickListener onHashtagClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int itemPosition = followedTagsRecyclerView.getChildLayoutPosition(view);
if(itemPosition > -1 && itemPosition < followedTags.length) {
String tag = followedTags[itemPosition];
((MainActivity)getActivity()).openDiasporaUrl(urls.getSearchTagsUrl(tag));
}
}
};
public static class FollowedTagsAdapter extends RecyclerView.Adapter<FollowedTagsAdapter.ViewHolder> {
private String[] followedTagsList;
private View.OnClickListener itemClickListener;
public static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView title;
public ViewHolder(View v) {
super(v);
title = (TextView) v.findViewById(R.id.recycler_view__list_item__text);
}
}
// Provide a suitable constructor (depends on the kind of dataset)
public FollowedTagsAdapter(String[] tags, View.OnClickListener itemClickListener) {
this.followedTagsList = tags;
this.itemClickListener = itemClickListener;
}
@Override
public FollowedTagsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_view__list_item, parent, false);
v.setOnClickListener(itemClickListener);
return new ViewHolder(v);
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.title.setText(followedTagsList[position]);
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return followedTagsList.length;
}
}
}

View file

@ -16,7 +16,7 @@
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.activity;
package com.github.dfa.diaspora_android.fragment;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@ -28,64 +28,103 @@ import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
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.data.AppSettings;
import com.github.dfa.diaspora_android.task.GetPodsService;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.WebHelper;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemClick;
/**
* Fragment that lets the user choose a Pod
* Created by vanitas on 01.10.16.
*/
public class PodSelectionFragment extends CustomFragment {
public static final String TAG = "com.github.dfa.diaspora_android.PodSelectionFragment";
public class PodSelectionActivity extends AppCompatActivity {
private App app;
protected EditText editFilter;
protected ListView listPods;
protected ImageView selectPodButton;
@BindView(R.id.podselection__edit_filter)
EditText editFilter;
@BindView(R.id.podselection__listpods)
ListView listPods;
@BindView(R.id.toolbar)
Toolbar toolbar;
protected App app;
protected AppSettings appSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.podselection__activity);
ButterKnife.bind(this);
app = (App) getApplication();
setSupportActionBar(toolbar);
listPods.setTextFilterEnabled(true);
setListedPods(app.getSettings().getPreviousPodlist());
LocalBroadcastManager.getInstance(this).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
AppLog.d(this, "onCreateView()");
return inflater.inflate(R.layout.podselection__fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.app = (App) getActivity().getApplication();
this.appSettings = app.getSettings();
this.editFilter = (EditText) view.findViewById(R.id.podselection__edit_filter);
this.listPods = (ListView) view.findViewById(R.id.podselection__listpods);
this.selectPodButton = (ImageView) view.findViewById(R.id.podselection__button_select_pod);
listPods.setTextFilterEnabled(true);
listPods.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
showPodConfirmationDialog((String) listPods.getAdapter().getItem(i));
}
});
setListedPods(appSettings.getPreviousPodlist());
LocalBroadcastManager.getInstance(getContext()).registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE_PODS_RECEIVED));
if (!WebHelper.isOnline(getContext())) {
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
selectPodButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editFilter.getText().length() > 4 && editFilter.getText().toString().contains("")) {
showPodConfirmationDialog(editFilter.getText().toString());
} else {
Snackbar.make(listPods, R.string.valid_pod, Snackbar.LENGTH_LONG).show();
}
}
});
}
@Override
public String getFragmentTag() {
return TAG;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override
public boolean onBackPressed() {
return false;
}
private final BroadcastReceiver podListReceiver = new BroadcastReceiver() {
@Override
@ -104,20 +143,11 @@ public class PodSelectionActivity extends AppCompatActivity {
}
};
@OnClick(R.id.podselection__button_select_pod)
public void onButtonSelectPodClicked(View view) {
if (editFilter.getText().length() > 4 && editFilter.getText().toString().contains("")) {
showPodConfirmationDialog(editFilter.getText().toString());
} else {
Snackbar.make(listPods, R.string.valid_pod, Snackbar.LENGTH_LONG).show();
}
}
@Override
protected void onResume() {
public void onResume() {
super.onResume();
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
startService(i);
Intent i = new Intent(getContext(), GetPodsService.class);
getContext().startService(i);
}
@ -128,7 +158,7 @@ public class PodSelectionActivity extends AppCompatActivity {
}
final ArrayAdapter<String> adapter = new ArrayAdapter<>(
PodSelectionActivity.this,
getContext(),
android.R.layout.simple_list_item_1,
listedPodsList);
@ -154,24 +184,19 @@ public class PodSelectionActivity extends AppCompatActivity {
});
}
@OnItemClick(R.id.podselection__listpods)
public void onListPodsItemClicked(int position) {
showPodConfirmationDialog((String) listPods.getAdapter().getItem(position));
}
private void showPodConfirmationDialog(final String selectedPod) {
// Make a clickable link
final SpannableString dialogMessage = new SpannableString(getString(R.string.confirm_pod, selectedPod));
Linkify.addLinks(dialogMessage, Linkify.ALL);
// Check if online
if (!WebHelper.isOnline(PodSelectionActivity.this)) {
if (!WebHelper.isOnline(getContext())) {
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
return;
}
// Show dialog
new AlertDialog.Builder(PodSelectionActivity.this)
new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.confirmation))
.setMessage(dialogMessage)
.setPositiveButton(android.R.string.yes,
@ -201,40 +226,28 @@ public class PodSelectionActivity extends AppCompatActivity {
e.printStackTrace();
}
Helpers.animateToActivity(this, MainActivity.class, true);
}
@Override
public void onBackPressed() {
Snackbar.make(listPods, R.string.confirm_exit, Snackbar.LENGTH_LONG)
.setAction(android.R.string.yes, new View.OnClickListener() {
public void onClick(View view) {
finish();
}
})
.show();
((MainActivity)getActivity()).openDiasporaUrl(new DiasporaUrlHelper(appSettings).getPodUrl());
}
@Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(podListReceiver);
public void onDestroy() {
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(podListReceiver);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.podselection__menu, menu);
return true;
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.podselection__menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_reload: {
if (WebHelper.isOnline(PodSelectionActivity.this)) {
Intent i = new Intent(PodSelectionActivity.this, GetPodsService.class);
startService(i);
if (WebHelper.isOnline(getContext())) {
Intent i = new Intent(getContext(), GetPodsService.class);
getContext().startService(i);
return true;
} else {
Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();

View file

@ -1,4 +1,22 @@
package com.github.dfa.diaspora_android.receivers;
/*
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.receiver;
import android.app.Activity;
import android.content.BroadcastReceiver;
@ -9,7 +27,6 @@ import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;
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.data.AppSettings;
@ -17,7 +34,6 @@ import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.Log;
/**
* BroadcastReceiver that opens links in a Chrome CustomTab

View file

@ -1,4 +1,22 @@
package com.github.dfa.diaspora_android.receivers;
/*
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.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;

View file

@ -1,3 +1,21 @@
/*
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.ui;
import android.content.Context;

View file

@ -123,22 +123,49 @@ public class ContextMenuWebView extends NestedWebView {
case ID_SHARE_IMAGE:
if (url != null) {
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
new ImageDownloadTask(null, local.getPath()) {
@Override
protected void onPostExecute(Bitmap result) {
Uri myUri = Uri.fromFile(new File(local.getPath()));
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
sharingIntent.setType("image/png");
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(sharingIntent, "Share image using"));
boolean writeToStoragePermitted = true;
if (android.os.Build.VERSION.SDK_INT >= 23) {
int hasWRITE_EXTERNAL_STORAGE = parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
writeToStoragePermitted = false;
if (!parentActivity.shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
new AlertDialog.Builder(parentActivity)
.setMessage(R.string.permissions_image)
.setPositiveButton(context.getText(android.R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (android.os.Build.VERSION.SDK_INT >= 23)
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
}
})
.setNegativeButton(context.getText(android.R.string.no), null)
.show();
} else {
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
}
}
}.execute(url);
}
if (writeToStoragePermitted) {
final Uri local = Uri.parse(Environment.getExternalStorageDirectory() + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
new ImageDownloadTask(null, local.getPath()) {
@Override
protected void onPostExecute(Bitmap result) {
Uri myUri = Uri.fromFile(new File(local.getPath()));
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
sharingIntent.setType("image/png");
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.action_share_dotdotdot)));
}
}.execute(url);
}
} else {
Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
}
break;
case ID_IMAGE_EXTERNAL_BROWSER:

View file

@ -1,3 +1,21 @@
/*
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;
/**

View file

@ -1,3 +1,21 @@
/*
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.CustomTabHelpers;
import android.app.Activity;

View file

@ -1,3 +1,21 @@
/*
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.CustomTabHelpers;
import android.app.Activity;
@ -118,6 +136,10 @@ public class CustomTabActivityHelper {
return session.mayLaunchUrl(uri, extras, otherLikelyBundles);
}
public boolean warmup(int flags) {
return mClient.warmup(flags);
}
/**
* A Callback for when the service is connected or disconnected. Use those callbacks to
* handle UI changes when the service is connected or disconnected

View file

@ -1,3 +1,21 @@
/*
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.CustomTabHelpers;
import android.content.Context;

View file

@ -1,3 +1,21 @@
/*
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 com.github.dfa.diaspora_android.data.AppSettings;

View file

@ -62,7 +62,7 @@ public class WebHelper {
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.documentElement.style.paddingBottom = '50px';" +
" document.getElementById('main').style.paddingTop = '5px';" +
" if(document.getElementById('main_nav')) {" +
" document.getElementById('main_nav').parentNode.removeChild(" +

View file

@ -16,7 +16,7 @@
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.ui;
package com.github.dfa.diaspora_android.webview;
import android.content.Intent;
import android.net.Uri;
@ -37,6 +37,7 @@ public class CustomWebViewClient extends WebViewClient {
this.webView = webView;
}
//Open non-diaspora links in customtab/external browser
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.contains(app.getSettings().getPodDomain())) {
Intent i = new Intent(MainActivity.ACTION_OPEN_EXTERNAL_URL);

View file

@ -0,0 +1,62 @@
/*
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.webview;
import android.webkit.WebView;
import android.widget.ProgressBar;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.WebHelper;
/**
* Created by vanitas on 26.09.16.
*/
public class DiasporaStreamWebChromeClient extends FileUploadWebChromeClient {
protected SharedTextCallback sharedTextCallback;
public DiasporaStreamWebChromeClient(WebView webView, ProgressBar progressBar, FileUploadCallback fileUploadCallback, SharedTextCallback callback) {
super(webView, progressBar, fileUploadCallback);
this.sharedTextCallback = callback;
}
@Override
public void onProgressChanged(WebView wv, int progress) {
super.onProgressChanged(wv, progress);
if (progress > 0 && progress <= 60) {
WebHelper.getUserProfile(wv);
WebHelper.optimizeMobileSiteLayout(wv);
}
if (progress > 60) {
WebHelper.optimizeMobileSiteLayout(wv);
String textToBeShared = sharedTextCallback.getSharedText();
if (textToBeShared != null) {
AppLog.d(this, "Share text into webView");
WebHelper.shareTextIntoWebView(wv, textToBeShared);
}
}
}
public interface SharedTextCallback {
String getSharedText();
void setSharedText(String shared);
}
}

View file

@ -0,0 +1,59 @@
/*
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.webview;
import android.net.Uri;
import android.webkit.ValueCallback;
import android.webkit.WebView;
import android.widget.ProgressBar;
/**
* Created by vanitas on 26.09.16.
*/
public class FileUploadWebChromeClient extends ProgressBarWebChromeClient {
protected FileUploadCallback fileUploadCallback;
public FileUploadWebChromeClient(WebView webView, ProgressBar progressBar, FileUploadCallback fileUploadCallback) {
super(webView, progressBar);
this.fileUploadCallback = fileUploadCallback;
}
@Override
public void onProgressChanged(WebView wv, int progress) {
super.onProgressChanged(wv, progress);
}
//For Android 4.1/4.2 only. DO NOT REMOVE!
@SuppressWarnings("unused")
protected void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
{
fileUploadCallback.legacyImageUpload(uploadMsg, acceptType, capture);
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
return fileUploadCallback.imageUpload(webView, filePathCallback, fileChooserParams);
}
public interface FileUploadCallback {
boolean imageUpload(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams);
void legacyImageUpload(ValueCallback<Uri> uploadMsg, String acceptType, String capture);
}
}

View file

@ -0,0 +1,44 @@
/*
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.webview;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
/**
* WebChromeClient that connects the ProgressBar and the WebView and updates the progress of the progressBar.
* Created by vanitas on 26.09.16.
*/
public class ProgressBarWebChromeClient extends WebChromeClient {
protected final ProgressBar progressBar;
protected final WebView webView;
public ProgressBarWebChromeClient(WebView webView, ProgressBar progressBar) {
this.webView = webView;
this.progressBar = progressBar;
}
public void onProgressChanged(WebView wv, int progress) {
progressBar.setProgress(progress);
progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
}
}