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.Fragment;
|
|
|
|
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;
|
|
|
|
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-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-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-10-07 02:43:12 +02:00
|
|
|
import com.github.dfa.diaspora_android.data.DiasporaPodList;
|
2016-06-04 03:48:57 +02:00
|
|
|
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
2016-09-28 21:43:25 +02:00
|
|
|
import com.github.dfa.diaspora_android.fragment.BrowserFragment;
|
2016-09-21 21:15:34 +02:00
|
|
|
import com.github.dfa.diaspora_android.fragment.CustomFragment;
|
2016-09-28 21:43:25 +02:00
|
|
|
import com.github.dfa.diaspora_android.fragment.DiasporaStreamFragment;
|
2016-09-30 23:15:10 +02:00
|
|
|
import com.github.dfa.diaspora_android.fragment.HashtagListFragment;
|
2016-10-01 01:18:42 +02:00
|
|
|
import com.github.dfa.diaspora_android.fragment.PodSelectionFragment;
|
2016-03-29 19:38:50 +02:00
|
|
|
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
|
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-09-19 01:10:29 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.AppLog;
|
2016-09-11 12:35:16 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
|
2016-08-10 17:14:05 +02:00
|
|
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
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-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-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity
|
2016-09-21 22:49:37 +02:00
|
|
|
implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener, CustomTabActivityHelper.ConnectionCallback {
|
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-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-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-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-09-11 14:51:23 +02:00
|
|
|
private OpenExternalLinkReceiver brOpenExternalLink;
|
2016-09-11 15:22:16 +02:00
|
|
|
private BroadcastReceiver brSetTitle;
|
2016-06-16 22:55:06 +02:00
|
|
|
private Snackbar snackbarExitApp;
|
2016-06-24 13:31:01 +02:00
|
|
|
private Snackbar snackbarNoInternet;
|
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-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-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-09-19 01:10:29 +02:00
|
|
|
if ((app = (App) getApplication()) == null) AppLog.e(this, "App is null!");
|
|
|
|
if ((appSettings = app.getSettings()) == null) AppLog.e(this, "AppSettings is null!");
|
|
|
|
if ((podUserProfile = app.getPodUserProfile()) == null)
|
|
|
|
AppLog.e(this, "PodUserProfile is null!");
|
2016-06-05 17:25:11 +02:00
|
|
|
podUserProfile.setCallbackHandler(uiHandler);
|
|
|
|
podUserProfile.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-03-03 17:46:31 +01:00
|
|
|
|
2016-09-21 21:35:03 +02:00
|
|
|
fm = getSupportFragmentManager();
|
2016-09-11 13:05:26 +02:00
|
|
|
setupUI(savedInstanceState);
|
|
|
|
|
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() {
|
|
|
|
@Override
|
|
|
|
public void setTitle(int rId) {
|
|
|
|
MainActivity.this.setTitle(rId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTitle(String title) {
|
|
|
|
MainActivity.this.setTitle(title);
|
|
|
|
}
|
|
|
|
});
|
2016-10-01 01:18:42 +02:00
|
|
|
|
2016-10-07 02:43:12 +02:00
|
|
|
if(!appSettings.hasPod()) {
|
2016-10-01 01:30:58 +02:00
|
|
|
AppLog.d(this, "We have no pod. Show PodSelectionFragment");
|
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-09-05 20:42:57 +02:00
|
|
|
private void setupUI(Bundle savedInstanceState) {
|
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);
|
|
|
|
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() {
|
|
|
|
@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-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-03-03 17:46:31 +01:00
|
|
|
|
2016-07-31 15:16:22 +02:00
|
|
|
if (!appSettings.isIntellihideToolbars()) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Disable intelligent hiding of toolbars");
|
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-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
|
|
|
/**
|
|
|
|
* Show DiasporaStreamFragment if necessary and load URL url
|
|
|
|
* @param url URL to load in the DiasporaStreamFragment
|
|
|
|
*/
|
2016-09-30 23:15:10 +02:00
|
|
|
public void openDiasporaUrl(String url) {
|
2016-09-22 23:40:35 +02:00
|
|
|
AppLog.v(this, "openDiasporaUrl()");
|
2016-09-28 21:43:25 +02:00
|
|
|
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
|
|
|
|
showFragment(streamFragment);
|
2016-09-21 21:15:34 +02:00
|
|
|
streamFragment.loadUrl(url);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* If there is no Fragment with the corresponding Tag, return null.
|
|
|
|
* @param fragmentTag tag
|
|
|
|
* @return corresponding Fragment
|
|
|
|
*/
|
|
|
|
protected CustomFragment getFragment(String fragmentTag) {
|
|
|
|
CustomFragment fragment = (CustomFragment) fm.findFragmentByTag(fragmentTag);
|
|
|
|
if(fragment != null) {
|
|
|
|
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-09-30 23:15:10 +02:00
|
|
|
case HashtagListFragment.TAG:
|
|
|
|
HashtagListFragment hlf = new HashtagListFragment();
|
|
|
|
fm.beginTransaction().add(hlf, fragmentTag).commit();
|
|
|
|
return hlf;
|
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:
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the Fragment fragment in R.id.fragment_container. If the fragment was already visible, do nothing.
|
|
|
|
* @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);
|
|
|
|
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-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-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);
|
2016-09-21 21:15:34 +02:00
|
|
|
//Handle clicks on profile picture
|
2016-08-10 17:28:54 +02:00
|
|
|
navheaderProfileSection.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
navDrawer.closeDrawer(GravityCompat.START);
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-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-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());
|
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-07 02:43:12 +02:00
|
|
|
// Hide all pod related options if no pod is selected
|
|
|
|
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), appSettings.getPod() != null);
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-09-21 21:15:34 +02:00
|
|
|
@OnClick(R.id.main__topbar)
|
2016-06-04 17:10:24 +02:00
|
|
|
public void onToolBarClicked(View view) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onToolBarClicked()");
|
2016-06-04 21:46:54 +02:00
|
|
|
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
|
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-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-09-22 23:40:35 +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-09-28 21:43:25 +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-09-28 21:43:25 +02:00
|
|
|
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true);
|
2016-08-07 02:28:37 +02:00
|
|
|
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Recreate activity");
|
2016-08-07 02:28:37 +02:00
|
|
|
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) {
|
|
|
|
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
|
|
|
|
|
|
|
@Override
|
2016-03-20 22:49:11 +01:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2016-09-29 19:44:42 +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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onSaveInstanceState()");
|
2016-03-03 17:46:31 +01:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "onRestoreInstanceState()");
|
2016-03-03 17:46:31 +01:00
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
2016-09-21 21:15:34 +02:00
|
|
|
}
|
|
|
|
|
2016-09-28 21:43:25 +02:00
|
|
|
private CustomFragment getTopFragment() {
|
|
|
|
Fragment top = fm.findFragmentById(R.id.fragment_container);
|
|
|
|
if(top != null) {
|
|
|
|
return (CustomFragment) top;
|
2016-09-21 21:15:34 +02:00
|
|
|
}
|
|
|
|
return null;
|
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-09-21 21:15:34 +02:00
|
|
|
if(top != null) {
|
2016-09-22 23:40:35 +02:00
|
|
|
AppLog.v(this, "Top Fragment is not null");
|
2016-09-21 21:15:34 +02:00
|
|
|
if(!top.onBackPressed()) {
|
2016-09-22 23:40:35 +02:00
|
|
|
AppLog.v(this, "Top Fragment.onBackPressed was false");
|
2016-09-29 19:44:42 +02:00
|
|
|
AppLog.v(this, "BackStackEntryCount: "+fm.getBackStackEntryCount());
|
2016-09-28 21:43:25 +02:00
|
|
|
if(fm.getBackStackEntryCount()>0) {
|
|
|
|
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-09-10 16:54:48 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
if(top != null) {
|
2016-10-01 01:18:42 +02:00
|
|
|
//Are we displaying a Fragment other than PodSelectionFragment?
|
|
|
|
if(!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
|
|
|
|
getMenuInflater().inflate(R.menu.main__menu_top, menu);
|
|
|
|
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
|
|
|
|
top.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
|
|
|
|
}
|
|
|
|
//PodSelectionFragment
|
|
|
|
else {
|
|
|
|
//Hide bottom toolbar
|
|
|
|
toolbarBottom.setVisibility(View.GONE);
|
|
|
|
}
|
2016-09-29 19:44:42 +02:00
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2016-09-11 17:15:26 +02:00
|
|
|
MenuItem item;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-09-11 17:15:26 +02:00
|
|
|
if ((item = menu.findItem(R.id.action_notifications)) != null) {
|
|
|
|
LayerDrawable icon = (LayerDrawable) item.getIcon();
|
|
|
|
BadgeDrawable.setBadgeCount(this, icon, podUserProfile.getNotificationCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((item = menu.findItem(R.id.action_conversations)) != null) {
|
|
|
|
LayerDrawable icon = (LayerDrawable) item.getIcon();
|
|
|
|
BadgeDrawable.setBadgeCount(this, icon, podUserProfile.getUnreadMessagesCount());
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|
|
|
|
return super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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()) {
|
|
|
|
case R.id.action_notifications: {
|
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-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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-21 12:36:42 +02:00
|
|
|
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);
|
|
|
|
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-08-27 12:34:08 +02:00
|
|
|
final android.support.v7.app.AlertDialog dialog = new android.support.v7.app.AlertDialog.Builder(this)
|
|
|
|
.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
|
|
|
|
public void onUserProfileNameChanged(String name) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onUserProfileNameChanged()");
|
2016-03-25 00:12:00 +01:00
|
|
|
navheaderTitle.setText(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUserProfileAvatarChanged(String avatarUrl) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onUserProfileAvatarChanged()");
|
2016-03-25 00:12:00 +01:00
|
|
|
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
|
|
|
|
}
|
|
|
|
|
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-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-08-27 00:04:07 +02:00
|
|
|
body = body + "\n\n" + getString(R.string.shared_by_diaspora_android);
|
|
|
|
}
|
|
|
|
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-09-19 01:10:29 +02:00
|
|
|
AppLog.v(this, "Set shared text; Subject: \"" + sharedSubject + "\" Body: \"" + sharedBody + "\"");
|
2016-09-22 23:20:13 +02:00
|
|
|
textToBeShared = escapedBody;
|
2016-08-02 23:58:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
public void onNotificationCountChanged(int notificationCount) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onNotificationCountChanged()");
|
2016-08-07 11:39:20 +02:00
|
|
|
// Count saved in PodUserProfile
|
|
|
|
invalidateOptionsMenu();
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUnreadMessageCountChanged(int unreadMessageCount) {
|
2016-09-19 01:10:29 +02:00
|
|
|
AppLog.i(this, "onUnreadMessageCountChanged()");
|
2016-08-07 11:39:20 +02:00
|
|
|
// Count saved in PodUserProfile
|
|
|
|
invalidateOptionsMenu();
|
2016-03-25 00:12:00 +01:00
|
|
|
}
|
|
|
|
|
2016-09-21 22:49:37 +02:00
|
|
|
@Override
|
|
|
|
public void onCustomTabsConnected() {
|
|
|
|
if(customTabsSession == null) {
|
|
|
|
AppLog.i(this, "CustomTabs warmup: "+customTabActivityHelper.warmup(0));
|
|
|
|
customTabsSession = customTabActivityHelper.getSession();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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: {
|
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(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-09-30 23:15:10 +02:00
|
|
|
showFragment(getFragment(HashtagListFragment.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-09-21 21:15:34 +02:00
|
|
|
//TODO: Replace with fragment
|
2016-03-20 22:49:11 +01:00
|
|
|
case R.id.nav_aspects: {
|
2016-09-28 21:43:25 +02:00
|
|
|
DiasporaStreamFragment stream = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
|
2016-08-07 14:29:52 +02:00
|
|
|
if (WebHelper.isOnline(MainActivity.this)) {
|
2016-09-21 21:15:34 +02:00
|
|
|
openDiasporaUrl(DiasporaUrlHelper.URL_BLANK);
|
2016-09-28 21:43:25 +02:00
|
|
|
WebHelper.showAspectList(stream.getWebView(), 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-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-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-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
|
|
|
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-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-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
|
|
|
|
|
|
|
public String getTextToBeShared() {
|
|
|
|
return textToBeShared;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTextToBeShared(String textToBeShared) {
|
|
|
|
this.textToBeShared = textToBeShared;
|
|
|
|
}
|
2016-07-29 14:00:28 +02:00
|
|
|
}
|