2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.fragments;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2020-10-12 20:11:23 +02:00
|
|
|
import android.os.Looper;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2022-04-06 17:27:02 +02:00
|
|
|
import androidx.core.content.ContextCompat;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
2022-04-06 17:27:02 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
2020-03-17 11:32:03 +01:00
|
|
|
import org.mian.gitnex.activities.CreateOrganizationActivity;
|
2020-10-23 20:13:13 +02:00
|
|
|
import org.mian.gitnex.activities.MainActivity;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.adapters.OrganizationsListAdapter;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.FragmentOrganizationsBinding;
|
2022-04-04 10:00:54 +02:00
|
|
|
import org.mian.gitnex.helpers.Constants;
|
2022-04-06 17:27:02 +02:00
|
|
|
import org.mian.gitnex.helpers.DividerItemDecorator;
|
2022-04-04 10:00:54 +02:00
|
|
|
import org.mian.gitnex.viewmodels.OrganizationsViewModel;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-04-04 10:00:54 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class OrganizationsFragment extends Fragment {
|
|
|
|
|
2022-04-22 17:18:38 +02:00
|
|
|
private OrganizationsViewModel organizationsViewModel;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
public static boolean orgCreated = false;
|
2022-04-04 10:00:54 +02:00
|
|
|
private FragmentOrganizationsBinding fragmentOrganizationsBinding;
|
|
|
|
private OrganizationsListAdapter adapter;
|
|
|
|
private int page = 1;
|
2022-04-22 17:18:38 +02:00
|
|
|
private int resultLimit;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding = FragmentOrganizationsBinding.inflate(inflater, container, false);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
setHasOptionsMenu(true);
|
|
|
|
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navOrg));
|
2022-04-22 17:18:38 +02:00
|
|
|
organizationsViewModel = new ViewModelProvider(this).get(OrganizationsViewModel.class);
|
|
|
|
|
|
|
|
resultLimit = Constants.getCurrentResultLimit(getContext());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.addNewOrganization.setOnClickListener(view -> {
|
|
|
|
Intent intent = new Intent(view.getContext(), CreateOrganizationActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.recyclerView.setHasFixedSize(true);
|
|
|
|
fragmentOrganizationsBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
2022-04-06 17:27:02 +02:00
|
|
|
|
|
|
|
RecyclerView.ItemDecoration dividerItemDecoration = new DividerItemDecorator(ContextCompat.getDrawable(requireContext(), R.drawable.shape_list_divider));
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.recyclerView.addItemDecoration(dividerItemDecoration);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
page = 1;
|
|
|
|
fragmentOrganizationsBinding.pullToRefresh.setRefreshing(false);
|
2022-04-18 09:10:54 +02:00
|
|
|
fetchDataAsync();
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.progressBar.setVisibility(View.VISIBLE);
|
|
|
|
}, 50));
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
fetchDataAsync();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
return fragmentOrganizationsBinding.getRoot();
|
|
|
|
};
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private void fetchDataAsync() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-22 17:18:38 +02:00
|
|
|
organizationsViewModel.getUserOrg(page, resultLimit, getContext()).observe(getViewLifecycleOwner(), orgListMain -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-25 07:42:52 +02:00
|
|
|
adapter = new OrganizationsListAdapter(requireContext(), orgListMain);
|
2022-04-04 10:00:54 +02:00
|
|
|
adapter.setLoadMoreListener(new OrganizationsListAdapter.OnLoadMoreListener() {
|
2020-10-12 20:11:23 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
@Override
|
|
|
|
public void onLoadMore() {
|
2020-10-12 20:11:23 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
page += 1;
|
2022-04-22 17:18:38 +02:00
|
|
|
organizationsViewModel.loadMoreOrgList(page, resultLimit, getContext(), adapter);
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.progressBar.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
@Override
|
|
|
|
public void onLoadFinished() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
fragmentOrganizationsBinding.progressBar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-04 10:00:54 +02:00
|
|
|
if(adapter.getItemCount() > 0) {
|
|
|
|
fragmentOrganizationsBinding.recyclerView.setAdapter(adapter);
|
|
|
|
fragmentOrganizationsBinding.noDataOrg.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
adapter.notifyDataChanged();
|
|
|
|
fragmentOrganizationsBinding.recyclerView.setAdapter(adapter);
|
|
|
|
fragmentOrganizationsBinding.noDataOrg.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fragmentOrganizationsBinding.progressBar.setVisibility(View.GONE);
|
|
|
|
});
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume(){
|
|
|
|
super.onResume();
|
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
if(orgCreated) {
|
2022-04-22 17:18:38 +02:00
|
|
|
organizationsViewModel.loadOrgList(page, resultLimit, getContext());
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
orgCreated = false;
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
|
|
|
|
|
|
|
inflater.inflate(R.menu.search_menu, menu);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
|
|
|
|
MenuItem searchItem = menu.findItem(R.id.action_search);
|
|
|
|
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
|
|
|
|
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
|
|
|
|
|
|
|
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
2022-04-04 10:00:54 +02:00
|
|
|
if(fragmentOrganizationsBinding.recyclerView.getAdapter() != null) {
|
2019-09-12 10:30:07 +02:00
|
|
|
adapter.getFilter().filter(newText);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|