Commit 8b26deb0 authored by Thomas's avatar Thomas
Browse files

More update on view

parent 6ef2683e
Loading
Loading
Loading
Loading
+27 −51
Original line number Diff line number Diff line
@@ -14,13 +14,10 @@ package app.fedilab.android.peertube.fragment;
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */

import android.content.Context;
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 +26,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.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.data.AccountData;
@@ -47,23 +44,18 @@ import es.dmoral.toasty.Toasty;
public class DisplayAccountsFragment extends Fragment implements AccountsListAdapter.AllAccountsRemoved {

    private boolean flag_loading;
    private Context context;
    private AccountsListAdapter accountsListAdapter;
    private String max_id;
    private List<AccountData.PeertubeAccount> accounts;
    private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
    private boolean firstLoad;
    private SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView lv_accounts;
    private View rootView;
    private RetrofitPeertubeAPI.DataType accountFetch;
    private 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();
        Bundle bundle = this.getArguments();
        accounts = new ArrayList<>();
        if (bundle != null) {
@@ -75,27 +67,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
        firstLoad = true;
        flag_loading = true;

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


        lv_accounts = rootView.findViewById(R.id.lv_elements);
        lv_accounts.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);
        mainLoader.setVisibility(View.VISIBLE);
        nextElementLoader.setVisibility(View.GONE);
        binding.lvElements.addItemDecoration(new DividerItemDecoration(requireActivity(), DividerItemDecoration.VERTICAL));
        binding.loader.setVisibility(View.VISIBLE);
        binding.loadingNext.setVisibility(View.GONE);
        accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
        accountsListAdapter.allAccountsRemoved = this;
        lv_accounts.setAdapter(accountsListAdapter);
        TextView no_action_text = rootView.findViewById(R.id.no_action_text);
        binding.lvElements.setAdapter(accountsListAdapter);
        if (accountFetch == RetrofitPeertubeAPI.DataType.MUTED) {
            no_action_text.setText(context.getString(R.string.no_muted));
            binding.noActionText.setText(getString(R.string.no_muted));
        }
        final LinearLayoutManager mLayoutManager;
        mLayoutManager = new LinearLayoutManager(context);
        lv_accounts.setLayoutManager(mLayoutManager);
        lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
        final LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
        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();
@@ -106,18 +89,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
                            flag_loading = true;
                            AccountsVM viewModel = new ViewModelProvider(DisplayAccountsFragment.this).get(AccountsVM.class);
                            viewModel.getAccounts(accountFetch, max_id).observe(DisplayAccountsFragment.this.requireActivity(), apiResponse -> manageViewAccounts(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);
        AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
        viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, max_id).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
        return rootView;
        return binding.getRoot();
    }

    @Override
@@ -134,7 +117,7 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        rootView = null;
        binding = null;
    }

    @Override
@@ -143,28 +126,21 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
    }


    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

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

    private void manageViewAccounts(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();
            swipeRefreshLayout.setRefreshing(false);
            Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
            binding.swipeContainer.setRefreshing(false);
            flag_loading = false;
            return;
        }
@@ -181,9 +157,9 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
            max_id = "0";
        }
        if (firstLoad && (accounts == null || accounts.size() == 0))
            textviewNoAction.setVisibility(View.VISIBLE);
            binding.noAction.setVisibility(View.VISIBLE);
        else
            textviewNoAction.setVisibility(View.GONE);
            binding.noAction.setVisibility(View.GONE);
        max_id = String.valueOf(Integer.parseInt(max_id) + 20);
        if (accounts != null && accounts.size() > 0) {
            int previousPosition = this.accounts.size();
@@ -192,11 +168,11 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
            if (previousPosition == 0) {
                accountsListAdapter = new AccountsListAdapter(accountFetch, this.accounts);
                accountsListAdapter.allAccountsRemoved = this;
                lv_accounts.setAdapter(accountsListAdapter);
                binding.lvElements.setAdapter(accountsListAdapter);
            } else
                accountsListAdapter.notifyItemRangeChanged(currentPosition, accounts.size());
        }
        swipeRefreshLayout.setRefreshing(false);
        binding.swipeContainer.setRefreshing(false);
        firstLoad = false;
    }

