Remove static calls from viewmodels

This commit is contained in:
M M Arif
2022-04-19 16:16:10 +05:00
parent 49a532e462
commit 8aeb413b82
31 changed files with 111 additions and 106 deletions
@@ -14,11 +14,12 @@ import org.mian.gitnex.databinding.ActivityAdminCronTasksBinding;
import org.mian.gitnex.viewmodels.AdminCronTasksViewModel;
/**
* Author M M Arif
* @author M M Arif
*/
public class AdminCronTasksActivity extends BaseActivity {
private AdminCronTasksViewModel adminCronTasksViewModel;
private View.OnClickListener onClickListener;
private AdminCronTasksAdapter adapter;
@@ -34,6 +35,7 @@ public class AdminCronTasksActivity extends BaseActivity {
activityAdminCronTasksBinding = ActivityAdminCronTasksBinding.inflate(getLayoutInflater());
setContentView(activityAdminCronTasksBinding.getRoot());
adminCronTasksViewModel = new ViewModelProvider(this).get(AdminCronTasksViewModel.class);
initCloseListener();
activityAdminCronTasksBinding.close.setOnClickListener(onClickListener);
@@ -51,7 +53,7 @@ public class AdminCronTasksActivity extends BaseActivity {
activityAdminCronTasksBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
activityAdminCronTasksBinding.pullToRefresh.setRefreshing(false);
AdminCronTasksViewModel.loadCronTasksList(ctx, PAGE, LIMIT);
adminCronTasksViewModel.loadCronTasksList(ctx, PAGE, LIMIT);
}, 500));
@@ -29,6 +29,7 @@ import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
public class AdminGetUsersActivity extends BaseActivity implements BottomSheetListener {
private AdminGetUsersViewModel adminGetUsersViewModel;
private View.OnClickListener onClickListener;
private ActivityAdminGetUsersBinding activityAdminGetUsersBinding;
private AdminGetUsersAdapter adapter;
@@ -42,6 +43,7 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetLi
activityAdminGetUsersBinding = ActivityAdminGetUsersBinding.inflate(getLayoutInflater());
setContentView(activityAdminGetUsersBinding.getRoot());
adminGetUsersViewModel = new ViewModelProvider(this).get(AdminGetUsersViewModel.class);
Toolbar toolbar = activityAdminGetUsersBinding.toolbar;
setSupportActionBar(toolbar);
@@ -79,7 +81,7 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetLi
public void onLoadMore() {
page += 1;
AdminGetUsersViewModel.loadMoreUsersList(page, resultLimit, ctx, adapter);
adminGetUsersViewModel.loadMoreUsersList(page, resultLimit, ctx, adapter);
activityAdminGetUsersBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -12,6 +12,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
import org.gitnex.tea4j.v2.models.CreateLabelOption;
import org.gitnex.tea4j.v2.models.EditLabelOption;
@@ -30,13 +31,15 @@ import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
* @author M M Arif
*/
public class CreateLabelActivity extends BaseActivity {
public static boolean refreshLabels = false;
private OrganizationLabelsViewModel organizationLabelsViewModel;
private LabelsViewModel labelsViewModel;
private View.OnClickListener onClickListener;
private TextView colorPicker;
private EditText labelName;
@@ -53,6 +56,8 @@ public class CreateLabelActivity extends BaseActivity {
ActivityCreateLabelBinding activityCreateLabelBinding = ActivityCreateLabelBinding.inflate(getLayoutInflater());
setContentView(activityCreateLabelBinding.getRoot());
labelsViewModel = new ViewModelProvider(this).get(LabelsViewModel.class);
organizationLabelsViewModel = new ViewModelProvider(this).get(OrganizationLabelsViewModel.class);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -345,11 +350,11 @@ public class CreateLabelActivity extends BaseActivity {
Toasty.success(ctx, getString(R.string.labelDeleteText));
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
OrganizationLabelsViewModel.loadOrgLabelsList(getIntent().getStringExtra("orgName"), ctx, null, null);
organizationLabelsViewModel.loadOrgLabelsList(getIntent().getStringExtra("orgName"), ctx, null, null);
}
else {
LabelsViewModel.loadLabelsList(repository.getOwner(), repository.getName(), ctx);
labelsViewModel.loadLabelsList(repository.getOwner(), repository.getName(), ctx);
}
}
}
@@ -26,6 +26,7 @@ import org.mian.gitnex.viewmodels.IssuesViewModel;
public class ExploreIssuesFragment extends Fragment {
private IssuesViewModel issuesViewModel;
private FragmentSearchIssuesBinding viewBinding;
private ExploreIssuesAdapter adapter;
private int page = 1;
@@ -35,6 +36,7 @@ public class ExploreIssuesFragment extends Fragment {
viewBinding = FragmentSearchIssuesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
issuesViewModel = new ViewModelProvider(this).get(IssuesViewModel.class);
viewBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
@@ -55,9 +57,7 @@ public class ExploreIssuesFragment extends Fragment {
private void fetchDataAsync(String searchKeyword) {
IssuesViewModel issuesModel = new ViewModelProvider(this).get(IssuesViewModel.class);
issuesModel.getIssuesList(searchKeyword, "issues", null, "open", null, getContext()).observe(getViewLifecycleOwner(), issuesListMain -> {
issuesViewModel.getIssuesList(searchKeyword, "issues", null, "open", null, getContext()).observe(getViewLifecycleOwner(), issuesListMain -> {
adapter = new ExploreIssuesAdapter(issuesListMain, getContext());
adapter.setLoadMoreListener(new ExploreIssuesAdapter.OnLoadMoreListener() {
@@ -66,7 +66,7 @@ public class ExploreIssuesFragment extends Fragment {
public void onLoadMore() {
page += 1;
IssuesViewModel.loadMoreIssues(searchKeyword, "issues", null, "open", page, null, getContext(), adapter);
issuesViewModel.loadMoreIssues(searchKeyword, "issues", null, "open", page, null, getContext(), adapter);
viewBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -22,11 +22,12 @@ import org.mian.gitnex.helpers.contexts.RepositoryContext;
import org.mian.gitnex.viewmodels.LabelsViewModel;
/**
* Author M M Arif
* @author M M Arif
*/
public class LabelsFragment extends Fragment {
private LabelsViewModel labelsViewModel;
private ProgressBar mProgressBar;
private RecyclerView mRecyclerView;
private LabelsAdapter adapter;
@@ -55,6 +56,7 @@ public class LabelsFragment extends Fragment {
FragmentLabelsBinding fragmentLabelsBinding = FragmentLabelsBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
labelsViewModel = new ViewModelProvider(this).get(LabelsViewModel.class);
final SwipeRefreshLayout swipeRefresh = fragmentLabelsBinding.pullToRefresh;
noData = fragmentLabelsBinding.noData;
@@ -72,7 +74,7 @@ public class LabelsFragment extends Fragment {
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
swipeRefresh.setRefreshing(false);
LabelsViewModel.loadLabelsList(repository.getOwner(), repository.getName(), getContext());
labelsViewModel.loadLabelsList(repository.getOwner(), repository.getName(), getContext());
}, 200));
fetchDataAsync(repository.getOwner(), repository.getName());
@@ -87,7 +89,7 @@ public class LabelsFragment extends Fragment {
if(CreateLabelActivity.refreshLabels) {
LabelsViewModel.loadLabelsList(repository.getOwner(), repository.getName(), getContext());
labelsViewModel.loadLabelsList(repository.getOwner(), repository.getName(), getContext());
CreateLabelActivity.refreshLabels = false;
}
}
@@ -33,6 +33,7 @@ import java.util.List;
public class MilestonesFragment extends Fragment {
private MilestonesViewModel milestonesViewModel;
private FragmentMilestonesBinding viewBinding;
private Menu menu;
private List<Milestone> dataList;
@@ -60,6 +61,7 @@ public class MilestonesFragment extends Fragment {
viewBinding = FragmentMilestonesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
Context ctx = getContext();
milestonesViewModel = new ViewModelProvider(this).get(MilestonesViewModel.class);
milestoneId = requireActivity().getIntent().getStringExtra("milestoneId");
requireActivity().getIntent().removeExtra("milestoneId");
@@ -106,8 +108,6 @@ public class MilestonesFragment extends Fragment {
private void fetchDataAsync(String repoOwner, String repoName, String state) {
MilestonesViewModel milestonesViewModel = new ViewModelProvider(this).get(MilestonesViewModel.class);
milestonesViewModel.getMilestonesList(repoOwner, repoName, state, getContext()).observe(getViewLifecycleOwner(), milestonesListMain -> {
adapter = new MilestonesAdapter(getContext(), milestonesListMain, repository);
@@ -117,7 +117,7 @@ public class MilestonesFragment extends Fragment {
public void onLoadMore() {
page += 1;
MilestonesViewModel.loadMoreMilestones(repoOwner, repoName, page, state, getContext(), adapter);
milestonesViewModel.loadMoreMilestones(repoOwner, repoName, page, state, getContext(), adapter);
viewBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -27,6 +27,7 @@ import org.mian.gitnex.viewmodels.IssuesViewModel;
public class MyIssuesFragment extends Fragment {
private IssuesViewModel issuesViewModel;
private FragmentIssuesBinding fragmentIssuesBinding;
private ExploreIssuesAdapter adapter;
private int page = 1;
@@ -39,6 +40,7 @@ public class MyIssuesFragment extends Fragment {
fragmentIssuesBinding = FragmentIssuesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
issuesViewModel = new ViewModelProvider(this).get(IssuesViewModel.class);
fragmentIssuesBinding.recyclerView.setHasFixedSize(true);
fragmentIssuesBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
@@ -68,7 +70,7 @@ public class MyIssuesFragment extends Fragment {
page = 1;
fragmentIssuesBinding.pullToRefresh.setRefreshing(false);
IssuesViewModel.loadIssuesList(null, "issues", true, state, assignedToMe, getContext());
issuesViewModel.loadIssuesList(null, "issues", true, state, assignedToMe, getContext());
fragmentIssuesBinding.progressBar.setVisibility(View.VISIBLE);
}, 50));
@@ -79,9 +81,7 @@ public class MyIssuesFragment extends Fragment {
private void fetchDataAsync(String query, String state, boolean assignedToMe) {
IssuesViewModel issuesModel = new ViewModelProvider(this).get(IssuesViewModel.class);
issuesModel.getIssuesList(query, "issues", true, state, assignedToMe, getContext()).observe(getViewLifecycleOwner(), issuesListMain -> {
issuesViewModel.getIssuesList(query, "issues", true, state, assignedToMe, getContext()).observe(getViewLifecycleOwner(), issuesListMain -> {
adapter = new ExploreIssuesAdapter(issuesListMain, getContext());
adapter.setLoadMoreListener(new ExploreIssuesAdapter.OnLoadMoreListener() {
@@ -90,7 +90,7 @@ public class MyIssuesFragment extends Fragment {
public void onLoadMore() {
page += 1;
IssuesViewModel.loadMoreIssues(query, "issues", true, state, page, assignedToMe, getContext(), adapter);
issuesViewModel.loadMoreIssues(query, "issues", true, state, page, assignedToMe, getContext(), adapter);
fragmentIssuesBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -20,11 +20,12 @@ import org.mian.gitnex.databinding.FragmentProfileEmailsBinding;
import org.mian.gitnex.viewmodels.ProfileEmailsViewModel;
/**
* Author M M Arif
* @author M M Arif
*/
public class MyProfileEmailsFragment extends Fragment {
private ProfileEmailsViewModel profileEmailsViewModel;
public static boolean refreshEmails = false;
private ProgressBar mProgressBar;
@@ -40,6 +41,7 @@ public class MyProfileEmailsFragment extends Fragment {
Bundle savedInstanceState) {
FragmentProfileEmailsBinding fragmentProfileEmailsBinding = FragmentProfileEmailsBinding.inflate(inflater, container, false);
profileEmailsViewModel = new ViewModelProvider(this).get(ProfileEmailsViewModel.class);
final SwipeRefreshLayout swipeRefresh = fragmentProfileEmailsBinding.pullToRefresh;
@@ -57,21 +59,18 @@ public class MyProfileEmailsFragment extends Fragment {
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
swipeRefresh.setRefreshing(false);
ProfileEmailsViewModel.loadEmailsList(getContext());
profileEmailsViewModel.loadEmailsList(getContext());
}, 200));
fetchDataAsync();
return fragmentProfileEmailsBinding.getRoot();
}
private void fetchDataAsync() {
ProfileEmailsViewModel profileEmailModel = new ViewModelProvider(this).get(ProfileEmailsViewModel.class);
profileEmailModel.getEmailsList(getContext()).observe(getViewLifecycleOwner(), emailsListMain -> {
profileEmailsViewModel.getEmailsList(getContext()).observe(getViewLifecycleOwner(), emailsListMain -> {
adapter = new MyProfileEmailsAdapter(getContext(), emailsListMain);
if(adapter.getItemCount() > 0) {
mRecyclerView.setAdapter(adapter);
@@ -89,13 +88,11 @@ public class MyProfileEmailsFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
if(refreshEmails) {
ProfileEmailsViewModel.loadEmailsList(getContext());
profileEmailsViewModel.loadEmailsList(getContext());
refreshEmails = false;
}
}
}
@@ -31,6 +31,7 @@ import org.mian.gitnex.viewmodels.RepositoriesViewModel;
public class MyRepositoriesFragment extends Fragment {
private RepositoriesViewModel repositoriesViewModel;
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
private ReposListAdapter adapter;
private int page = 1;
@@ -40,9 +41,10 @@ public class MyRepositoriesFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentRepositoriesBinding = FragmentRepositoriesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navMyRepos));
repositoriesViewModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
final String userLogin = ((BaseActivity) requireActivity()).getAccount().getAccount().getUserName();
fragmentRepositoriesBinding.addNewRepo.setOnClickListener(view -> {
@@ -71,9 +73,7 @@ public class MyRepositoriesFragment extends Fragment {
private void fetchDataAsync(String userLogin) {
RepositoriesViewModel reposModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
reposModel.getRepositories(page, resultLimit, userLogin, "myRepos", null, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
repositoriesViewModel.getRepositories(page, resultLimit, userLogin, "myRepos", null, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
adapter = new ReposListAdapter(reposListMain, getContext());
adapter.setLoadMoreListener(new ReposListAdapter.OnLoadMoreListener() {
@@ -82,7 +82,7 @@ public class MyRepositoriesFragment extends Fragment {
public void onLoadMore() {
page += 1;
RepositoriesViewModel.loadMoreRepos(page, resultLimit, userLogin, "myRepos", null, getContext(), adapter);
repositoriesViewModel.loadMoreRepos(page, resultLimit, userLogin, "myRepos", null, getContext(), adapter);
fragmentRepositoriesBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -21,11 +21,12 @@ import org.mian.gitnex.databinding.FragmentLabelsBinding;
import org.mian.gitnex.viewmodels.OrganizationLabelsViewModel;
/**
* Author M M Arif
* @author M M Arif
*/
public class OrganizationLabelsFragment extends Fragment {
private OrganizationLabelsViewModel organizationLabelsViewModel;
private ProgressBar mProgressBar;
private RecyclerView mRecyclerView;
private LabelsAdapter adapter;
@@ -60,6 +61,7 @@ public class OrganizationLabelsFragment extends Fragment {
FragmentLabelsBinding fragmentLabelsBinding = FragmentLabelsBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
organizationLabelsViewModel = new ViewModelProvider(this).get(OrganizationLabelsViewModel.class);
final SwipeRefreshLayout swipeRefresh = fragmentLabelsBinding.pullToRefresh;
noData = fragmentLabelsBinding.noData;
@@ -77,7 +79,7 @@ public class OrganizationLabelsFragment extends Fragment {
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
swipeRefresh.setRefreshing(false);
OrganizationLabelsViewModel.loadOrgLabelsList(repoOwner, getContext(), mProgressBar, noData);
organizationLabelsViewModel.loadOrgLabelsList(repoOwner, getContext(), mProgressBar, noData);
}, 200));
@@ -94,15 +96,13 @@ public class OrganizationLabelsFragment extends Fragment {
if(CreateLabelActivity.refreshLabels) {
OrganizationLabelsViewModel.loadOrgLabelsList(repoOwner, getContext(), mProgressBar, noData);
organizationLabelsViewModel.loadOrgLabelsList(repoOwner, getContext(), mProgressBar, noData);
CreateLabelActivity.refreshLabels = false;
}
}
private void fetchDataAsync(String owner) {
OrganizationLabelsViewModel organizationLabelsViewModel = new ViewModelProvider(this).get(OrganizationLabelsViewModel.class);
organizationLabelsViewModel.getOrgLabelsList(owner, getContext(), mProgressBar, noData).observe(getViewLifecycleOwner(), labelsListMain -> {
adapter = new LabelsAdapter(getContext(), labelsListMain, type, owner);
@@ -32,6 +32,7 @@ import org.mian.gitnex.viewmodels.OrganizationsViewModel;
public class OrganizationsFragment extends Fragment {
private OrganizationsViewModel organizationsViewModel;
public static boolean orgCreated = false;
private FragmentOrganizationsBinding fragmentOrganizationsBinding;
private OrganizationsListAdapter adapter;
@@ -45,6 +46,7 @@ public class OrganizationsFragment extends Fragment {
setHasOptionsMenu(true);
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navOrg));
organizationsViewModel = new ViewModelProvider(this).get(OrganizationsViewModel.class);
fragmentOrganizationsBinding.addNewOrganization.setOnClickListener(view -> {
Intent intent = new Intent(view.getContext(), CreateOrganizationActivity.class);
@@ -72,9 +74,7 @@ public class OrganizationsFragment extends Fragment {
private void fetchDataAsync() {
OrganizationsViewModel orgModel = new ViewModelProvider(this).get(OrganizationsViewModel.class);
orgModel.getUserOrg(page, resultLimit, getContext()).observe(getViewLifecycleOwner(), orgListMain -> {
organizationsViewModel.getUserOrg(page, resultLimit, getContext()).observe(getViewLifecycleOwner(), orgListMain -> {
adapter = new OrganizationsListAdapter(orgListMain, getContext());
adapter.setLoadMoreListener(new OrganizationsListAdapter.OnLoadMoreListener() {
@@ -83,7 +83,7 @@ public class OrganizationsFragment extends Fragment {
public void onLoadMore() {
page += 1;
OrganizationsViewModel.loadMoreOrgList(page, resultLimit, getContext(), adapter);
organizationsViewModel.loadMoreOrgList(page, resultLimit, getContext(), adapter);
fragmentOrganizationsBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -113,7 +113,7 @@ public class OrganizationsFragment extends Fragment {
super.onResume();
if(orgCreated) {
OrganizationsViewModel.loadOrgList(page, resultLimit, getContext());
organizationsViewModel.loadOrgList(page, resultLimit, getContext());
orgCreated = false;
}
}
@@ -25,7 +25,7 @@ import org.mian.gitnex.viewmodels.ReleasesViewModel;
import java.util.List;
/**
* Author M M Arif
* @author M M Arif
*/
public class ReleasesFragment extends Fragment {
@@ -28,6 +28,7 @@ import org.mian.gitnex.viewmodels.RepositoriesViewModel;
public class RepositoriesByOrgFragment extends Fragment {
private RepositoriesViewModel repositoriesViewModel;
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
private ReposListAdapter adapter;
private int page = 1;
@@ -57,8 +58,8 @@ public class RepositoriesByOrgFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentRepositoriesBinding = FragmentRepositoriesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
repositoriesViewModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
fragmentRepositoriesBinding.addNewRepo.setVisibility(View.GONE);
@@ -83,9 +84,7 @@ public class RepositoriesByOrgFragment extends Fragment {
private void fetchDataAsync() {
RepositoriesViewModel reposModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
reposModel.getRepositories(page, resultLimit, "", "org", orgName, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
repositoriesViewModel.getRepositories(page, resultLimit, "", "org", orgName, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
adapter = new ReposListAdapter(reposListMain, getContext());
adapter.setLoadMoreListener(new ReposListAdapter.OnLoadMoreListener() {
@@ -94,7 +93,7 @@ public class RepositoriesByOrgFragment extends Fragment {
public void onLoadMore() {
page += 1;
RepositoriesViewModel.loadMoreRepos(page, resultLimit, "", "org", orgName, getContext(), adapter);
repositoriesViewModel.loadMoreRepos(page, resultLimit, "", "org", orgName, getContext(), adapter);
fragmentRepositoriesBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -125,7 +124,7 @@ public class RepositoriesByOrgFragment extends Fragment {
super.onResume();
if(MainActivity.repoCreated) {
RepositoriesViewModel.loadReposList(page, resultLimit, null, "org", orgName, getContext());
repositoriesViewModel.loadReposList(page, resultLimit, null, "org", orgName, getContext());
MainActivity.repoCreated = false;
}
@@ -32,6 +32,7 @@ import org.mian.gitnex.viewmodels.RepositoriesViewModel;
public class RepositoriesFragment extends Fragment {
private RepositoriesViewModel repositoriesViewModel;
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
private ReposListAdapter adapter;
private int page = 1;
@@ -41,9 +42,9 @@ public class RepositoriesFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentRepositoriesBinding = FragmentRepositoriesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navRepos));
repositoriesViewModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
fragmentRepositoriesBinding.addNewRepo.setOnClickListener(view -> {
Intent intent = new Intent(view.getContext(), CreateRepoActivity.class);
@@ -71,9 +72,7 @@ public class RepositoriesFragment extends Fragment {
private void fetchDataAsync() {
RepositoriesViewModel reposModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
reposModel.getRepositories(page, resultLimit, null, "repos", null, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
repositoriesViewModel.getRepositories(page, resultLimit, null, "repos", null, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
adapter = new ReposListAdapter(reposListMain, getContext());
adapter.setLoadMoreListener(new ReposListAdapter.OnLoadMoreListener() {
@@ -82,7 +81,7 @@ public class RepositoriesFragment extends Fragment {
public void onLoadMore() {
page += 1;
RepositoriesViewModel.loadMoreRepos(page, resultLimit, null, "repos", null, getContext(), adapter);
repositoriesViewModel.loadMoreRepos(page, resultLimit, null, "repos", null, getContext(), adapter);
fragmentRepositoriesBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -30,6 +30,7 @@ import org.mian.gitnex.viewmodels.RepositoriesViewModel;
public class StarredRepositoriesFragment extends Fragment {
private RepositoriesViewModel repositoriesViewModel;
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
private ReposListAdapter adapter;
private int page = 1;
@@ -39,9 +40,9 @@ public class StarredRepositoriesFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragmentRepositoriesBinding = FragmentRepositoriesBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navStarredRepos));
repositoriesViewModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
fragmentRepositoriesBinding.addNewRepo.setOnClickListener(view -> {
Intent intent = new Intent(view.getContext(), CreateRepoActivity.class);
@@ -69,9 +70,7 @@ public class StarredRepositoriesFragment extends Fragment {
private void fetchDataAsync() {
RepositoriesViewModel reposModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
reposModel.getRepositories(page, resultLimit, "", "starredRepos", null, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
repositoriesViewModel.getRepositories(page, resultLimit, "", "starredRepos", null, getContext()).observe(getViewLifecycleOwner(), reposListMain -> {
adapter = new ReposListAdapter(reposListMain, getContext());
adapter.setLoadMoreListener(new ReposListAdapter.OnLoadMoreListener() {
@@ -80,7 +79,7 @@ public class StarredRepositoriesFragment extends Fragment {
public void onLoadMore() {
page += 1;
RepositoriesViewModel.loadMoreRepos(page, resultLimit, "", "starredRepos", null, getContext(), adapter);
repositoriesViewModel.loadMoreRepos(page, resultLimit, "", "starredRepos", null, getContext(), adapter);
fragmentRepositoriesBinding.progressBar.setVisibility(View.VISIBLE);
}
@@ -31,6 +31,7 @@ import org.mian.gitnex.viewmodels.TeamsByOrgViewModel;
public class TeamsByOrgFragment extends Fragment {
private TeamsByOrgViewModel teamsByOrgViewModel;
public static boolean resumeTeams = false;
private ProgressBar mProgressBar;
@@ -68,6 +69,7 @@ public class TeamsByOrgFragment extends Fragment {
FragmentTeamsByOrgBinding fragmentTeamsByOrgBinding = FragmentTeamsByOrgBinding.inflate(inflater, container, false);
setHasOptionsMenu(true);
teamsByOrgViewModel = new ViewModelProvider(this).get(TeamsByOrgViewModel.class);
noDataTeams = fragmentTeamsByOrgBinding.noDataTeams;
@@ -86,7 +88,7 @@ public class TeamsByOrgFragment extends Fragment {
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
swipeRefresh.setRefreshing(false);
TeamsByOrgViewModel.loadTeamsByOrgList(orgName, getContext(), noDataTeams, mProgressBar);
teamsByOrgViewModel.loadTeamsByOrgList(orgName, getContext(), noDataTeams, mProgressBar);
}, 200));
@@ -99,16 +101,14 @@ public class TeamsByOrgFragment extends Fragment {
public void onResume() {
super.onResume();
if(resumeTeams) {
TeamsByOrgViewModel.loadTeamsByOrgList(orgName, getContext(), noDataTeams, mProgressBar);
teamsByOrgViewModel.loadTeamsByOrgList(orgName, getContext(), noDataTeams, mProgressBar);
resumeTeams = false;
}
}
private void fetchDataAsync(String owner) {
TeamsByOrgViewModel teamModel = new ViewModelProvider(this).get(TeamsByOrgViewModel.class);
teamModel.getTeamsByOrg(owner, getContext(), noDataTeams, mProgressBar).observe(getViewLifecycleOwner(), orgTeamsListMain -> {
teamsByOrgViewModel.getTeamsByOrg(owner, getContext(), noDataTeams, mProgressBar).observe(getViewLifecycleOwner(), orgTeamsListMain -> {
adapter = new TeamsByOrgAdapter(getContext(), orgTeamsListMain, permissions, orgName);
if(adapter.getItemCount() > 0) {
mRecyclerView.setAdapter(adapter);
@@ -21,7 +21,7 @@ import retrofit2.Response;
public class AdminCronTasksViewModel extends ViewModel {
private static MutableLiveData<List<Cron>> tasksList;
private MutableLiveData<List<Cron>> tasksList;
public LiveData<List<Cron>> getCronTasksList(Context ctx, int page, int limit) {
@@ -31,7 +31,7 @@ public class AdminCronTasksViewModel extends ViewModel {
return tasksList;
}
public static void loadCronTasksList(final Context ctx, int page, int limit) {
public void loadCronTasksList(final Context ctx, int page, int limit) {
Call<List<Cron>> call = RetrofitClient
.getApiInterface(ctx)
@@ -21,7 +21,7 @@ import retrofit2.Response;
public class AdminGetUsersViewModel extends ViewModel {
private static MutableLiveData<List<User>> usersList;
private MutableLiveData<List<User>> usersList;
public LiveData<List<User>> getUsersList(int page, int resultLimit, Context ctx) {
@@ -31,7 +31,7 @@ public class AdminGetUsersViewModel extends ViewModel {
return usersList;
}
public static void loadUsersList(int page, int resultLimit, Context ctx) {
public void loadUsersList(int page, int resultLimit, Context ctx) {
Call<List<User>> call = RetrofitClient
.getApiInterface(ctx)
@@ -57,7 +57,7 @@ public class AdminGetUsersViewModel extends ViewModel {
});
}
public static void loadMoreUsersList(int page, int resultLimit, Context ctx, AdminGetUsersAdapter adapter) {
public void loadMoreUsersList(int page, int resultLimit, Context ctx, AdminGetUsersAdapter adapter) {
Call<List<User>> call = RetrofitClient
.getApiInterface(ctx)
@@ -20,7 +20,7 @@ import retrofit2.Response;
public class CollaboratorsViewModel extends ViewModel {
private static MutableLiveData<List<User>> collaboratorsList;
private MutableLiveData<List<User>> collaboratorsList;
public LiveData<List<User>> getCollaboratorsList(String owner, String repo, Context ctx) {
@@ -30,7 +30,7 @@ public class CollaboratorsViewModel extends ViewModel {
return collaboratorsList;
}
private static void loadCollaboratorsListList(String owner, String repo, Context ctx) {
private void loadCollaboratorsListList(String owner, String repo, Context ctx) {
Call<List<User>> call = RetrofitClient
.getApiInterface(ctx)
@@ -25,8 +25,8 @@ import retrofit2.Response;
public class FilesViewModel extends ViewModel {
private static MutableLiveData<List<ContentsResponse>> filesList;
private static MutableLiveData<List<ContentsResponse>> filesList2;
private MutableLiveData<List<ContentsResponse>> filesList;
private MutableLiveData<List<ContentsResponse>> filesList2;
public LiveData<List<ContentsResponse>> getFilesList(String owner, String repo, String ref, Context ctx, ProgressBar progressBar, TextView noDataFiles) {
@@ -36,7 +36,7 @@ public class FilesViewModel extends ViewModel {
return filesList;
}
private static void loadFilesList(String owner, String repo, String ref, final Context ctx, ProgressBar progressBar, TextView noDataFiles) {
private void loadFilesList(String owner, String repo, String ref, final Context ctx, ProgressBar progressBar, TextView noDataFiles) {
Call<List<ContentsResponse>> call = RetrofitClient
.getApiInterface(ctx)
@@ -73,7 +73,7 @@ public class FilesViewModel extends ViewModel {
return filesList2;
}
private static void loadFilesList2(String owner, String repo, String filesDir, String ref, final Context ctx, ProgressBar progressBar, TextView noDataFiles) {
private void loadFilesList2(String owner, String repo, String filesDir, String ref, final Context ctx, ProgressBar progressBar, TextView noDataFiles) {
Call<List<ContentsResponse>> call = RetrofitClient
.getApiInterface(ctx)
@@ -23,8 +23,8 @@ import retrofit2.Response;
public class IssuesViewModel extends ViewModel {
private static MutableLiveData<List<Issue>> issuesList;
private static int resultLimit = Constants.resultLimitOldGiteaInstances;
private MutableLiveData<List<Issue>> issuesList;
private int resultLimit = Constants.resultLimitOldGiteaInstances;
public LiveData<List<Issue>> getIssuesList(String searchKeyword, String type, Boolean created, String state, Boolean assignedToMe, Context ctx) {
@@ -40,7 +40,7 @@ public class IssuesViewModel extends ViewModel {
return issuesList;
}
public static void loadIssuesList(String searchKeyword, String type, Boolean created, String state, Boolean assignedToMe, Context ctx) {
public void loadIssuesList(String searchKeyword, String type, Boolean created, String state, Boolean assignedToMe, Context ctx) {
Call<List<Issue>> call = RetrofitClient.getApiInterface(ctx)
.issueSearchIssues(state, null, null, searchKeyword, null, type, null, null, assignedToMe, created, null, null, null, null, 1,
@@ -67,7 +67,7 @@ public class IssuesViewModel extends ViewModel {
});
}
public static void loadMoreIssues(String searchKeyword, String type, Boolean created, String state, int page, Boolean assignedToMe, Context ctx, ExploreIssuesAdapter adapter) {
public void loadMoreIssues(String searchKeyword, String type, Boolean created, String state, int page, Boolean assignedToMe, Context ctx, ExploreIssuesAdapter adapter) {
Call<List<Issue>> call = RetrofitClient.getApiInterface(ctx)
.issueSearchIssues(state, null, null, searchKeyword, null, type, null, null, assignedToMe, created, null, null, null, null, page, resultLimit);
@@ -20,7 +20,7 @@ import retrofit2.Response;
public class LabelsViewModel extends ViewModel {
private static MutableLiveData<List<Label>> labelsList;
private MutableLiveData<List<Label>> labelsList;
public LiveData<List<Label>> getLabelsList(String owner, String repo, Context ctx) {
@@ -30,7 +30,7 @@ public class LabelsViewModel extends ViewModel {
return labelsList;
}
public static void loadLabelsList(String owner, String repo, Context ctx) {
public void loadLabelsList(String owner, String repo, Context ctx) {
Call<List<Label>> call = RetrofitClient
.getApiInterface(ctx)
@@ -20,7 +20,7 @@ import retrofit2.Response;
public class MembersByOrgViewModel extends ViewModel {
private static MutableLiveData<List<User>> membersList;
private MutableLiveData<List<User>> membersList;
public LiveData<List<User>> getMembersList(String owner, Context ctx) {
@@ -30,7 +30,7 @@ public class MembersByOrgViewModel extends ViewModel {
return membersList;
}
private static void loadMembersList(String owner, Context ctx) {
private void loadMembersList(String owner, Context ctx) {
Call<List<User>> call = RetrofitClient
.getApiInterface(ctx)
@@ -22,8 +22,8 @@ import retrofit2.Response;
public class MilestonesViewModel extends ViewModel {
private static MutableLiveData<List<Milestone>> milestonesList;
private static final int resultLimit = Constants.resultLimitNewGiteaInstances;
private MutableLiveData<List<Milestone>> milestonesList;
private final int resultLimit = Constants.resultLimitNewGiteaInstances;
public LiveData<List<Milestone>> getMilestonesList(String repoOwner, String repoName, String milestoneState, Context ctx) {
@@ -33,7 +33,7 @@ public class MilestonesViewModel extends ViewModel {
return milestonesList;
}
public static void loadMilestonesList(String repoOwner, String repoName, String milestoneState, Context ctx) {
public void loadMilestonesList(String repoOwner, String repoName, String milestoneState, Context ctx) {
Call<List<Milestone>> call = RetrofitClient.getApiInterface(ctx).issueGetMilestonesList(repoOwner, repoName, milestoneState, null, 1, resultLimit);
@@ -58,7 +58,7 @@ public class MilestonesViewModel extends ViewModel {
});
}
public static void loadMoreMilestones(String repoOwner, String repoName, int page, String milestoneState, Context ctx, MilestonesAdapter adapter) {
public void loadMoreMilestones(String repoOwner, String repoName, int page, String milestoneState, Context ctx, MilestonesAdapter adapter) {
Call<List<Milestone>> call = RetrofitClient.getApiInterface(ctx).issueGetMilestonesList(repoOwner, repoName, milestoneState, null, page, resultLimit);
@@ -23,7 +23,7 @@ import retrofit2.Response;
public class OrganizationLabelsViewModel extends ViewModel {
private static MutableLiveData<List<Label>> orgLabelsList;
private MutableLiveData<List<Label>> orgLabelsList;
public LiveData<List<Label>> getOrgLabelsList(String owner, Context ctx, ProgressBar progressBar, TextView noData) {
@@ -33,7 +33,7 @@ public class OrganizationLabelsViewModel extends ViewModel {
return orgLabelsList;
}
public static void loadOrgLabelsList(String owner, Context ctx, ProgressBar progressBar, TextView noData) {
public void loadOrgLabelsList(String owner, Context ctx, ProgressBar progressBar, TextView noData) {
Call<List<Label>> call = RetrofitClient
.getApiInterface(ctx)
@@ -21,7 +21,7 @@ import retrofit2.Response;
public class OrganizationsViewModel extends ViewModel {
private static MutableLiveData<List<Organization>> orgList;
private MutableLiveData<List<Organization>> orgList;
public LiveData<List<Organization>> getUserOrg(int page, int resultLimit, Context ctx) {
@@ -31,7 +31,7 @@ public class OrganizationsViewModel extends ViewModel {
return orgList;
}
public static void loadOrgList(int page, int resultLimit, Context ctx) {
public void loadOrgList(int page, int resultLimit, Context ctx) {
Call<List<Organization>> call = RetrofitClient
.getApiInterface(ctx)
@@ -58,7 +58,7 @@ public class OrganizationsViewModel extends ViewModel {
});
}
public static void loadMoreOrgList(int page, int resultLimit, Context ctx, OrganizationsListAdapter adapter) {
public void loadMoreOrgList(int page, int resultLimit, Context ctx, OrganizationsListAdapter adapter) {
Call<List<Organization>> call = RetrofitClient
.getApiInterface(ctx)
@@ -20,7 +20,7 @@ import retrofit2.Response;
public class ProfileEmailsViewModel extends ViewModel {
private static MutableLiveData<List<Email>> emailsList;
private MutableLiveData<List<Email>> emailsList;
public LiveData<List<Email>> getEmailsList(Context ctx) {
@@ -30,7 +30,7 @@ public class ProfileEmailsViewModel extends ViewModel {
return emailsList;
}
public static void loadEmailsList(Context ctx) {
public void loadEmailsList(Context ctx) {
Call<List<Email>> call = RetrofitClient
.getApiInterface(ctx)
@@ -20,7 +20,7 @@ import retrofit2.Response;
public class RepoStargazersViewModel extends ViewModel {
private static MutableLiveData<List<User>> stargazersList;
private MutableLiveData<List<User>> stargazersList;
public LiveData<List<User>> getRepoStargazers(String repoOwner, String repoName, Context ctx) {
@@ -30,7 +30,7 @@ public class RepoStargazersViewModel extends ViewModel {
return stargazersList;
}
private static void loadRepoStargazers(String repoOwner, String repoName, Context ctx) {
private void loadRepoStargazers(String repoOwner, String repoName, Context ctx) {
Call<List<User>> call = RetrofitClient
.getApiInterface(ctx)
@@ -20,7 +20,7 @@ import retrofit2.Response;
public class RepoWatchersViewModel extends ViewModel {
private static MutableLiveData<List<User>> watchersList;
private MutableLiveData<List<User>> watchersList;
public LiveData<List<User>> getRepoWatchers(String repoOwner, String repoName, Context ctx) {
@@ -30,7 +30,7 @@ public class RepoWatchersViewModel extends ViewModel {
return watchersList;
}
private static void loadRepoWatchers(String repoOwner, String repoName, Context ctx) {
private void loadRepoWatchers(String repoOwner, String repoName, Context ctx) {
Call<List<User>> call = RetrofitClient
.getApiInterface(ctx)
@@ -21,7 +21,7 @@ import retrofit2.Response;
public class RepositoriesViewModel extends ViewModel {
private static MutableLiveData<List<Repository>> reposList;
private MutableLiveData<List<Repository>> reposList;
public LiveData<List<Repository>> getRepositories(int page, int resultLimit, String userLogin, String type, String orgName, Context ctx) {
@@ -31,7 +31,7 @@ public class RepositoriesViewModel extends ViewModel {
return reposList;
}
public static void loadReposList(int page, int resultLimit, String userLogin, String type, String orgName, Context ctx) {
public void loadReposList(int page, int resultLimit, String userLogin, String type, String orgName, Context ctx) {
Call<List<Repository>> call;
@@ -74,7 +74,7 @@ public class RepositoriesViewModel extends ViewModel {
});
}
public static void loadMoreRepos(int page, int resultLimit, String userLogin, String type, String orgName, Context ctx, ReposListAdapter adapter) {
public void loadMoreRepos(int page, int resultLimit, String userLogin, String type, String orgName, Context ctx, ReposListAdapter adapter) {
Call<List<Repository>> call;
@@ -23,7 +23,7 @@ import retrofit2.Response;
public class TeamsByOrgViewModel extends ViewModel {
private static MutableLiveData<List<Team>> teamsList;
private MutableLiveData<List<Team>> teamsList;
public LiveData<List<Team>> getTeamsByOrg(String orgName, Context ctx, TextView noDataTeams, ProgressBar mProgressBar) {
@@ -33,7 +33,7 @@ public class TeamsByOrgViewModel extends ViewModel {
return teamsList;
}
public static void loadTeamsByOrgList(String orgName, Context ctx, TextView noDataTeams, ProgressBar mProgressBar) {
public void loadTeamsByOrgList(String orgName, Context ctx, TextView noDataTeams, ProgressBar mProgressBar) {
Call<List<Team>> call = RetrofitClient
.getApiInterface(ctx)