Commit 6ef2683e authored by Thomas's avatar Thomas
Browse files

redo notification

parent e0b12ab0
Loading
Loading
Loading
Loading
+2 −14
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

@@ -55,7 +54,6 @@ import app.fedilab.android.peertube.fragment.DisplayAccountsFragment;
import app.fedilab.android.peertube.fragment.DisplayChannelsFragment;
import app.fedilab.android.peertube.fragment.DisplayNotificationsFragment;
import app.fedilab.android.peertube.helper.Helper;
import app.fedilab.android.peertube.helper.SwitchAccountHelper;


public class AccountActivity extends BaseBarActivity {
@@ -95,17 +93,14 @@ public class AccountActivity extends BaseBarActivity {

        AccountData.PeertubeAccount account = baseAccount.peertube_account;

        setTitle(String.format("@%s", account.getUsername()));
        setTitle(String.format("@%s@%s", account.getUsername(), baseAccount.instance));

        Helper.loadAvatar(AccountActivity.this, account, binding.profilePicture);
        binding.username.setText(String.format("@%s", account.getUsername()));
        binding.displayname.setText(account.getDisplayName());

        binding.instance.setText(account.getHost());

        binding.editButton.setOnClickListener(v -> {
            startActivity(new Intent(AccountActivity.this, MyAccountActivity.class));
        });
        binding.editButton.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class)));


        TabLayout.Tab notificationTab = binding.accountTabLayout.newTab();
@@ -227,11 +222,6 @@ public class AccountActivity extends BaseBarActivity {
        super.onResume();
    }

    @Override
    public boolean onCreateOptionsMenu(@NotNull Menu menu) {
        getMenuInflater().inflate(R.menu.main_profile_peertube, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
@@ -239,8 +229,6 @@ public class AccountActivity extends BaseBarActivity {
            finish();
            overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up_down);
            return true;
        } else if (item.getItemId() == R.id.action_add_account) {
            SwitchAccountHelper.switchDialog(AccountActivity.this, true);
        }
        return super.onOptionsItemSelected(item);
    }
