2017-05-05 16:36:04 +02:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2017-07-10 10:33:24 +02:00
|
|
|
* This file is a part of Mastalab
|
2017-05-05 16:36:04 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
2017-07-10 10:33:24 +02:00
|
|
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-05-05 16:36:04 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2017-08-04 11:11:27 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
2017-05-05 16:36:04 +02:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
package fr.gouv.etalab.mastodon.activities;
|
|
|
|
|
2017-08-24 11:56:29 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2017-08-28 19:25:19 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
2017-09-12 19:18:55 +02:00
|
|
|
import android.content.ComponentName;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.content.Context;
|
2017-06-19 19:20:20 +02:00
|
|
|
import android.content.DialogInterface;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.content.Intent;
|
2017-08-28 19:25:19 +02:00
|
|
|
import android.content.IntentFilter;
|
2017-09-12 19:18:55 +02:00
|
|
|
import android.content.ServiceConnection;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2017-08-08 15:33:02 +02:00
|
|
|
import android.graphics.PorterDuff;
|
2017-08-21 17:55:54 +02:00
|
|
|
import android.net.Uri;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.os.AsyncTask;
|
2017-09-04 07:36:04 +02:00
|
|
|
import android.os.Build;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.os.Bundle;
|
2017-09-12 19:18:55 +02:00
|
|
|
import android.os.IBinder;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.design.widget.FloatingActionButton;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.support.design.widget.TabLayout;
|
|
|
|
import android.support.v4.app.Fragment;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.support.v4.app.FragmentManager;
|
2017-08-08 15:33:02 +02:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-08-28 19:25:19 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.support.v4.view.ViewPager;
|
2017-06-19 19:20:20 +02:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.support.v7.widget.SearchView;
|
2017-08-01 15:44:26 +02:00
|
|
|
import android.support.v7.widget.SwitchCompat;
|
2017-09-04 07:36:04 +02:00
|
|
|
import android.util.Patterns;
|
2017-08-01 15:44:26 +02:00
|
|
|
import android.view.LayoutInflater;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.support.design.widget.NavigationView;
|
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.widget.ImageView;
|
2017-05-05 16:36:04 +02:00
|
|
|
import android.widget.LinearLayout;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.widget.RelativeLayout;
|
2017-08-15 11:45:33 +02:00
|
|
|
import android.widget.SeekBar;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.widget.TextView;
|
2017-06-19 19:20:20 +02:00
|
|
|
import android.widget.Toast;
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
|
|
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
|
|
|
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
|
|
|
|
|
|
|
|
import java.io.File;
|
2017-08-22 00:10:05 +02:00
|
|
|
import java.util.ArrayList;
|
2017-05-05 16:36:04 +02:00
|
|
|
import java.util.HashMap;
|
2017-09-09 11:38:26 +02:00
|
|
|
import java.util.List;
|
2017-06-19 19:20:20 +02:00
|
|
|
import java.util.Locale;
|
2017-07-21 19:28:29 +02:00
|
|
|
import java.util.Stack;
|
2017-09-04 07:36:04 +02:00
|
|
|
import java.util.regex.Matcher;
|
2017-09-02 10:59:07 +02:00
|
|
|
|
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMetaDataAsyncTask;
|
2017-05-17 16:19:50 +02:00
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
2017-09-13 08:38:08 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
2017-05-25 13:33:33 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
|
2017-06-07 11:12:40 +02:00
|
|
|
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
2017-07-16 17:09:35 +02:00
|
|
|
import fr.gouv.etalab.mastodon.fragments.DisplayScheduledTootsFragment;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
2017-09-02 10:59:07 +02:00
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
|
2017-08-28 19:25:19 +02:00
|
|
|
import fr.gouv.etalab.mastodon.services.StreamingService;
|
2017-05-05 16:36:04 +02:00
|
|
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
|
|
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
|
|
|
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
|
|
|
import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment;
|
|
|
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
|
|
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
|
|
|
|
2017-07-23 17:09:23 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
2017-07-26 18:31:26 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_USER_INTENT;
|
2017-05-20 15:15:02 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
2017-05-05 16:36:04 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
2017-05-20 15:15:02 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
2017-05-28 14:58:04 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
2017-08-21 09:02:01 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
2017-05-28 14:58:04 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
2017-07-21 17:03:21 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
|
2017-05-28 14:10:19 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
2017-07-23 17:09:23 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
|
2017-05-28 14:10:19 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
|
2017-07-21 17:03:21 +02:00
|
|
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity
|
2017-09-02 10:59:07 +02:00
|
|
|
implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface {
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
private FloatingActionButton toot;
|
|
|
|
private HashMap<String, String> tagTile = new HashMap<>();
|
|
|
|
private HashMap<String, Integer> tagItem = new HashMap<>();
|
2017-07-21 17:03:21 +02:00
|
|
|
private TextView toolbarTitle;
|
|
|
|
private ImageView pp_actionBar;
|
|
|
|
private SearchView toolbar_search;
|
2017-05-17 16:19:50 +02:00
|
|
|
private ImageLoader imageLoader;
|
|
|
|
private DisplayImageOptions options;
|
|
|
|
private View headerLayout;
|
2017-07-03 11:30:36 +02:00
|
|
|
public static String currentLocale;
|
2017-07-21 17:03:21 +02:00
|
|
|
private TabLayout tabLayout;
|
|
|
|
private ViewPager viewPager;
|
|
|
|
private RelativeLayout main_app_container;
|
2017-07-21 19:28:29 +02:00
|
|
|
private Stack<Integer> stackBack = new Stack<>();
|
2017-08-26 16:27:14 +02:00
|
|
|
|
2017-08-24 15:22:04 +02:00
|
|
|
private DisplayStatusFragment homeFragment;
|
|
|
|
private DisplayNotificationsFragment notificationsFragment;
|
2017-08-28 15:01:45 +02:00
|
|
|
private BroadcastReceiver receive_data;
|
2017-09-01 17:17:22 +02:00
|
|
|
private boolean display_local, display_global;
|
2017-09-13 08:47:59 +02:00
|
|
|
public static int countNewStatus = 0;
|
|
|
|
public static int countNewNotifications = 0;
|
2017-09-01 17:17:22 +02:00
|
|
|
|
2017-07-21 19:28:29 +02:00
|
|
|
public MainActivity() {
|
|
|
|
}
|
2017-06-19 15:59:34 +02:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-08-29 07:30:25 +02:00
|
|
|
|
2017-09-02 18:17:00 +02:00
|
|
|
|
|
|
|
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
2017-08-28 19:25:19 +02:00
|
|
|
receive_data = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
Bundle b = intent.getExtras();
|
2017-08-30 08:59:15 +02:00
|
|
|
StreamingService.EventStreaming eventStreaming = (StreamingService.EventStreaming) intent.getSerializableExtra("eventStreaming");
|
|
|
|
if( eventStreaming == StreamingService.EventStreaming.NOTIFICATION){
|
2017-08-29 08:32:09 +02:00
|
|
|
if(notificationsFragment != null){
|
2017-09-13 08:38:08 +02:00
|
|
|
Notification notification = b.getParcelable("data");
|
|
|
|
notificationsFragment.refresh(notification);
|
2017-09-13 19:09:35 +02:00
|
|
|
countNewStatus++;
|
2017-08-28 19:25:19 +02:00
|
|
|
}
|
2017-08-30 08:59:15 +02:00
|
|
|
}else if(eventStreaming == StreamingService.EventStreaming.UPDATE){
|
2017-09-13 08:38:08 +02:00
|
|
|
Status status = b.getParcelable("data");
|
2017-08-29 08:32:09 +02:00
|
|
|
if( homeFragment != null){
|
2017-09-13 08:38:08 +02:00
|
|
|
homeFragment.refresh(status);
|
2017-09-13 19:09:35 +02:00
|
|
|
countNewNotifications++;
|
2017-08-28 19:25:19 +02:00
|
|
|
}
|
2017-08-30 08:59:15 +02:00
|
|
|
}else if(eventStreaming == StreamingService.EventStreaming.DELETE){
|
2017-08-28 19:25:19 +02:00
|
|
|
String id = b.getString("id");
|
2017-08-29 08:55:03 +02:00
|
|
|
if(notificationsFragment != null) {
|
|
|
|
if (notificationsFragment.getUserVisibleHint()) {
|
2017-08-28 19:25:19 +02:00
|
|
|
|
2017-08-29 08:55:03 +02:00
|
|
|
} else {
|
2017-08-28 19:25:19 +02:00
|
|
|
|
2017-08-29 08:55:03 +02:00
|
|
|
}
|
2017-08-28 19:25:19 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-03 10:36:27 +02:00
|
|
|
updateNotifCounter();
|
|
|
|
updateHomeCounter();
|
2017-08-28 19:25:19 +02:00
|
|
|
}
|
|
|
|
};
|
2017-09-12 19:18:55 +02:00
|
|
|
Intent intentService = new Intent(this, StreamingService.class);
|
|
|
|
bindService(intentService, serviceConnection, Context.BIND_AUTO_CREATE);
|
2017-08-28 15:01:45 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(receive_data, new IntentFilter(Helper.RECEIVE_DATA));
|
2017-08-28 19:25:19 +02:00
|
|
|
|
2017-09-02 18:17:00 +02:00
|
|
|
|
2017-06-30 17:09:07 +02:00
|
|
|
|
2017-07-21 19:28:29 +02:00
|
|
|
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
2017-06-30 17:09:07 +02:00
|
|
|
if( theme == Helper.THEME_LIGHT){
|
|
|
|
setTheme(R.style.AppTheme_NoActionBar);
|
|
|
|
}else {
|
|
|
|
setTheme(R.style.AppThemeDark_NoActionBar);
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
setContentView(R.layout.activity_main);
|
2017-07-21 17:03:21 +02:00
|
|
|
|
2017-09-01 17:17:22 +02:00
|
|
|
display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true);
|
|
|
|
display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true);
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
//Test if user is still log in
|
|
|
|
if( ! Helper.isLoggedIn(getApplicationContext())) {
|
|
|
|
//It is not, the user is redirected to the login page
|
|
|
|
Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
|
|
|
|
startActivity(myIntent);
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
2017-09-09 11:38:26 +02:00
|
|
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
List<Account> accounts = new AccountDAO(getApplicationContext(), db).getAllAccount();
|
|
|
|
if( accounts != null){
|
|
|
|
for (Account account: accounts) {
|
|
|
|
Intent intent = new Intent(getApplicationContext(), StreamingService.class);
|
2017-09-09 19:05:43 +02:00
|
|
|
intent.putExtra("accountId", account.getId());
|
2017-09-09 11:38:26 +02:00
|
|
|
intent.putExtra("accountAcct", account.getAcct());
|
|
|
|
startService(intent);
|
|
|
|
}
|
|
|
|
}
|
2017-06-19 15:59:34 +02:00
|
|
|
Helper.fillMapEmoji(getApplicationContext());
|
2017-05-05 16:36:04 +02:00
|
|
|
//Here, the user is authenticated
|
2017-07-21 17:03:21 +02:00
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
2017-05-05 16:36:04 +02:00
|
|
|
setSupportActionBar(toolbar);
|
2017-07-21 17:03:21 +02:00
|
|
|
toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
|
|
|
|
pp_actionBar = (ImageView) toolbar.findViewById(R.id.pp_actionBar);
|
|
|
|
toolbar_search = (SearchView) toolbar.findViewById(R.id.toolbar_search);
|
|
|
|
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
|
2017-08-24 11:56:29 +02:00
|
|
|
TabLayout.Tab tabHome = tabLayout.newTab();
|
|
|
|
TabLayout.Tab tabNotif = tabLayout.newTab();
|
2017-08-24 18:05:57 +02:00
|
|
|
TabLayout.Tab tabLocal = tabLayout.newTab();
|
|
|
|
TabLayout.Tab tabPublic = tabLayout.newTab();
|
2017-08-24 11:56:29 +02:00
|
|
|
tabHome.setCustomView(R.layout.tab_badge);
|
|
|
|
tabNotif.setCustomView(R.layout.tab_badge);
|
2017-08-24 18:05:57 +02:00
|
|
|
tabLocal.setCustomView(R.layout.tab_badge);
|
|
|
|
tabPublic.setCustomView(R.layout.tab_badge);
|
2017-08-24 11:56:29 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
|
|
|
ImageView iconHome = (ImageView) tabHome.getCustomView().findViewById(R.id.tab_icon);
|
2017-08-26 16:38:10 +02:00
|
|
|
iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
2017-08-24 11:56:29 +02:00
|
|
|
iconHome.setImageResource(R.drawable.ic_action_home_tl);
|
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
|
|
|
ImageView iconNotif = (ImageView) tabNotif.getCustomView().findViewById(R.id.tab_icon);
|
2017-08-26 16:38:10 +02:00
|
|
|
iconNotif.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
2017-08-24 11:56:29 +02:00
|
|
|
iconNotif.setImageResource(R.drawable.ic_notifications_tl);
|
|
|
|
|
2017-08-24 18:05:57 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
|
|
|
ImageView iconLocal = (ImageView) tabLocal.getCustomView().findViewById(R.id.tab_icon);
|
2017-08-26 16:38:10 +02:00
|
|
|
iconLocal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
2017-08-24 18:05:57 +02:00
|
|
|
iconLocal.setImageResource(R.drawable.ic_action_users_tl);
|
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
|
|
|
ImageView iconGlobal = (ImageView) tabPublic.getCustomView().findViewById(R.id.tab_icon);
|
2017-08-26 16:38:10 +02:00
|
|
|
iconGlobal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
2017-08-24 18:05:57 +02:00
|
|
|
iconGlobal.setImageResource(R.drawable.ic_action_globe_tl);
|
|
|
|
|
2017-08-24 11:56:29 +02:00
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_home_tl,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_notifications_tl,R.color.dark_text);
|
2017-08-24 18:05:57 +02:00
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_users_tl,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe_tl,R.color.dark_text);
|
|
|
|
|
|
|
|
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
|
|
|
|
tabLayout.setTabMode(TabLayout.MODE_FIXED);
|
2017-08-24 11:56:29 +02:00
|
|
|
|
|
|
|
tabLayout.addTab(tabHome);
|
|
|
|
tabLayout.addTab(tabNotif);
|
2017-09-01 17:17:22 +02:00
|
|
|
if( display_local)
|
|
|
|
tabLayout.addTab(tabLocal);
|
|
|
|
if( display_global)
|
|
|
|
tabLayout.addTab(tabPublic);
|
2017-08-24 11:56:29 +02:00
|
|
|
|
2017-07-21 17:03:21 +02:00
|
|
|
viewPager = (ViewPager) findViewById(R.id.viewpager);
|
2017-09-13 08:38:08 +02:00
|
|
|
int countPage = 2;
|
|
|
|
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
|
|
|
|
countPage++;
|
|
|
|
if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
|
|
|
|
countPage++;
|
|
|
|
viewPager.setOffscreenPageLimit(countPage);
|
2017-07-21 17:03:21 +02:00
|
|
|
main_app_container = (RelativeLayout) findViewById(R.id.main_app_container);
|
2017-08-17 15:48:36 +02:00
|
|
|
PagerAdapter adapter = new PagerAdapter
|
|
|
|
(getSupportFragmentManager(), tabLayout.getTabCount());
|
|
|
|
viewPager.setAdapter(adapter);
|
2017-07-21 17:03:21 +02:00
|
|
|
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
|
|
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(TabLayout.Tab tab) {
|
|
|
|
viewPager.setCurrentItem(tab.getPosition());
|
2017-07-21 19:28:29 +02:00
|
|
|
if (stackBack.empty())
|
|
|
|
stackBack.push(0);
|
|
|
|
if (stackBack.contains(tab.getPosition())) {
|
|
|
|
stackBack.remove(stackBack.indexOf(tab.getPosition()));
|
|
|
|
stackBack.push(tab.getPosition());
|
|
|
|
} else {
|
|
|
|
stackBack.push(tab.getPosition());
|
|
|
|
}
|
2017-07-21 17:03:21 +02:00
|
|
|
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
|
|
|
MenuItem item = null;
|
|
|
|
String fragmentTag = null;
|
|
|
|
main_app_container.setVisibility(View.GONE);
|
|
|
|
viewPager.setVisibility(View.VISIBLE);
|
2017-08-12 13:48:06 +02:00
|
|
|
Helper.switchLayout(MainActivity.this);
|
2017-09-01 17:17:22 +02:00
|
|
|
if( tab.getPosition() == 0) {
|
|
|
|
item = navigationView.getMenu().findItem(R.id.nav_home);
|
|
|
|
fragmentTag = "HOME_TIMELINE";
|
|
|
|
}else if( tab.getPosition() == 1) {
|
|
|
|
fragmentTag = "NOTIFICATIONS";
|
|
|
|
item = navigationView.getMenu().findItem(R.id.nav_notification);
|
|
|
|
}else if( tab.getPosition() == 2 && display_local) {
|
|
|
|
fragmentTag = "LOCAL_TIMELINE";
|
|
|
|
item = navigationView.getMenu().findItem(R.id.nav_local);
|
|
|
|
}else if( tab.getPosition() == 2 && !display_local) {
|
2017-07-21 17:03:21 +02:00
|
|
|
item = navigationView.getMenu().findItem(R.id.nav_global);
|
|
|
|
fragmentTag = "PUBLIC_TIMELINE";
|
2017-09-01 17:17:22 +02:00
|
|
|
}else if( tab.getPosition() == 3){
|
|
|
|
item = navigationView.getMenu().findItem(R.id.nav_global);
|
|
|
|
fragmentTag = "PUBLIC_TIMELINE";
|
2017-07-21 17:03:21 +02:00
|
|
|
}
|
|
|
|
if( item != null){
|
|
|
|
toolbarTitle.setText(item.getTitle());
|
|
|
|
populateTitleWithTag(fragmentTag, item.getTitle().toString(), item.getItemId());
|
2017-07-26 09:21:47 +02:00
|
|
|
unCheckAllMenuItems(navigationView);
|
2017-07-21 17:03:21 +02:00
|
|
|
item.setChecked(true);
|
|
|
|
}
|
2017-08-17 21:24:18 +02:00
|
|
|
if( tab.getPosition() != 1 )
|
2017-07-21 19:28:29 +02:00
|
|
|
toot.setVisibility(View.VISIBLE);
|
|
|
|
else
|
|
|
|
toot.setVisibility(View.GONE);
|
2017-07-21 17:03:21 +02:00
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(TabLayout.Tab tab) {
|
2017-07-21 19:28:29 +02:00
|
|
|
if( viewPager.getVisibility() == View.GONE){
|
|
|
|
viewPager.setVisibility(View.VISIBLE);
|
2017-08-12 13:48:06 +02:00
|
|
|
Helper.switchLayout(MainActivity.this);
|
2017-07-21 19:28:29 +02:00
|
|
|
main_app_container.setVisibility(View.GONE);
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
}
|
2017-08-17 21:24:18 +02:00
|
|
|
if( tab.getPosition() != 1 )
|
2017-07-21 19:28:29 +02:00
|
|
|
toot.setVisibility(View.VISIBLE);
|
|
|
|
else
|
|
|
|
toot.setVisibility(View.GONE);
|
2017-08-17 15:48:36 +02:00
|
|
|
Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, tab.getPosition());
|
|
|
|
switch (tab.getPosition()){
|
|
|
|
case 0:
|
2017-09-03 15:06:07 +02:00
|
|
|
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
2017-09-13 08:38:08 +02:00
|
|
|
countNewStatus = 0;
|
2017-09-03 15:06:07 +02:00
|
|
|
updateHomeCounter();
|
2017-09-13 15:21:03 +02:00
|
|
|
if( displayStatusFragment != null )
|
|
|
|
displayStatusFragment.scrollToTop();
|
2017-09-03 15:06:07 +02:00
|
|
|
break;
|
2017-08-17 15:48:36 +02:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2017-09-03 15:06:07 +02:00
|
|
|
displayStatusFragment = ((DisplayStatusFragment) fragment);
|
2017-08-17 15:48:36 +02:00
|
|
|
if( displayStatusFragment != null )
|
|
|
|
displayStatusFragment.scrollToTop();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
2017-09-13 08:38:08 +02:00
|
|
|
countNewNotifications = 0;
|
2017-09-03 15:06:07 +02:00
|
|
|
updateNotifCounter();
|
2017-09-13 15:21:03 +02:00
|
|
|
if( displayNotificationsFragment != null )
|
|
|
|
displayNotificationsFragment.scrollToTop();
|
2017-08-17 15:48:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-07-21 17:03:21 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-20 18:46:32 +02:00
|
|
|
|
|
|
|
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
//Scroll to top when top bar is clicked for favourites/blocked/muted
|
|
|
|
toolbarTitle.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
|
|
|
|
if( navigationView.getMenu().findItem(R.id.nav_favorites).isChecked()){
|
|
|
|
DisplayStatusFragment faveFrag = (DisplayStatusFragment) fragmentManager.findFragmentByTag("FAVOURITES");
|
|
|
|
if (faveFrag != null && faveFrag.isVisible()) {
|
|
|
|
faveFrag.scrollToTop();
|
|
|
|
}
|
|
|
|
} else if (navigationView.getMenu().findItem(R.id.nav_blocked).isChecked()) {
|
|
|
|
DisplayAccountsFragment blockFrag = (DisplayAccountsFragment) fragmentManager.findFragmentByTag("BLOCKS");
|
|
|
|
|
|
|
|
if (blockFrag != null && blockFrag.isVisible()) {
|
|
|
|
blockFrag.scrollToTop();
|
|
|
|
}
|
|
|
|
} else if (navigationView.getMenu().findItem(R.id.nav_muted).isChecked()) {
|
|
|
|
DisplayAccountsFragment muteFrag = (DisplayAccountsFragment) fragmentManager.findFragmentByTag("MUTED");
|
|
|
|
|
|
|
|
if (muteFrag != null && muteFrag.isVisible()) {
|
|
|
|
muteFrag.scrollToTop();
|
|
|
|
}
|
|
|
|
//Scroll to top when top bar is clicked (THEME_MENU only)
|
|
|
|
} else if (Helper.THEME_MENU == sharedpreferences.getInt(Helper.SET_TABS, Helper.THEME_TABS)) {
|
|
|
|
int pos = tabLayout.getSelectedTabPosition();
|
|
|
|
Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, pos);
|
|
|
|
switch (pos) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
|
|
|
if (displayStatusFragment != null)
|
|
|
|
displayStatusFragment.scrollToTop();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
|
|
|
if (displayNotificationsFragment != null)
|
|
|
|
displayNotificationsFragment.scrollToTop();
|
|
|
|
break;
|
2017-08-20 00:40:07 +02:00
|
|
|
}
|
2017-08-19 20:25:21 +02:00
|
|
|
}
|
2017-08-20 18:46:32 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-21 17:03:21 +02:00
|
|
|
|
|
|
|
toolbar_search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
|
|
|
//Hide keyboard
|
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.hideSoftInputFromWindow(toolbar_search.getWindowToken(), 0);
|
|
|
|
Intent intent = new Intent(MainActivity.this, SearchResultActivity.class);
|
|
|
|
intent.putExtra("search", query);
|
|
|
|
startActivity(intent);
|
2017-08-28 10:55:55 +02:00
|
|
|
toolbar_search.setQuery("", false);
|
|
|
|
toolbar_search.setIconified(true);
|
|
|
|
toolbarTitle.setVisibility(View.VISIBLE);
|
|
|
|
pp_actionBar.setVisibility(View.VISIBLE);
|
|
|
|
return false;
|
2017-07-21 17:03:21 +02:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//Hide/Close the searchview
|
2017-07-21 19:28:29 +02:00
|
|
|
|
|
|
|
|
2017-07-21 17:03:21 +02:00
|
|
|
toolbar_search.setOnCloseListener(new SearchView.OnCloseListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onClose() {
|
|
|
|
toolbarTitle.setVisibility(View.VISIBLE);
|
|
|
|
pp_actionBar.setVisibility(View.VISIBLE);
|
|
|
|
//your code here
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2017-07-21 19:28:29 +02:00
|
|
|
toolbar_search.setOnSearchClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if( toolbar_search.isIconified()){
|
|
|
|
toolbarTitle.setVisibility(View.VISIBLE);
|
|
|
|
pp_actionBar.setVisibility(View.VISIBLE);
|
|
|
|
}else {
|
|
|
|
toolbarTitle.setVisibility(View.GONE);
|
|
|
|
pp_actionBar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-21 17:03:21 +02:00
|
|
|
|
|
|
|
//Hide the default title
|
|
|
|
if( getSupportActionBar() != null)
|
|
|
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
2017-07-03 11:30:36 +02:00
|
|
|
//Defines the current locale of the device in a static variable
|
|
|
|
currentLocale = Helper.currentLocale(getApplicationContext());
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
toot = (FloatingActionButton) findViewById(R.id.toot);
|
|
|
|
toot.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
Intent intent = new Intent(getApplicationContext(), TootActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
|
|
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
2017-06-11 11:58:46 +02:00
|
|
|
drawer.addDrawerListener(toggle);
|
2017-05-05 16:36:04 +02:00
|
|
|
toggle.syncState();
|
|
|
|
|
2017-08-20 18:46:32 +02:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
//Image loader configuration
|
|
|
|
imageLoader = ImageLoader.getInstance();
|
|
|
|
File cacheDir = new File(getCacheDir(), getString(R.string.app_name));
|
|
|
|
ImageLoaderConfiguration configImg = new ImageLoaderConfiguration.Builder(this)
|
2017-05-25 13:33:33 +02:00
|
|
|
.imageDownloader(new PatchBaseImageDownloader(getApplicationContext()))
|
2017-05-05 16:36:04 +02:00
|
|
|
.threadPoolSize(5)
|
|
|
|
.threadPriority(Thread.MIN_PRIORITY + 3)
|
|
|
|
.denyCacheImageMultipleSizesInMemory()
|
|
|
|
.diskCache(new UnlimitedDiskCache(cacheDir))
|
|
|
|
.build();
|
|
|
|
imageLoader.init(configImg);
|
2017-05-17 16:19:50 +02:00
|
|
|
options = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(90)).cacheInMemory(false)
|
2017-05-05 16:36:04 +02:00
|
|
|
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
|
|
|
|
|
|
|
|
2017-05-17 16:19:50 +02:00
|
|
|
headerLayout = navigationView.getHeaderView(0);
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2017-09-02 10:59:07 +02:00
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
2017-05-28 14:10:19 +02:00
|
|
|
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
|
2017-07-21 17:03:21 +02:00
|
|
|
loadPPInActionBar(MainActivity.this, account.getAvatar());
|
2017-06-07 13:58:21 +02:00
|
|
|
//Locked account can see follow request
|
|
|
|
if (account.isLocked()) {
|
|
|
|
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);
|
|
|
|
} else {
|
|
|
|
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
|
|
|
|
}
|
|
|
|
|
2017-05-28 14:10:19 +02:00
|
|
|
LinearLayout owner_container = (LinearLayout) headerLayout.findViewById(R.id.owner_container);
|
|
|
|
owner_container.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
menuAccounts(MainActivity.this);
|
|
|
|
}
|
|
|
|
});
|
2017-05-31 18:58:56 +02:00
|
|
|
boolean matchingIntent = mamageNewIntent(getIntent());
|
|
|
|
if (savedInstanceState == null && !matchingIntent) {
|
2017-05-05 16:36:04 +02:00
|
|
|
navigationView.setCheckedItem(R.id.nav_home);
|
|
|
|
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
2017-07-21 19:28:29 +02:00
|
|
|
toolbarTitle.setText(R.string.home_menu);
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
2017-08-01 15:44:26 +02:00
|
|
|
|
|
|
|
boolean popupShown = sharedpreferences.getBoolean(Helper.SET_POPUP_PUSH, false);
|
|
|
|
if(!popupShown){
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
|
|
|
|
LayoutInflater inflater = getLayoutInflater();
|
2017-08-26 10:57:08 +02:00
|
|
|
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.popup_quick_settings, null);
|
2017-08-01 15:44:26 +02:00
|
|
|
dialogBuilder.setView(dialogView);
|
|
|
|
|
|
|
|
final SwitchCompat set_push_hometimeline = (SwitchCompat) dialogView.findViewById(R.id.set_push_hometimeline);
|
|
|
|
final SwitchCompat set_push_notification = (SwitchCompat) dialogView.findViewById(R.id.set_push_notification);
|
|
|
|
boolean notif_hometimeline = sharedpreferences.getBoolean(Helper.SET_NOTIF_HOMETIMELINE, true);
|
|
|
|
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
|
|
|
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
|
|
|
boolean notif_ask = sharedpreferences.getBoolean(Helper.SET_NOTIF_ASK, true);
|
|
|
|
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
|
|
|
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
|
|
|
boolean notifif_notifications = !( !notif_follow && !notif_add && !notif_ask && !notif_mention && !notif_share);
|
|
|
|
set_push_hometimeline.setChecked(notif_hometimeline);
|
|
|
|
set_push_notification.setChecked(notifif_notifications);
|
|
|
|
|
|
|
|
dialogBuilder.setTitle(R.string.settings_popup_title);
|
|
|
|
dialogBuilder.setCancelable(false);
|
|
|
|
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_FOLLOW, set_push_notification.isChecked());
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_ADD, set_push_notification.isChecked());
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_ASK, set_push_notification.isChecked());
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_MENTION, set_push_notification.isChecked());
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_SHARE, set_push_notification.isChecked());
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_HOMETIMELINE, set_push_hometimeline.isChecked());
|
|
|
|
editor.putBoolean(Helper.SET_POPUP_PUSH, true);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
2017-08-12 09:53:07 +02:00
|
|
|
Helper.switchLayout(MainActivity.this);
|
2017-08-22 20:38:25 +02:00
|
|
|
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 10:17:01 +02:00
|
|
|
|
2017-08-22 20:38:25 +02:00
|
|
|
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
2017-05-28 14:58:04 +02:00
|
|
|
mamageNewIntent(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages new intents
|
|
|
|
* @param intent Intent - intent related to a notification in top bar
|
|
|
|
*/
|
2017-05-31 18:58:56 +02:00
|
|
|
private boolean mamageNewIntent(Intent intent){
|
2017-05-05 16:36:04 +02:00
|
|
|
if( intent == null || intent.getExtras() == null )
|
2017-05-31 18:58:56 +02:00
|
|
|
return false;
|
2017-06-30 17:09:07 +02:00
|
|
|
|
2017-06-06 18:50:01 +02:00
|
|
|
String action = intent.getAction();
|
|
|
|
String type = intent.getType();
|
2017-05-05 16:36:04 +02:00
|
|
|
Bundle extras = intent.getExtras();
|
2017-05-28 14:58:04 +02:00
|
|
|
String userIdIntent;
|
2017-05-31 18:58:56 +02:00
|
|
|
boolean matchingIntent = false;
|
2017-05-05 16:36:04 +02:00
|
|
|
if( extras.containsKey(INTENT_ACTION) ){
|
2017-05-20 15:15:02 +02:00
|
|
|
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
2017-05-28 14:58:04 +02:00
|
|
|
userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent
|
2017-05-20 15:15:02 +02:00
|
|
|
if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){
|
2017-07-23 17:09:23 +02:00
|
|
|
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
|
2017-07-26 09:21:47 +02:00
|
|
|
unCheckAllMenuItems(navigationView);
|
2017-08-26 10:57:08 +02:00
|
|
|
if( tabLayout.getTabAt(1) != null)
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
tabLayout.getTabAt(1).select();
|
2017-05-31 18:58:56 +02:00
|
|
|
matchingIntent = true;
|
2017-05-20 15:15:02 +02:00
|
|
|
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
|
2017-07-26 18:31:26 +02:00
|
|
|
changeUser(MainActivity.this, userIdIntent, true); //Connects the account which is related to the notification
|
2017-07-23 17:09:23 +02:00
|
|
|
}else if( extras.getInt(INTENT_ACTION) == CHANGE_THEME_INTENT){
|
2017-07-26 09:21:47 +02:00
|
|
|
unCheckAllMenuItems(navigationView);
|
2017-07-23 17:09:23 +02:00
|
|
|
navigationView.setCheckedItem(R.id.nav_settings);
|
|
|
|
navigationView.getMenu().performIdentifierAction(R.id.nav_settings, 0);
|
|
|
|
toolbarTitle.setText(R.string.settings);
|
2017-05-31 18:58:56 +02:00
|
|
|
matchingIntent = true;
|
2017-07-26 18:31:26 +02:00
|
|
|
}else if( extras.getInt(INTENT_ACTION) == CHANGE_USER_INTENT){
|
|
|
|
unCheckAllMenuItems(navigationView);
|
|
|
|
navigationView.setCheckedItem(R.id.nav_home);
|
|
|
|
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
|
|
|
toolbarTitle.setText(R.string.home_menu);
|
|
|
|
matchingIntent = true;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
2017-08-21 19:13:09 +02:00
|
|
|
}else if( Intent.ACTION_SEND.equals(action) && type != null ) {
|
2017-06-06 18:50:01 +02:00
|
|
|
if ("text/plain".equals(type)) {
|
2017-06-24 17:50:54 +02:00
|
|
|
String sharedSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
2017-06-06 18:50:01 +02:00
|
|
|
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
|
|
if (sharedText != null) {
|
2017-09-03 21:29:21 +02:00
|
|
|
/* Some apps don't send the URL as the first part of the EXTRA_TEXT,
|
|
|
|
the BBC News app being one such, in this case find where the URL
|
|
|
|
is and strip that out into sharedText.
|
|
|
|
*/
|
2017-09-04 07:36:04 +02:00
|
|
|
Matcher matcher;
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT)
|
|
|
|
matcher = Patterns.WEB_URL.matcher(sharedText);
|
|
|
|
else
|
|
|
|
matcher = Helper.urlPattern.matcher(sharedText);
|
|
|
|
while (matcher.find()){
|
|
|
|
int matchStart = matcher.start(1);
|
|
|
|
int matchEnd = matcher.end();
|
|
|
|
sharedText = sharedText.substring(matchStart, matchEnd);
|
2017-09-03 21:29:21 +02:00
|
|
|
}
|
2017-09-02 10:59:07 +02:00
|
|
|
new RetrieveMetaDataAsyncTask(sharedText, MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2017-06-06 18:50:01 +02:00
|
|
|
Intent intentToot = new Intent(getApplicationContext(), TootActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
2017-06-24 17:50:54 +02:00
|
|
|
b.putString("sharedSubject", sharedSubject);
|
2017-06-06 18:50:01 +02:00
|
|
|
b.putString("sharedContent", sharedText);
|
|
|
|
intentToot.putExtras(b);
|
|
|
|
startActivity(intentToot);
|
|
|
|
}
|
2017-08-22 11:31:58 +02:00
|
|
|
|
2017-08-22 00:10:05 +02:00
|
|
|
} else if (type.startsWith("image/")) {
|
|
|
|
|
2017-08-26 10:57:08 +02:00
|
|
|
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
2017-08-21 17:55:54 +02:00
|
|
|
|
|
|
|
if (imageUri != null) {
|
|
|
|
|
|
|
|
Intent intentToot = new Intent(getApplicationContext(), TootActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
|
|
|
|
b.putParcelable("sharedUri", imageUri);
|
2017-08-22 11:59:25 +02:00
|
|
|
b.putInt("uriNumber", 1);
|
2017-08-22 00:10:05 +02:00
|
|
|
intentToot.putExtras(b);
|
|
|
|
startActivity(intentToot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null ) {
|
|
|
|
if (type.startsWith("image/")) {
|
2017-08-22 11:31:58 +02:00
|
|
|
|
2017-08-22 00:10:05 +02:00
|
|
|
ArrayList<Uri> imageList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
|
|
if (imageList != null) {
|
|
|
|
Intent intentToot = new Intent(getApplicationContext(), TootActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
|
|
|
|
b.putParcelableArrayList("sharedUri", imageList);
|
2017-08-22 11:59:25 +02:00
|
|
|
b.putInt("uriNumber", imageList.size());
|
2017-08-21 17:55:54 +02:00
|
|
|
intentToot.putExtras(b);
|
|
|
|
startActivity(intentToot);
|
|
|
|
}
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
intent.replaceExtras(new Bundle());
|
|
|
|
intent.setAction("");
|
|
|
|
intent.setData(null);
|
|
|
|
intent.setFlags(0);
|
2017-05-31 18:58:56 +02:00
|
|
|
return matchingIntent;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
} else {
|
2017-05-05 18:48:19 +02:00
|
|
|
//Hide search bar on back pressed
|
2017-07-21 17:03:21 +02:00
|
|
|
if( !toolbar_search.isIconified()){
|
|
|
|
toolbar_search.setIconified(true);
|
2017-08-28 10:55:55 +02:00
|
|
|
return;
|
2017-05-05 18:48:19 +02:00
|
|
|
}
|
2017-07-21 19:28:29 +02:00
|
|
|
if( viewPager.getVisibility() == View.VISIBLE){
|
|
|
|
if (stackBack.size() > 1) {
|
|
|
|
stackBack.pop();
|
|
|
|
viewPager.setCurrentItem(stackBack.lastElement());
|
|
|
|
}else {
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
viewPager.setVisibility(View.VISIBLE);
|
2017-08-12 13:48:06 +02:00
|
|
|
Helper.switchLayout(MainActivity.this);
|
2017-07-21 19:28:29 +02:00
|
|
|
main_app_container.setVisibility(View.GONE);
|
|
|
|
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
2017-07-26 09:21:47 +02:00
|
|
|
unCheckAllMenuItems(navigationView);
|
2017-08-26 18:24:46 +02:00
|
|
|
toot.setVisibility(View.VISIBLE);
|
2017-08-21 09:02:01 +02:00
|
|
|
//Manages theme for icon colors
|
2017-09-10 08:52:41 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
2017-08-21 09:02:01 +02:00
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
if( theme == Helper.THEME_DARK){
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_reply,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_more,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_lock_open,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_lock_closed,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_local_post_office,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_retweet_black,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_fav_black,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_photo,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_remove_red_eye,R.color.dark_text);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_translate,R.color.dark_text);
|
|
|
|
}else {
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_reply,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_more,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_lock_open,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_lock_closed,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_local_post_office,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_retweet_black,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_fav_black,R.color.black);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_photo,R.color.white);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_remove_red_eye,R.color.white);
|
|
|
|
changeDrawableColor(getApplicationContext(), R.drawable.ic_translate,R.color.white);
|
|
|
|
}
|
2017-07-21 19:28:29 +02:00
|
|
|
switch (viewPager.getCurrentItem()){
|
|
|
|
case 0:
|
|
|
|
toolbarTitle.setText(R.string.home_menu);
|
|
|
|
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
|
|
|
|
break;
|
|
|
|
case 1:
|
2017-08-17 21:24:18 +02:00
|
|
|
toot.setVisibility(View.GONE);
|
2017-08-16 10:40:54 +02:00
|
|
|
toolbarTitle.setText(R.string.notifications);
|
|
|
|
navigationView.getMenu().findItem(R.id.nav_notification).setChecked(true);
|
2017-07-21 19:28:29 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-08-16 10:40:54 +02:00
|
|
|
toolbarTitle.setText(R.string.local_menu);
|
|
|
|
navigationView.getMenu().findItem(R.id.nav_local).setChecked(true);
|
2017-07-21 19:28:29 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-08-26 16:27:14 +02:00
|
|
|
toolbarTitle.setText(R.string.global_menu);
|
2017-08-16 10:40:54 +02:00
|
|
|
navigationView.getMenu().findItem(R.id.nav_global).setChecked(true);
|
2017-07-21 19:28:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
getMenuInflater().inflate(R.menu.main, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
if(id == R.id.action_logout) {
|
|
|
|
Helper.logout(getApplicationContext());
|
|
|
|
Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
|
|
|
|
startActivity(myIntent);
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}else if(id == R.id.action_about){
|
|
|
|
Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
|
|
|
|
startActivity(intent);
|
2017-06-03 15:54:19 +02:00
|
|
|
}else if(id == R.id.action_privacy){
|
|
|
|
Intent intent = new Intent(getApplicationContext(), PrivacyActivity.class);
|
|
|
|
startActivity(intent);
|
2017-06-05 11:57:02 +02:00
|
|
|
}else if(id == R.id.action_about_instance){
|
|
|
|
Intent intent = new Intent(getApplicationContext(), InstanceActivity.class);
|
|
|
|
startActivity(intent);
|
2017-06-19 19:20:20 +02:00
|
|
|
} else if( id == R.id.action_cache){ //Cache clear feature
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
|
|
builder.setTitle(R.string.cache_title);
|
|
|
|
long sizeCache = Helper.cacheSize(getCacheDir());
|
|
|
|
float cacheSize = 0;
|
|
|
|
if( sizeCache > 0 ) {
|
|
|
|
if (sizeCache > 0) {
|
|
|
|
cacheSize = (float) sizeCache / 1000000.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final float finalCacheSize = cacheSize;
|
2017-08-08 23:01:59 +02:00
|
|
|
builder.setMessage(getString(R.string.cache_message, String.format("%s %s", String.format(Locale.getDefault(), "%.2f", cacheSize), getString(R.string.cache_units))))
|
2017-06-19 19:20:20 +02:00
|
|
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// continue with delete
|
|
|
|
try {
|
|
|
|
String path = getCacheDir().getPath();
|
|
|
|
File dir = new File(path);
|
|
|
|
if (dir.isDirectory()) {
|
|
|
|
Helper.deleteDir(dir);
|
|
|
|
}
|
|
|
|
} catch (Exception ignored) {}
|
2017-08-08 23:01:59 +02:00
|
|
|
Toast.makeText(MainActivity.this, getString(R.string.toast_cache_clear,String.format("%s %s", String.format(Locale.getDefault(), "%.2f", finalCacheSize), getString(R.string.cache_units))), Toast.LENGTH_LONG).show();
|
2017-06-19 19:20:20 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.show();
|
2017-08-15 11:45:33 +02:00
|
|
|
}else if( id == R.id.action_size){
|
|
|
|
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
2017-08-18 17:50:54 +02:00
|
|
|
int textSize = sharedpreferences.getInt(Helper.SET_TEXT_SIZE,110);
|
|
|
|
int iconSize = sharedpreferences.getInt(Helper.SET_ICON_SIZE,130);
|
2017-08-15 11:45:33 +02:00
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
|
|
builder.setTitle(R.string.text_size);
|
|
|
|
|
2017-08-26 10:57:08 +02:00
|
|
|
@SuppressLint("InflateParams") View popup_quick_settings = getLayoutInflater().inflate( R.layout.popup_text_size, null );
|
2017-08-15 11:45:33 +02:00
|
|
|
builder.setView(popup_quick_settings);
|
|
|
|
|
|
|
|
SeekBar set_text_size = (SeekBar) popup_quick_settings.findViewById(R.id.set_text_size);
|
|
|
|
SeekBar set_icon_size = (SeekBar) popup_quick_settings.findViewById(R.id.set_icon_size);
|
|
|
|
final TextView set_text_size_value = (TextView) popup_quick_settings.findViewById(R.id.set_text_size_value);
|
|
|
|
final TextView set_icon_size_value = (TextView) popup_quick_settings.findViewById(R.id.set_icon_size_value);
|
|
|
|
set_text_size_value.setText(String.format("%s%%",String.valueOf(textSize)));
|
|
|
|
set_icon_size_value.setText(String.format("%s%%",String.valueOf(iconSize)));
|
|
|
|
|
2017-08-15 12:12:51 +02:00
|
|
|
set_text_size.setMax(20);
|
|
|
|
set_icon_size.setMax(20);
|
2017-08-15 11:45:33 +02:00
|
|
|
|
2017-08-18 09:11:38 +02:00
|
|
|
set_text_size.setProgress(((textSize-80)/5));
|
|
|
|
set_icon_size.setProgress(((iconSize-80)/5));
|
2017-08-15 11:45:33 +02:00
|
|
|
|
|
|
|
set_text_size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {}
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
|
|
|
2017-08-18 09:11:38 +02:00
|
|
|
int value = 80 + progress*5;
|
2017-08-15 11:45:33 +02:00
|
|
|
set_text_size_value.setText(String.format("%s%%",String.valueOf(value)));
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putInt(Helper.SET_TEXT_SIZE, value);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
set_icon_size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {}
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
2017-08-18 09:11:38 +02:00
|
|
|
int value = 80 + progress*5;
|
2017-08-15 11:45:33 +02:00
|
|
|
set_icon_size_value.setText(String.format("%s%%",String.valueOf(value)));
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putInt(Helper.SET_ICON_SIZE, value);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2017-08-15 12:12:51 +02:00
|
|
|
MainActivity.this.recreate();
|
2017-08-15 11:45:33 +02:00
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.show();
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume(){
|
|
|
|
super.onResume();
|
2017-08-28 19:25:19 +02:00
|
|
|
MainActivity.activityResumed();
|
2017-09-03 10:36:27 +02:00
|
|
|
updateNotifCounter();
|
|
|
|
updateHomeCounter();
|
2017-05-05 16:36:04 +02:00
|
|
|
//Proceeds to update of the authenticated account
|
|
|
|
if(Helper.isLoggedIn(getApplicationContext()))
|
2017-05-17 16:19:50 +02:00
|
|
|
new UpdateAccountInfoByIDAsyncTask(getApplicationContext(), MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 19:18:55 +02:00
|
|
|
|
|
|
|
StreamingService streamingService = null;
|
|
|
|
boolean mBound = false;
|
|
|
|
private ServiceConnection serviceConnection = new ServiceConnection() {
|
|
|
|
@Override
|
|
|
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
|
|
StreamingService.StreamingServiceBinder binder = (StreamingService.StreamingServiceBinder) service;
|
|
|
|
streamingService = binder.getService();
|
|
|
|
mBound = true;
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(MainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
|
|
|
streamingService.connect(account);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onServiceDisconnected(ComponentName arg0) {
|
|
|
|
mBound = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-28 15:01:45 +02:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
MainActivity.activityPaused();
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
|
2017-08-28 15:01:45 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroy(){
|
|
|
|
super.onDestroy();
|
2017-09-12 19:18:55 +02:00
|
|
|
if( streamingService != null)
|
|
|
|
streamingService.disconnect();
|
|
|
|
if (mBound) {
|
|
|
|
unbindService(serviceConnection);
|
|
|
|
mBound = false;
|
|
|
|
}
|
2017-08-28 15:01:45 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
|
|
|
}
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("StatementWithEmptyBody")
|
|
|
|
@Override
|
|
|
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
|
|
// Handle navigation view item clicks here.
|
|
|
|
int id = item.getItemId();
|
2017-08-22 17:34:26 +02:00
|
|
|
if( id == R.id.nav_remote_follow){
|
|
|
|
Intent remoteFollow = new Intent(getApplicationContext(), RemoteFollowActivity.class);
|
|
|
|
startActivity(remoteFollow);
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-21 21:09:32 +02:00
|
|
|
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
2017-07-26 09:21:47 +02:00
|
|
|
unCheckAllMenuItems(navigationView);
|
2017-07-21 21:09:32 +02:00
|
|
|
item.setChecked(true);
|
2017-05-05 16:36:04 +02:00
|
|
|
//Remove the search bar
|
2017-07-21 17:03:21 +02:00
|
|
|
if( !toolbar_search.isIconified() ) {
|
|
|
|
toolbarTitle.setVisibility(View.VISIBLE);
|
|
|
|
pp_actionBar.setVisibility(View.VISIBLE);
|
|
|
|
toolbar_search.setIconified(true);
|
|
|
|
}
|
2017-08-20 18:36:42 +02:00
|
|
|
toolbarTitle.setText(item.getTitle());
|
2017-07-21 17:03:21 +02:00
|
|
|
if (id == R.id.nav_home) {
|
2017-09-03 16:35:45 +02:00
|
|
|
if( tabLayout.getSelectedTabPosition() != 0)
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
tabLayout.getTabAt(0).select();
|
2017-07-21 17:03:21 +02:00
|
|
|
return true;
|
2017-08-16 10:40:54 +02:00
|
|
|
} else if( id == R.id.nav_notification){
|
2017-09-03 16:35:45 +02:00
|
|
|
if( tabLayout.getSelectedTabPosition() != 1)
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
tabLayout.getTabAt(1).select();
|
2017-07-21 17:03:21 +02:00
|
|
|
return true;
|
2017-08-16 10:40:54 +02:00
|
|
|
}else if (id == R.id.nav_local) {
|
2017-09-03 16:35:45 +02:00
|
|
|
|
|
|
|
if( tabLayout.getSelectedTabPosition() != 2)
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
tabLayout.getTabAt(2).select();
|
2017-07-21 17:03:21 +02:00
|
|
|
return true;
|
2017-08-16 10:40:54 +02:00
|
|
|
} else if (id == R.id.nav_global) {
|
2017-09-03 16:35:45 +02:00
|
|
|
if( tabLayout.getSelectedTabPosition() != 3)
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
tabLayout.getTabAt(3).select();
|
2017-07-21 17:03:21 +02:00
|
|
|
return true;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
DisplayStatusFragment statusFragment;
|
|
|
|
DisplayAccountsFragment accountsFragment;
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
String fragmentTag = null;
|
2017-07-21 17:03:21 +02:00
|
|
|
|
|
|
|
main_app_container.setVisibility(View.VISIBLE);
|
|
|
|
viewPager.setVisibility(View.GONE);
|
|
|
|
tabLayout.setVisibility(View.GONE);
|
|
|
|
if (id == R.id.nav_settings) {
|
2017-05-05 16:36:04 +02:00
|
|
|
toot.setVisibility(View.GONE);
|
|
|
|
TabLayoutSettingsFragment tabLayoutSettingsFragment= new TabLayoutSettingsFragment();
|
|
|
|
fragmentTag = "TABLAYOUT_SETTINGS";
|
|
|
|
fragmentManager.beginTransaction()
|
2017-07-21 19:28:29 +02:00
|
|
|
.replace(R.id.main_app_container, tabLayoutSettingsFragment, fragmentTag).commit();
|
2017-05-05 16:36:04 +02:00
|
|
|
|
|
|
|
} else if (id == R.id.nav_favorites) {
|
|
|
|
toot.setVisibility(View.GONE);
|
|
|
|
statusFragment = new DisplayStatusFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.FAVOURITES);
|
|
|
|
statusFragment.setArguments(bundle);
|
|
|
|
fragmentTag = "FAVOURITES";
|
|
|
|
fragmentManager.beginTransaction()
|
2017-07-21 19:28:29 +02:00
|
|
|
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
|
2017-05-05 16:36:04 +02:00
|
|
|
} else if (id == R.id.nav_blocked) {
|
|
|
|
toot.setVisibility(View.GONE);
|
|
|
|
accountsFragment = new DisplayAccountsFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.BLOCKED);
|
|
|
|
accountsFragment.setArguments(bundle);
|
|
|
|
fragmentTag = "BLOCKS";
|
|
|
|
fragmentManager.beginTransaction()
|
2017-07-21 19:28:29 +02:00
|
|
|
.replace(R.id.main_app_container, accountsFragment, fragmentTag).commit();
|
2017-05-05 16:36:04 +02:00
|
|
|
}else if (id == R.id.nav_muted) {
|
|
|
|
toot.setVisibility(View.GONE);
|
|
|
|
accountsFragment = new DisplayAccountsFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.MUTED);
|
|
|
|
accountsFragment.setArguments(bundle);
|
2017-05-24 19:35:07 +02:00
|
|
|
fragmentTag = "MUTED";
|
2017-05-05 16:36:04 +02:00
|
|
|
fragmentManager.beginTransaction()
|
2017-07-21 19:28:29 +02:00
|
|
|
.replace(R.id.main_app_container, accountsFragment, fragmentTag).commit();
|
2017-07-16 17:09:35 +02:00
|
|
|
}else if (id == R.id.nav_scheduled) {
|
2017-07-17 15:29:59 +02:00
|
|
|
toot.setVisibility(View.VISIBLE);
|
2017-07-16 17:09:35 +02:00
|
|
|
DisplayScheduledTootsFragment displayScheduledTootsFragment = new DisplayScheduledTootsFragment();
|
|
|
|
fragmentTag = "SCHEDULED";
|
|
|
|
fragmentManager.beginTransaction()
|
2017-07-21 19:28:29 +02:00
|
|
|
.replace(R.id.main_app_container, displayScheduledTootsFragment, fragmentTag).commit();
|
2017-06-07 11:12:40 +02:00
|
|
|
}else if( id == R.id.nav_follow_request){
|
|
|
|
toot.setVisibility(View.GONE);
|
|
|
|
DisplayFollowRequestSentFragment followRequestSentFragment = new DisplayFollowRequestSentFragment();
|
|
|
|
fragmentTag = "FOLLOW_REQUEST_SENT";
|
|
|
|
fragmentManager.beginTransaction()
|
2017-07-21 19:28:29 +02:00
|
|
|
.replace(R.id.main_app_container, followRequestSentFragment, fragmentTag).commit();
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
2017-08-20 18:36:42 +02:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
populateTitleWithTag(fragmentTag, item.getTitle().toString(), item.getItemId());
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 16:19:50 +02:00
|
|
|
|
2017-05-05 16:36:04 +02:00
|
|
|
private void populateTitleWithTag(String tag, String title, int index){
|
|
|
|
if( tag == null)
|
|
|
|
return;
|
|
|
|
if ( tagTile.get(tag) == null)
|
|
|
|
tagTile.put(tag, title);
|
|
|
|
if ( tagItem.get(tag) == null)
|
|
|
|
tagItem.put(tag, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTitle(CharSequence title) {
|
2017-07-21 17:03:21 +02:00
|
|
|
if(toolbarTitle != null )
|
|
|
|
toolbarTitle.setText(title);
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateAccountInfo(boolean error) {
|
|
|
|
if( error){
|
2017-05-17 16:19:50 +02:00
|
|
|
//An error occurred, the user is redirected to the login page
|
2017-05-05 16:36:04 +02:00
|
|
|
Helper.logout(getApplicationContext());
|
|
|
|
Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
|
|
|
|
startActivity(myIntent);
|
|
|
|
finish();
|
2017-05-17 16:19:50 +02:00
|
|
|
}else {
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(MainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
2017-05-28 14:10:19 +02:00
|
|
|
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-10 16:01:10 +02:00
|
|
|
|
2017-07-21 17:03:21 +02:00
|
|
|
|
2017-09-02 10:59:07 +02:00
|
|
|
@Override
|
|
|
|
public void onRetrieveMetaData(boolean error, String image, String title, String description) {
|
|
|
|
if( !error) {
|
|
|
|
Intent intentSendImage = new Intent(Helper.RECEIVE_PICTURE);
|
|
|
|
intentSendImage.putExtra("image", image);
|
|
|
|
intentSendImage.putExtra("title", title);
|
|
|
|
intentSendImage.putExtra("description", description);
|
|
|
|
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentSendImage);
|
|
|
|
}
|
|
|
|
}
|
2017-08-26 16:27:14 +02:00
|
|
|
|
|
|
|
|
2017-06-11 11:58:46 +02:00
|
|
|
/**
|
2017-07-21 17:03:21 +02:00
|
|
|
* Page Adapter for settings
|
2017-06-11 11:58:46 +02:00
|
|
|
*/
|
2017-07-26 18:31:26 +02:00
|
|
|
private class PagerAdapter extends FragmentStatePagerAdapter {
|
2017-07-21 17:03:21 +02:00
|
|
|
int mNumOfTabs;
|
|
|
|
|
|
|
|
private PagerAdapter(FragmentManager fm, int NumOfTabs) {
|
|
|
|
super(fm);
|
|
|
|
this.mNumOfTabs = NumOfTabs;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fragment getItem(int position) {
|
|
|
|
//Remove the search bar
|
|
|
|
if( !toolbar_search.isIconified() ) {
|
|
|
|
toolbarTitle.setVisibility(View.VISIBLE);
|
|
|
|
pp_actionBar.setVisibility(View.VISIBLE);
|
|
|
|
toolbar_search.setIconified(true);
|
2017-06-10 16:01:10 +02:00
|
|
|
}
|
2017-07-21 17:03:21 +02:00
|
|
|
//Selection comes from another menu, no action to do
|
|
|
|
DisplayStatusFragment statusFragment;
|
|
|
|
Bundle bundle = new Bundle();
|
2017-09-01 17:17:22 +02:00
|
|
|
if (position == 0) {
|
|
|
|
homeFragment = new DisplayStatusFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME);
|
|
|
|
homeFragment.setArguments(bundle);
|
|
|
|
return homeFragment;
|
|
|
|
}else if( position == 1) {
|
|
|
|
notificationsFragment = new DisplayNotificationsFragment();
|
|
|
|
return notificationsFragment;
|
|
|
|
}else if( position == 2 && display_local) {
|
2017-07-21 17:03:21 +02:00
|
|
|
statusFragment = new DisplayStatusFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL);
|
|
|
|
statusFragment.setArguments(bundle);
|
|
|
|
return statusFragment;
|
2017-09-01 17:17:22 +02:00
|
|
|
}else if( position == 2 && !display_local){
|
2017-07-21 17:03:21 +02:00
|
|
|
statusFragment = new DisplayStatusFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
|
|
|
statusFragment.setArguments(bundle);
|
|
|
|
return statusFragment;
|
2017-09-01 17:17:22 +02:00
|
|
|
}else if (position == 3){
|
|
|
|
statusFragment = new DisplayStatusFragment();
|
|
|
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
|
|
|
statusFragment.setArguments(bundle);
|
|
|
|
return statusFragment;
|
2017-06-10 16:01:10 +02:00
|
|
|
}
|
2017-07-21 17:03:21 +02:00
|
|
|
return null;
|
2017-06-10 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
2017-07-21 17:03:21 +02:00
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return mNumOfTabs;
|
2017-06-10 16:01:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 13:03:22 +02:00
|
|
|
|
2017-08-28 15:30:15 +02:00
|
|
|
public void updateHomeCounter(){
|
2017-08-24 15:22:04 +02:00
|
|
|
if( tabLayout.getTabAt(0) == null )
|
|
|
|
return;
|
2017-08-26 10:57:08 +02:00
|
|
|
//noinspection ConstantConditions
|
2017-08-24 15:22:04 +02:00
|
|
|
View tabHome = tabLayout.getTabAt(0).getCustomView();
|
2017-08-26 10:57:08 +02:00
|
|
|
if( tabHome == null)
|
|
|
|
return;
|
2017-08-24 15:22:04 +02:00
|
|
|
TextView tabCounterHome = (TextView) tabHome.findViewById(R.id.tab_counter);
|
2017-09-13 15:21:03 +02:00
|
|
|
tabCounterHome.setText(String.valueOf(countNewStatus));
|
2017-09-13 08:38:08 +02:00
|
|
|
if( countNewStatus> 0){
|
2017-08-24 15:22:04 +02:00
|
|
|
//New data are available
|
|
|
|
//The fragment is not displayed, so the counter is displayed
|
2017-09-03 16:35:45 +02:00
|
|
|
tabCounterHome.setVisibility(View.VISIBLE);
|
2017-08-24 15:22:04 +02:00
|
|
|
}else {
|
|
|
|
tabCounterHome.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 15:30:15 +02:00
|
|
|
public void updateNotifCounter(){
|
2017-08-24 15:22:04 +02:00
|
|
|
if(tabLayout.getTabAt(1) == null)
|
|
|
|
return;
|
2017-08-26 10:57:08 +02:00
|
|
|
//noinspection ConstantConditions
|
2017-08-24 15:22:04 +02:00
|
|
|
View tabNotif = tabLayout.getTabAt(1).getCustomView();
|
2017-08-26 10:57:08 +02:00
|
|
|
if( tabNotif == null)
|
|
|
|
return;
|
2017-08-24 15:22:04 +02:00
|
|
|
TextView tabCounterNotif = (TextView) tabNotif.findViewById(R.id.tab_counter);
|
2017-09-13 15:21:03 +02:00
|
|
|
tabCounterNotif.setText(String.valueOf(countNewNotifications));
|
2017-09-13 08:38:08 +02:00
|
|
|
if( countNewNotifications > 0){
|
2017-09-03 16:35:45 +02:00
|
|
|
tabCounterNotif.setVisibility(View.VISIBLE);
|
2017-08-24 15:22:04 +02:00
|
|
|
}else {
|
|
|
|
tabCounterNotif.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 15:01:45 +02:00
|
|
|
public static boolean isActivityVisible() {
|
|
|
|
return activityVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void activityResumed() {
|
|
|
|
activityVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void activityPaused() {
|
|
|
|
activityVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean activityVisible;
|
2017-05-05 16:36:04 +02:00
|
|
|
}
|