@@ -205,14 +181,14 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
        accounts = new ArrayList<>();
        firstLoad = true;
        flag_loading = true;
        swipeRefreshLayout.setRefreshing(true);
        binding.swipeContainer.setRefreshing(true);
        AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
        viewModel.getAccounts(RetrofitPeertubeAPI.DataType.MUTED, null).observe(DisplayAccountsFragment.this.requireActivity(), this::manageViewAccounts);
    }

    @Override
    public void onAllAccountsRemoved() {
        textviewNoAction.setVisibility(View.VISIBLE);
        binding.noAction.setVisibility(View.VISIBLE);
    }


+2 −5
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
    private ChannelListAdapter channelListAdapter;
    private List<ChannelData.Channel> channels;
    private String name;
    private View rootView;
    private FloatingActionButton action_button;
    private FragmentRecyclerviewPeertubeBinding binding;
    private AddChannelPeertubeBinding bindingDialog;
@@ -88,8 +87,6 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap


        binding = FragmentRecyclerviewPeertubeBinding.inflate(LayoutInflater.from(context));
        rootView = binding.getRoot();
        context = getContext();
        Bundle bundle = this.getArguments();
        channels = new ArrayList<>();
        max_id = "0";
@@ -119,7 +116,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
        binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);

        loadChannels(max_id);
        return rootView;
        return binding.getRoot();
    }

    private void loadChannels(String max_id) {
@@ -168,7 +165,7 @@ public class DisplayChannelsFragment extends Fragment implements ChannelListAdap
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        rootView = null;
        binding = null;
    }

    @Override
+30 −50
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
@@ -35,7 +33,6 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import org.jetbrains.annotations.NotNull;

@@ -45,6 +42,7 @@ import java.util.List;
import java.util.Map;

import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentOverviewPeertubeBinding;
import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.data.VideoData;
import app.fedilab.android.peertube.client.entities.OverviewVideo;
@@ -63,20 +61,16 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
    private LinearLayoutManager mLayoutManager;
    private GridLayoutManager gLayoutManager;
    private boolean flag_loading;
    private Context context;
    private PeertubeAdapter peertubeAdapater;
    private int page;
    private List<VideoData.Video> peertubes;
    private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
    private boolean firstLoad;
    private SwipeRefreshLayout swipeRefreshLayout;
    private TextView textviewNoActionText;
    private View rootView;
    private RecyclerView lv_status;
    private TimelineVM viewModelFeeds;
    private Map<String, Boolean> relationship;
    private Map<String, List<PlaylistExist>> playlists;

    private FragmentOverviewPeertubeBinding binding;

    public DisplayOverviewFragment() {
    }
@@ -84,23 +78,17 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_overview_peertube, container, false);

        binding = FragmentOverviewPeertubeBinding.inflate(getLayoutInflater());

        peertubes = new ArrayList<>();
        context = getContext();
        lv_status = rootView.findViewById(R.id.lv_status);
        page = 1;
        flag_loading = true;
        firstLoad = true;

        swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
        mainLoader = rootView.findViewById(R.id.loader);
        nextElementLoader = rootView.findViewById(R.id.loading_next_status);
        textviewNoAction = rootView.findViewById(R.id.no_action);
        textviewNoActionText = rootView.findViewById(R.id.no_action_text);
        mainLoader.setVisibility(View.VISIBLE);
        nextElementLoader.setVisibility(View.GONE);
        binding.loader.setVisibility(View.VISIBLE);
        binding.loadingNextStatus.setVisibility(View.GONE);

        peertubeAdapater = new PeertubeAdapter(this.peertubes);

