dandelion/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java

1280 lines
51 KiB
Java
Raw Normal View History

2016-03-03 17:46:31 +01:00
/*
This file is part of the dandelion*.
2016-03-03 17:46:31 +01:00
dandelion* 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.
dandelion* 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
along with the dandelion*.
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;
import android.content.res.ColorStateList;
import android.graphics.Color;
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;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
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.ActionBar;
2016-03-03 17:46:31 +01:00
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
2016-03-03 17:46:31 +01:00
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
2016-03-03 17:46:31 +01:00
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
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;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
import android.widget.RelativeLayout;
2016-03-03 17:46:31 +01:00
import android.widget.TextView;
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.DiasporaAspect;
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;
import com.github.dfa.diaspora_android.receiver.OpenExternalLinkReceiver;
import com.github.dfa.diaspora_android.receiver.UpdateTitleReceiver;
import com.github.dfa.diaspora_android.ui.BadgeDrawable;
import com.github.dfa.diaspora_android.ui.PodSelectionDialog;
import com.github.dfa.diaspora_android.ui.SearchOrCustomTextDialogCreator;
2016-10-26 16:23:14 +02:00
import com.github.dfa.diaspora_android.ui.theme.ThemeHelper;
import com.github.dfa.diaspora_android.ui.theme.ThemedActivity;
import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder;
2018-03-30 00:24:52 +02:00
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
2017-09-11 18:48:58 +02:00
import com.github.dfa.diaspora_android.util.ActivityUtils;
import com.github.dfa.diaspora_android.util.AndroidBug5497Workaround;
import com.github.dfa.diaspora_android.util.AppLog;
2016-10-26 16:23:14 +02:00
import com.github.dfa.diaspora_android.util.AppSettings;
2017-09-11 20:32:40 +02:00
import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
2016-10-26 16:23:14 +02:00
import com.github.dfa.diaspora_android.web.BrowserFragment;
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;
import net.gsantner.opoc.format.markdown.SimpleMarkdownParser;
2017-09-11 18:48:58 +02:00
import java.io.IOException;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
2016-03-03 17:46:31 +01:00
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
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,
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
CustomTabActivityHelper.ConnectionCallback,
IntellihideToolbarActivityListener,
2016-10-26 16:23:14 +02:00
PodSelectionDialog.PodSelectionDialogResultListener {
2016-03-03 17:46:31 +01:00
public static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
public static final int REQUEST_CODE__ACCESS_EXTERNAL_STORAGE = 124;
public static final int INPUT_FILE_REQUEST_CODE_NEW = 1;
public static final int INPUT_FILE_REQUEST_CODE_OLD = 2;
public static final String ACTION_OPEN_URL = "com.github.dfa.diaspora_android.MainActivity.open_url";
public static final String ACTION_OPEN_EXTERNAL_URL = "com.github.dfa.diaspora_android.MainActivity.open_external_url";
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
2016-07-26 22:52:26 +02:00
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
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";
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/";
2016-03-24 13:56:30 +01:00
private App app;
private CustomTabActivityHelper customTabActivityHelper;
2017-09-11 18:48:58 +02:00
private AppSettings _appSettings;
private DiasporaUrlHelper urls;
2016-10-26 16:23:14 +02:00
private DiasporaUserProfile diasporaUserProfile;
private final Handler uiHandler = new Handler();
private OpenExternalLinkReceiver brOpenExternalLink;
private BroadcastReceiver brSetTitle;
private Snackbar snackbarExitApp, snackbarNoInternet, snackbarLastVisitedTimestampInStream;
private FragmentManager fm;
2016-09-21 22:49:37 +02:00
private CustomTabsSession customTabsSession;
/**
* UI Bindings
*/
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
@BindView(R.id.main__appbar)
AppBarLayout appBarLayout;
@BindView(R.id.main__topbar)
Toolbar toolbarTop;
@BindView(R.id.fragment_container)
FrameLayout fragmentContainer;
@BindView(R.id.main__navigaion_view)
2016-06-04 21:46:54 +02:00
NavigationView navView;
@BindView(R.id.main__navdrawer)
2016-06-04 21:46:54 +02:00
DrawerLayout navDrawer;
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
RelativeLayout navDrawerLayout;
LinearLayout navProfilePictureArea;
2016-06-05 01:42:10 +02:00
// NavHeader cannot be bound by Butterknife
private TextView navheaderTitle;
private TextView navheaderDescription;
private ImageView navheaderImage;
private String textToBeShared;
2016-03-03 17:46:31 +01:00
/**
* END UI Bindings
*/
2016-03-03 17:46:31 +01:00
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppLog.v(this, "onCreate()");
2016-03-03 17:46:31 +01:00
2017-09-11 20:32:40 +02:00
// Pre UI
ContextUtils.get().setAppLanguage(AppSettings.get().getLanguage());
2017-09-11 18:48:58 +02:00
if (AppSettings.get().isEditorStatusBarHidden()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
2017-09-11 20:32:40 +02:00
2017-09-11 20:32:40 +02:00
// Bind UI
2016-06-04 11:11:51 +02:00
setContentView(R.layout.main__activity);
ButterKnife.bind(this);
2017-09-11 18:48:58 +02:00
if (AppSettings.get().isEditorStatusBarHidden()) {
AndroidBug5497Workaround.assistActivity(this);
}
app = (App) getApplication();
2017-09-11 18:48:58 +02:00
_appSettings = app.getSettings();
diasporaUserProfile = app.getDiasporaUserProfile();
2016-10-26 16:23:14 +02:00
diasporaUserProfile.setCallbackHandler(uiHandler);
diasporaUserProfile.setListener(this);
2017-09-11 18:48:58 +02:00
urls = new DiasporaUrlHelper(_appSettings);
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
fm = getSupportFragmentManager();
setupUI();
2016-09-11 13:05:26 +02:00
brOpenExternalLink = new OpenExternalLinkReceiver(this);
brSetTitle = new UpdateTitleReceiver(app, urls, new UpdateTitleReceiver.TitleCallback() {
public void setTitle(String url, int resId) {
2018-03-30 00:24:52 +02:00
ThemedFragment top = getTopFragment();
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
MainActivity.this.setTitle(resId);
showLastVisitedTimestampMessageIfNeeded(url);
}
}
public void setTitle(String url, String title) {
2018-03-30 00:24:52 +02:00
ThemedFragment top = getTopFragment();
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
MainActivity.this.setTitle(title);
}
}
});
2017-09-11 18:48:58 +02:00
if (!_appSettings.hasPod()) {
AppLog.d(this, "We have no pod. Show PodSelectionFragment");
updateNavigationViewEntryVisibilities();
showFragment(getFragment(PodSelectionFragment.TAG));
2016-09-28 21:43:25 +02:00
} else {
AppLog.d(this, "Pod found. Handle intents.");
//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
}
// Show first start / update dialog
try {
if (_appSettings.isAppCurrentVersionFirstStart(true)) {
SimpleMarkdownParser smp = SimpleMarkdownParser.get().setDefaultSmpFilter(SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW);
String html = "";
html += smp.parse(getString(R.string.copyright_license_text_official).replace("\n", " \n"), "").getHtml();
html += "<br/><br/><br/><big><big>" + getString(R.string.changelog) + "</big></big><br/>" + smp.parse(getResources().openRawResource(R.raw.changelog), "", SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW, SimpleMarkdownParser.FILTER_CHANGELOG).getHtml();
html += "<br/><br/><br/><big><big>" + getString(R.string.licenses) + "</big></big><br/>" + smp.parse(getResources().openRawResource(R.raw.licenses_3rd_party), "").getHtml();
ActivityUtils _au = new ActivityUtils(this);
_au.showDialogWithHtmlTextView(R.string.licenses, html);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Setup the user interface. Set up both toolbars and initialize the snackbars.
* Initialize the navigation drawer and apply intellihide settings.
*/
private void setupUI() {
AppLog.i(this, "setupUI()");
2017-09-11 20:32:40 +02:00
// Setup _toolbar
setSupportActionBar(toolbarTop);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
2016-06-07 19:13:37 +02:00
setTitle(R.string.app_name);
2016-03-25 18:25:59 +01:00
//Setup snackbar
snackbarExitApp = Snackbar
2018-09-04 19:16:51 +02:00
.make(fragmentContainer, R.string.do_you_want_to_exit, Snackbar.LENGTH_LONG)
.setAction(android.R.string.yes, new View.OnClickListener() {
public void onClick(View view) {
2016-07-31 15:16:22 +02:00
finish();
moveTaskToBack(true);
}
});
snackbarLastVisitedTimestampInStream =
Snackbar.make(fragmentContainer,
2018-09-04 19:16:51 +02:00
R.string.jump_to_last_visited_page_in_stream__appspecific, Snackbar.LENGTH_LONG)
.setAction(android.R.string.yes, new View.OnClickListener() {
public void onClick(View view) {
openDiasporaUrl(urls.getStreamWithTimestampUrl(diasporaUserProfile.getLastVisitedPositionInStream()));
}
});
2018-09-04 19:16:51 +02:00
snackbarNoInternet = Snackbar.make(fragmentContainer, R.string.sorry_need_to_be_connected_to_internet, Snackbar.LENGTH_LONG);
// Load app settings
setupNavigationSlider();
AppLog.v(this, "UI successfully set up");
}
2016-09-28 21:43:25 +02:00
/**
2018-03-30 00:24:52 +02:00
* Get an instance of the ThemedFragment with the tag fragmentTag.
2016-09-28 21:43:25 +02:00
* 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 the top fragment.
*
2016-09-28 21:43:25 +02:00
* @param fragmentTag tag
* @return corresponding Fragment
*/
2018-03-30 00:24:52 +02:00
protected ThemedFragment getFragment(String fragmentTag) {
ThemedFragment fragment = (ThemedFragment) fm.findFragmentByTag(fragmentTag);
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;
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.");
return getTopFragment();
2016-09-28 21:43:25 +02:00
}
}
}
/**
* Show DiasporaStreamFragment if necessary and load URL url
*
* @param url URL to load in the DiasporaStreamFragment
*/
public void openDiasporaUrl(final String url) {
AppLog.v(this, "openDiasporaUrl()");
if (url != null && url.startsWith("http://127.0.0.1")) {
// This URL seems to be called somehow, but it doesn't make sense ;)
toolbarTop.postDelayed(() -> {
Intent i = new Intent(ACTION_OPEN_EXTERNAL_URL);
2018-05-13 12:08:27 +02:00
i.putExtra(EXTRA_URL, "https://github.com/gsantner/dandelion/blob/master/README.md");
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
}, 1000);
return;
}
if (_appSettings.getPod() != null && _appSettings.getPod().getPodUrl() != null && _appSettings.getPod().getPodUrl().getBaseUrl() != null
&& url.startsWith(_appSettings.getPod().getPodUrl().getBaseUrl()) && !url.startsWith("https://dia.so/")) {
DiasporaStreamFragment streamFragment = (DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG);
showFragment(streamFragment);
showLastVisitedTimestampMessageIfNeeded(url);
streamFragment.loadUrl(url);
} else {
toolbarTop.postDelayed(() -> {
Intent i = new Intent(ACTION_OPEN_EXTERNAL_URL);
i.putExtra(EXTRA_URL, url);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(i);
}, 1000);
}
}
2016-12-18 15:07:23 +01:00
public void showLastVisitedTimestampMessageIfNeeded(String url) {
if (url.equals(urls.getStreamUrl()) && diasporaUserProfile.hasLastVisitedTimestampInStream()) {
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-09-28 21:43:25 +02:00
* @param fragment Fragment to show
*/
2018-03-30 00:24:52 +02:00
protected void showFragment(ThemedFragment fragment) {
if (PodSelectionFragment.TAG.equals(fragment.getTag())) {
Fragment fragment1 = fm.findFragmentByTag(DiasporaStreamFragment.TAG);
if (fragment1 != null) {
new net.gsantner.opoc.util.ContextUtils(this).restartApp(MainActivity.class);
}
}
2016-09-29 19:44:42 +02:00
AppLog.v(this, "showFragment()");
2018-03-30 00:24:52 +02:00
ThemedFragment currentTop = (ThemedFragment) 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();
2017-10-29 17:26:13 +01:00
setToolbarIntellihide(_appSettings.isIntellihideToolbars() && fragment.isAllowedIntellihide());
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.");
}
}
/**
* Initialize the navigation slider
*/
private void setupNavigationSlider() {
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
2018-09-04 19:16:51 +02:00
this, navDrawer, toolbarTop, R.string.open_navdrawer, R.string.close_navdrawer);
2016-06-04 21:46:54 +02:00
navDrawer.addDrawerListener(toggle);
toggle.syncState();
2016-06-04 21:46:54 +02:00
//NavigationView navView = ButterKnife.findById(this, R.id.nav_view);
navView.setNavigationItemSelectedListener(this);
2016-06-04 21:46:54 +02:00
View navHeader = navView.getHeaderView(0);
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
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);
//Handle clicks on profile picture
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
navDrawer.closeDrawer(GravityCompat.START);
2017-09-11 18:48:58 +02:00
if (!_appSettings.getProfileId().equals("")) {
openDiasporaUrl(urls.getProfileUrl());
}
}
});
navheaderTitle = ButterKnife.findById(navHeader, R.id.navheader_title);
navheaderDescription = ButterKnife.findById(navHeader, R.id.podselection__podupti_notice);
navheaderImage = ButterKnife.findById(navHeader, R.id.navheader_user_image);
2017-09-11 18:48:58 +02:00
if (!_appSettings.getName().equals("")) {
navheaderTitle.setText(_appSettings.getName());
}
2017-09-11 18:48:58 +02:00
if (_appSettings.getPod() != null) {
navheaderDescription.setText(_appSettings.getPod().getName());
}
2017-09-11 18:48:58 +02:00
String avatarUrl = _appSettings.getAvatarUrl();
if (!avatarUrl.equals("")) {
//Display app launcher icon instead of default avatar asset
//(Which would by the way not load because of missing pod domain prefix in the url)
if (avatarUrl.startsWith("/assets/user/default")) {
AppLog.v(this, "Avatar appears to be an asset. Display launcher icon instead (avatarUrl=" + avatarUrl + ")");
navheaderImage.setImageResource(R.drawable.ic_launcher);
} else {
// Try to load image
if (!app.getAvatarImageLoader().loadToImageView(navheaderImage)) {
// If not yet loaded, start download
AppLog.v(this, "Avatar not cached. Start download: " + avatarUrl);
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
}
}
}
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
updateNavigationViewEntryVisibilities();
}
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
protected void updateNavigationViewEntryVisibilities() {
Menu navMenu = navView.getMenu();
// Initially show all items visible when logged in
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), true);
// Hide by app settings
2017-09-11 18:48:58 +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_contacts).setVisible(_appSettings.isVisibleInNavContacts());
navMenu.findItem(R.id.nav_commented).setVisible(_appSettings.isVisibleInNavCommented());
navMenu.findItem(R.id.nav_followed_tags).setVisible(_appSettings.isVisibleInNavFollowed_tags());
navMenu.findItem(R.id.nav_about).setVisible(_appSettings.isVisibleInNavHelp_license());
navMenu.findItem(R.id.nav_liked).setVisible(_appSettings.isVisibleInNavLiked());
navMenu.findItem(R.id.nav_mentions).setVisible(_appSettings.isVisibleInNavMentions());
navMenu.findItem(R.id.nav_profile).setVisible(_appSettings.isVisibleInNavProfile());
navMenu.findItem(R.id.nav_public).setVisible(_appSettings.isVisibleInNavPublic_activities());
navMenu.findItem(R.id.nav_stream).setVisible(true);
2017-09-11 18:48:58 +02:00
navMenu.findItem(R.id.nav_statistics).setVisible(_appSettings.isVisibleInNavStatistics());
navMenu.findItem(R.id.nav_reports).setVisible(_appSettings.isVisibleInNavReports());
navMenu.findItem(R.id.nav_toggle_desktop_page).setVisible(_appSettings.isVisibleInNavToggleMobileDesktop());
navMenu.findItem(R.id.nav_product_support).setVisible(_appSettings.isVisibleInNavGsantnerAccount());
// Hide whole group (for logged in use) if no pod was selected
2017-09-11 18:48:58 +02:00
if (!_appSettings.hasPod()) {
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), false);
}
}
/**
2017-09-11 20:32:40 +02:00
* Open Stream when clicked on top _toolbar AND preference stream shortcut is true
*
* @param view selected view
*/
@OnClick(R.id.main__topbar)
public void onToolBarClicked(View view) {
AppLog.i(this, "onToolBarClicked()");
2017-09-11 18:48:58 +02:00
if (_appSettings.isTopbarStreamShortcutEnabled() && _appSettings.hasPod()) {
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
}
}
/**
* Forward incoming intents to handleIntent()
*
* @param intent incoming
*/
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
/**
* Handle intents and execute intent specific actions
*
* @param intent intent to get handled
*/
private void handleIntent(Intent intent) {
AppLog.i(this, "handleIntent()");
if (intent == null) {
AppLog.v(this, "Intent was null");
return;
}
String action = intent.getAction();
String type = intent.getType();
String loadUrl = null;
AppLog.v(this, "Action: " + action + " Type: " + type);
if (Intent.ACTION_MAIN.equals(action)) {
loadUrl = urls.getStreamUrl();
} else if (ACTION_OPEN_URL.equals(action)) {
loadUrl = intent.getStringExtra(URL_MESSAGE);
} else if (Intent.ACTION_VIEW.equals(action) && intent.getDataString() != null) {
Uri data = intent.getData();
if (data != null && data.toString().startsWith(CONTENT_HASHTAG)) {
handleHashtag(intent);
return;
} else {
loadUrl = intent.getDataString();
AppLog.v(this, "Intent has a delicious URL for us: " + loadUrl);
}
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
2017-09-11 18:48:58 +02:00
_appSettings.setPod(null);
runOnUiThread(new Runnable() {
public void run() {
navheaderTitle.setText(R.string.app_name);
navheaderDescription.setText(R.string.app_subtitle);
navheaderImage.setImageResource(R.drawable.ic_launcher);
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
}
});
showFragment(getFragment(PodSelectionFragment.TAG));
} else if (ACTION_CLEAR_CACHE.equals(action)) {
AppLog.v(this, "Clear WebView cache");
runOnUiThread(new Runnable() {
public void run() {
ContextMenuWebView wv = ((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView();
2016-11-04 03:08:59 +01:00
if (wv != null) {
wv.clearCache(true);
}
}
});
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
switch (type) {
case "text/plain":
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
handleSendSubject(intent);
} else {
handleSendText(intent);
}
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 */
return;
} else if ("sc_new_post".equals(action)) {
openDiasporaUrl(urls.getNewPostUrl());
return;
} else if ("sc_activities".equals(action)) {
openDiasporaUrl(urls.getActivityUrl());
return;
2019-02-07 10:31:18 +01:00
} else if ("sc_contacts".equals(action)) {
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_aspects));
return;
2019-02-07 10:31:18 +01:00
} else if ("sc_tags".equals(action)) {
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_followed_tags));
return;
}
//Catch split screen recreation
if (action != null && action.equals(Intent.ACTION_MAIN) && getTopFragment() != null) {
return;
}
if (loadUrl != null) {
navDrawer.closeDrawers();
openDiasporaUrl(loadUrl);
}
}
2016-03-03 17:46:31 +01:00
/**
* Handle activity results
*
* @param requestCode reqCode
* @param resultCode resCode
* @param data data
*/
2016-03-03 17:46:31 +01:00
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
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
}
/**
* Return the fragment which is currently displayed in R.id.fragment_container
*
* @return top fragment or null if there is none displayed
*/
2018-03-30 00:24:52 +02:00
private ThemedFragment getTopFragment() {
return (ThemedFragment) fm.findFragmentById(R.id.fragment_container);
2016-03-03 17:46:31 +01:00
}
/**
* Handle presses on the back button
*/
2016-03-03 17:46:31 +01:00
@Override
public void onBackPressed() {
AppLog.v(this, "onBackPressed()");
2016-06-04 21:46:54 +02:00
if (navDrawer.isDrawerOpen(navView)) {
navDrawer.closeDrawer(navView);
return;
}
2018-03-30 00:24:52 +02:00
ThemedFragment top = getTopFragment();
if (top != null) {
2016-09-22 23:40:35 +02:00
AppLog.v(this, "Top Fragment is not null");
if (!top.onBackPressed()) {
2016-09-22 23:40:35 +02:00
AppLog.v(this, "Top Fragment.onBackPressed was false");
AppLog.v(this, "BackStackEntryCount: " + fm.getBackStackEntryCount());
if (fm.getBackStackEntryCount() > 0) {
2016-09-28 21:43:25 +02:00
fm.popBackStack();
} else {
snackbarExitApp.show();
}
return;
} else {
2016-09-22 23:40:35 +02:00
AppLog.v(this, "Top Fragment.onBackPressed was true");
return;
}
2016-08-07 11:39:20 +02:00
}
if (!snackbarExitApp.isShown()) {
snackbarExitApp.show();
2016-03-03 17:46:31 +01: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() {
AppLog.v(this, "onPause()");
AppLog.v(this, "Unregister BroadcastReceivers");
LocalBroadcastManager.getInstance(this).unregisterReceiver(brSetTitle);
LocalBroadcastManager.getInstance(this).unregisterReceiver(brOpenExternalLink);
2016-03-03 17:46:31 +01:00
super.onPause();
}
@Override
protected void onResume() {
AppLog.v(this, "onResume()");
super.onResume();
AppLog.v(this, "Register BroadcastReceivers");
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
LocalBroadcastManager.getInstance(this).registerReceiver(brOpenExternalLink, new IntentFilter(ACTION_OPEN_EXTERNAL_URL));
invalidateOptionsMenu();
2017-09-11 18:48:58 +02:00
_appSettings = getAppSettings();
2017-09-11 20:32:40 +02:00
if (_appSettings.isRecreateMainActivity()) {
2017-09-11 18:48:58 +02:00
recreate();
}
2017-10-29 17:26:13 +01:00
setToolbarIntellihide(_appSettings.isIntellihideToolbars());
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(AppSettings.get().isShowTitleInMainView());
}
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
updateNavigationViewEntryVisibilities();
}
/**
2017-09-11 20:32:40 +02:00
* Clear and repopulate top and bottom _toolbar.
* Also add menu items of the displayed fragment
*
2017-09-11 20:32:40 +02:00
* @param menu top _toolbar
* @return boolean
*/
2016-03-03 17:46:31 +01:00
@Override
public boolean onCreateOptionsMenu(Menu menu) {
AppLog.v(this, "onCreateOptionsMenu()");
boolean cache;
//Clear the menus
2016-09-29 19:44:42 +02:00
menu.clear();
2018-03-30 00:24:52 +02:00
ThemedFragment top = getTopFragment();
if (top != null) {
2017-10-29 17:26:13 +01:00
if (!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
cache = _appSettings.isExtendedNotificationsActivated();
getMenuInflater().inflate(R.menu.main__menu_top, menu);
menu.findItem(R.id.action_notifications).setVisible(!cache);
menu.findItem(R.id.action_notifications_extended).setVisible(cache);
}
2016-09-29 19:44:42 +02:00
}
2018-03-12 00:05:53 +01:00
ContextUtils cu = ContextUtils.get();
final boolean darkBg = cu.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor());
cu.tintMenuItems(menu, true, ContextCompat.getColor(this, darkBg ? R.color.white : R.color.black));
cu.setSubMenuIconsVisiblity(menu, true);
2016-03-03 17:46:31 +01:00
return true;
}
/**
2017-09-11 20:32:40 +02:00
* Set the notification and messages counter in the top _toolbar
*
* @param menu menu
* @return boolean
*/
2016-03-03 17:46:31 +01:00
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item;
updateNavigationViewEntryVisibilities();
2016-10-07 04:29:32 +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());
}
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);
}
/**
* Handle clicks on the optionsmenu
*
* @param item item
* @return boolean
*/
2016-03-03 17:46:31 +01:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
AppLog.i(this, "onOptionsItemSelected()");
switch (item.getItemId()) {
case R.id.action_notifications: {
2017-09-11 18:48:58 +02:00
if (_appSettings.isExtendedNotificationsActivated()) {
return true;
}
//Otherwise we execute the action of action_notifications_all
}
case R.id.action_notifications_all: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getNotificationsUrl());
return true;
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
return false;
}
2016-03-03 17:46:31 +01: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;
}
}
case R.id.action_conversations: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getConversationsUrl());
return true;
} else {
snackbarNoInternet.show();
return false;
}
}
case R.id.action_compose: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getNewPostUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
return true;
}
case R.id.action_search: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
2016-11-08 20:41:53 +01:00
@SuppressLint("InflateParams") View layout = getLayoutInflater().inflate(R.layout.ui__dialog_search__people_tags, null, false);
final EditText input = layout.findViewById(R.id.dialog_search__input);
input.setMaxLines(1);
input.setSingleLine(true);
ThemeHelper.updateEditTextColor(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 ? "\\*" : "\\#"), "");
if (query.equals("")) {
2018-09-04 19:16:51 +02:00
Snackbar.make(fragmentContainer, R.string.please_add_a_name, Snackbar.LENGTH_LONG).show();
} else {
openDiasporaUrl(which == DialogInterface.BUTTON_NEGATIVE ? urls.getSearchPeopleUrl(query) : urls.getSearchTagsUrl(query));
}
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
}
};
2017-09-11 18:48:58 +02:00
final AlertDialog dialog = new ThemedAlertDialogBuilder(this, _appSettings)
.setView(layout).setTitle(R.string.search_alert_title)
.setCancelable(true)
2018-09-04 19:16:51 +02:00
.setPositiveButton(R.string.by_tags, clickListener)
.setNegativeButton(R.string.by_people, clickListener)
.create();
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
dialog.hide();
clickListener.onClick(null, 0);
return true;
}
return false;
}
});
// Popup keyboard
dialog.show();
input.requestFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
return true;
}
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);
}
@Override
2016-10-26 16:23:14 +02:00
public void onUserProfileNameChanged(DiasporaUserProfile diasporaUserProfile, String name) {
AppLog.i(this, "onUserProfileNameChanged()");
2016-10-26 16:23:14 +02:00
// Update the profile name in the navigation slider
navheaderTitle.setText(name);
}
@Override
2016-10-26 16:23:14 +02:00
public void onUserProfileAvatarChanged(DiasporaUserProfile diasporaUserProfile, String avatarUrl) {
AppLog.i(this, "onUserProfileAvatarChanged()");
2016-10-26 16:23:14 +02:00
// Update the profile picture in the navigation slider
app.getAvatarImageLoader().startImageDownload(navheaderImage, avatarUrl);
}
/**
* Handle hashtag clicks. Open the new-post-url and inject the clicked hashtag into the post-editor
*
* @param intent intent
*/
private void handleHashtag(Intent intent) {
AppLog.v(this, "handleHashtag()");
try {
setSharedTexts(null, intent.getData().toString().split("/")[3]);
} catch (Exception e) {
AppLog.e(this, e.toString());
}
openDiasporaUrl(urls.getNewPostUrl());
}
/**
* Open the new-post-url and inject text that was shared into the app into the post editors text field
*
* @param intent shareTextIntent
*/
private void handleSendText(Intent intent) {
AppLog.v(this, "handleSendText()");
try {
setSharedTexts(null, intent.getStringExtra(Intent.EXTRA_TEXT));
openDiasporaUrl(urls.getNewPostUrl());
} catch (Exception e) {
AppLog.e(this, e.toString());
}
}
/**
* Handle sent text + subject
*
* @param intent intent
*/
private void handleSendSubject(Intent intent) {
AppLog.v(this, "handleSendSubject()");
try {
setSharedTexts(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT));
openDiasporaUrl(urls.getNewPostUrl());
} catch (Exception e) {
AppLog.e(this, e.toString());
}
}
2016-08-07 14:29:52 +02:00
/**
* TODO: MOVE
* 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
*
* @param sharedSubject post subject or null
* @param sharedBody post text
*/
private void setSharedTexts(String sharedSubject, String sharedBody) {
AppLog.i(this, "setSharedTexts()");
String body = WebHelper.replaceUrlWithMarkdown(sharedBody);
2017-09-11 18:48:58 +02:00
if (_appSettings.isAppendSharedViaApp()) {
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);
}
final String escapedBody = WebHelper.escapeHtmlText(body);
if (sharedSubject != null) {
AppLog.v(this, "Append subject to shared text");
String escapedSubject = WebHelper.escapeHtmlText(WebHelper.replaceUrlWithMarkdown(sharedSubject));
AppLog.v(this, "Set shared text; Subject: \"" + escapedSubject + "\" Body: \"" + escapedBody + "\"");
textToBeShared = "**" + escapedSubject + "** " + escapedBody;
} else {
2016-11-08 20:41:53 +01:00
AppLog.v(this, "Set shared text; Subject: \"null\" Body: \"" + sharedBody + "\"");
textToBeShared = escapedBody;
}
}
/**
* Share an image shared to the app via diaspora
*
* @param intent shareImageIntent
*/
//TODO: Implement some day
private void handleSendImage(Intent intent) {
AppLog.i(this, "handleSendImage()");
final Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
AppLog.v(this, "imageUri is not null. Handle shared image");
} else {
AppLog.w(this, "imageUri is null. Cannot precede.");
}
Toast.makeText(this, "Not yet implemented.", Toast.LENGTH_SHORT).show();
}
@Override
2016-10-26 16:23:14 +02:00
public void onNotificationCountChanged(DiasporaUserProfile diasporaUserProfile, int notificationCount) {
AppLog.i(this, "onNotificationCountChanged()");
2016-10-26 16:23:14 +02:00
// Count saved in DiasporaUserProfile
2017-09-11 20:32:40 +02:00
// Invalidate the top _toolbar to update the unread messages counter
2016-08-07 11:39:20 +02:00
invalidateOptionsMenu();
}
2016-10-26 16:23:14 +02:00
@Override
2016-10-26 16:23:14 +02:00
public void onUnreadMessageCountChanged(DiasporaUserProfile diasporaUserProfile, int unreadMessageCount) {
AppLog.i(this, "onUnreadMessageCountChanged()");
2016-10-26 16:23:14 +02:00
// Count saved in DiasporaUserProfile
2017-09-11 20:32:40 +02:00
// Invalidate the top _toolbar to update the unread messages counter
2016-08-07 11:39:20 +02:00
invalidateOptionsMenu();
}
2016-09-21 22:49:37 +02:00
@Override
public void onCustomTabsConnected() {
if (customTabsSession == null) {
AppLog.i(this, "CustomTabs warmup: " + customTabActivityHelper.warmup(0));
2016-09-21 22:49:37 +02:00
customTabsSession = customTabActivityHelper.getSession();
}
}
@Override
public void onPodSelectionDialogResult(DiasporaPodList.DiasporaPod pod, boolean accepted) {
2016-10-26 16:23:14 +02:00
if (accepted) {
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) {
AppLog.v(this, "onNavigationItemsSelected()");
2016-03-03 17:46:31 +01:00
// Handle navigation view item clicks here.
switch (item.getItemId()) {
case R.id.nav_stream: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getStreamUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
2016-03-03 17:46:31 +01:00
}
break;
2016-03-03 17:46:31 +01:00
2016-08-10 17:47:21 +02:00
case R.id.nav_profile: {
2017-09-11 18:48:58 +02:00
if (!_appSettings.getProfileId().equals("")) {
openDiasporaUrl(urls.getProfileUrl());
2016-08-10 17:47:21 +02:00
}
}
break;
case R.id.nav_followed_tags: {
SearchOrCustomTextDialogCreator.showDiasporaTagsDialog(this, arg -> {
if (arg.startsWith(SearchOrCustomTextDialogCreator.SPECIAL_PREFIX)) {
arg = arg.replace(SearchOrCustomTextDialogCreator.SPECIAL_PREFIX, "").trim();
2018-09-04 17:02:34 +02:00
if (arg.equals(getString(R.string.manage_hashtags))) {
openDiasporaUrl(urls.getManageTagsUrl());
} else {
openDiasporaUrl(urls.getAllFollowedTagsUrl());
}
} else {
openDiasporaUrl(urls.getSearchTagsUrl(arg));
}
});
2016-03-03 17:46:31 +01:00
}
break;
2016-03-03 17:46:31 +01:00
case R.id.nav_aspects: {
SearchOrCustomTextDialogCreator.showDiasporaAspectsDialog(this, arg -> {
if (arg.startsWith(SearchOrCustomTextDialogCreator.SPECIAL_PREFIX)) {
arg = arg.replace(SearchOrCustomTextDialogCreator.SPECIAL_PREFIX, "").trim();
2018-09-04 17:02:34 +02:00
if (arg.equals(getString(R.string.manage_your_contact_list))) {
openDiasporaUrl(urls.getContactsUrl());
} else if (arg.equals(getString(R.string.nav_profile))) {
openDiasporaUrl(urls.getProfileUrl());
}
} else {
for (DiasporaAspect daspect : _appSettings.getAspects()) {
if (arg.equals(daspect.name)) {
openDiasporaUrl(urls.getAspectUrl(Long.toString(daspect.id)));
break;
}
}
}
});
2016-03-03 17:46:31 +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)) {
openDiasporaUrl(urls.getContactsUrl());
2016-10-25 17:56:35 +02:00
} else {
snackbarNoInternet.show();
}
}
break;
2016-10-25 17:56:35 +02:00
case R.id.nav_activities: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getActivityUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
2016-03-03 17:46:31 +01:00
}
break;
2016-03-03 17:46:31 +01:00
case R.id.nav_liked: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getLikedPostsUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
2016-03-03 17:46:31 +01:00
}
break;
2016-03-03 17:46:31 +01:00
case R.id.nav_commented: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getCommentedUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
2016-03-03 17:46:31 +01:00
}
break;
2016-03-03 17:46:31 +01:00
case R.id.nav_mentions: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getMentionsUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
2016-03-03 17:46:31 +01:00
}
break;
2016-03-03 17:46:31 +01:00
case R.id.nav_public: {
2016-08-07 14:29:52 +02:00
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getPublicUrl());
} else {
2016-06-24 13:31:01 +02:00
snackbarNoInternet.show();
}
}
break;
case R.id.nav_reports: {
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getReportsUrl());
} else {
snackbarNoInternet.show();
}
}
break;
case R.id.nav_statistics: {
if (WebHelper.isOnline(MainActivity.this)) {
openDiasporaUrl(urls.getStatisticsUrl());
} else {
snackbarNoInternet.show();
}
}
break;
case R.id.nav_toggle_desktop_page: {
openDiasporaUrl(urls.getToggleMobileUrl());
}
break;
case R.id.nav_product_support: {
openDiasporaUrl(urls.getProfileUrl("d1cbdd70095301341e834860008dbc6c"));
}
break;
case R.id.nav_exit: {
moveTaskToBack(true);
finish();
}
break;
2016-03-03 17:46:31 +01:00
case R.id.nav_settings: {
startActivity(new Intent(this, SettingsActivity.class));
}
break;
2016-03-08 15:42:02 +01:00
2016-09-28 21:43:25 +02:00
case R.id.nav_about: {
startActivity(new Intent(MainActivity.this, AboutActivity.class));
2016-03-08 15:42:02 +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;
}
/**
* React to results of requestPermission
*
* @param requestCode resCode
* @param permissions requested permissions
* @param grantResults granted results
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE__ACCESS_EXTERNAL_STORAGE:
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
AppLog.i(this, "onRequestPermissionsResult: Permission to access external storage granted");
Toast.makeText(this, R.string.permission_granted_try_again, Toast.LENGTH_SHORT).show();
} else {
AppLog.w(this, "onRequestPermissionsResult: Permission to access external storage denied");
Toast.makeText(this, R.string.permission_denied, Toast.LENGTH_SHORT).show();
}
return;
default:
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
}
}
/**
* Return the string that will be shared into the new-post-editor
*
* @return String
*/
public String getTextToBeShared() {
return textToBeShared;
}
/**
* Set the string that will be shared into the new-post-editor
*
2016-11-08 20:41:53 +01:00
* @param textToBeShared text that will be shared into the post-editor
*/
public void setTextToBeShared(String textToBeShared) {
this.textToBeShared = textToBeShared;
}
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
@Override
protected void applyColorToViews() {
ThemeHelper.updateToolbarColor(toolbarTop);
2017-09-11 18:48:58 +02:00
navDrawerLayout.setBackgroundColor(_appSettings.getPrimaryColor());
navProfilePictureArea.setBackgroundColor(_appSettings.getPrimaryColor());
if (_appSettings.isAmoledColorMode()) {
2017-06-10 13:01:57 +02:00
navView.setItemTextColor(ColorStateList.valueOf(Color.GRAY));
navView.setItemIconTintList(ColorStateList.valueOf(Color.GRAY));
navView.setBackgroundColor(Color.BLACK);
navheaderTitle.setTextColor(Color.GRAY);
navheaderDescription.setTextColor(Color.DKGRAY);
}
int popupTheme = ContextUtils.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor())
? R.style.AppTheme_PopupOverlay_Dark : R.style.AppTheme_PopupOverlay_Light;
toolbarTop.setPopupTheme(popupTheme);
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
}
2017-10-29 17:26:13 +01:00
public void setToolbarIntellihide(boolean enable) {
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
2017-10-29 17:26:13 +01:00
if (enable) {
AppLog.d(this, "Enable Intellihide");
params.setScrollFlags(toolbarDefaultScrollFlags);
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
2017-10-29 17:26:13 +01:00
} else {
AppLog.d(this, "Disable Intellihide");
params.setScrollFlags(0); // clear all scroll flags
}
Proxy tor preset Set windowSoftInputMode to adjustResize, Repair sharing text into app, Repair image sharing on 4.2 Fix view intent Update TR; Update buildToolsVersion -> 24.0.2 Update ISSUE_TEMPLATE.md Update README.md Switch ic_launcher back to png Replace blowball image on splash with character Reworked UI using Fragments Merge branch 'master' into rework_fragments Update README.md Fixed top/bottom menu entry population Added HashtagFragment Moved WebClients and ChromeClients to webview package Removed SplashActivity, migrated PodSelectionActivity to PodSelectionFragment Merge branch 'master' into rework_fragments Handle Intent.Action.Main in handleIntent() Update strings-about.xml Fixed image sharing to other apps Get title for image sharing dialog from resources instead of using hardcoded string. Also do not show multiple permission dialogs stacked Removed test Fragments and old SplashActivity related stuff Merge branch 'master' into rework_fragments Added some documentation to MainActivity Fixed clear webview cache. Thanks @di72nn Only set window title depending on webviews content, when DiasporaStreamFragment is displayed (do not overwrite other fragments title when the webview loads in the background) Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Proxy tor preset Reworked custom themes Set customtab color Do not open load the stream when clicked on toolbar Added note about customtabs and proxys. Fixes #77 Resolved merge conflicts Removed duplicate method getAppSettings Fixed default color was id instead of color value bug Update TR Some improvements of code quality Moved colorpicker repo up Fixed applying of settings Fixed bug causing ClassCastException Moved ThemeHelper and ColorPalette to util.theming Added missing license headers to source files Merge branch 'master' into proper-themes Apply nav-slider entry visibilities in onResume SettingsActivity: Switched to Toolbar and fixed toolbar color issue Fixed BrowserFragment reloading in onResume and added credits to LeafPic Added reference to ColorPicker in 3rd party licenses and updated support libraries Merged master Fixed applying proxy settings Merged master proxy changes Fixed nav slider layout color issue Merge branch 'proper-themes' of github.com:Diaspora-for-Android/diaspora-android into proper-themes
2016-10-13 16:56:31 +02:00
appBarLayout.setExpanded(true, true);
}
2016-12-22 13:23:20 +01:00
}