2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Filter;
|
|
|
|
import android.widget.Filterable;
|
2022-02-22 07:23:46 +01:00
|
|
|
import android.widget.LinearLayout;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.TextView;
|
2021-02-11 11:23:35 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2022-02-22 07:23:46 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
2021-02-11 11:23:35 +01:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.OrganizationPermissions;
|
|
|
|
import org.gitnex.tea4j.v2.models.Team;
|
|
|
|
import org.gitnex.tea4j.v2.models.User;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
2022-02-22 07:23:46 +01:00
|
|
|
import org.mian.gitnex.activities.OrganizationTeamInfoActivity;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2019-06-03 23:25:05 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2022-02-22 07:23:46 +01:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class TeamsByOrgAdapter extends RecyclerView.Adapter<TeamsByOrgAdapter.OrgTeamsViewHolder> implements Filterable {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private final List<Team> teamList;
|
2021-04-13 16:19:42 +02:00
|
|
|
private final Context context;
|
2022-04-18 09:10:54 +02:00
|
|
|
private final List<Team> teamListFull;
|
|
|
|
private final OrganizationPermissions permissions;
|
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
|
|
|
private final String orgName;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
static class OrgTeamsViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private Team team;
|
2021-04-13 16:19:42 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private OrganizationPermissions permissions;
|
2021-04-13 16:19:42 +02:00
|
|
|
private final TextView teamTitle;
|
|
|
|
private final TextView teamDescription;
|
2022-02-22 07:23:46 +01:00
|
|
|
private final LinearLayout membersPreviewFrame;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private final List<User> userInfos;
|
2022-02-22 07:23:46 +01:00
|
|
|
private final TeamMembersByOrgPreviewAdapter adapter;
|
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
|
|
|
private String orgName;
|
2021-04-13 16:19:42 +02:00
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
private OrgTeamsViewHolder(View itemView) {
|
2019-06-03 23:25:05 +02:00
|
|
|
super(itemView);
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
teamTitle = itemView.findViewById(R.id.teamTitle);
|
|
|
|
teamDescription = itemView.findViewById(R.id.teamDescription);
|
2022-02-22 07:23:46 +01:00
|
|
|
membersPreviewFrame = itemView.findViewById(R.id.membersPreviewFrame);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
RecyclerView membersPreview = itemView.findViewById(R.id.membersPreview);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
userInfos = new ArrayList<>();
|
|
|
|
adapter = new TeamMembersByOrgPreviewAdapter(itemView.getContext(), userInfos);
|
|
|
|
|
|
|
|
membersPreview.setLayoutManager(new LinearLayoutManager(itemView.getContext(), RecyclerView.HORIZONTAL, false));
|
|
|
|
membersPreview.setAdapter(adapter);
|
|
|
|
|
|
|
|
itemView.setOnClickListener(v -> {
|
2021-04-13 16:19:42 +02:00
|
|
|
Context context = v.getContext();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
Intent intent = new Intent(context, OrganizationTeamInfoActivity.class);
|
|
|
|
intent.putExtra("team", team);
|
2022-02-11 15:27:31 +01:00
|
|
|
intent.putExtra("permissions", permissions);
|
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
|
|
|
intent.putExtra("orgName", orgName);
|
2021-04-13 16:19:42 +02:00
|
|
|
context.startActivity(intent);
|
2019-06-03 23:25:05 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
public TeamsByOrgAdapter(Context ctx, List<Team> teamListMain, OrganizationPermissions permissions, String orgName) {
|
2021-04-13 16:19:42 +02:00
|
|
|
this.context = ctx;
|
2019-06-03 23:25:05 +02:00
|
|
|
this.teamList = teamListMain;
|
2022-02-11 15:27:31 +01:00
|
|
|
this.permissions = permissions;
|
2019-06-03 23:25:05 +02:00
|
|
|
teamListFull = new ArrayList<>(teamList);
|
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
|
|
|
this.orgName = orgName;
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public TeamsByOrgAdapter.OrgTeamsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2020-03-28 11:52:09 +01:00
|
|
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_teams_by_org, parent, false);
|
2019-06-03 23:25:05 +02:00
|
|
|
return new TeamsByOrgAdapter.OrgTeamsViewHolder(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull TeamsByOrgAdapter.OrgTeamsViewHolder holder, int position) {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
Team currentItem = teamList.get(position);
|
2021-04-13 16:19:42 +02:00
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
holder.team = currentItem;
|
2019-06-03 23:25:05 +02:00
|
|
|
holder.teamTitle.setText(currentItem.getName());
|
2022-02-11 15:27:31 +01:00
|
|
|
holder.permissions = permissions;
|
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
|
|
|
holder.orgName = orgName;
|
2021-04-13 16:19:42 +02:00
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
holder.membersPreviewFrame.setVisibility(View.GONE);
|
|
|
|
holder.userInfos.clear();
|
|
|
|
holder.adapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
RetrofitClient.getApiInterface(context)
|
2022-04-18 09:10:54 +02:00
|
|
|
.orgListTeamMembers(currentItem.getId(), null, null)
|
|
|
|
.enqueue(new Callback<List<User>>() {
|
2022-02-22 07:23:46 +01:00
|
|
|
@Override
|
2022-04-18 09:10:54 +02:00
|
|
|
public void onResponse(@NonNull Call<List<User>> call, @NonNull Response<List<User>> response) {
|
2022-02-22 07:23:46 +01:00
|
|
|
if(response.isSuccessful() &&
|
|
|
|
response.body() != null &&
|
|
|
|
response.body().size() > 0) {
|
|
|
|
|
|
|
|
holder.membersPreviewFrame.setVisibility(View.VISIBLE);
|
|
|
|
holder.userInfos.addAll(response.body().stream()
|
|
|
|
.limit(Math.min(response.body().size(), 6))
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
|
|
holder.adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
@Override public void onFailure(@NonNull Call<List<User>> call, @NonNull Throwable t) {}
|
2022-02-22 07:23:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (currentItem.getDescription() != null && !currentItem.getDescription().isEmpty()) {
|
2019-06-03 23:25:05 +02:00
|
|
|
holder.teamDescription.setVisibility(View.VISIBLE);
|
|
|
|
holder.teamDescription.setText(currentItem.getDescription());
|
2022-02-22 07:23:46 +01:00
|
|
|
} else {
|
2019-06-03 23:25:05 +02:00
|
|
|
holder.teamDescription.setVisibility(View.GONE);
|
|
|
|
holder.teamDescription.setText("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return teamList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Filter getFilter() {
|
|
|
|
return orgTeamsFilter;
|
|
|
|
}
|
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
private final Filter orgTeamsFilter = new Filter() {
|
2019-06-03 23:25:05 +02:00
|
|
|
@Override
|
|
|
|
protected FilterResults performFiltering(CharSequence constraint) {
|
2022-04-18 09:10:54 +02:00
|
|
|
List<Team> filteredList = new ArrayList<>();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
if (constraint == null || constraint.length() == 0) {
|
|
|
|
filteredList.addAll(teamListFull);
|
|
|
|
} else {
|
|
|
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
for (Team item : teamListFull) {
|
2019-06-03 23:25:05 +02:00
|
|
|
if (item.getName().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
|
|
|
filteredList.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterResults results = new FilterResults();
|
|
|
|
results.values = filteredList;
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
|
|
|
teamList.clear();
|
2022-04-18 09:10:54 +02:00
|
|
|
teamList.addAll((List<Team>) results.values);
|
2019-06-03 23:25:05 +02:00
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|