Organization labels (#771)
List, Create, Edit & Delete OrgLabels Co-authored-by: M M Arif <mmarif@swatian.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/771 Reviewed-by: 6543 <6543@noreply.codeberg.org>
This commit is contained in:
@@ -28,6 +28,7 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
|
||||
TextView createTeam = v.findViewById(R.id.createTeam);
|
||||
TextView createRepository = v.findViewById(R.id.createRepository);
|
||||
TextView copyOrgUrl = v.findViewById(R.id.copyOrgUrl);
|
||||
TextView createLabel = v.findViewById(R.id.createLabel);
|
||||
|
||||
createTeam.setOnClickListener(v1 -> {
|
||||
|
||||
@@ -35,6 +36,12 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
|
||||
dismiss();
|
||||
});
|
||||
|
||||
createLabel.setOnClickListener(v1 -> {
|
||||
|
||||
bmListener.onButtonClicked("label");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
createRepository.setOnClickListener(v12 -> {
|
||||
|
||||
bmListener.onButtonClicked("repository");
|
||||
|
||||
@@ -10,9 +10,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -22,9 +20,7 @@ import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.adapters.LabelsAdapter;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.models.Labels;
|
||||
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@@ -38,6 +34,7 @@ public class LabelsFragment extends Fragment {
|
||||
private TextView noData;
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private final String type = "repo";
|
||||
|
||||
private String repoName;
|
||||
private String repoOwner;
|
||||
@@ -48,6 +45,7 @@ public class LabelsFragment extends Fragment {
|
||||
}
|
||||
|
||||
public static LabelsFragment newInstance(String param1, String param2) {
|
||||
|
||||
LabelsFragment fragment = new LabelsFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
@@ -58,8 +56,11 @@ public class LabelsFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getArguments() != null) {
|
||||
|
||||
repoName = getArguments().getString(repoNameF);
|
||||
repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
@@ -88,17 +89,16 @@ public class LabelsFragment extends Fragment {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
LabelsViewModel.loadLabelsList(Authorization.get(getContext()), repoOwner, repoName, getContext());
|
||||
|
||||
}, 200));
|
||||
|
||||
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
final TinyDB tinyDb = TinyDB.getInstance(getContext());
|
||||
|
||||
@@ -108,24 +108,29 @@ public class LabelsFragment extends Fragment {
|
||||
final String repoName = parts[1];
|
||||
|
||||
if(tinyDb.getBoolean("labelsRefresh")) {
|
||||
|
||||
LabelsViewModel.loadLabelsList(Authorization.get(getContext()), repoOwner, repoName, getContext());
|
||||
tinyDb.putBoolean("labelsRefresh", false);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -133,21 +138,23 @@ public class LabelsFragment extends Fragment {
|
||||
|
||||
LabelsViewModel labelsModel = new ViewModelProvider(this).get(LabelsViewModel.class);
|
||||
|
||||
labelsModel.getLabelsList(instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Labels>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<Labels> labelsListMain) {
|
||||
adapter = new LabelsAdapter(getContext(), labelsListMain);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
labelsModel.getLabelsList(instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), labelsListMain -> {
|
||||
|
||||
adapter = new LabelsAdapter(getContext(), labelsListMain, type, owner);
|
||||
|
||||
if(adapter.getItemCount() > 0) {
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
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.R;
|
||||
import org.mian.gitnex.adapters.LabelsAdapter;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.viewmodels.OrganizationLabelsViewModel;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class OrganizationLabelsFragment extends Fragment {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView mRecyclerView;
|
||||
private LabelsAdapter adapter;
|
||||
private TextView noData;
|
||||
private static final String repoOwnerF = "param1";
|
||||
private final String type = "org";
|
||||
|
||||
private String repoOwner;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
public static OrganizationLabelsFragment newInstance(String param1) {
|
||||
|
||||
OrganizationLabelsFragment fragment = new OrganizationLabelsFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getArguments() != null) {
|
||||
|
||||
repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_labels, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
|
||||
mRecyclerView = v.findViewById(R.id.recyclerView);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(getContext()), repoOwner, getContext(), mProgressBar, noData);
|
||||
|
||||
}, 200));
|
||||
|
||||
fetchDataAsync(Authorization.get(getContext()), repoOwner);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
final TinyDB tinyDb = TinyDB.getInstance(getContext());
|
||||
|
||||
if(tinyDb.getBoolean("labelsRefresh")) {
|
||||
|
||||
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(getContext()), repoOwner, getContext(), mProgressBar, noData);
|
||||
tinyDb.putBoolean("labelsRefresh", false);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceToken, String owner) {
|
||||
|
||||
OrganizationLabelsViewModel organizationLabelsViewModel = new ViewModelProvider(this).get(OrganizationLabelsViewModel.class);
|
||||
|
||||
organizationLabelsViewModel.getOrgLabelsList(instanceToken, owner, getContext(), mProgressBar, noData).observe(getViewLifecycleOwner(), labelsListMain -> {
|
||||
|
||||
adapter = new LabelsAdapter(getContext(), labelsListMain, type, owner);
|
||||
|
||||
if(adapter.getItemCount() > 0) {
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user