133 lines
4.4 KiB
Java
133 lines
4.4 KiB
Java
package org.mian.gitnex.fragments;
|
|
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.TextView;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.fragment.app.Fragment;
|
|
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 org.mian.gitnex.adapters.ProfileFollowersAdapter;
|
|
import org.mian.gitnex.databinding.FragmentProfileFollowersBinding;
|
|
import org.mian.gitnex.helpers.Authorization;
|
|
import org.mian.gitnex.viewmodels.ProfileFollowersViewModel;
|
|
|
|
/**
|
|
* Author M M Arif
|
|
*/
|
|
|
|
public class ProfileFollowersFragment extends Fragment {
|
|
|
|
private ProgressBar mProgressBar;
|
|
private ProfileFollowersAdapter adapter;
|
|
private RecyclerView mRecyclerView;
|
|
private TextView noDataFollowers;
|
|
private static String repoNameF = "param2";
|
|
private static String repoOwnerF = "param1";
|
|
|
|
private String repoName;
|
|
private String repoOwner;
|
|
|
|
private OnFragmentInteractionListener mListener;
|
|
|
|
public ProfileFollowersFragment() {
|
|
}
|
|
|
|
public static ProfileFollowersFragment newInstance(String param1, String param2) {
|
|
ProfileFollowersFragment fragment = new ProfileFollowersFragment();
|
|
Bundle args = new Bundle();
|
|
args.putString(repoOwnerF, param1);
|
|
args.putString(repoNameF, param2);
|
|
fragment.setArguments(args);
|
|
return fragment;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if (getArguments() != null) {
|
|
repoName = getArguments().getString(repoNameF);
|
|
repoOwner = getArguments().getString(repoOwnerF);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
|
Bundle savedInstanceState) {
|
|
|
|
FragmentProfileFollowersBinding fragmentProfileFollowersBinding = FragmentProfileFollowersBinding.inflate(inflater, container, false);
|
|
|
|
final SwipeRefreshLayout swipeRefresh = fragmentProfileFollowersBinding.pullToRefresh;
|
|
|
|
noDataFollowers = fragmentProfileFollowersBinding.noDataFollowers;
|
|
mRecyclerView = fragmentProfileFollowersBinding.recyclerView;
|
|
|
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
|
|
|
mRecyclerView.setHasFixedSize(true);
|
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
|
|
|
mProgressBar = fragmentProfileFollowersBinding.progressBar;
|
|
|
|
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
|
|
|
swipeRefresh.setRefreshing(false);
|
|
ProfileFollowersViewModel.loadFollowersList(Authorization.get(getContext()), getContext());
|
|
|
|
}, 200));
|
|
|
|
fetchDataAsync(Authorization.get(getContext()));
|
|
|
|
return fragmentProfileFollowersBinding.getRoot();
|
|
}
|
|
|
|
private void fetchDataAsync(String instanceToken) {
|
|
|
|
ProfileFollowersViewModel pfModel = new ViewModelProvider(this).get(ProfileFollowersViewModel.class);
|
|
|
|
pfModel.getFollowersList(instanceToken, getContext()).observe(getViewLifecycleOwner(), pfListMain -> {
|
|
|
|
adapter = new ProfileFollowersAdapter(getContext(), pfListMain);
|
|
|
|
if(adapter.getItemCount() > 0) {
|
|
mRecyclerView.setAdapter(adapter);
|
|
noDataFollowers.setVisibility(View.GONE);
|
|
}
|
|
else {
|
|
adapter.notifyDataSetChanged();
|
|
mRecyclerView.setAdapter(adapter);
|
|
noDataFollowers.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
mProgressBar.setVisibility(View.GONE);
|
|
});
|
|
|
|
}
|
|
|
|
public void onButtonPressed(Uri uri) {
|
|
if (mListener != null) {
|
|
mListener.onFragmentInteraction(uri);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onDetach() {
|
|
super.onDetach();
|
|
mListener = null;
|
|
}
|
|
|
|
public interface OnFragmentInteractionListener {
|
|
void onFragmentInteraction(Uri uri);
|
|
}
|
|
}
|