diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java | 1454 |
1 files changed, 261 insertions, 1193 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 08eb50674..2a23aed5f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -23,9 +23,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; -import android.graphics.BitmapFactory; import android.graphics.PorterDuff; import android.net.Uri; import android.os.AsyncTask; @@ -41,7 +39,6 @@ import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; import android.support.v4.view.ViewPager; @@ -56,7 +53,6 @@ import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; import android.util.Patterns; -import android.util.SparseArray; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -83,16 +79,10 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.File; import java.lang.reflect.Method; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Locale; -import java.util.Random; import java.util.Stack; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -107,11 +97,13 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveMetaDataAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeInformationAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteDataAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.SyncTimelinesAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Filters; +import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines; import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.Entities.Status; @@ -130,7 +122,6 @@ import fr.gouv.etalab.mastodon.fragments.DisplayMutedInstanceFragment; import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment; import fr.gouv.etalab.mastodon.fragments.DisplayPeertubeNotificationsFragment; import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment; -import fr.gouv.etalab.mastodon.fragments.SettingsFragment; import fr.gouv.etalab.mastodon.fragments.SettingsPeertubeFragment; import fr.gouv.etalab.mastodon.fragments.TabLayoutNotificationsFragment; import fr.gouv.etalab.mastodon.fragments.TabLayoutScheduleFragment; @@ -145,14 +136,14 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; +import fr.gouv.etalab.mastodon.interfaces.OnSyncTimelineInterface; import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface; import fr.gouv.etalab.mastodon.services.BackupStatusService; import fr.gouv.etalab.mastodon.services.LiveNotificationService; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.InstancesDAO; -import fr.gouv.etalab.mastodon.sqlite.SearchDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; -import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO; +import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO; import static fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask.action.GET_ALL_FILTER; import static fr.gouv.etalab.mastodon.helper.Helper.ADD_USER_INTENT; @@ -165,9 +156,11 @@ import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_TARGETED_ACCOUNT; import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT; import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID; +import static fr.gouv.etalab.mastodon.helper.Helper.REFRESH_TIMELINE; import static fr.gouv.etalab.mastodon.helper.Helper.RELOAD_MYVIDEOS; import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_INSTANCE; import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_REMOTE; +import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_TAG; import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_URL; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK; import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; @@ -182,7 +175,7 @@ import static fr.gouv.etalab.mastodon.sqlite.Sqlite.importDB; public abstract class BaseMainActivity extends BaseActivity - implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface, OnRetrieveRemoteAccountInterface, OnRetrieveEmojiAccountInterface, OnFilterActionInterface, OnListActionInterface { + implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface, OnRetrieveRemoteAccountInterface, OnRetrieveEmojiAccountInterface, OnFilterActionInterface, OnListActionInterface, OnSyncTimelineInterface { private FloatingActionButton toot, delete_all, add_new; private HashMap<String, String> tagTile = new HashMap<>(); @@ -194,18 +187,11 @@ public abstract class BaseMainActivity extends BaseActivity private TabLayout tabLayout; private ViewPager viewPager; private RelativeLayout main_app_container; - private Stack<Integer> stackBack = new Stack<>(); public static List<Filters> filters = new ArrayList<>(); - private DisplayStatusFragment homeFragment, federatedFragment, localFragment, artFragment; - private TabLayoutNotificationsFragment tabLayoutNotificationsFragment; - private static final int ERROR_DIALOG_REQUEST_CODE = 97; - private boolean display_direct, display_local, display_global, display_art; public static int countNewStatus; public static int countNewNotifications; public static String lastHomeId = null, lastNotificationId = null; - boolean notif_follow, notif_add, notif_mention, notif_share, show_boosts, show_replies , show_nsfw; - String show_filtered; private AppBarLayout appBar; private String userId; private String instance; @@ -219,13 +205,14 @@ public abstract class BaseMainActivity extends BaseActivity private String instance_id; private int style; private Activity activity; - private HashMap<String, Integer> tabPosition = new HashMap<>(); public static HashMap<Integer, RetrieveFeedsAsyncTask.Type> typePosition = new HashMap<>(); private FloatingActionButton federatedTimelines; public static UpdateAccountInfoAsyncTask.SOCIAL social; - SparseArray<Fragment> registeredFragments = new SparseArray<>(); private final int PICK_IMPORT = 5556; private AlertDialog.Builder dialogBuilderOptin; + private List<ManageTimelines> timelines; + + public static HashMap<Integer, Fragment> mPageReferenceMap = new HashMap<>(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -287,10 +274,6 @@ public abstract class BaseMainActivity extends BaseActivity } setContentView(R.layout.activity_main); - display_direct = sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true); - display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true); - display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true); - display_art = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true); //Test if user is still log in if( ! Helper.isLoggedIn(getApplicationContext())) { //It is not, the user is redirected to the login page @@ -348,428 +331,10 @@ public abstract class BaseMainActivity extends BaseActivity delete_all = findViewById(R.id.delete_all); add_new = findViewById(R.id.add_new); + main_app_container = findViewById(R.id.main_app_container); if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { - TabLayout.Tab tabHome = tabLayout.newTab(); - TabLayout.Tab tabNotif = tabLayout.newTab(); - TabLayout.Tab tabDirect = tabLayout.newTab(); - TabLayout.Tab tabLocal = tabLayout.newTab(); - TabLayout.Tab tabPublic = tabLayout.newTab(); - TabLayout.Tab tabArt = tabLayout.newTab(); - - tabHome.setCustomView(R.layout.tab_badge); - tabNotif.setCustomView(R.layout.tab_badge); - tabDirect.setCustomView(R.layout.tab_badge); - tabLocal.setCustomView(R.layout.tab_badge); - tabPublic.setCustomView(R.layout.tab_badge); - tabArt.setCustomView(R.layout.tab_badge); - - @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") - ImageView iconHome = tabHome.getCustomView().findViewById(R.id.tab_icon); - - iconHome.setImageResource(R.drawable.ic_home); - - if (theme == THEME_BLACK) - iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_icon), PorterDuff.Mode.SRC_IN); - else - iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.mastodonC4), PorterDuff.Mode.SRC_IN); - - - @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") - ImageView iconNotif = tabNotif.getCustomView().findViewById(R.id.tab_icon); - iconNotif.setImageResource(R.drawable.ic_notifications); - - - @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") - ImageView iconDirect = tabDirect.getCustomView().findViewById(R.id.tab_icon); - iconDirect.setImageResource(R.drawable.ic_direct_messages); - - @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") - ImageView iconLocal = tabLocal.getCustomView().findViewById(R.id.tab_icon); - iconLocal.setImageResource(R.drawable.ic_people); - - @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") - ImageView iconGlobal = tabPublic.getCustomView().findViewById(R.id.tab_icon); - iconGlobal.setImageResource(R.drawable.ic_public); - - - @SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") - ImageView iconArt = tabArt.getCustomView().findViewById(R.id.tab_icon); - iconArt.setImageResource(R.drawable.ic_color_lens); - - iconHome.setContentDescription(getString(R.string.home_menu)); - iconNotif.setContentDescription(getString(R.string.notifications)); - iconDirect.setContentDescription(getString(R.string.direct_message)); - iconLocal.setContentDescription(getString(R.string.local_menu)); - iconGlobal.setContentDescription(getString(R.string.global_menu)); - iconArt.setContentDescription(getString(R.string.art_menu)); - - if (theme == THEME_LIGHT) { - iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); - iconNotif.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); - iconDirect.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); - iconLocal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); - iconGlobal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); - iconArt.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.action_light_header), PorterDuff.Mode.SRC_IN); - } else { - iconHome.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - iconNotif.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - iconDirect.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - iconLocal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - iconGlobal.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - iconArt.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - } - - - - tabLayout.addTab(tabHome); - tabLayout.addTab(tabNotif); - tabPosition.put("home",0); - if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - typePosition.put(0, RetrieveFeedsAsyncTask.Type.HOME); - else - typePosition.put(0, RetrieveFeedsAsyncTask.Type.GNU_HOME); - tabPosition.put("notifications",1); - if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - typePosition.put(1, RetrieveFeedsAsyncTask.Type.NOTIFICATION); - else - typePosition.put(0, RetrieveFeedsAsyncTask.Type.GNU_NOTIFICATION); - int i = 2; - if( display_direct) { - tabLayout.addTab(tabDirect); - tabPosition.put("direct",i); - - if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { - userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext())); - - String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null); - if (instanceVersion != null) { - Version currentVersion = new Version(instanceVersion); - Version minVersion = new Version("2.6"); - if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) { - typePosition.put(i, RetrieveFeedsAsyncTask.Type.CONVERSATION); - } else { - typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT); - } - } else { - typePosition.put(i, RetrieveFeedsAsyncTask.Type.DIRECT); - } - }else{ - typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_DM); - } - i++; - } - if( display_local) { - tabLayout.addTab(tabLocal); - tabPosition.put("local", i); - if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - typePosition.put(i, RetrieveFeedsAsyncTask.Type.LOCAL); - else - typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_LOCAL); - i++; - } - if( social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - display_global = false; - if( display_global) { - tabLayout.addTab(tabPublic); - tabPosition.put("global", i); - if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA ) - typePosition.put(i, RetrieveFeedsAsyncTask.Type.PUBLIC); - else - typePosition.put(i, RetrieveFeedsAsyncTask.Type.GNU_WHOLE); - i++; - } - if( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - display_art = false; - if( display_art ) { - tabLayout.addTab(tabArt); - tabPosition.put("art", i); - typePosition.put(i, RetrieveFeedsAsyncTask.Type.ART); - } - - if( (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) - tabLayout.setTabMode(TabLayout.MODE_FIXED); - else if( i > 3 && !Helper.isTablet(getApplicationContext())){ - tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); - }else{ - tabLayout.setTabMode(TabLayout.MODE_FIXED); - } - //Display filter for notification when long pressing the tab - final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0); - if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA ) - tabStrip.getChildAt(1).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - //Only shown if the tab has focus - if( tabLayoutNotificationsFragment != null && tabLayoutNotificationsFragment.getUserVisibleHint()){ - PopupMenu popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(1)); - popup.getMenuInflater() - .inflate(R.menu.option_filter_notifications, popup.getMenu()); - Menu menu = popup.getMenu(); - final MenuItem itemFavourite = menu.findItem(R.id.action_favorite); - final MenuItem itemFollow = menu.findItem(R.id.action_follow); - final MenuItem itemMention = menu.findItem(R.id.action_mention); - final MenuItem itemBoost = menu.findItem(R.id.action_boost); - notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, true); - notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true); - notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true); - notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true); - itemFavourite.setChecked(notif_add); - itemFollow.setChecked(notif_follow); - itemMention.setChecked(notif_mention); - itemBoost.setChecked(notif_share); - popup.setOnDismissListener(new PopupMenu.OnDismissListener() { - @Override - public void onDismiss(PopupMenu menu) { - if( tabLayoutNotificationsFragment != null) - tabLayoutNotificationsFragment.refreshAll(); - } - }); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); - item.setActionView(new View(getApplicationContext())); - item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return false; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - return false; - } - }); - switch (item.getItemId()) { - case R.id.action_favorite: - SharedPreferences.Editor editor = sharedpreferences.edit(); - notif_add = !notif_add; - editor.putBoolean(Helper.SET_NOTIF_ADD_FILTER, notif_add); - itemFavourite.setChecked(notif_add); - editor.apply(); - break; - case R.id.action_follow: - editor = sharedpreferences.edit(); - notif_follow = !notif_follow; - editor.putBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, notif_follow); - itemFollow.setChecked(notif_follow); - editor.apply(); - break; - case R.id.action_mention: - editor = sharedpreferences.edit(); - notif_mention = !notif_mention; - editor.putBoolean(Helper.SET_NOTIF_MENTION_FILTER, notif_mention); - itemMention.setChecked(notif_mention); - editor.apply(); - break; - case R.id.action_boost: - editor = sharedpreferences.edit(); - notif_share = !notif_share; - editor.putBoolean(Helper.SET_NOTIF_SHARE_FILTER, notif_share); - itemBoost.setChecked(notif_share); - editor.apply(); - break; - } - return false; - } - }); - popup.show(); - } - return true; - } - }); - - - tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - - countPage = 2; - if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true)) - countPage++; - if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true)) - countPage++; - if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true) && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA ) - countPage++; - if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true)&& social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - countPage++; - - if( tabPosition.containsKey("global")) - tabStrip.getChildAt(tabPosition.get("global")).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - if( tabPosition.containsKey("local")) - tabStrip.getChildAt(tabPosition.get("local")).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - if( tabPosition.containsKey("art")) - tabStrip.getChildAt(tabPosition.get("art")).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - boolean optimize_loading = sharedpreferences.getBoolean(Helper.SET_OPTIMIZE_LOADING, false); - if( !optimize_loading) - viewPager.setOffscreenPageLimit(countPage); - main_app_container = findViewById(R.id.main_app_container); - adapter = new PagerAdapter - (getSupportFragmentManager(), tabLayout.getTabCount()); - viewPager.setAdapter(adapter); - viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); - tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { - @Override - public void onTabSelected(TabLayout.Tab tab) { - viewPager.setCurrentItem(tab.getPosition()); - 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()); - } - main_app_container.setVisibility(View.GONE); - viewPager.setVisibility(View.VISIBLE); - delete_instance.setVisibility(View.GONE); - Helper.switchLayout(BaseMainActivity.this); - if( tab.getPosition() == 1 || (tabPosition.containsKey("art") && tab.getPosition() == tabPosition.get("art"))) { - toot.hide(); - federatedTimelines.hide(); - }else { - tootShow(); - if( !displayFollowInstance) - federatedTimelines.hide(); - else - federatedTimelinesShow(); - } - DrawerLayout drawer = findViewById(R.id.drawer_layout); - drawer.closeDrawer(GravityCompat.START); - if( tab.getCustomView() != null) { - ImageView icon = tab.getCustomView().findViewById(R.id.tab_icon); - if( icon != null) - if( theme == THEME_BLACK) - icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_icon), PorterDuff.Mode.SRC_IN); - else - icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.mastodonC4), PorterDuff.Mode.SRC_IN); - - } - } - - @Override - public void onTabUnselected(TabLayout.Tab tab) { - if( tab.getCustomView() != null) { - ImageView icon = tab.getCustomView().findViewById(R.id.tab_icon); - if( icon != null) - if( theme == THEME_LIGHT) - icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_icon), PorterDuff.Mode.SRC_IN); - else - icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_text), PorterDuff.Mode.SRC_IN); - } - } - - @Override - public void onTabReselected(TabLayout.Tab tab) { - if( viewPager.getVisibility() == View.GONE){ - viewPager.setVisibility(View.VISIBLE); - delete_instance.setVisibility(View.GONE); - Helper.switchLayout(BaseMainActivity.this); - main_app_container.setVisibility(View.GONE); - DrawerLayout drawer = findViewById(R.id.drawer_layout); - drawer.closeDrawer(GravityCompat.START); - } - if( tab.getPosition() == 1 || (tabPosition.containsKey("art") && tab.getPosition() == tabPosition.get("art"))) { - toot.hide(); - federatedTimelines.hide(); - }else { - tootShow(); - if( !displayFollowInstance) - federatedTimelines.hide(); - else - federatedTimelinesShow(); - } - - if( viewPager.getAdapter() != null) { - Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, tab.getPosition()); + new SyncTimelinesAsyncTask(BaseMainActivity.this, 0, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - DisplayStatusFragment displayStatusFragment; - if (tab.getPosition() == 0) { - displayStatusFragment = ((DisplayStatusFragment) fragment); - countNewStatus = 0; - updateHomeCounter(); - displayStatusFragment.scrollToTop(); - displayStatusFragment.updateLastReadToot(); - } else if( tab.getPosition() == 1) { - countNewNotifications = 0; - updateNotifCounter(); - }else if (tab.getPosition() > 1) { - if (typePosition.containsKey(tab.getPosition())) - updateTimeLine(typePosition.get(tab.getPosition()), 0); - displayStatusFragment = ((DisplayStatusFragment) fragment); - displayStatusFragment.scrollToTop(); - } - } - if( tab.getCustomView() != null) { - ImageView icon = tab.getCustomView().findViewById(R.id.tab_icon); - if( icon != null) - if( theme == THEME_BLACK) - icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.dark_icon), PorterDuff.Mode.SRC_IN); - else - icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.mastodonC4), PorterDuff.Mode.SRC_IN); - } - } - }); - - //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) != null && 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) != null && 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) != null && 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 { - int pos = tabLayout.getSelectedTabPosition(); - if( viewPager.getAdapter() != null) { - Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, pos); - switch (pos) { - case 0: - case 2: - case 3: - case 4: - DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment); - displayStatusFragment.scrollToTop(); - break; - case 1: - break; - } - } - } - } - }); }else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){ TabLayout.Tab pTabsub = tabLayout.newTab(); TabLayout.Tab pTabOver = tabLayout.newTab(); @@ -845,7 +410,7 @@ public abstract class BaseMainActivity extends BaseActivity - main_app_container = findViewById(R.id.main_app_container); + adapter = new PagerAdapter (getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); @@ -854,14 +419,6 @@ public abstract class BaseMainActivity extends BaseActivity @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); - 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()); - } main_app_container.setVisibility(View.GONE); viewPager.setVisibility(View.VISIBLE); delete_instance.setVisibility(View.GONE); @@ -906,7 +463,6 @@ public abstract class BaseMainActivity extends BaseActivity else icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.mastodonC4), PorterDuff.Mode.SRC_IN); if( viewPager.getAdapter() != null) { - Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, tab.getPosition()); DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment); displayStatusFragment.scrollToTop(); @@ -989,8 +545,6 @@ public abstract class BaseMainActivity extends BaseActivity tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); - - main_app_container = findViewById(R.id.main_app_container); adapter = new PagerAdapter (getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); @@ -999,14 +553,6 @@ public abstract class BaseMainActivity extends BaseActivity @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); - 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()); - } main_app_container.setVisibility(View.GONE); viewPager.setVisibility(View.VISIBLE); delete_instance.setVisibility(View.GONE); @@ -1105,15 +651,6 @@ public abstract class BaseMainActivity extends BaseActivity startSreaming(); - if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - Helper.refreshSearchTag(BaseMainActivity.this, tabLayout, adapter); - int tabCount = tabLayout.getTabCount(); - if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - for( int j = countPage ; j < tabCount ; j++){ - attacheDelete(j); - } - - toolbar_search.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { @@ -1242,11 +779,12 @@ public abstract class BaseMainActivity extends BaseActivity //Defines the current locale of the device in a static variable currentLocale = Helper.currentLocale(getApplicationContext()); - if( tabLayout.getTabAt(0) == null) { + /*if( tabLayout.getTabAt(0) == null) { Helper.logout(BaseMainActivity.this); return; } tabLayout.getTabAt(0).select(); + */ if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { toot.setOnClickListener(new View.OnClickListener() { @Override @@ -1567,241 +1105,10 @@ public abstract class BaseMainActivity extends BaseActivity } - public void removeSearchTab(String tag){ - Helper.removeSearchTag(tag, tabLayout, adapter); - int allTabCount = tabLayout.getTabCount(); - if( allTabCount == countPage){ - main_app_container.setVisibility(View.GONE); - viewPager.setVisibility(View.VISIBLE); - tabLayout.setVisibility(View.VISIBLE); - toolbarTitle.setVisibility(View.GONE); - delete_instance.setVisibility(View.GONE); - } - } - protected abstract void rateThisApp(); - private boolean manageFilters(LinearLayout tabStrip, final SharedPreferences sharedpreferences){ - //Only shown if the tab has focus - if( - (homeFragment != null && homeFragment.getUserVisibleHint()) || - (federatedFragment != null && federatedFragment.getUserVisibleHint()) || - (localFragment != null && localFragment.getUserVisibleHint()) || - (artFragment != null && artFragment.getUserVisibleHint()) - ){ - PopupMenu popup = null; - if(homeFragment != null && homeFragment.getUserVisibleHint()) - popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(0)); |