+30 −50
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
@@ -29,12 +27,12 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentRecyclerviewPeertubeBinding;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.data.NotificationData.Notification;
import app.fedilab.android.peertube.drawer.PeertubeNotificationsListAdapter;
@@ -69,44 +67,35 @@ public class DisplayNotificationsFragment extends Fragment {
    private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
    private String max_id;
    private List<Notification> notifications;
    private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
    private boolean firstLoad;
    private SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView lv_notifications;
    private View rootView;
    private NotificationsVM viewModel;
    FragmentRecyclerviewPeertubeBinding binding;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        rootView = inflater.inflate(R.layout.fragment_recyclerview_peertube, container, false);

        binding = FragmentRecyclerviewPeertubeBinding.inflate(getLayoutInflater());
        context = getContext();
        notifications = new ArrayList<>();
        max_id = "0";
        firstLoad = true;
        flag_loading = true;

        swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);

        viewModel = new ViewModelProvider(this).get(NotificationsVM.class);

        lv_notifications = rootView.findViewById(R.id.lv_elements);
        lv_notifications.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        mainLoader = rootView.findViewById(R.id.loader);
        nextElementLoader = rootView.findViewById(R.id.loading_next);
        textviewNoAction = rootView.findViewById(R.id.no_action);
        TextView no_action_text = rootView.findViewById(R.id.no_action_text);
        no_action_text.setText(context.getString(R.string.no_notifications));
        mainLoader.setVisibility(View.VISIBLE);
        nextElementLoader.setVisibility(View.GONE);

        binding.lvElements.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        binding.noActionText.setText(context.getString(R.string.no_notifications));
        binding.loader.setVisibility(View.VISIBLE);
        binding.loadingNext.setVisibility(View.GONE);
        peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
        lv_notifications.setAdapter(peertubeNotificationsListAdapter);
        binding.lvElements.setAdapter(peertubeNotificationsListAdapter);

        final LinearLayoutManager mLayoutManager;
        mLayoutManager = new LinearLayoutManager(context);
        lv_notifications.setLayoutManager(mLayoutManager);
        lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
        binding.lvElements.setLayoutManager(mLayoutManager);
        binding.lvElements.addOnScrollListener(new RecyclerView.OnScrollListener() {
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                if (dy > 0) {
                    int visibleItemCount = mLayoutManager.getChildCount();
@@ -116,48 +105,40 @@ public class DisplayNotificationsFragment extends Fragment {
                        if (!flag_loading) {
                            flag_loading = true;
                            viewModel.getNotifications(null, max_id).observe(DisplayNotificationsFragment.this.requireActivity(), apiResponse -> manageVIewNotifications(apiResponse));
                            nextElementLoader.setVisibility(View.VISIBLE);
                            binding.loadingNext.setVisibility(View.VISIBLE);
                        }
                    } else {
                        nextElementLoader.setVisibility(View.GONE);
                        binding.loadingNext.setVisibility(View.GONE);
                    }
                }
            }
        });
        swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
        binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);

        viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
        return rootView;
        return binding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        rootView = null;
        binding = null;
    }


    @Override
    public void onPause() {
        super.onPause();
        if (swipeRefreshLayout != null) {
            swipeRefreshLayout.setEnabled(false);
            swipeRefreshLayout.setRefreshing(false);
            swipeRefreshLayout.clearAnimation();
        }
        binding.swipeContainer.setEnabled(false);
        binding.swipeContainer.setRefreshing(false);
        binding.swipeContainer.clearAnimation();
    }


    @Override
    public void onResume() {
        super.onResume();
        swipeRefreshLayout.setEnabled(true);
        if (getActivity() != null && getActivity() != null) {
            View action_button = getActivity().findViewById(R.id.action_button);
            if (action_button != null) {
                action_button.setVisibility(View.GONE);
            }
        }
        binding.swipeContainer.setEnabled(true);
    }

    @Override
@@ -177,8 +158,7 @@ public class DisplayNotificationsFragment extends Fragment {
    }

    public void scrollToTop() {
        if (lv_notifications != null)
            lv_notifications.setAdapter(peertubeNotificationsListAdapter);
        binding.lvElements.setAdapter(peertubeNotificationsListAdapter);
    }


