Commit db066c6b authored by Thomas's avatar Thomas
Browse files

Some fixes

parent 1dbc5b7a
Loading
Loading
Loading
Loading
+116 −122
Original line number Diff line number Diff line
@@ -164,8 +164,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
    public static boolean show_boosts, show_replies, show_art_nsfw;
    public static String regex_home, regex_local, regex_public;
    public static BaseAccount currentAccount;
    public static iconLauncher mLauncher = iconLauncher.BUBBLES;
    Fragment currentFragment;

    private AppBarConfiguration mAppBarConfiguration;
    private ActivityMainBinding binding;
    private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() {
@@ -195,8 +195,101 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
            }
        }
    };

    public static iconLauncher mLauncher = iconLauncher.BUBBLES;
    private Pinned pinned;
    private BottomMenu bottomMenu;
    private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle b = intent.getExtras();
            if (b != null) {
                if (b.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) {
                    List<MastodonList> mastodonLists = (List<MastodonList>) b.getSerializable(Helper.RECEIVE_MASTODON_LIST);
                    redrawPinned(mastodonLists);
                }
                if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) {
                    bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
                    if (bottomMenu != null) {
                        //ManageClick on bottom menu items
                        if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
                            binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
                                int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
                                if (position >= 0) {
                                    manageFilters(position);
                                }
                                return false;
                            });
                        }
                        if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
                            binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
                                int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
                                if (position >= 0) {
                                    manageFilters(position);
                                }
                                return false;
                            });
                        }
                        if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
                            binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
                                int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
                                if (position >= 0) {
                                    manageFilters(position);
                                }
                                return false;
                            });
                        }
                        binding.bottomNavView.setOnItemSelectedListener(item -> {
                            int itemId = item.getItemId();
                            int position = BottomMenu.getPosition(bottomMenu, itemId);
                            if (position >= 0) {
                                if (binding.viewPager.getCurrentItem() == position) {
                                    scrollToTop();
                                } else {
                                    binding.viewPager.setCurrentItem(position, false);
                                }
                            }
                            return true;
                        });
                    }
                } else if (b.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) {
                    Cyanea.getInstance().edit().apply().recreate(BaseMainActivity.this);
                } else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
                    Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION);
                    String statusEditId = b.getString(Helper.ARG_EDIT_STATUS_ID, null);
                    Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
                            .setAction(getString(R.string.display), view -> {
                                Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
                                intentContext.putExtra(Helper.ARG_STATUS, statusSent);
                                intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intentContext);
                            })
                            .setTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor))
                            .setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference))
                            .setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
                            .show();
                    //The message was edited, we need to update the timeline
                    if (statusEditId != null) {
                        //Update message in cache
                        new Thread(() -> {
                            StatusCache statusCache = new StatusCache();
                            statusCache.instance = BaseMainActivity.currentInstance;
                            statusCache.user_id = BaseMainActivity.currentUserID;
                            statusCache.status = statusSent;
                            statusCache.status_id = statusEditId;
                            try {
                                new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
                            } catch (DBException e) {
                                e.printStackTrace();
                            }
                        }).start();
                        //Update timelines
                        sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null);
                    }
                }
            }
        }
    };
    private NetworkStateReceiver networkStateReceiver;
    private boolean headerMenuOpen;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -214,7 +307,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        }



        mamageNewIntent(getIntent());
        ThemeHelper.initiliazeColors(BaseMainActivity.this);
        filterFetched = false;
