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.annotation.SuppressLint;
|
|
|
|
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;
|
2016-09-19 01:10:29 +02:00
|
|
|
import android.graphics.drawable.LayerDrawable;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.support.annotation.NonNull;
|
2016-09-21 22:49:37 +02:00
|
|
|
import android.support.customtabs.CustomTabsSession;
|
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-09-21 21:15:34 +02:00
|
|
|
import android.support.v4.app.FragmentManager;
|
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;
|
2016-11-10 14:18:22 +01:00
|
|
|
import android.support.v7.app.ActionBar;
|
2016-03-03 17:46:31 +01:00
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
2016-11-06 16:23:18 +01:00
|
|
|
import android.support.v7.app.AlertDialog;
|
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-06-04 19:44:38 +02:00
|
|
|
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.widget.EditText;
|
2016-09-05 20:42:57 +02:00
|
|
|
import android.widget.FrameLayout;
|
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-10-13 16:56:31 +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;
|
2016-10-22 19:21:26 +02:00
|
|
|
import com.github.dfa.diaspora_android.data.DiasporaPodList;
|
2016-10-26 16:23:14 +02:00
|
|
|
import com.github.dfa.diaspora_android.data.DiasporaUserProfile;
|
|
|
|
import com.github.dfa.diaspora_android.listener.DiasporaUserProfileChangedListener;
|
|
|
|
import com.github.dfa.diaspora_android.listener.IntellihideToolbarActivityListener;
|
2016-09-21 21:15:34 +02:00
|
|
|
import com.github.dfa.diaspora_android.receiver.OpenExternalLinkReceiver;
|
|
|
|
import com.github.dfa.diaspora_android.receiver.UpdateTitleReceiver;
|
2016-09-11 17:15:26 +02:00
|
|
|
import com.github.dfa.diaspora_android.ui.BadgeDrawable;
|
2016-10-22 19:21:26 +02:00
|
|
|
import com.github.dfa.diaspora_android.ui.PodSelectionDialog;
|
2016-10-26 16:23:14 +02:00
|
|
|
import com.github.dfa.diaspora_android.ui.theme.CustomFragment;
|
|
|
|
import com.github.dfa.diaspora_android.ui.theme.ThemeHelper;
|
|
|
|
import com.github.dfa.diaspora_android.ui.theme.ThemedActivity;
|
2016-11-06 16:23:18 +01:00
|
|
|
import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder;
|
2016-09-19 01:10:29 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.AppLog;
|
2016-10-26 16:23:14 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.AppSettings;
|
2016-08-10 17:14:05 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
2016-10-26 16:23:14 +02:00
|
|
|
import com.github.dfa.diaspora_android.web.BrowserFragment;
|
2016-10-26 21:53:27 +02:00
|
|
|
import com.github.dfa.diaspora_android.web.ContextMenuWebView;
|
2016-10-26 16:23:14 +02:00
|
|
|
import com.github.dfa.diaspora_android.web.ProxyHandler;
|
|
|
|
import com.github.dfa.diaspora_android.web.WebHelper;
|
|
|
|
import com.github.dfa.diaspora_android.web.custom_tab.CustomTabActivityHelper;
|
2016-03-25 00:12:00 +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-11-10 14:18:22 +01:00
|
|
|
import butterknife.OnClick;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-10-13 16:56:31 +02:00
|
|
|
public class MainActivity extends ThemedActivity
|
|
|
|
implements NavigationView.OnNavigationItemSelectedListener,
|
2016-10-26 16:23:14 +02:00
|
|
|
DiasporaUserProfileChangedListener,
|
2016-10-13 16:56:31 +02:00
|
|
|
CustomTabActivityHelper.ConnectionCallback,
|
2016-10-22 19:21:26 +02:00
|
|
|
IntellihideToolbarActivityListener,
|
2016-10-26 16:23:14 +02:00
|
|
|
PodSelectionDialog.PodSelectionDialogResultListener {
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
|
2016-09-21 21:15:34 +02:00
|
|
|
public static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
2016-09-10 16:54:48 +02:00
|
|
|
public static final int REQUEST_CODE__ACCESS_EXTERNAL_STORAGE = 124;
|
2016-09-22 00:29:32 +02:00
|
|
|
public static final int INPUT_FILE_REQUEST_CODE_NEW = 1;
|
|
|
|
public static final int INPUT_FILE_REQUEST_CODE_OLD = 2;
|
2016-07-26 22:47:11 +02:00
|
|
|
|
|
|
|
public static final String ACTION_OPEN_URL = "com.github.dfa.diaspora_android.MainActivity.open_url";
|
2016-09-11 12:35:16 +02:00
|
|
|
public static final String ACTION_OPEN_EXTERNAL_URL = "com.github.dfa.diaspora_android.MainActivity.open_external_url";
|
2016-07-26 22:47:11 +02:00
|
|
|
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-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-08-27 00:04:07 +02:00
|
|
|
public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/";
|
2016-03-20 22:49:11 +01:00
|
|
|
|
2016-03-24 13:56:30 +01:00
|
|
|
private App app;
|
2016-09-11 12:35:16 +02:00
|
|
|
private CustomTabActivityHelper customTabActivityHelper;
|
2016-03-24 11:58:28 +01:00
|
|
|
private AppSettings appSettings;
|
2016-08-10 17:14:05 +02:00
|
|
|
private DiasporaUrlHelper urls;
|
2016-10-26 16:23:14 +02:00
|
|
|
private DiasporaUserProfile diasporaUserProfile;
|
2016-03-25 00:12:00 +01:00
|
|
|
private final Handler uiHandler = new Handler();
|
2016-09-11 14:51:23 +02:00
|
|
|
private OpenExternalLinkReceiver brOpenExternalLink;
|
2016-09-11 15:22:16 +02:00
|
|
|
private BroadcastReceiver brSetTitle;
|
2016-12-18 15:07:00 +01:00
|
|
|
private Snackbar snackbarExitApp, snackbarNoInternet, snackbarLastVisitedTimestampInStream;
|
2016-09-21 21:15:34 +02:00
|
|
|
private FragmentManager fm;
|
2016-09-21 22:49:37 +02:00
|
|
|
private CustomTabsSession customTabsSession;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-06-04 17:10:24 +02:00
|
|
|
/**
|
|
|
|
* UI Bindings
|
|
|
|
*/
|
2016-10-13 16:56:31 +02:00
|
|
|
@BindView(R.id.main__appbar)
|
|
|
|
AppBarLayout appBarLayout;
|
|
|
|
|
2016-09-21 21:15:34 +02:00
|
|
|
@BindView(R.id.main__topbar)
|
2016-06-04 17:10:24 +02:00
|
|
|
Toolbar toolbarTop;
|
|
|
|
|
2016-09-21 21:15:34 +02:00
|
|
|
@BindView(R.id.main__bottombar)
|
2016-06-04 17:10:24 +02:00
|
|
|
ActionMenuView toolbarBottom;
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-09-21 21:15:34 +02:00
|
|
|
@BindView(R.id.fragment_container)
|
|
|
|
FrameLayout fragmentContainer;
|
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;
|
|
|
|
|
2016-09-21 21:15:34 +02:00
|
|
|
@BindView(R.id.main__navdrawer)
|
2016-06-04 21:46:54 +02:00
|
|
|
DrawerLayout navDrawer;
|
2016-06-04 17:10:24 +02:00
|
|
|
|
2016-10-13 16:56:31 +02:00
|
|
|
RelativeLayout navDrawerLayout;
|
|
|
|
LinearLayout navProfilePictureArea;
|
|
|
|
|
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-09-22 23:20:13 +02:00
|
|
|
private String textToBeShared;
|
|
|
|
|
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-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onCreate()");
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
// Bind UI
|
2016-06-04 11:11:51 +02:00
|
|
|
setContentView(R.layout.main__activity);
|
2016-09-21 21:15:34 +02:00
|
|
|
ButterKnife.bind(this);
|
|
|
|
|
2016-12-16 05:24:03 +01:00
|
|
|
app = (App) getApplication();
|
|
|
|
appSettings = app.getSettings();
|
|
|
|
diasporaUserProfile = app.getDiasporaUserProfile();
|
2016-10-26 16:23:14 +02:00
|
|
|
diasporaUserProfile.setCallbackHandler(uiHandler);
|
|
|
|
diasporaUserProfile.setListener(this);
|
2016-08-10 17:14:05 +02:00
|
|
|
urls = new DiasporaUrlHelper(appSettings);
|
2016-09-11 12:35:16 +02:00
|
|
|
customTabActivityHelper = new CustomTabActivityHelper();
|
2016-09-21 22:49:37 +02:00
|
|
|
customTabActivityHelper.setConnectionCallback(this);
|
2016-10-10 17:47:04 +02:00
|
|
|
ProxyHandler.getInstance().updateProxySettings(this);
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-09-21 21:35:03 +02:00
|
|
|
fm = getSupportFragmentManager();
|
2016-10-02 22:22:08 +02:00
|
|
|
setupUI();
|
2016-09-11 13:05:26 +02:00
|
|
|
|
2016-09-11 14:51:23 +02:00
|
|
|
brOpenExternalLink = new OpenExternalLinkReceiver(this);
|
2016-09-11 15:22:16 +02:00
|
|
|
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
|
2016-12-18 15:07:00 +01:00
|
|
|
public void setTitle(String url, int resId) {
|
2016-10-03 23:04:09 +02:00
|
|
|
CustomFragment top = getTopFragment();
|
2016-10-14 01:26:56 +02:00
|
|
|
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
|
2016-12-16 05:24:03 +01:00
|
|
|
MainActivity.this.setTitle(resId);
|
2016-12-18 15:07:00 +01:00
|
|
|
showLastVisitedTimestampMessageIfNeeded(url);
|
2016-10-03 23:04:09 +02:00
|
|
|
}
|
2016-09-11 15:22:16 +02:00
|
|
|
}
|
|
|
|
|
2016-12-18 15:07:00 +01:00
|
|
|
public void setTitle(String url, String title) {
|
2016-10-03 23:04:09 +02:00
|
|
|
CustomFragment top = getTopFragment();
|
2016-10-14 01:26:56 +02:00
|
|
|
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
|
2016-10-03 23:04:09 +02:00
|
|
|
MainActivity.this.setTitle(title);
|
|
|
|
}
|
2016-09-11 15:22:16 +02:00
|
|
|
}
|
|
|
|
});
|
2016-10-01 01:18:42 +02:00
|
|
|
|
2016-10-07 04:29:32 +02:00
|
|
|
if (!appSettings.hasPod()) {
|
2016-10-01 01:30:58 +02:00
|
|
|
AppLog.d(this, "We have no pod. Show PodSelectionFragment");
|
2016-10-14 01:26:56 +02:00
|
|
|
updateNavigationViewEntryVisibilities();
|
2016-10-01 01:18:42 +02:00
|
|
|
showFragment(getFragment(PodSelectionFragment.TAG));
|
2016-09-28 21:43:25 +02:00
|
|
|
} else {
|
2016-10-01 01:30:58 +02:00
|
|
|
AppLog.d(this, "Pod found. Handle intents.");
|
2016-10-01 01:18:42 +02:00
|
|
|
//Handle intent
|
|
|
|
Intent intent = getIntent();
|
|
|
|
if (intent != null && intent.getAction() != null) {
|
|
|
|
handleIntent(intent);
|
|
|
|
} else {
|
|
|
|
openDiasporaUrl(urls.getStreamUrl());
|
|
|
|
}
|
2016-09-28 21:43:25 +02:00
|
|
|
}
|
2016-09-05 20:42:57 +02:00
|
|
|
}
|
2016-04-08 21:59:46 +02:00
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Setup the user interface. Set up both toolbars and initialize the snackbars.
|
|
|
|
* Initialize the navigation drawer and apply intellihide settings.
|
|
|
|
*/
|
|
|
|
private void setupUI() {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "setupUI()");
|
2016-09-11 15:22:16 +02:00
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
// Setup toolbar
|
2016-06-04 17:10:24 +02:00
|
|
|
setSupportActionBar(toolbarTop);
|
2016-11-10 14:18:22 +01:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
2016-12-16 05:24:03 +01:00
|
|
|
if (actionBar != null) {
|
2016-11-10 14:18:22 +01:00
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
2016-06-04 17:10:24 +02:00
|
|
|
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
2016-09-28 21:43:25 +02:00
|
|
|
CustomFragment top = getTopFragment();
|
|
|
|
return MainActivity.this.onOptionsItemSelected(item) || (top != null && top.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-09-21 21:15:34 +02:00
|
|
|
.make(fragmentContainer, R.string.confirm_exit, Snackbar.LENGTH_LONG)
|
2016-06-16 22:55:06 +02:00
|
|
|
.setAction(android.R.string.yes, new View.OnClickListener() {
|
|
|
|
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-12-22 13:23:20 +01:00
|
|
|
snackbarLastVisitedTimestampInStream =
|
|
|
|
Snackbar.make(fragmentContainer,
|
|
|
|
R.string.jump_to_last_visited_timestamp_in_stream, Snackbar.LENGTH_LONG)
|
2016-12-18 15:07:00 +01:00
|
|
|
.setAction(android.R.string.yes, new View.OnClickListener() {
|
|
|
|
public void onClick(View view) {
|
|
|
|
openDiasporaUrl(urls.getStreamWithTimestampUrl(diasporaUserProfile.getLastVisitedPositionInStream()));
|
|
|
|
}
|
|
|
|
});
|
2016-09-21 21:15:34 +02:00
|
|
|
snackbarNoInternet = Snackbar.make(fragmentContainer, 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-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "UI successfully set up");
|
2016-06-16 22:55:06 +02:00
|
|
|
}
|
|
|
|
|
2016-09-28 21:43:25 +02:00
|
|
|
/**
|
|
|
|
* Get an instance of the CustomFragment with the tag fragmentTag.
|
|
|
|
* If there was no instance so far, create a new one and add it to the FragmentManagers pool.
|
2016-10-02 22:22:08 +02:00
|
|
|
* If there is no Fragment with the corresponding Tag, return the top fragment.
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-09-28 21:43:25 +02:00
|
|
|
* @param fragmentTag tag
|
|
|
|
* @return corresponding Fragment
|
|
|
|
*/
|
|
|
|
protected CustomFragment getFragment(String fragmentTag) {
|
|
|
|
CustomFragment fragment = (CustomFragment) fm.findFragmentByTag(fragmentTag);
|
2016-10-14 01:26:56 +02:00
|
|
|
if (fragment != null) {
|
2016-09-28 21:43:25 +02:00
|
|
|
return fragment;
|
|
|
|
} else {
|
|
|
|
switch (fragmentTag) {
|
|
|
|
case DiasporaStreamFragment.TAG:
|
|
|
|
DiasporaStreamFragment dsf = new DiasporaStreamFragment();
|
|
|
|
fm.beginTransaction().add(dsf, fragmentTag).commit();
|
|
|
|
return dsf;
|
|
|
|
case BrowserFragment.TAG:
|
|
|
|
BrowserFragment bf = new BrowserFragment();
|
|
|
|
fm.beginTransaction().add(bf, fragmentTag).commit();
|
|
|
|
return bf;
|
2016-10-26 16:23:14 +02:00
|
|
|
case TagListFragment.TAG:
|
|
|
|
TagListFragment hlf = new TagListFragment();
|
2016-09-30 23:15:10 +02:00
|
|
|
fm.beginTransaction().add(hlf, fragmentTag).commit();
|
|
|
|
return hlf;
|
2016-10-26 14:33:05 +02:00
|
|
|
case AspectListFragment.TAG:
|
|
|
|
AspectListFragment alf = new AspectListFragment();
|
|
|
|
fm.beginTransaction().add(alf, fragmentTag).commit();
|
|
|
|
return alf;
|
2016-10-01 01:18:42 +02:00
|
|
|
case PodSelectionFragment.TAG:
|
|
|
|
PodSelectionFragment psf = new PodSelectionFragment();
|
|
|
|
fm.beginTransaction().add(psf, fragmentTag).commit();
|
|
|
|
return psf;
|
2016-09-28 21:43:25 +02:00
|
|
|
default:
|
2016-10-14 01:26:56 +02:00
|
|
|
AppLog.e(this, "Invalid Fragment Tag: " + fragmentTag
|
|
|
|
+ "\nAdd Fragments Tag to getFragment()'s switch case.");
|
2016-10-02 13:36:57 +02:00
|
|
|
return getTopFragment();
|
2016-09-28 21:43:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-18 15:07:00 +01:00
|
|
|
/**
|
|
|
|
* Show DiasporaStreamFragment if necessary and load URL url
|
|
|
|
*
|
|
|
|
* @param url URL to load in the DiasporaStreamFragment
|
|
|
|
*/
|
|
|
|
public void openDiasporaUrl(String url) {
|
|
|
|
AppLog.v(this, "openDiasporaUrl()");
|
|
|
|
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
|
|
|
|
showFragment(streamFragment);
|
|
|
|
showLastVisitedTimestampMessageIfNeeded(url);
|
|
|
|
streamFragment.loadUrl(url);
|
|
|
|
}
|
|
|
|
|
2016-12-18 15:07:23 +01:00
|
|
|
public void showLastVisitedTimestampMessageIfNeeded(String url) {
|
|
|
|
if (url.equals(urls.getStreamUrl()) && diasporaUserProfile.hasLastVisitedTimestampInStream()) {
|
2016-12-18 15:07:00 +01:00
|
|
|
snackbarLastVisitedTimestampInStream.show();
|
|
|
|
diasporaUserProfile.resetLastVisitedPositionInStream();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-28 21:43:25 +02:00
|
|
|
/**
|
|
|
|
* Show the Fragment fragment in R.id.fragment_container. If the fragment was already visible, do nothing.
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-09-28 21:43:25 +02:00
|
|
|
* @param fragment Fragment to show
|
|
|
|
*/
|
|
|
|
protected void showFragment(CustomFragment fragment) {
|
2016-09-29 19:44:42 +02:00
|
|
|
AppLog.v(this, "showFragment()");
|
2016-09-28 21:43:25 +02:00
|
|
|
CustomFragment currentTop = (CustomFragment) fm.findFragmentById(R.id.fragment_container);
|
2016-10-14 01:26:56 +02:00
|
|
|
if (currentTop == null || !currentTop.getFragmentTag().equals(fragment.getFragmentTag())) {
|
2016-09-29 19:44:42 +02:00
|
|
|
AppLog.v(this, "Fragment was not visible. Replace it.");
|
2016-09-28 21:43:25 +02:00
|
|
|
fm.beginTransaction().addToBackStack(null).replace(R.id.fragment_container, fragment, fragment.getFragmentTag()).commit();
|
2016-09-29 19:44:42 +02:00
|
|
|
invalidateOptionsMenu();
|
2016-10-27 12:55:42 +02:00
|
|
|
if (appSettings.isIntellihideToolbars() && fragment.isAllowedIntellihide()) {
|
|
|
|
this.enableToolbarHiding();
|
|
|
|
} else {
|
|
|
|
this.disableToolbarHiding();
|
|
|
|
}
|
2016-09-28 21:43:25 +02:00
|
|
|
} else {
|
2016-09-29 19:44:42 +02:00
|
|
|
AppLog.v(this, "Fragment was already visible. Do nothing.");
|
2016-09-21 21:15:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Initialize the navigation slider
|
|
|
|
*/
|
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-10-13 16:56:31 +02:00
|
|
|
navProfilePictureArea = ButterKnife.findById(navHeader, R.id.nav_profile_picture);
|
|
|
|
navDrawerLayout = ButterKnife.findById(navHeader, R.id.nav_drawer);
|
2016-09-21 21:15:34 +02:00
|
|
|
//Handle clicks on profile picture
|
2016-10-13 16:56:31 +02:00
|
|
|
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
|
2016-08-10 17:28:54 +02:00
|
|
|
public void onClick(View view) {
|
|
|
|
navDrawer.closeDrawer(GravityCompat.START);
|
2016-12-16 05:24:03 +01:00
|
|
|
if (!appSettings.getProfileId().equals("")) {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(urls.getProfileUrl());
|
2016-08-10 17:28:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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-10-07 02:43:12 +02:00
|
|
|
if (appSettings.getPod() != null) {
|
|
|
|
navheaderDescription.setText(appSettings.getPod().getName());
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
2016-09-10 16:54:48 +02:00
|
|
|
String avatarUrl = appSettings.getAvatarUrl();
|
|
|
|
if (!avatarUrl.equals("")) {
|
2016-08-21 17:04:51 +02:00
|
|
|
//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)
|
2016-09-19 01:10:29 +02:00
|
|
|
if (avatarUrl.startsWith("/assets/user/default")) {
|
|
|
|
AppLog.v(this, "Avatar appears to be an asset. Display launcher icon instead (avatarUrl=" + avatarUrl + ")");
|
2016-08-21 17:04:51 +02:00
|
|
|
navheaderImage.setImageResource(R.drawable.ic_launcher);
|
|
|
|
} else {
|
|
|
|
// Try to load image
|
|
|
|
if (!app.getAvatarImageLoader().loadToImageView(navheaderImage)) {
|
|
|
|
// If not yet loaded, start download
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Avatar not cached. Start download: " + avatarUrl);
|
2016-09-10 16:54:48 +02:00
|
|
|
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
|
2016-08-21 17:04:51 +02:00
|
|
|
}
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-13 16:56:31 +02:00
|
|
|
updateNavigationViewEntryVisibilities();
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-10-13 16:56:31 +02:00
|
|
|
protected void updateNavigationViewEntryVisibilities() {
|
2016-08-07 02:28:37 +02:00
|
|
|
Menu navMenu = navView.getMenu();
|
2016-10-22 19:21:26 +02:00
|
|
|
|
|
|
|
// Initially show all items visible when logged in
|
|
|
|
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), true);
|
|
|
|
|
|
|
|
// Hide by app settings
|
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());
|
2016-10-25 17:56:35 +02:00
|
|
|
navMenu.findItem(R.id.nav_contacts).setVisible(appSettings.isVisibleInNavContacts());
|
2016-08-13 14:13:14 +02:00
|
|
|
navMenu.findItem(R.id.nav_commented).setVisible(appSettings.isVisibleInNavCommented());
|
|
|
|
navMenu.findItem(R.id.nav_followed_tags).setVisible(appSettings.isVisibleInNavFollowed_tags());
|
2016-09-28 21:43:25 +02:00
|
|
|
navMenu.findItem(R.id.nav_about).setVisible(appSettings.isVisibleInNavHelp_license());
|
2016-08-13 14:13:14 +02:00
|
|
|
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-10-22 19:21:26 +02:00
|
|
|
navMenu.findItem(R.id.nav_stream).setVisible(true);
|
2016-11-06 20:36:43 +01:00
|
|
|
navMenu.findItem(R.id.nav_reports).setVisible(appSettings.isVisibleInNavReports());
|
2016-12-20 12:19:43 +01:00
|
|
|
navMenu.findItem(R.id.nav_toggle_desktop_page).setVisible(appSettings.isVisibleToggleMobileDesktop());
|
2016-03-25 00:12:00 +01:00
|
|
|
|
2016-10-22 19:21:26 +02:00
|
|
|
|
|
|
|
// Hide whole group (for logged in use) if no pod was selected
|
2016-10-14 01:26:56 +02:00
|
|
|
if (!appSettings.hasPod()) {
|
2016-10-14 00:44:23 +02:00
|
|
|
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), false);
|
|
|
|
}
|
|
|
|
}
|
2016-10-14 01:26:56 +02:00
|
|
|
|
2016-11-10 14:18:22 +01:00
|
|
|
/**
|
2016-11-11 20:17:59 +01:00
|
|
|
* Open Stream when clicked on top toolbar AND preference stream shortcut is true
|
2016-12-16 05:24:03 +01:00
|
|
|
*
|
2016-11-10 14:18:22 +01:00
|
|
|
* @param view selected view
|
|
|
|
*/
|
|
|
|
@OnClick(R.id.main__topbar)
|
|
|
|
public void onToolBarClicked(View view) {
|
|
|
|
AppLog.i(this, "onToolBarClicked()");
|
2016-12-16 05:24:03 +01:00
|
|
|
if (appSettings.isTopbarStreamShortcutEnabled() && appSettings.hasPod()) {
|
2016-11-10 14:18:22 +01:00
|
|
|
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Forward incoming intents to handleIntent()
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param intent incoming
|
|
|
|
*/
|
2016-07-26 22:47:11 +02:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Handle intents and execute intent specific actions
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param intent intent to get handled
|
|
|
|
*/
|
2016-07-26 22:47:11 +02:00
|
|
|
private void handleIntent(Intent intent) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "handleIntent()");
|
2016-07-30 16:48:43 +02:00
|
|
|
if (intent == null) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Intent was null");
|
2016-07-30 16:48:43 +02:00
|
|
|
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;
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Action: " + action + " Type: " + type);
|
2016-10-01 01:30:58 +02:00
|
|
|
if (Intent.ACTION_MAIN.equals(action)) {
|
|
|
|
loadUrl = urls.getStreamUrl();
|
|
|
|
} else if (ACTION_OPEN_URL.equals(action)) {
|
2016-07-30 16:48:43 +02:00
|
|
|
loadUrl = intent.getStringExtra(URL_MESSAGE);
|
|
|
|
} else if (Intent.ACTION_VIEW.equals(action) && intent.getDataString() != null) {
|
2016-08-27 00:04:07 +02:00
|
|
|
Uri data = intent.getData();
|
2016-09-19 01:10:29 +02:00
|
|
|
if (data != null && data.toString().startsWith(CONTENT_HASHTAG)) {
|
2016-08-27 00:04:07 +02:00
|
|
|
handleHashtag(intent);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
loadUrl = intent.getDataString();
|
2016-10-14 01:26:56 +02:00
|
|
|
AppLog.v(this, "Intent has a delicious URL for us: " + loadUrl);
|
2016-08-27 00:04:07 +02:00
|
|
|
}
|
2016-07-30 16:48:43 +02:00
|
|
|
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
|
2016-10-01 01:18:42 +02:00
|
|
|
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
|
2016-10-07 02:43:12 +02:00
|
|
|
appSettings.setPod(null);
|
2016-10-25 17:37:22 +02:00
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2016-12-16 05:24:03 +01:00
|
|
|
navheaderTitle.setText(R.string.app_name);
|
|
|
|
navheaderDescription.setText(R.string.app_subtitle);
|
|
|
|
navheaderImage.setImageResource(R.drawable.ic_launcher);
|
2016-10-25 17:37:22 +02:00
|
|
|
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
|
|
|
|
}
|
|
|
|
});
|
2016-10-01 01:18:42 +02:00
|
|
|
showFragment(getFragment(PodSelectionFragment.TAG));
|
2016-07-30 16:48:43 +02:00
|
|
|
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Clear WebView cache");
|
2016-10-25 17:37:22 +02:00
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
2016-10-26 21:53:27 +02:00
|
|
|
ContextMenuWebView wv = ((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView();
|
2016-11-04 03:08:59 +01:00
|
|
|
if (wv != null) {
|
2016-10-26 21:53:27 +02:00
|
|
|
wv.clearCache(true);
|
|
|
|
}
|
2016-10-25 17:37:22 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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) {
|
2016-10-02 22:22:08 +02:00
|
|
|
/* TODO: Implement and add filter to manifest */
|
|
|
|
return;
|
2016-07-26 22:47:11 +02:00
|
|
|
}
|
2016-10-31 22:24:26 +01:00
|
|
|
//Catch split screen recreation
|
2016-11-06 16:23:18 +01:00
|
|
|
if (action != null && action.equals(Intent.ACTION_MAIN) && getTopFragment() != null) {
|
2016-10-31 22:24:26 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-07-30 16:48:43 +02:00
|
|
|
|
|
|
|
if (loadUrl != null) {
|
|
|
|
navDrawer.closeDrawers();
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Handle activity results
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param requestCode reqCode
|
2016-10-14 01:26:56 +02:00
|
|
|
* @param resultCode resCode
|
|
|
|
* @param data data
|
2016-10-02 22:22:08 +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) {
|
2016-10-14 01:26:56 +02:00
|
|
|
AppLog.v(this, "onActivityResult(): " + requestCode);
|
2016-09-07 23:55:25 +02:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Return the fragment which is currently displayed in R.id.fragment_container
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @return top fragment or null if there is none displayed
|
|
|
|
*/
|
2016-09-28 21:43:25 +02:00
|
|
|
private CustomFragment getTopFragment() {
|
2016-10-27 21:42:41 +02:00
|
|
|
return (CustomFragment) fm.findFragmentById(R.id.fragment_container);
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Handle presses on the back button
|
|
|
|
*/
|
2016-03-03 17:46:31 +01:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "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-09-28 21:43:25 +02:00
|
|
|
CustomFragment top = getTopFragment();
|
2016-10-14 01:26:56 +02:00
|
|
|
if (top != null) {
|
2016-09-22 23:40:35 +02:00
|
|
|
AppLog.v(this, "Top Fragment is not null");
|
2016-10-14 01:26:56 +02:00
|
|
|
if (!top.onBackPressed()) {
|
2016-09-22 23:40:35 +02:00
|
|
|
AppLog.v(this, "Top Fragment.onBackPressed was false");
|
2016-10-14 01:26:56 +02:00
|
|
|
AppLog.v(this, "BackStackEntryCount: " + fm.getBackStackEntryCount());
|
|
|
|
if (fm.getBackStackEntryCount() > 0) {
|
2016-09-28 21:43:25 +02:00
|
|
|
fm.popBackStack();
|
|
|
|
} else {
|
|
|
|
snackbarExitApp.show();
|
|
|
|
}
|
2016-09-21 21:15:34 +02:00
|
|
|
return;
|
|
|
|
} else {
|
2016-09-22 23:40:35 +02:00
|
|
|
AppLog.v(this, "Top Fragment.onBackPressed was true");
|
2016-09-21 21:15:34 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-07 11:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!snackbarExitApp.isShown()) {
|
|
|
|
snackbarExitApp.show();
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 12:35:16 +02:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
customTabActivityHelper.bindCustomTabsService(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
customTabActivityHelper.unbindCustomTabsService(this);
|
|
|
|
}
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onPause()");
|
|
|
|
AppLog.v(this, "Unregister BroadcastReceivers");
|
2016-08-01 01:14:44 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(brSetTitle);
|
2016-09-11 12:35:16 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(brOpenExternalLink);
|
2016-03-03 17:46:31 +01:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2016-09-10 16:54:48 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onResume()");
|
2016-09-10 16:54:48 +02:00
|
|
|
super.onResume();
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Register BroadcastReceivers");
|
2016-09-10 16:54:48 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
|
2016-09-11 12:35:16 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(brOpenExternalLink, new IntentFilter(ACTION_OPEN_EXTERNAL_URL));
|
2016-10-14 12:57:17 +02:00
|
|
|
invalidateOptionsMenu();
|
2016-10-13 16:56:31 +02:00
|
|
|
this.appSettings = getAppSettings();
|
2016-11-04 03:08:59 +01:00
|
|
|
if (appSettings.isIntellihideToolbars()) {
|
2016-10-28 12:51:45 +02:00
|
|
|
enableToolbarHiding();
|
|
|
|
} else {
|
|
|
|
disableToolbarHiding();
|
|
|
|
}
|
2016-10-13 16:56:31 +02:00
|
|
|
updateNavigationViewEntryVisibilities();
|
2016-09-10 16:54:48 +02:00
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Clear and repopulate top and bottom toolbar.
|
|
|
|
* Also add menu items of the displayed fragment
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param menu top toolbar
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2016-03-03 17:46:31 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onCreateOptionsMenu()");
|
2016-10-01 01:18:42 +02:00
|
|
|
//Clear the menus
|
2016-09-29 19:44:42 +02:00
|
|
|
menu.clear();
|
|
|
|
toolbarBottom.getMenu().clear();
|
2016-10-01 01:18:42 +02:00
|
|
|
toolbarBottom.setVisibility(View.VISIBLE);
|
|
|
|
|
2016-09-29 19:44:42 +02:00
|
|
|
CustomFragment top = getTopFragment();
|
2016-10-14 01:26:56 +02:00
|
|
|
if (top != null) {
|
2016-10-14 12:57:17 +02:00
|
|
|
//PodSelectionFragment?
|
|
|
|
if (top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
|
|
|
|
///Hide bottom toolbar
|
|
|
|
toolbarBottom.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
getMenuInflater().inflate(appSettings.isExtendedNotificationsActivated() ?
|
|
|
|
R.menu.main__menu_top__notifications_dropdown : R.menu.main__menu_top, menu);
|
2016-10-01 01:18:42 +02:00
|
|
|
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
|
|
|
top.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
|
|
|
|
}
|
2016-09-29 19:44:42 +02:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Set the notification and messages counter in the top toolbar
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param menu menu
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2016-03-03 17:46:31 +01:00
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2016-09-11 17:15:26 +02:00
|
|
|
MenuItem item;
|
2016-10-14 00:44:23 +02:00
|
|
|
updateNavigationViewEntryVisibilities();
|
2016-10-07 04:29:32 +02:00
|
|
|
|
2016-09-11 17:15:26 +02:00
|
|
|
if ((item = menu.findItem(R.id.action_notifications)) != null) {
|
|
|
|
LayerDrawable icon = (LayerDrawable) item.getIcon();
|
2016-10-26 16:23:14 +02:00
|
|
|
BadgeDrawable.setBadgeCount(this, icon, diasporaUserProfile.getNotificationCount());
|
2016-09-11 17:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((item = menu.findItem(R.id.action_conversations)) != null) {
|
|
|
|
LayerDrawable icon = (LayerDrawable) item.getIcon();
|
2016-10-26 16:23:14 +02:00
|
|
|
BadgeDrawable.setBadgeCount(this, icon, diasporaUserProfile.getUnreadMessagesCount());
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
return super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Handle clicks on the optionsmenu
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param item item
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2016-03-03 17:46:31 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onOptionsItemSelected()");
|
2016-03-20 22:49:11 +01:00
|
|
|
switch (item.getItemId()) {
|
2016-10-14 12:57:17 +02:00
|
|
|
case R.id.action_notifications: {
|
2016-10-26 16:23:14 +02:00
|
|
|
if (appSettings.isExtendedNotificationsActivated()) {
|
2016-10-14 12:57:17 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//Otherwise we execute the action of action_notifications_all
|
|
|
|
}
|
2016-10-14 01:44:43 +02:00
|
|
|
case R.id.action_notifications_all: {
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-10-14 01:44:43 +02:00
|
|
|
|
|
|
|
case R.id.action_notifications_also_commented: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
openDiasporaUrl(urls.getSuburlNotificationsAlsoCommentedUrl());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_notifications_comment_on_post: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
openDiasporaUrl(urls.getSuburlNotificationsCommentOnPostUrl());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_notifications_liked: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
openDiasporaUrl(urls.getSuburlNotificationsLikedUrl());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_notifications_mentioned: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
openDiasporaUrl(urls.getSuburlNotificationsMentionedUrl());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_notifications_reshared: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
openDiasporaUrl(urls.getSuburlNotificationsResharedUrl());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case R.id.action_notifications_started_sharing: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
|
|
|
openDiasporaUrl(urls.getSuburlNotificationsStartedSharingUrl());
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(urls.getConversationsUrl());
|
2016-08-07 23:11:47 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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_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);
|
2016-08-27 12:34:08 +02:00
|
|
|
|
2016-11-08 20:41:53 +01:00
|
|
|
@SuppressLint("InflateParams") View layout = getLayoutInflater().inflate(R.layout.ui__dialog_search__people_tags, null, false);
|
2016-08-27 12:34:08 +02:00
|
|
|
final EditText input = (EditText) layout.findViewById(R.id.dialog_search__input);
|
2016-12-24 15:33:52 +01:00
|
|
|
input.setMaxLines(1);
|
|
|
|
input.setSingleLine(true);
|
2016-11-08 16:21:06 +01:00
|
|
|
ThemeHelper.updateEditTextColor(input);
|
2016-08-27 12:34:08 +02:00
|
|
|
final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int which) {
|
|
|
|
String query = input.getText().toString().trim().replaceAll((which == DialogInterface.BUTTON_NEGATIVE ? "\\*" : "\\#"), "");
|
2016-09-19 01:10:29 +02:00
|
|
|
if (query.equals("")) {
|
2016-09-21 21:15:34 +02:00
|
|
|
Snackbar.make(fragmentContainer, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
|
2016-08-27 12:34:08 +02:00
|
|
|
} else {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(which == DialogInterface.BUTTON_NEGATIVE ? urls.getSearchPeopleUrl(query) : urls.getSearchTagsUrl(query));
|
2016-06-04 19:44:38 +02:00
|
|
|
}
|
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
|
|
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-06 16:23:18 +01:00
|
|
|
final AlertDialog dialog = new ThemedAlertDialogBuilder(this, appSettings)
|
2016-08-27 12:34:08 +02:00
|
|
|
.setView(layout).setTitle(R.string.search_alert_title)
|
2016-06-04 19:44:38 +02:00
|
|
|
.setCancelable(true)
|
2016-08-27 12:34:08 +02:00
|
|
|
.setPositiveButton(R.string.search_alert_tag, clickListener)
|
|
|
|
.setNegativeButton(R.string.search_alert_people, clickListener)
|
2016-06-04 19:44:38 +02:00
|
|
|
.create();
|
|
|
|
|
|
|
|
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
dialog.hide();
|
2016-08-27 12:34:08 +02:00
|
|
|
clickListener.onClick(null, 0);
|
2016-06-04 19:44:38 +02:00
|
|
|
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-03-25 00:12:00 +01:00
|
|
|
@Override
|
2016-10-26 16:23:14 +02:00
|
|
|
public void onUserProfileNameChanged(DiasporaUserProfile diasporaUserProfile, String name) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onUserProfileNameChanged()");
|
2016-10-26 16:23:14 +02:00
|
|
|
// Update the profile name in the navigation slider
|
2016-03-25 00:12:00 +01:00
|
|
|
navheaderTitle.setText(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-26 16:23:14 +02:00
|
|
|
public void onUserProfileAvatarChanged(DiasporaUserProfile diasporaUserProfile, String avatarUrl) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onUserProfileAvatarChanged()");
|
2016-10-26 16:23:14 +02:00
|
|
|
// Update the profile picture in the navigation slider
|
2016-03-25 00:12:00 +01:00
|
|
|
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Handle hashtag clicks. Open the new-post-url and inject the clicked hashtag into the post-editor
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param intent intent
|
|
|
|
*/
|
2016-08-27 00:04:07 +02:00
|
|
|
private void handleHashtag(Intent intent) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "handleHashtag()");
|
2016-09-10 16:54:48 +02:00
|
|
|
try {
|
|
|
|
setSharedTexts(null, intent.getData().toString().split("/")[3]);
|
|
|
|
} catch (Exception e) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.e(this, e.toString());
|
2016-09-10 16:54:48 +02:00
|
|
|
}
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(urls.getNewPostUrl());
|
2016-08-27 00:04:07 +02:00
|
|
|
}
|
2016-08-08 08:24:58 +02:00
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Open the new-post-url and inject text that was shared into the app into the post editors text field
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param intent shareTextIntent
|
|
|
|
*/
|
2016-08-27 00:04:07 +02:00
|
|
|
private void handleSendText(Intent intent) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "handleSendText()");
|
2016-09-10 16:54:48 +02:00
|
|
|
try {
|
|
|
|
setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT));
|
2016-09-22 23:20:13 +02:00
|
|
|
openDiasporaUrl(urls.getNewPostUrl());
|
2016-09-10 16:54:48 +02:00
|
|
|
} catch (Exception e) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.e(this, e.toString());
|
2016-09-10 16:54:48 +02:00
|
|
|
}
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle sent text + subject
|
2016-08-13 14:13:14 +02:00
|
|
|
*
|
2016-08-23 21:23:36 +02:00
|
|
|
* @param intent intent
|
2016-08-02 23:58:36 +02:00
|
|
|
*/
|
2016-08-23 21:23:36 +02:00
|
|
|
private void handleSendSubject(Intent intent) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "handleSendSubject()");
|
2016-09-10 16:54:48 +02:00
|
|
|
try {
|
|
|
|
setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT));
|
2016-09-22 23:20:13 +02:00
|
|
|
openDiasporaUrl(urls.getNewPostUrl());
|
2016-09-10 16:54:48 +02:00
|
|
|
} catch (Exception e) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.e(this, e.toString());
|
2016-09-10 16:54:48 +02:00
|
|
|
}
|
2016-08-27 00:04:07 +02:00
|
|
|
}
|
2016-08-07 14:29:52 +02:00
|
|
|
|
2016-08-27 00:04:07 +02:00
|
|
|
/**
|
2016-09-21 21:15:34 +02:00
|
|
|
* TODO: MOVE
|
2016-08-27 00:04:07 +02:00
|
|
|
* Set sharedText variable to escaped and formatted subject + body.
|
|
|
|
* If subject is null, only the body will be set. Else the subject will be set as header.
|
|
|
|
* Depending on whether the user has the setting isAppendSharedViaApp set, a reference to
|
|
|
|
* the app will be added at the bottom
|
2016-09-19 01:10:29 +02:00
|
|
|
*
|
2016-08-27 00:04:07 +02:00
|
|
|
* @param sharedSubject post subject or null
|
2016-09-19 01:10:29 +02:00
|
|
|
* @param sharedBody post text
|
2016-08-27 00:04:07 +02:00
|
|
|
*/
|
|
|
|
private void setSharedTexts(String sharedSubject, String sharedBody) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "setSharedTexts()");
|
2016-08-27 00:04:07 +02:00
|
|
|
String body = WebHelper.replaceUrlWithMarkdown(sharedBody);
|
2016-08-02 23:58:36 +02:00
|
|
|
if (appSettings.isAppendSharedViaApp()) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Append app reference to shared text");
|
2016-11-20 16:43:38 +01:00
|
|
|
body = body + "\n\n" + getString(R.string.shared_via_app);
|
2016-08-27 00:04:07 +02:00
|
|
|
}
|
|
|
|
final String escapedBody = WebHelper.escapeHtmlText(body);
|
2016-09-19 01:10:29 +02:00
|
|
|
if (sharedSubject != null) {
|
|
|
|
AppLog.v(this, "Append subject to shared text");
|
2016-08-27 00:04:07 +02:00
|
|
|
String escapedSubject = WebHelper.escapeHtmlText(WebHelper.replaceUrlWithMarkdown(sharedSubject));
|
2016-09-22 23:20:13 +02:00
|
|
|
AppLog.v(this, "Set shared text; Subject: \"" + escapedSubject + "\" Body: \"" + escapedBody + "\"");
|
|
|
|
textToBeShared = "**" + escapedSubject + "** " + escapedBody;
|
2016-08-27 00:04:07 +02:00
|
|
|
} else {
|
2016-11-08 20:41:53 +01:00
|
|
|
AppLog.v(this, "Set shared text; Subject: \"null\" Body: \"" + sharedBody + "\"");
|
2016-09-22 23:20:13 +02:00
|
|
|
textToBeShared = escapedBody;
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Share an image shared to the app via diaspora
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param intent shareImageIntent
|
|
|
|
*/
|
2016-10-02 13:36:57 +02:00
|
|
|
//TODO: Implement some day
|
2016-08-02 23:58:36 +02:00
|
|
|
private void handleSendImage(Intent intent) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "handleSendImage()");
|
2016-08-23 21:23:36 +02:00
|
|
|
final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
2016-08-02 23:58:36 +02:00
|
|
|
if (imageUri != null) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "imageUri is not null. Handle shared image");
|
2016-09-10 16:54:48 +02:00
|
|
|
} else {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.w(this, "imageUri is null. Cannot precede.");
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
|
|
|
Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
@Override
|
2016-10-26 16:23:14 +02:00
|
|
|
public void onNotificationCountChanged(DiasporaUserProfile diasporaUserProfile, int notificationCount) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onNotificationCountChanged()");
|
2016-10-26 16:23:14 +02:00
|
|
|
// Count saved in DiasporaUserProfile
|
|
|
|
// Invalidate the top toolbar to update the unread messages counter
|
2016-08-07 11:39:20 +02:00
|
|
|
invalidateOptionsMenu();
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-10-26 16:23:14 +02:00
|
|
|
|
2016-03-25 00:12:00 +01:00
|
|
|
@Override
|
2016-10-26 16:23:14 +02:00
|
|
|
public void onUnreadMessageCountChanged(DiasporaUserProfile diasporaUserProfile, int unreadMessageCount) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onUnreadMessageCountChanged()");
|
2016-10-26 16:23:14 +02:00
|
|
|
// Count saved in DiasporaUserProfile
|
|
|
|
// Invalidate the top toolbar to update the unread messages counter
|
2016-08-07 11:39:20 +02:00
|
|
|
invalidateOptionsMenu();
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-09-21 22:49:37 +02:00
|
|
|
@Override
|
|
|
|
public void onCustomTabsConnected() {
|
2016-10-14 01:26:56 +02:00
|
|
|
if (customTabsSession == null) {
|
|
|
|
AppLog.i(this, "CustomTabs warmup: " + customTabActivityHelper.warmup(0));
|
2016-09-21 22:49:37 +02:00
|
|
|
customTabsSession = customTabActivityHelper.getSession();
|
|
|
|
}
|
|
|
|
}
|
2016-10-22 19:21:26 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPodSelectionDialogResult(DiasporaPodList.DiasporaPod pod, boolean accepted) {
|
2016-10-26 16:23:14 +02:00
|
|
|
if (accepted) {
|
2016-10-22 19:21:26 +02:00
|
|
|
invalidateOptionsMenu();
|
|
|
|
navheaderDescription.setText(pod.getName());
|
|
|
|
}
|
|
|
|
}
|
2016-09-21 22:49:37 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCustomTabsDisconnected() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
@SuppressWarnings("StatementWithEmptyBody")
|
|
|
|
@Override
|
|
|
|
public boolean onNavigationItemSelected(MenuItem item) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onNavigationItemsSelected()");
|
2016-03-03 17:46:31 +01:00
|
|
|
// 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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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: {
|
2016-12-16 05:24:03 +01:00
|
|
|
if (!appSettings.getProfileId().equals("")) {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(urls.getProfileUrl());
|
2016-08-10 17:47:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_followed_tags: {
|
2016-10-26 16:23:14 +02:00
|
|
|
showFragment(getFragment(TagListFragment.TAG));
|
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-10-26 14:33:05 +02:00
|
|
|
showFragment(getFragment(AspectListFragment.TAG));
|
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-10-25 17:56:35 +02:00
|
|
|
case R.id.nav_contacts: {
|
2016-10-26 16:23:14 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-10-25 17:56:35 +02:00
|
|
|
openDiasporaUrl(urls.getManageContactsUrl());
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-03-03 17:46:31 +01:00
|
|
|
}
|
2016-11-06 20:36:43 +01: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-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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
|
|
|
}
|
2016-11-06 20:36:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case R.id.nav_reports: {
|
2016-12-16 05:24:03 +01:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-11-06 20:36:43 +01:00
|
|
|
openDiasporaUrl(urls.getReportsUrl());
|
|
|
|
} else {
|
|
|
|
snackbarNoInternet.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-08-07 02:28:37 +02:00
|
|
|
|
2016-12-20 12:19:43 +01:00
|
|
|
case R.id.nav_toggle_desktop_page: {
|
|
|
|
openDiasporaUrl(urls.getToggleMobileUrl());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-08-07 02:28:37 +02:00
|
|
|
case R.id.nav_exit: {
|
|
|
|
moveTaskToBack(true);
|
|
|
|
finish();
|
2016-03-20 22:49:11 +01:00
|
|
|
}
|
2016-11-06 20:36:43 +01:00
|
|
|
break;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-08-28 17:54:35 +02:00
|
|
|
case R.id.nav_settings: {
|
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-09-28 21:43:25 +02:00
|
|
|
case R.id.nav_about: {
|
2016-08-26 17:08:57 +02:00
|
|
|
startActivity(new Intent(MainActivity.this, AboutActivity.class));
|
2016-03-08 15:42:02 +01:00
|
|
|
}
|
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-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* React to results of requestPermission
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
|
|
|
* @param requestCode resCode
|
|
|
|
* @param permissions requested permissions
|
2016-10-02 22:22:08 +02:00
|
|
|
* @param grantResults granted results
|
|
|
|
*/
|
2016-04-08 21:59:46 +02:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
switch (requestCode) {
|
2016-09-10 16:54:48 +02:00
|
|
|
case REQUEST_CODE__ACCESS_EXTERNAL_STORAGE:
|
2016-04-08 21:59:46 +02:00
|
|
|
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onRequestPermissionsResult: Permission to access external storage granted");
|
2016-04-08 21:59:46 +02:00
|
|
|
Toast.makeText(this, R.string.permission_granted_try_again, Toast.LENGTH_SHORT).show();
|
2016-04-09 13:53:06 +02:00
|
|
|
} else {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.w(this, "onRequestPermissionsResult: Permission to access external storage denied");
|
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-09-22 23:20:13 +02:00
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Return the string that will be shared into the new-post-editor
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-10-02 22:22:08 +02:00
|
|
|
* @return String
|
|
|
|
*/
|
2016-09-22 23:20:13 +02:00
|
|
|
public String getTextToBeShared() {
|
|
|
|
return textToBeShared;
|
|
|
|
}
|
|
|
|
|
2016-10-02 22:22:08 +02:00
|
|
|
/**
|
|
|
|
* Set the string that will be shared into the new-post-editor
|
2016-10-14 01:26:56 +02:00
|
|
|
*
|
2016-11-08 20:41:53 +01:00
|
|
|
* @param textToBeShared text that will be shared into the post-editor
|
2016-10-02 22:22:08 +02:00
|
|
|
*/
|
2016-09-22 23:20:13 +02:00
|
|
|
public void setTextToBeShared(String textToBeShared) {
|
|
|
|
this.textToBeShared = textToBeShared;
|
|
|
|
}
|
2016-10-13 16:56:31 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void applyColorToViews() {
|
|
|
|
ThemeHelper.updateToolbarColor(toolbarTop);
|
|
|
|
ThemeHelper.updateActionMenuViewColor(toolbarBottom);
|
|
|
|
navDrawerLayout.setBackgroundColor(appSettings.getPrimaryColor());
|
|
|
|
navProfilePictureArea.setBackgroundColor(appSettings.getPrimaryColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void enableToolbarHiding() {
|
|
|
|
AppLog.d(this, "Enable Intellihide");
|
|
|
|
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
|
|
|
|
//scroll|enterAlways|snap
|
|
|
|
params.setScrollFlags(toolbarDefaultScrollFlags);
|
|
|
|
appBarLayout.setExpanded(true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disableToolbarHiding() {
|
|
|
|
AppLog.d(this, "Disable Intellihide");
|
|
|
|
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
|
|
|
|
params.setScrollFlags(0); // clear all scroll flags
|
|
|
|
appBarLayout.setExpanded(true, true);
|
|
|
|
}
|
2016-12-22 13:23:20 +01:00
|
|
|
}
|