2016-03-03 17:46:31 +01:00
|
|
|
/*
|
2016-06-04 03:48:57 +02:00
|
|
|
This file is part of the Diaspora for Android.
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
Diaspora for Android is free software: you can redistribute it and/or modify
|
2016-03-03 17:46:31 +01:00
|
|
|
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.
|
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
Diaspora for Android is distributed in the hope that it will be useful,
|
2016-03-03 17:46:31 +01:00
|
|
|
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
|
2016-06-04 03:48:57 +02:00
|
|
|
along with the Diaspora for Android.
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-03-29 19:38:50 +02:00
|
|
|
package com.github.dfa.diaspora_android.activity;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
import android.Manifest;
|
2016-06-04 17:10:24 +02:00
|
|
|
import android.animation.ObjectAnimator;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.Activity;
|
2016-06-09 01:03:50 +02:00
|
|
|
import android.app.AlarmManager;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.app.AlertDialog;
|
2016-06-09 01:03:50 +02:00
|
|
|
import android.app.PendingIntent;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Handler;
|
2016-06-09 01:03:50 +02:00
|
|
|
import android.os.StrictMode;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.support.annotation.NonNull;
|
2016-07-31 15:16:22 +02:00
|
|
|
import android.support.design.widget.AppBarLayout;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.support.design.widget.NavigationView;
|
|
|
|
import android.support.design.widget.Snackbar;
|
2016-08-01 01:14:44 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2016-06-04 17:10:24 +02:00
|
|
|
import android.support.v7.widget.ActionMenuView;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2016-03-08 15:42:02 +01:00
|
|
|
import android.text.Html;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.text.util.Linkify;
|
2016-08-21 17:04:51 +02:00
|
|
|
import android.util.Log;
|
2016-06-04 19:44:38 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.KeyEvent;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2016-06-04 19:44:38 +02:00
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
import android.webkit.ValueCallback;
|
|
|
|
import android.webkit.WebChromeClient;
|
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.widget.EditText;
|
2016-03-25 00:12:00 +01:00
|
|
|
import android.widget.ImageView;
|
2016-06-04 19:44:38 +02:00
|
|
|
import android.widget.LinearLayout;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.widget.ProgressBar;
|
2016-08-07 23:11:47 +02:00
|
|
|
import android.widget.RelativeLayout;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.widget.TextView;
|
2016-04-08 21:59:46 +02:00
|
|
|
import android.widget.Toast;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-29 19:38:50 +02:00
|
|
|
import com.github.dfa.diaspora_android.App;
|
|
|
|
import com.github.dfa.diaspora_android.R;
|
|
|
|
import com.github.dfa.diaspora_android.data.AppSettings;
|
2016-06-04 03:48:57 +02:00
|
|
|
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
2016-03-29 19:38:50 +02:00
|
|
|
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
2016-04-08 21:59:46 +02:00
|
|
|
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
|
2016-06-04 03:48:57 +02:00
|
|
|
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
|
2016-08-10 17:14:05 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
2016-03-29 19:38:50 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.Helpers;
|
2016-08-07 14:29:52 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.WebHelper;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-03-24 13:56:30 +01:00
|
|
|
import org.json.JSONException;
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
2016-04-11 19:10:30 +02:00
|
|
|
import java.io.OutputStream;
|
2016-04-23 20:58:37 +02:00
|
|
|
import java.text.DateFormat;
|
2016-03-03 17:46:31 +01:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
2016-04-28 21:36:27 +02:00
|
|
|
import java.util.Locale;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-02 13:58:09 +02:00
|
|
|
import butterknife.BindView;
|
2016-03-25 00:12:00 +01:00
|
|
|
import butterknife.ButterKnife;
|
2016-06-04 17:10:24 +02:00
|
|
|
import butterknife.OnClick;
|
2016-06-09 01:03:50 +02:00
|
|
|
import info.guardianproject.netcipher.NetCipher;
|
2016-08-23 14:36:03 +02:00
|
|
|
import info.guardianproject.netcipher.webkit.WebkitProxy;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity
|
2016-03-25 00:12:00 +01:00
|
|
|
implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener {
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
|
2016-03-23 22:26:23 +01:00
|
|
|
static final int INPUT_FILE_REQUEST_CODE = 1;
|
2016-03-20 22:49:11 +01:00
|
|
|
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
2016-04-08 21:59:46 +02:00
|
|
|
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
|
2016-07-26 22:47:11 +02:00
|
|
|
|
|
|
|
public static final String ACTION_OPEN_URL = "com.github.dfa.diaspora_android.MainActivity.open_url";
|
|
|
|
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
|
2016-07-26 22:52:26 +02:00
|
|
|
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
|
2016-08-01 01:14:44 +02:00
|
|
|
public static final String ACTION_UPDATE_TITLE_FROM_URL = "com.github.dfa.diaspora_android.MainActivity.set_title";
|
2016-08-07 02:28:37 +02:00
|
|
|
public static final String ACTION_RELOAD_ACTIVITY = "com.github.dfa.diaspora_android.MainActivity.reload_activity";
|
2016-06-18 15:53:49 +02:00
|
|
|
public static final String URL_MESSAGE = "URL_MESSAGE";
|
2016-08-01 01:14:44 +02:00
|
|
|
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
|
2016-03-20 22:49:11 +01:00
|
|
|
|
2016-03-24 13:56:30 +01:00
|
|
|
private App app;
|
2016-03-20 22:49:11 +01:00
|
|
|
private String podDomain;
|
|
|
|
private ValueCallback<Uri[]> mFilePathCallback;
|
|
|
|
private String mCameraPhotoPath;
|
2016-03-25 00:12:00 +01:00
|
|
|
private WebSettings webSettings;
|
2016-03-24 11:58:28 +01:00
|
|
|
private AppSettings appSettings;
|
2016-08-10 17:14:05 +02:00
|
|
|
private DiasporaUrlHelper urls;
|
2016-06-04 03:48:57 +02:00
|
|
|
private PodUserProfile podUserProfile;
|
2016-03-25 00:12:00 +01:00
|
|
|
private final Handler uiHandler = new Handler();
|
2016-06-04 03:48:57 +02:00
|
|
|
private CustomWebViewClient webViewClient;
|
2016-06-16 22:55:06 +02:00
|
|
|
private Snackbar snackbarExitApp;
|
2016-06-24 13:31:01 +02:00
|
|
|
private Snackbar snackbarNewNotification;
|
|
|
|
private Snackbar snackbarNoInternet;
|
2016-08-08 07:41:36 +02:00
|
|
|
public String textToBeShared = null;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
/**
|
|
|
|
* UI Bindings
|
|
|
|
*/
|
2016-08-07 23:11:47 +02:00
|
|
|
@BindView(R.id.content_layout)
|
|
|
|
RelativeLayout contentLayout;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-06-02 13:58:09 +02:00
|
|
|
@BindView(R.id.progressBar)
|
2016-03-25 00:12:00 +01:00
|
|
|
ProgressBar progressBar;
|
|
|
|
|
2016-06-02 13:58:09 +02:00
|
|
|
@BindView(R.id.toolbar)
|
2016-06-04 17:10:24 +02:00
|
|
|
Toolbar toolbarTop;
|
|
|
|
|
|
|
|
@BindView(R.id.toolbar2)
|
|
|
|
ActionMenuView toolbarBottom;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-06-02 13:58:09 +02:00
|
|
|
@BindView(R.id.webView)
|
2016-04-08 21:59:46 +02:00
|
|
|
ContextMenuWebView webView;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
@BindView(R.id.main__navigaion_view)
|
2016-06-04 21:46:54 +02:00
|
|
|
NavigationView navView;
|
|
|
|
|
|
|
|
@BindView(R.id.main__layout)
|
|
|
|
DrawerLayout navDrawer;
|
2016-06-04 17:10:24 +02:00
|
|
|
|
2016-06-05 01:42:10 +02:00
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
// NavHeader cannot be bound by Butterknife
|
|
|
|
private TextView navheaderTitle;
|
|
|
|
private TextView navheaderDescription;
|
|
|
|
private ImageView navheaderImage;
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
/**
|
|
|
|
* END UI Bindings
|
|
|
|
*/
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
@SuppressLint("SetJavaScriptEnabled")
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
// Bind UI
|
2016-06-04 11:11:51 +02:00
|
|
|
setContentView(R.layout.main__activity);
|
2016-03-25 00:12:00 +01:00
|
|
|
ButterKnife.bind(this);
|
|
|
|
|
2016-03-24 13:56:30 +01:00
|
|
|
app = (App) getApplication();
|
2016-03-25 00:12:00 +01:00
|
|
|
appSettings = app.getSettings();
|
2016-06-05 17:25:11 +02:00
|
|
|
podUserProfile = app.getPodUserProfile();
|
|
|
|
podUserProfile.setCallbackHandler(uiHandler);
|
|
|
|
podUserProfile.setListener(this);
|
2016-08-10 17:14:05 +02:00
|
|
|
urls = new DiasporaUrlHelper(appSettings);
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-07-30 16:48:43 +02:00
|
|
|
if (appSettings.isProxyEnabled()) {
|
|
|
|
if (!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
|
|
|
|
Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed, Toast.LENGTH_SHORT).show();
|
2016-06-16 23:01:23 +02:00
|
|
|
}
|
2016-07-30 16:48:43 +02:00
|
|
|
} else if (appSettings.wasProxyEnabled()) {
|
2016-06-16 23:36:52 +02:00
|
|
|
resetProxy();
|
2016-06-16 23:01:23 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 22:55:06 +02:00
|
|
|
setupWebView(savedInstanceState);
|
2016-04-08 21:59:46 +02:00
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
// Setup toolbar
|
2016-06-04 17:10:24 +02:00
|
|
|
setSupportActionBar(toolbarTop);
|
|
|
|
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
|
|
|
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
return MainActivity.this.onOptionsItemSelected(item);
|
2016-03-25 18:25:59 +01:00
|
|
|
}
|
|
|
|
});
|
2016-06-07 19:13:37 +02:00
|
|
|
setTitle(R.string.app_name);
|
2016-03-25 18:25:59 +01:00
|
|
|
|
2016-06-16 22:55:06 +02:00
|
|
|
//Setup snackbar
|
|
|
|
snackbarExitApp = Snackbar
|
2016-08-07 23:11:47 +02:00
|
|
|
.make(contentLayout, R.string.confirm_exit, Snackbar.LENGTH_LONG)
|
2016-06-16 22:55:06 +02:00
|
|
|
.setAction(android.R.string.yes, new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2016-07-31 15:16:22 +02:00
|
|
|
finish();
|
2016-06-16 22:55:06 +02:00
|
|
|
moveTaskToBack(true);
|
|
|
|
}
|
|
|
|
});
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNewNotification = Snackbar
|
2016-08-07 23:11:47 +02:00
|
|
|
.make(contentLayout, R.string.new_notifications, Snackbar.LENGTH_LONG)
|
2016-06-24 13:31:01 +02:00
|
|
|
.setAction(android.R.string.yes, new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getNotificationsUrl());
|
2016-06-24 13:31:01 +02:00
|
|
|
} else {
|
2016-08-07 23:11:47 +02:00
|
|
|
Snackbar.make(contentLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
|
2016-06-24 13:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-08-07 23:11:47 +02:00
|
|
|
snackbarNoInternet = Snackbar.make(contentLayout, R.string.no_internet, Snackbar.LENGTH_LONG);
|
2016-06-16 22:55:06 +02:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
// Load app settings
|
2016-03-25 00:12:00 +01:00
|
|
|
setupNavigationSlider();
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
2016-03-25 00:12:00 +01:00
|
|
|
podDomain = appSettings.getPodDomain();
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-08-10 17:14:05 +02:00
|
|
|
String url = urls.getPodUrl();
|
2016-06-16 22:55:06 +02:00
|
|
|
if (savedInstanceState == null) {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-06-16 22:55:06 +02:00
|
|
|
webView.loadData("", "text/html", null);
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(url);
|
2016-06-16 22:55:06 +02:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-06-16 22:55:06 +02:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-07-26 22:47:11 +02:00
|
|
|
|
2016-07-31 15:16:22 +02:00
|
|
|
if (!appSettings.isIntellihideToolbars()) {
|
2016-08-07 01:51:07 +02:00
|
|
|
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
|
2016-07-31 15:16:22 +02:00
|
|
|
params.setScrollFlags(0); // clear all scroll flags
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:47:11 +02:00
|
|
|
handleIntent(getIntent());
|
2016-06-16 22:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setupWebView(Bundle savedInstanceState) {
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
webSettings = webView.getSettings();
|
|
|
|
webSettings.setJavaScriptEnabled(true);
|
2016-08-13 00:42:13 +02:00
|
|
|
webSettings.setAllowFileAccess(false);
|
2016-03-25 00:12:00 +01:00
|
|
|
webSettings.setUseWideViewPort(true);
|
|
|
|
webSettings.setLoadWithOverviewMode(true);
|
|
|
|
webSettings.setDomStorageEnabled(true);
|
|
|
|
webSettings.setMinimumFontSize(appSettings.getMinimumFontSize());
|
|
|
|
webSettings.setLoadsImagesAutomatically(appSettings.isLoadImages());
|
2016-06-16 22:55:06 +02:00
|
|
|
webSettings.setAppCacheEnabled(true);
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
webView.restoreState(savedInstanceState);
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-16 22:55:06 +02:00
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
|
|
|
WebView.enableSlowWholeDocumentDraw();
|
2016-03-25 00:12:00 +01:00
|
|
|
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
2016-06-16 22:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.registerForContextMenu(webView);
|
|
|
|
webView.setParentActivity(this);
|
|
|
|
webView.setOverScrollMode(WebView.OVER_SCROLL_ALWAYS);
|
|
|
|
|
|
|
|
// Setup WebView
|
|
|
|
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-09 01:03:50 +02:00
|
|
|
//Set proxy
|
2016-07-30 16:48:43 +02:00
|
|
|
if (appSettings.isProxyEnabled()) {
|
|
|
|
if (!setProxy())
|
|
|
|
Toast.makeText(this, R.string.toast_set_proxy_failed, Toast.LENGTH_LONG).show();
|
2016-06-09 01:03:50 +02:00
|
|
|
}
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
/*
|
|
|
|
* WebViewClient
|
|
|
|
*/
|
2016-08-07 23:11:47 +02:00
|
|
|
webViewClient = new CustomWebViewClient(app, webView);
|
2016-06-04 03:48:57 +02:00
|
|
|
webView.setWebViewClient(webViewClient);
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* WebChromeClient
|
|
|
|
*/
|
|
|
|
webView.setWebChromeClient(new WebChromeClient() {
|
|
|
|
|
|
|
|
public void onProgressChanged(WebView wv, int progress) {
|
|
|
|
progressBar.setProgress(progress);
|
|
|
|
|
|
|
|
if (progress > 0 && progress <= 60) {
|
2016-08-07 14:29:52 +02:00
|
|
|
WebHelper.getUserProfile(wv);
|
|
|
|
WebHelper.optimizeMobileSiteLayout(wv);
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (progress > 60) {
|
2016-08-07 14:29:52 +02:00
|
|
|
WebHelper.optimizeMobileSiteLayout(wv);
|
2016-08-08 07:41:36 +02:00
|
|
|
|
2016-08-13 14:13:14 +02:00
|
|
|
if (textToBeShared != null) {
|
2016-08-08 07:41:36 +02:00
|
|
|
WebHelper.shareTextIntoWebView(wv, textToBeShared);
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-08-07 11:39:20 +02:00
|
|
|
progressBar.setVisibility(progress == 100 ? View.GONE : View.VISIBLE);
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
|
|
|
|
if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null);
|
|
|
|
|
|
|
|
mFilePathCallback = filePathCallback;
|
|
|
|
|
|
|
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
|
|
|
|
// Create the File where the photo should go
|
2016-03-23 22:26:23 +01:00
|
|
|
File photoFile;
|
2016-03-03 17:46:31 +01:00
|
|
|
try {
|
|
|
|
photoFile = createImageFile();
|
|
|
|
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// Error occurred while creating the File
|
2016-08-07 23:11:47 +02:00
|
|
|
Snackbar.make(contentLayout, R.string.unable_to_load_image, Snackbar.LENGTH_LONG).show();
|
2016-03-03 17:46:31 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-26 01:14:17 +01:00
|
|
|
private void setupNavigationSlider() {
|
2016-03-25 00:12:00 +01:00
|
|
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
2016-06-04 21:46:54 +02:00
|
|
|
this, navDrawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
|
|
|
navDrawer.addDrawerListener(toggle);
|
2016-03-25 00:12:00 +01:00
|
|
|
toggle.syncState();
|
|
|
|
|
2016-06-04 21:46:54 +02:00
|
|
|
//NavigationView navView = ButterKnife.findById(this, R.id.nav_view);
|
|
|
|
navView.setNavigationItemSelectedListener(this);
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-06-04 21:46:54 +02:00
|
|
|
View navHeader = navView.getHeaderView(0);
|
2016-08-10 17:28:54 +02:00
|
|
|
LinearLayout navheaderProfileSection = ButterKnife.findById(navHeader, R.id.nav_profile_picture);
|
|
|
|
navheaderProfileSection.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
navDrawer.closeDrawer(GravityCompat.START);
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getProfileUrl());
|
2016-08-10 17:28:54 +02:00
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-26 01:14:17 +01:00
|
|
|
navheaderTitle = ButterKnife.findById(navHeader, R.id.navheader_title);
|
2016-06-02 13:58:09 +02:00
|
|
|
navheaderDescription = ButterKnife.findById(navHeader, R.id.podselection__podupti_notice);
|
2016-03-26 01:14:17 +01:00
|
|
|
navheaderImage = ButterKnife.findById(navHeader, R.id.navheader_user_image);
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-03-26 01:14:17 +01:00
|
|
|
if (!appSettings.getName().equals("")) {
|
2016-03-25 00:12:00 +01:00
|
|
|
navheaderTitle.setText(appSettings.getName());
|
|
|
|
}
|
2016-03-26 01:14:17 +01:00
|
|
|
if (!appSettings.getPodDomain().equals("")) {
|
2016-03-25 00:12:00 +01:00
|
|
|
navheaderDescription.setText(appSettings.getPodDomain());
|
|
|
|
}
|
2016-03-26 01:14:17 +01:00
|
|
|
if (!appSettings.getAvatarUrl().equals("")) {
|
2016-08-21 17:04:51 +02:00
|
|
|
Log.d(App.TAG, "AVATAR URL != \"\": "+appSettings.getAvatarUrl());
|
|
|
|
//Display app launcher icon instead of default avatar asset
|
|
|
|
//(Which would by the way not load because of missing pod domain prefix in the url)
|
|
|
|
if(appSettings.getAvatarUrl().startsWith("/assets/user/default")) {
|
|
|
|
navheaderImage.setImageResource(R.drawable.ic_launcher);
|
|
|
|
} else {
|
|
|
|
// Try to load image
|
|
|
|
if (!app.getAvatarImageLoader().loadToImageView(navheaderImage)) {
|
|
|
|
// If not yet loaded, start download
|
|
|
|
app.getAvatarImageLoader().startImageDownload(navheaderImage, appSettings.getAvatarUrl());
|
|
|
|
}
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
2016-08-07 02:28:37 +02:00
|
|
|
|
2016-08-13 14:13:14 +02:00
|
|
|
// Set visibility
|
2016-08-07 02:28:37 +02:00
|
|
|
Menu navMenu = navView.getMenu();
|
2016-08-13 14:13:14 +02:00
|
|
|
navMenu.findItem(R.id.nav_exit).setVisible(appSettings.isVisibleInNavExit());
|
|
|
|
navMenu.findItem(R.id.nav_activities).setVisible(appSettings.isVisibleInNavActivities());
|
|
|
|
navMenu.findItem(R.id.nav_aspects).setVisible(appSettings.isVisibleInNavAspects());
|
|
|
|
navMenu.findItem(R.id.nav_commented).setVisible(appSettings.isVisibleInNavCommented());
|
|
|
|
navMenu.findItem(R.id.nav_followed_tags).setVisible(appSettings.isVisibleInNavFollowed_tags());
|
|
|
|
navMenu.findItem(R.id.nav_help_license).setVisible(appSettings.isVisibleInNavHelp_license());
|
|
|
|
navMenu.findItem(R.id.nav_liked).setVisible(appSettings.isVisibleInNavLiked());
|
|
|
|
navMenu.findItem(R.id.nav_mentions).setVisible(appSettings.isVisibleInNavMentions());
|
|
|
|
navMenu.findItem(R.id.nav_profile).setVisible(appSettings.isVisibleInNavProfile());
|
|
|
|
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
@OnClick(R.id.toolbar)
|
|
|
|
public void onToolBarClicked(View view) {
|
2016-06-04 21:46:54 +02:00
|
|
|
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private File createImageFile() throws IOException {
|
|
|
|
// Create an image file name
|
2016-04-28 21:36:27 +02:00
|
|
|
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
|
2016-03-03 17:46:31 +01:00
|
|
|
String imageFileName = "JPEG_" + timeStamp + "_";
|
|
|
|
File storageDir = Environment.getExternalStoragePublicDirectory(
|
|
|
|
Environment.DIRECTORY_PICTURES);
|
|
|
|
return File.createTempFile(
|
|
|
|
imageFileName, /* prefix */
|
|
|
|
".jpg", /* suffix */
|
|
|
|
storageDir /* directory */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:47:11 +02:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleIntent(Intent intent) {
|
2016-07-30 16:48:43 +02:00
|
|
|
if (intent == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:47:11 +02:00
|
|
|
String action = intent.getAction();
|
2016-08-02 23:58:36 +02:00
|
|
|
String type = intent.getType();
|
2016-07-30 16:48:43 +02:00
|
|
|
String loadUrl = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (ACTION_OPEN_URL.equals(action)) {
|
|
|
|
loadUrl = intent.getStringExtra(URL_MESSAGE);
|
|
|
|
} else if (Intent.ACTION_VIEW.equals(action) && intent.getDataString() != null) {
|
|
|
|
loadUrl = intent.getDataString();
|
|
|
|
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
|
2016-07-26 22:47:11 +02:00
|
|
|
app.resetPodData(webView);
|
|
|
|
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
2016-07-30 16:48:43 +02:00
|
|
|
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
2016-07-26 22:52:26 +02:00
|
|
|
webView.clearCache(true);
|
2016-08-07 02:28:37 +02:00
|
|
|
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
|
|
|
|
recreate();
|
|
|
|
return;
|
2016-08-02 23:58:36 +02:00
|
|
|
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
|
|
|
|
switch (type) {
|
|
|
|
case "text/plain":
|
|
|
|
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
|
|
|
|
handleSendSubject(intent);
|
|
|
|
} else {
|
2016-08-13 14:13:14 +02:00
|
|
|
handleSendText(intent);
|
|
|
|
}
|
2016-08-02 23:58:36 +02:00
|
|
|
break;
|
|
|
|
case "image/*":
|
|
|
|
handleSendImage(intent); //TODO: Add intent filter to Manifest and implement method
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
|
|
|
|
//TODO: Implement and add filter to manifest
|
2016-07-26 22:47:11 +02:00
|
|
|
}
|
2016-07-30 16:48:43 +02:00
|
|
|
|
|
|
|
if (loadUrl != null) {
|
|
|
|
webView.stopLoading();
|
|
|
|
navDrawer.closeDrawers();
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(loadUrl);
|
2016-07-30 16:48:43 +02:00
|
|
|
}
|
2016-07-26 22:47:11 +02:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
@Override
|
2016-03-20 22:49:11 +01:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
|
2016-03-03 17:46:31 +01:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Uri[] results = null;
|
2016-03-20 22:49:11 +01:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
if (data == null) {
|
|
|
|
if (mCameraPhotoPath != null) {
|
2016-03-03 17:46:31 +01:00
|
|
|
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String dataString = data.getDataString();
|
|
|
|
if (dataString != null) {
|
|
|
|
results = new Uri[]{Uri.parse(dataString)};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mFilePathCallback.onReceiveValue(results);
|
|
|
|
mFilePathCallback = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
webView.saveState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
|
webView.restoreState(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2016-08-01 01:14:44 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2016-06-04 21:46:54 +02:00
|
|
|
if (navDrawer.isDrawerOpen(navView)) {
|
|
|
|
navDrawer.closeDrawer(navView);
|
2016-06-04 17:10:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
if (webView.canGoBack()) {
|
|
|
|
webView.goBack();
|
2016-08-07 11:39:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!snackbarExitApp.isShown()) {
|
|
|
|
snackbarExitApp.show();
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 01:14:44 +02:00
|
|
|
private final BroadcastReceiver brSetTitle = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String url = intent.getStringExtra(EXTRA_URL);
|
2016-08-10 17:14:05 +02:00
|
|
|
if (url != null && url.startsWith(urls.getPodUrl())) {
|
|
|
|
String subUrl = url.substring((urls.getPodUrl()).length());
|
|
|
|
if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_stream);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) {
|
2016-08-01 01:21:35 +02:00
|
|
|
setTitle(R.string.diaspora); //TODO: Extract posts title somehow?
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NOTIFICATIONS)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.notifications);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_CONVERSATIONS)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.conversations);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NEW_POST)) {
|
2016-08-01 01:14:44 +02:00
|
|
|
setTitle(R.string.new_post);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PEOPLE + appSettings.getProfileId())) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_profile);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_ACTIVITY)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_activities);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_LIKED)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_liked);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_COMMENTED)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_commented);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_MENTIONS)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_mentions);
|
2016-08-10 17:14:05 +02:00
|
|
|
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_PUBLIC)) {
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.public_);
|
2016-08-13 15:31:27 +02:00
|
|
|
} else if (urls.isAspectUrl(url)){
|
|
|
|
setTitle(urls.getAspectNameFromUrl(url, app));
|
2016-08-01 01:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
2016-08-01 01:14:44 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(brSetTitle);
|
2016-03-03 17:46:31 +01:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2016-06-04 17:10:24 +02:00
|
|
|
getMenuInflater().inflate(R.menu.main__menu_top, menu);
|
2016-03-03 17:46:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2016-03-20 22:49:11 +01:00
|
|
|
MenuItem itemNotification = menu.findItem(R.id.action_notifications);
|
2016-03-03 17:46:31 +01:00
|
|
|
if (itemNotification != null) {
|
2016-08-07 03:42:20 +02:00
|
|
|
if (podUserProfile.getNotificationCount() > 0) {
|
2016-08-07 03:30:44 +02:00
|
|
|
itemNotification.setIcon(R.drawable.ic_notifications_colored_48px);
|
2016-03-03 17:46:31 +01:00
|
|
|
} else {
|
2016-08-07 03:30:44 +02:00
|
|
|
itemNotification.setIcon(R.drawable.ic_notifications_white_48px);
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
MenuItem itemConversation = menu.findItem(R.id.action_conversations);
|
2016-08-07 03:42:20 +02:00
|
|
|
if (podUserProfile.getUnreadMessagesCount() > 0) {
|
2016-08-07 03:30:44 +02:00
|
|
|
itemConversation.setIcon(R.drawable.ic_email_colored_48px);
|
2016-03-03 17:46:31 +01:00
|
|
|
} else {
|
2016-08-07 03:30:44 +02:00
|
|
|
itemConversation.setIcon(R.drawable.ic_mail_white_48px);
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2016-03-20 22:49:11 +01:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_notifications: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getNotificationsUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.action_conversations: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getConversationsUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-08 15:42:02 +01:00
|
|
|
|
2016-08-07 23:11:47 +02:00
|
|
|
case R.id.action_reload: {
|
2016-08-13 14:13:14 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-07 23:11:47 +02:00
|
|
|
webView.reload();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.action_exit: {
|
2016-03-23 21:07:53 +01:00
|
|
|
moveTaskToBack(true);
|
2016-07-31 15:16:22 +02:00
|
|
|
finish();
|
2016-06-04 17:10:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-17 19:43:28 +02:00
|
|
|
case R.id.action_toggle_desktop_page: {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getToggleMobileUrl());
|
2016-06-17 19:43:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
case R.id.action_compose: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getNewPostUrl());
|
2016-06-04 17:10:24 +02:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-06-04 17:10:24 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_go_to_top: {
|
|
|
|
// Scroll to top (animated)
|
|
|
|
ObjectAnimator anim = ObjectAnimator.ofInt(webView, "scrollY", webView.getScrollY(), 0);
|
|
|
|
anim.setDuration(400);
|
|
|
|
anim.start();
|
|
|
|
return true;
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-04 17:56:08 +02:00
|
|
|
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());
|
2016-08-10 17:14:05 +02:00
|
|
|
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.action_share_dotdotdot)));
|
2016-06-04 17:56:08 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-04-28 21:36:27 +02:00
|
|
|
|
2016-06-04 17:56:08 +02:00
|
|
|
case R.id.action_take_screenshot: {
|
|
|
|
makeScreenshotOfWebView(false);
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-23 20:58:37 +02:00
|
|
|
|
2016-06-04 17:56:08 +02:00
|
|
|
case R.id.action_share_screenshot: {
|
|
|
|
makeScreenshotOfWebView(true);
|
2016-06-04 17:10:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_search: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-06-04 19:44:38 +02:00
|
|
|
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
LinearLayout layout = new LinearLayout(this);
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
layout.setGravity(Gravity.CENTER_HORIZONTAL);
|
2016-06-04 17:10:24 +02:00
|
|
|
final EditText input = new EditText(this);
|
2016-06-04 19:44:38 +02:00
|
|
|
input.setSingleLine(true);
|
|
|
|
layout.setPadding(50, 0, 50, 0);
|
|
|
|
input.setHint(R.string.app_hashtag);
|
|
|
|
layout.addView(input);
|
|
|
|
|
|
|
|
final DialogInterface.OnClickListener onSearchAccepted = new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
boolean wasClickedOnSearchForPeople = which == DialogInterface.BUTTON_NEGATIVE;
|
|
|
|
|
|
|
|
String inputTag = input.getText().toString().trim();
|
|
|
|
String cleanTag = inputTag.replaceAll(wasClickedOnSearchForPeople ? "\\*" : "\\#", "");
|
|
|
|
// this validate the input data for tagfind
|
|
|
|
if (cleanTag == null || cleanTag.equals("")) {
|
2016-08-07 23:11:47 +02:00
|
|
|
Snackbar.make(contentLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
|
2016-06-04 19:44:38 +02:00
|
|
|
} else { // User have added a search tag
|
|
|
|
if (wasClickedOnSearchForPeople) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getSearchPeopleUrl(cleanTag));
|
2016-06-04 19:44:38 +02:00
|
|
|
} else {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getSearchTagsUrl(cleanTag));
|
2016-06-04 17:10:24 +02:00
|
|
|
}
|
2016-06-04 19:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
|
|
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
final AlertDialog dialog = new AlertDialog.Builder(this)
|
|
|
|
.setView(layout)
|
|
|
|
.setTitle(R.string.search_alert_title)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setPositiveButton(R.string.search_alert_tag, onSearchAccepted)
|
|
|
|
.setNegativeButton(R.string.search_alert_people, onSearchAccepted)
|
|
|
|
.create();
|
|
|
|
|
|
|
|
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
dialog.hide();
|
|
|
|
onSearchAccepted.onClick(null, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Popup keyboard
|
2016-06-04 17:10:24 +02:00
|
|
|
dialog.show();
|
2016-06-04 19:44:38 +02:00
|
|
|
input.requestFocus();
|
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
|
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-06-04 17:10:24 +02:00
|
|
|
}
|
|
|
|
return true;
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-06-04 17:56:08 +02:00
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2016-08-07 11:39:20 +02:00
|
|
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
2016-06-04 17:56:08 +02:00
|
|
|
private boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= 23) {
|
|
|
|
int hasWRITE_EXTERNAL_STORAGE = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
|
if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
|
new AlertDialog.Builder(MainActivity.this)
|
|
|
|
.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},
|
|
|
|
REQUEST_CODE_ASK_PERMISSIONS);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
|
|
|
REQUEST_CODE_ASK_PERMISSIONS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Date dateNow = new Date();
|
|
|
|
DateFormat dateFormat = new SimpleDateFormat("yy_MM_dd--HH_mm_ss", Locale.getDefault());
|
2016-07-18 13:25:10 +02:00
|
|
|
File fileSaveDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Diaspora");
|
2016-06-04 17:56:08 +02:00
|
|
|
|
2016-07-18 13:25:10 +02:00
|
|
|
String fileSaveName = hasToShareScreenshot ? ".DfA_share.jpg" : String.format("DfA_%s.jpg", dateFormat.format(dateNow));
|
2016-06-04 17:56:08 +02:00
|
|
|
if (!fileSaveDirectory.exists()) {
|
|
|
|
fileSaveDirectory.mkdirs();
|
|
|
|
}
|
|
|
|
|
2016-06-05 01:54:17 +02:00
|
|
|
if (!hasToShareScreenshot) {
|
2016-08-07 23:11:47 +02:00
|
|
|
Snackbar.make(contentLayout, getString(R.string.share__toast_screenshot) + " " + fileSaveName, Snackbar.LENGTH_LONG).show();
|
2016-06-05 01:54:17 +02:00
|
|
|
}
|
2016-06-04 17:56:08 +02:00
|
|
|
|
2016-07-04 11:19:09 +02:00
|
|
|
Bitmap bitmap;
|
2016-06-04 17:56:08 +02:00
|
|
|
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();
|
2016-08-07 11:39:20 +02:00
|
|
|
} catch (IOException _ignSaveored) {/* Nothing */}
|
2016-06-04 17:56:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2016-08-06 01:35:52 +02:00
|
|
|
startActivity(Intent.createChooser(sharingIntent, getString(R.string.action_share_dotdotdot)));
|
2016-07-18 13:25:10 +02:00
|
|
|
} else {
|
2016-06-05 01:54:17 +02:00
|
|
|
// 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);
|
|
|
|
sendBroadcast(intent);
|
|
|
|
}
|
2016-06-04 17:56:08 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
@Override
|
|
|
|
public void onUserProfileNameChanged(String name) {
|
|
|
|
navheaderTitle.setText(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUserProfileAvatarChanged(String avatarUrl) {
|
|
|
|
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
|
|
|
|
}
|
|
|
|
|
2016-08-02 23:58:36 +02:00
|
|
|
void handleSendText(Intent intent) {
|
2016-08-07 14:29:52 +02:00
|
|
|
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
|
2016-08-13 14:13:14 +02:00
|
|
|
if (appSettings.isAppendSharedViaApp()) {
|
2016-08-07 14:29:52 +02:00
|
|
|
// = \n
|
|
|
|
content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
2016-08-07 14:29:52 +02:00
|
|
|
|
|
|
|
final String sharedText = WebHelper.escapeHtmlText(content);
|
2016-08-02 23:58:36 +02:00
|
|
|
if (sharedText != null) {
|
2016-08-08 07:41:36 +02:00
|
|
|
textToBeShared = sharedText;
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
2016-08-08 08:24:58 +02:00
|
|
|
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getBlankUrl());
|
|
|
|
webView.loadUrlNew(urls.getNewPostUrl());
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle sent text + subject
|
2016-08-13 14:13:14 +02:00
|
|
|
*
|
2016-08-02 23:58:36 +02:00
|
|
|
* @param intent
|
|
|
|
*/
|
|
|
|
void handleSendSubject(Intent intent) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getNewPostUrl());
|
2016-08-07 14:29:52 +02:00
|
|
|
String content = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_TEXT));
|
|
|
|
String subject = WebHelper.replaceUrlWithMarkdown(intent.getStringExtra(Intent.EXTRA_SUBJECT));
|
|
|
|
|
2016-08-02 23:58:36 +02:00
|
|
|
if (appSettings.isAppendSharedViaApp()) {
|
2016-08-07 14:29:52 +02:00
|
|
|
// = \n
|
|
|
|
content = content + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
2016-08-07 14:29:52 +02:00
|
|
|
|
|
|
|
final String sharedSubject = WebHelper.escapeHtmlText(subject);
|
|
|
|
final String sharedContent = WebHelper.escapeHtmlText(content);
|
2016-08-08 08:24:58 +02:00
|
|
|
textToBeShared = "**" + sharedSubject + "** " + sharedContent;
|
2016-08-08 07:41:36 +02:00
|
|
|
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getBlankUrl());
|
|
|
|
webView.loadUrlNew(urls.getNewPostUrl());
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Implement?
|
|
|
|
private void handleSendImage(Intent intent) {
|
|
|
|
final Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
if (imageUri != null) {
|
|
|
|
// Update UI to reflect text being shared
|
|
|
|
}
|
|
|
|
Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
// TODO: Move from Javascript interface
|
|
|
|
@Override
|
|
|
|
public void onNotificationCountChanged(int notificationCount) {
|
2016-08-07 11:39:20 +02:00
|
|
|
// Count saved in PodUserProfile
|
|
|
|
invalidateOptionsMenu();
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-08-07 11:39:20 +02:00
|
|
|
if (notificationCount > 0 && !snackbarNewNotification.isShown()
|
2016-08-10 17:14:05 +02:00
|
|
|
&& !webView.getUrl().equals(urls.getNotificationsUrl())) {
|
2016-08-07 11:39:20 +02:00
|
|
|
snackbarNewNotification.show();
|
2016-08-07 03:42:20 +02:00
|
|
|
}
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Move from Javascript interface
|
|
|
|
@Override
|
|
|
|
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
2016-08-07 11:39:20 +02:00
|
|
|
// Count saved in PodUserProfile
|
|
|
|
invalidateOptionsMenu();
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-08-07 11:39:20 +02:00
|
|
|
if (unreadMessageCount > 0 && !snackbarNewNotification.isShown()
|
2016-08-10 17:14:05 +02:00
|
|
|
&& !webView.getUrl().equals(urls.getNotificationsUrl())) {
|
2016-08-07 11:39:20 +02:00
|
|
|
snackbarNewNotification.show();
|
2016-08-07 03:42:20 +02:00
|
|
|
}
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 22:26:23 +01:00
|
|
|
private class JavaScriptInterface {
|
2016-03-24 13:56:30 +01:00
|
|
|
@JavascriptInterface
|
|
|
|
public void setUserProfile(final String webMessage) throws JSONException {
|
2016-06-04 03:48:57 +02:00
|
|
|
if (podUserProfile.isRefreshNeeded()) {
|
|
|
|
podUserProfile.parseJson(webMessage);
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
2016-03-24 13:56:30 +01:00
|
|
|
}
|
2016-08-08 07:41:36 +02:00
|
|
|
|
|
|
|
@JavascriptInterface
|
2016-08-13 14:13:14 +02:00
|
|
|
public void contentHasBeenShared() {
|
2016-08-08 07:41:36 +02:00
|
|
|
textToBeShared = null;
|
|
|
|
}
|
2016-08-08 08:24:58 +02:00
|
|
|
|
|
|
|
@JavascriptInterface
|
2016-08-13 14:13:14 +02:00
|
|
|
public void log(final String log) {
|
2016-08-08 08:24:58 +02:00
|
|
|
//Log.d(App.TAG, "[wv] " + log);
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("StatementWithEmptyBody")
|
|
|
|
@Override
|
|
|
|
public boolean onNavigationItemSelected(MenuItem item) {
|
|
|
|
// Handle navigation view item clicks here.
|
2016-03-20 22:49:11 +01:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.nav_stream: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getStreamUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-08-10 17:47:21 +02:00
|
|
|
case R.id.nav_profile: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getProfileUrl());
|
2016-08-10 17:47:21 +02:00
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_followed_tags: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
WebHelper.showFollowedTagsList(webView, app);
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.nav_followed_tags);
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_aspects: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(DiasporaUrlHelper.URL_BLANK);
|
2016-08-07 14:29:52 +02:00
|
|
|
WebHelper.showAspectList(webView, app);
|
2016-08-06 01:35:52 +02:00
|
|
|
setTitle(R.string.aspects);
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_activities: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getActivityUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_liked: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getLikedPostsUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_commented: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getCommentedUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_mentions: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getMentionsUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-08-07 02:28:37 +02:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_public: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-08-13 15:31:27 +02:00
|
|
|
webView.loadUrlNew(urls.getPublicUrl());
|
2016-03-20 22:49:11 +01:00
|
|
|
} else {
|
2016-06-24 13:31:01 +02:00
|
|
|
snackbarNoInternet.show();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-08-07 02:28:37 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.nav_exit: {
|
|
|
|
moveTaskToBack(true);
|
|
|
|
finish();
|
|
|
|
break;
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-02 13:58:09 +02:00
|
|
|
case R.id.nav_settings_app: {
|
2016-07-26 22:47:11 +02:00
|
|
|
startActivity(new Intent(this, SettingsActivity.class));
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
|
|
|
break;
|
2016-03-08 15:42:02 +01:00
|
|
|
|
2016-08-13 14:13:14 +02:00
|
|
|
case R.id.nav_help_license: {
|
2016-08-07 23:37:02 +02:00
|
|
|
final CharSequence[] options = {getString(R.string.help_license__name), getString(R.string.help_markdown__name)};
|
2016-03-08 15:42:02 +01:00
|
|
|
new AlertDialog.Builder(MainActivity.this)
|
2016-03-20 22:49:11 +01:00
|
|
|
.setItems(options, new DialogInterface.OnClickListener() {
|
2016-03-08 15:42:02 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int item) {
|
2016-08-07 23:37:02 +02:00
|
|
|
if (options[item].equals(getString(R.string.help_license__name))) {
|
|
|
|
final SpannableString s = new SpannableString(Html.fromHtml(getString(R.string.help_license__content)));
|
2016-03-20 22:49:11 +01:00
|
|
|
Linkify.addLinks(s, Linkify.WEB_URLS);
|
|
|
|
final AlertDialog d = new AlertDialog.Builder(MainActivity.this)
|
2016-08-07 23:37:02 +02:00
|
|
|
.setTitle(R.string.help_license__years)
|
2016-03-20 22:49:11 +01:00
|
|
|
.setMessage(s)
|
2016-06-04 11:11:51 +02:00
|
|
|
.setPositiveButton(android.R.string.yes, null).show();
|
2016-03-20 22:49:11 +01:00
|
|
|
d.show();
|
|
|
|
((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
2016-08-07 23:37:02 +02:00
|
|
|
if (options[item].equals(getString(R.string.help_markdown__name))) {
|
|
|
|
Helpers.loadUrlInExternalBrowser(MainActivity.this, getString(R.string.help_markdown__weblink));
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
2016-03-08 15:42:02 +01:00
|
|
|
}).show();
|
|
|
|
}
|
2016-03-20 22:49:11 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:16:22 +02:00
|
|
|
navDrawer.closeDrawer(GravityCompat.START);
|
2016-03-03 17:46:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-08 21:59:46 +02:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE:
|
|
|
|
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
Toast.makeText(this, R.string.permission_granted_try_again, Toast.LENGTH_SHORT).show();
|
2016-04-09 13:53:06 +02:00
|
|
|
} else {
|
2016-04-08 21:59:46 +02:00
|
|
|
Toast.makeText(this, R.string.permission_denied, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions,
|
|
|
|
grantResults);
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 01:03:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2016-07-30 16:48:43 +02:00
|
|
|
*
|
2016-06-09 01:03:50 +02:00
|
|
|
* @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) {
|
2016-07-30 16:48:43 +02:00
|
|
|
if (host != null && !host.equals("") && port >= 0) {
|
2016-06-09 01:03:50 +02:00
|
|
|
//Temporary change thread policy
|
|
|
|
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
|
|
|
|
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
|
|
|
StrictMode.setThreadPolicy(tmp);
|
|
|
|
|
|
|
|
NetCipher.setProxy(host, port); //Proxy for HttpsUrlConnections
|
|
|
|
try {
|
|
|
|
//Proxy for the webview
|
|
|
|
WebkitProxy.setProxy(MainActivity.class.getName(), getApplicationContext(), null, host, port);
|
|
|
|
} catch (Exception e) { /*Nothing we can do*/ }
|
|
|
|
|
|
|
|
appSettings.setProxyEnabled(true);
|
2016-06-16 23:36:52 +02:00
|
|
|
appSettings.setProxyWasEnabled(true);
|
2016-06-09 01:03:50 +02:00
|
|
|
|
|
|
|
StrictMode.setThreadPolicy(old);
|
|
|
|
webView.reload();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean setProxy() {
|
|
|
|
return setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetProxy() {
|
|
|
|
appSettings.setProxyEnabled(false);
|
2016-06-16 23:36:52 +02:00
|
|
|
appSettings.setProxyWasEnabled(false);
|
2016-06-09 01:03:50 +02:00
|
|
|
|
|
|
|
//Temporary change thread policy
|
|
|
|
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
|
|
|
|
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
|
|
|
StrictMode.setThreadPolicy(tmp);
|
|
|
|
|
|
|
|
NetCipher.clearProxy();
|
2016-07-30 16:48:43 +02:00
|
|
|
try {
|
2016-06-09 01:03:50 +02:00
|
|
|
WebkitProxy.resetProxy(MainActivity.class.getName(), this);
|
2016-06-16 23:36:52 +02:00
|
|
|
} catch (Exception e) {/*Nothing*/}
|
2016-06-09 01:03:50 +02:00
|
|
|
|
|
|
|
StrictMode.setThreadPolicy(old);
|
|
|
|
|
|
|
|
//Restart app
|
|
|
|
Intent restartActivity = new Intent(this, MainActivity.class);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
|
|
|
|
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
|
|
|
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2016-07-29 14:00:28 +02:00
|
|
|
}
|