@@ -660,102 +752,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        }
    }

    private Pinned pinned;
    private BottomMenu bottomMenu;
    private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle b = intent.getExtras();
            if (b != null) {
                if (b.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) {
                    List<MastodonList> mastodonLists = (List<MastodonList>) b.getSerializable(Helper.RECEIVE_MASTODON_LIST);
                    redrawPinned(mastodonLists);
                }
                if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) {
                    bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
                    if (bottomMenu != null) {
                        //ManageClick on bottom menu items
                        if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
                            binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
                                int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
                                if (position >= 0) {
                                    manageFilters(position);
                                }
                                return false;
                            });
                        }
                        if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
                            binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
                                int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
                                if (position >= 0) {
                                    manageFilters(position);
                                }
                                return false;
                            });
                        }
                        if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
                            binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
                                int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
                                if (position >= 0) {
                                    manageFilters(position);
                                }
                                return false;
                            });
                        }
                        binding.bottomNavView.setOnItemSelectedListener(item -> {
                            int itemId = item.getItemId();
                            int position = BottomMenu.getPosition(bottomMenu, itemId);
                            if (position >= 0) {
                                if (binding.viewPager.getCurrentItem() == position) {
                                    scrollToTop();
                                } else {
                                    binding.viewPager.setCurrentItem(position, false);
                                }
                            }
                            return true;
                        });
                    }
                } else if (b.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) {
                    Cyanea.getInstance().edit().apply().recreate(BaseMainActivity.this);
                } else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
                    Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION);
                    String statusEditId = b.getString(Helper.ARG_EDIT_STATUS_ID, null);
                    Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
                            .setAction(getString(R.string.display), view -> {
                                Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
                                intentContext.putExtra(Helper.ARG_STATUS, statusSent);
                                intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intentContext);
                            })
                            .setTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor))
                            .setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference))
                            .setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
                            .show();
                    //The message was edited, we need to update the timeline
                    if (statusEditId != null) {
                        //Update message in cache
                        new Thread(() -> {
                            StatusCache statusCache = new StatusCache();
                            statusCache.instance = BaseMainActivity.currentInstance;
                            statusCache.user_id = BaseMainActivity.currentUserID;
                            statusCache.status = statusSent;
                            statusCache.status_id = statusEditId;
                            try {
                                new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
                            } catch (DBException e) {
                                e.printStackTrace();
                            }
                        }).start();
                        //Update timelines
                        sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null);
                    }
                }
            }
        }
    };
    private NetworkStateReceiver networkStateReceiver;
    private boolean headerMenuOpen;

    protected abstract void rateThisApp();

    @Override