@@ -110,19 +98,19 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
        lv_status.setAdapter(peertubeAdapater);


        if (!Helper.isTablet(context)) {
            mLayoutManager = new LinearLayoutManager(context);
        if (!Helper.isTablet(requireActivity())) {
            mLayoutManager = new LinearLayoutManager(requireActivity());
            lv_status.setLayoutManager(mLayoutManager);
        } else {
            gLayoutManager = new GridLayoutManager(context, 2);
            int spanCount = (int) Helper.convertDpToPixel(2, context);
            int spacing = (int) Helper.convertDpToPixel(5, context);
            gLayoutManager = new GridLayoutManager(requireActivity(), 2);
            int spanCount = (int) Helper.convertDpToPixel(2, requireActivity());
            int spacing = (int) Helper.convertDpToPixel(5, requireActivity());
            lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
            lv_status.setLayoutManager(gLayoutManager);
        }

        viewModelFeeds = new ViewModelProvider(DisplayOverviewFragment.this).get(TimelineVM.class);
        swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
        binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
        loadTimeline(page);
        lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@@ -131,14 +119,14 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
                    if (dy > 0) {
                        int visibleItemCount = mLayoutManager.getChildCount();
                        int totalItemCount = mLayoutManager.getItemCount();
                        if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
                        if (firstVisibleItem + visibleItemCount == totalItemCount) {
                            if (!flag_loading) {
                                flag_loading = true;
                                loadTimeline(page);
                                nextElementLoader.setVisibility(View.VISIBLE);
                                binding.loadingNextStatus.setVisibility(View.VISIBLE);
                            }
                        } else {
                            nextElementLoader.setVisibility(View.GONE);
                            binding.loadingNextStatus.setVisibility(View.GONE);
                        }
                    }
                } else if (gLayoutManager != null) {
@@ -146,14 +134,14 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
                    if (dy > 0) {
                        int visibleItemCount = gLayoutManager.getChildCount();
                        int totalItemCount = gLayoutManager.getItemCount();
                        if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
                        if (firstVisibleItem + visibleItemCount == totalItemCount) {
                            if (!flag_loading) {
                                flag_loading = true;
                                loadTimeline(page);
                                nextElementLoader.setVisibility(View.VISIBLE);
                                binding.loadingNextStatus.setVisibility(View.VISIBLE);
                            }
                        } else {
                            nextElementLoader.setVisibility(View.GONE);
                            binding.loadingNextStatus.setVisibility(View.GONE);
                        }
                    }
                }
@@ -167,11 +155,9 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
    @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();
        if (getActivity() != null) {
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null && getView() != null) {
@@ -187,12 +173,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
    }


    @Override
    public void onAttach(@NotNull Context context) {
        super.onAttach(context);
        this.context = context;
    }


    @Override
    public void onStop() {
@@ -207,16 +187,16 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter

    private void manageVIewVideos(APIResponse apiResponse) {
        //hide loaders
        mainLoader.setVisibility(View.GONE);
        nextElementLoader.setVisibility(View.GONE);
        binding.loader.setVisibility(View.GONE);
        binding.loadingNextStatus.setVisibility(View.GONE);
        //handle other API error
        if (this.peertubes == null || apiResponse == null || apiResponse.getOverviewVideo() == null || (apiResponse.getError() != null)) {
            if (apiResponse == null || apiResponse.getError() == null)
                Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
                Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
            else {
                Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
                Toasty.error(requireActivity(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
            }
            swipeRefreshLayout.setRefreshing(false);
            binding.swipeContainer.setRefreshing(false);
            flag_loading = false;
            return;
        }
@@ -313,11 +293,11 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
        } else
            peertubeAdapater.notifyItemRangeInserted(previousPosition, totalAdded);
        //remove handlers
        swipeRefreshLayout.setRefreshing(false);
        textviewNoAction.setVisibility(View.GONE);
        binding.swipeContainer.setRefreshing(false);
        binding.noAction.setVisibility(View.GONE);
        if (firstLoad && (this.peertubes == null || this.peertubes.size() == 0)) {
            textviewNoActionText.setText(R.string.no_video_to_display);
            textviewNoAction.setVisibility(View.VISIBLE);
            binding.noActionText.setText(R.string.no_video_to_display);
            binding.noAction.setVisibility(View.VISIBLE);
        }
        flag_loading = false;
        firstLoad = false;
@@ -339,7 +319,7 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
    @Override
    public void onResume() {
        super.onResume();
        swipeRefreshLayout.setEnabled(true);
        binding.swipeContainer.setEnabled(true);
    }


+94 −126

File changed.

Preview size limit exceeded, changes collapsed.

+6 −11
Original line number Diff line number Diff line
@@ -52,16 +52,13 @@
            android:layout_height="wrap_content"
            android:visibility="gone"
            app:layout_constraintTop_toTopOf="parent">

            <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_videos"
                android:textSize="25sp" />
                android:text="@string/no_videos" />
        </RelativeLayout>
        <!-- Main Loader -->
        <RelativeLayout
@@ -71,11 +68,10 @@
            android:gravity="center"
            android:visibility="gone">

            <com.github.ybq.android.spinkit.SpinKitView
            <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 videos -->
        <RelativeLayout
@@ -88,11 +84,10 @@
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent">

            <com.github.ybq.android.spinkit.SpinKitView
            <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                app:SpinKit_Color="?colorAccent" />
                android:layout_gravity="center" />
        </RelativeLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
 No newline at end of file
Loading