@@ -190,17 +170,17 @@ public class DisplayNotificationsFragment extends Fragment {
        peertubeNotificationsListAdapter.notifyItemRangeRemoved(0, size);
        firstLoad = true;
        flag_loading = true;
        swipeRefreshLayout.setRefreshing(true);
        binding.swipeContainer.setRefreshing(true);
        viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
    }

    private void manageVIewNotifications(APIResponse apiResponse) {
        mainLoader.setVisibility(View.GONE);
        nextElementLoader.setVisibility(View.GONE);
        binding.loader.setVisibility(View.GONE);
        binding.loadingNext.setVisibility(View.GONE);
        if (apiResponse.getError() != null) {
            Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
            flag_loading = false;
            swipeRefreshLayout.setRefreshing(false);
            binding.swipeContainer.setRefreshing(false);
            return;
        }

@@ -208,23 +188,23 @@ public class DisplayNotificationsFragment extends Fragment {
        max_id = String.valueOf(Integer.parseInt(max_id) + 20);
        List<Notification> notifications = apiResponse.getPeertubeNotifications();
        if (firstLoad && (notifications == null || notifications.size() == 0))
            textviewNoAction.setVisibility(View.VISIBLE);
            binding.noAction.setVisibility(View.VISIBLE);
        else
            textviewNoAction.setVisibility(View.GONE);
            binding.noAction.setVisibility(View.GONE);


        if (notifications != null && notifications.size() > 0) {
            this.notifications.addAll(notifications);
            if (previousPosition == 0) {
                peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
                lv_notifications.setAdapter(peertubeNotificationsListAdapter);
                binding.lvElements.setAdapter(peertubeNotificationsListAdapter);
            } else
                peertubeNotificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
        } else {
            if (firstLoad)
                textviewNoAction.setVisibility(View.VISIBLE);
                binding.noAction.setVisibility(View.VISIBLE);
        }
        swipeRefreshLayout.setRefreshing(false);
        binding.swipeContainer.setRefreshing(false);
        firstLoad = false;
        //The initial call comes from a classic tab refresh
        flag_loading = (max_id == null);
+10 −29
Original line number Diff line number Diff line
@@ -32,34 +32,21 @@
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <LinearLayout
            <androidx.appcompat.widget.LinearLayoutCompat
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/instance"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="18sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="10dp">

                    <ImageView
                    <androidx.appcompat.widget.AppCompatImageView
                        android:id="@+id/profile_picture"
                        android:layout_width="72dp"
                        android:layout_height="72dp"
@@ -68,20 +55,19 @@
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <TextView
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/displayname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="20dp"
                        android:ellipsize="end"
                        android:singleLine="true"
                        android:textColor="@android:color/white"
                        android:textSize="18sp"
                        app:layout_constraintRight_toLeftOf="@+id/button_container"
                        app:layout_constraintStart_toEndOf="@+id/profile_picture"
                        app:layout_constraintTop_toTopOf="@+id/profile_picture" />

                    <TextView
                    <androidx.appcompat.widget.AppCompatTextView
                        android:id="@+id/username"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
@@ -89,7 +75,6 @@
                        android:layout_marginTop="30dp"
                        android:ellipsize="end"
                        android:singleLine="true"
                        android:textColor="@android:color/white"
                        android:textSize="14sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintRight_toLeftOf="@+id/button_container"
@@ -105,10 +90,10 @@
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent">

                        <Button
                        <com.google.android.material.button.MaterialButton
                            android:id="@+id/edit_button"
                            style="@style/Widget.AppCompat.Button.Colored"
                            android:layout_width="0dp"
                            style="@style/Widget.Material3.Button"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:text="@string/edit"
@@ -116,10 +101,9 @@
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />


                    </androidx.constraintlayout.widget.ConstraintLayout>
                </androidx.constraintlayout.widget.ConstraintLayout>
            </LinearLayout>
            </androidx.appcompat.widget.LinearLayoutCompat>
        </com.google.android.material.appbar.CollapsingToolbarLayout>

        <com.google.android.material.tabs.TabLayout
@@ -127,12 +111,10 @@
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabSelectedTextColor="?colorAccent"
            app:tabTextColor="@android:color/white" />
            app:tabMode="fixed" />
    </com.google.android.material.appbar.AppBarLayout>

    <TextView
    <androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/remote_account"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
@@ -157,7 +139,6 @@
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_baseline_add_24"
        android:tint="@android:color/white"
        android:visibility="gone"
        tools:ignore="ContentDescription" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
 No newline at end of file
+6 −9
Original line number Diff line number Diff line
@@ -39,15 +39,14 @@
        android:layout_height="wrap_content"
        android:visibility="gone">

        <TextView
        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/no_action_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/no_channels"
            android:textSize="25sp" />
            android:text="@string/no_channels" />
    </RelativeLayout>
    <!-- Main Loader -->
    <RelativeLayout
@@ -57,11 +56,10 @@
        android:gravity="center"
        android:visibility="gone">

        <com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            app:SpinKit_Color="?colorAccent" />
            android:layout_gravity="center" />
    </RelativeLayout>
    <!-- Loader for next accounts -->
    <RelativeLayout
@@ -73,11 +71,10 @@
        android:gravity="bottom|center_horizontal"
        android:visibility="gone">

        <com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            app:SpinKit_Color="?colorAccent" />
            android:layout_gravity="center" />
    </RelativeLayout>
</RelativeLayout>
+0 −9
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_add_account"
        android:icon="@drawable/ic_baseline_person_add_24"
        android:title="@string/add_account"
        app:showAsAction="ifRoom" />
</menu>