@@ -987,16 +983,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt

    }

    public enum iconLauncher {
        BUBBLES,
        FEDIVERSE,
        HERO,
        ATOM,
        BRAINCRASH,
        MASTALAB
    }


    private void manageFilters(int position) {
        View view = binding.bottomNavView.findViewById(R.id.nav_home);
        boolean showExtendedFilter = true;
@@ -1338,7 +1324,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        }
    }


    public void redrawPinned(List<MastodonList> mastodonLists) {
        int currentItem = binding.viewPager.getCurrentItem();
        new ViewModelProvider(BaseMainActivity.this).get(TopBarVM.class).getDBPinned()
@@ -1389,6 +1374,17 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        }
    }

    @Override
    public boolean onSupportNavigateUp() {
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
        //unselect all tag elements
        for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
            pinnedTimeline.isSelected = false;
        }
        return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                || super.onSupportNavigateUp();
    }

   /* @Override
    public boolean onCreateOptionsMenu(@NonNull Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
@@ -1418,17 +1414,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        return true;
    }*/

    @Override
    public boolean onSupportNavigateUp() {
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
        //unselect all tag elements
        for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
            pinnedTimeline.isSelected = false;
        }
        return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                || super.onSupportNavigateUp();
    }

    @Override
    public void networkAvailable() {
        networkAvailable = status.CONNECTED;
@@ -1439,6 +1424,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        networkAvailable = DISCONNECTED;
    }

    public enum iconLauncher {
        BUBBLES,
        FEDIVERSE,
        HERO,
        ATOM,
        BRAINCRASH,
        MASTALAB
    }


    public enum status {
        UNKNOWN,
+14 −16
Original line number Diff line number Diff line
@@ -41,25 +41,9 @@ public class Notification {
    public boolean cached;

    public PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM;

    public enum PositionFetchMore {
        TOP,
        BOTTOM
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        boolean same = false;
        if (obj instanceof Notification) {
            same = this.id.equals(((Notification) obj).id);
        }
        return same;
    }

    public transient List<Notification> relatedNotifications;
    public boolean isFetchMore;


    /**
     * Serialized a list of Notification class
     *
@@ -91,4 +75,18 @@ public class Notification {
        }
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        boolean same = false;
        if (obj instanceof Notification) {
            same = this.id.equals(((Notification) obj).id);
        }
        return same;
    }

    public enum PositionFetchMore {
        TOP,
        BOTTOM
    }

}
+6 −8
Original line number Diff line number Diff line
@@ -113,12 +113,6 @@ public class Status implements Serializable, Cloneable {
    public transient boolean submitted = false;
    public transient boolean spoilerChecked = false;


    public enum PositionFetchMore {
        TOP,
        BOTTOM
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        boolean same = false;
@@ -127,12 +121,11 @@ public class Status implements Serializable, Cloneable {
        }
        return same;
    }
    //Some extra spannable element - They will be filled automatically when fetching the status

    public synchronized Spannable getSpanContent(Context context, WeakReference<View> viewWeakReference) {
        return SpannableHelper.convert(context, content, this, null, null, true, viewWeakReference);
    }

    //Some extra spannable element - They will be filled automatically when fetching the status

    public Spannable getSpanContentNitter() {
        return SpannableHelper.convertNitter(content);
@@ -151,4 +144,9 @@ public class Status implements Serializable, Cloneable {
        return super.clone();
    }

    public enum PositionFetchMore {
        TOP,
        BOTTOM
    }

}
+20 −23
Original line number Diff line number Diff line
@@ -376,6 +376,8 @@ public class Helper {
    };
    public static int counter = 1;
    private static int notificationId = 1;
    //Allow to store in shared preference first visible fragment when the app starts
    private static String slugOfFirstFragment;

    static {
        LinkedHashMap<PatternType, Pattern> aMap = new LinkedHashMap<>();
@@ -1855,6 +1857,24 @@ public class Helper {
        }
    }

    public static String getSlugOfFirstFragment(Context context, String userId, String instance) {
        if (slugOfFirstFragment != null) {
            return slugOfFirstFragment;
        }
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
        return sharedpreferences.getString(Helper.ARG_SLUG_OF_FIRST_FRAGMENT + userId + instance, Timeline.TimeLineEnum.HOME.getValue());
    }

    public static void setSlugOfFirstFragment(Context context, String slug, String userId, String instance) {
        if (slug != null) {
            SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
            SharedPreferences.Editor editor = sharedpreferences.edit();
            slugOfFirstFragment = slug;
            editor.putString(Helper.ARG_SLUG_OF_FIRST_FRAGMENT + userId + instance, slug);
            editor.apply();
        }
    }


    //Enum that described actions to replace inside a toot content
    public enum PatternType {
@@ -1876,30 +1896,7 @@ public class Helper {
        TOOT
    }


    public interface OnAttachmentCopied {
        void onAttachmentCopied(Attachment attachment);
    }


    //Allow to store in shared preference first visible fragment when the app starts
    private static String slugOfFirstFragment;

    public static String getSlugOfFirstFragment(Context context, String userId, String instance) {
        if (slugOfFirstFragment != null) {
            return slugOfFirstFragment;
        }
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
        return sharedpreferences.getString(Helper.ARG_SLUG_OF_FIRST_FRAGMENT + userId + instance, Timeline.TimeLineEnum.HOME.getValue());
    }

    public static void setSlugOfFirstFragment(Context context, String slug, String userId, String instance) {
        if (slug != null) {
            SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
            SharedPreferences.Editor editor = sharedpreferences.edit();
            slugOfFirstFragment = slug;
            editor.putString(Helper.ARG_SLUG_OF_FIRST_FRAGMENT + userId + instance, slug);
            editor.apply();
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -134,12 +134,12 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
    private final BaseAccount account;
    private final String visibility;
    private final app.fedilab.android.client.entities.api.Account mentionedAccount;
    private final String editMessageId;
    public ManageDrafts manageDrafts;
    private int statusCount;
    private Context context;
    private AlertDialog alertDialogEmoji;
    private List<Emoji> emojisList = new ArrayList<>();
    private final String editMessageId;

    public ComposeAdapter(List<Status> statusList, int statusCount, BaseAccount account, app.fedilab.android.client.entities.api.Account mentionedAccount, String visibility, String editMessageId) {
        this.statusList = statusList;
Loading