2022-02-22 07:23:46 +01:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.OrganizationPermissions;
|
|
|
|
import org.gitnex.tea4j.v2.models.Team;
|
2022-02-22 07:23:46 +01:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.databinding.ActivityOrgTeamInfoBinding;
|
|
|
|
import org.mian.gitnex.fragments.BottomSheetOrganizationTeamsFragment;
|
|
|
|
import org.mian.gitnex.fragments.OrganizationTeamInfoMembersFragment;
|
|
|
|
import org.mian.gitnex.fragments.OrganizationTeamInfoPermissionsFragment;
|
2022-04-21 23:02:59 +02:00
|
|
|
import org.mian.gitnex.fragments.OrganizationTeamInfoReposFragment;
|
2022-02-22 07:23:46 +01:00
|
|
|
import org.mian.gitnex.structs.BottomSheetListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class OrganizationTeamInfoActivity extends BaseActivity implements BottomSheetListener {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private Team team;
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
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
|
|
|
org.mian.gitnex.databinding.ActivityOrgTeamInfoBinding binding = ActivityOrgTeamInfoBinding.inflate(getLayoutInflater());
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
setSupportActionBar(binding.toolbar);
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
team = (Team) getIntent().getSerializableExtra("team");
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
if(team.getName() != null && !team.getName().isEmpty()) {
|
|
|
|
binding.toolbarTitle.setText(team.getName());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
binding.toolbarTitle.setText(R.string.orgTeamMembers);
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.close.setOnClickListener(view -> finish());
|
2022-04-21 23:02:59 +02:00
|
|
|
binding.pager.setOffscreenPageLimit(1);
|
2022-02-22 07:23:46 +01:00
|
|
|
binding.pager.setAdapter(new FragmentStateAdapter(getSupportFragmentManager(), getLifecycle()) {
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Fragment createFragment(int position) {
|
|
|
|
switch(position) {
|
|
|
|
case 0:
|
2022-04-21 23:02:59 +02:00
|
|
|
return OrganizationTeamInfoReposFragment.newInstance(team);
|
2022-02-22 07:23:46 +01:00
|
|
|
case 1:
|
2022-04-21 23:02:59 +02:00
|
|
|
return OrganizationTeamInfoMembersFragment.newInstance(team);
|
|
|
|
case 2:
|
2022-02-22 07:23:46 +01:00
|
|
|
return OrganizationTeamInfoPermissionsFragment.newInstance(team);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2022-04-21 23:02:59 +02:00
|
|
|
return 3;
|
2022-02-22 07:23:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
new TabLayoutMediator(binding.tabs, binding.pager, (tab, position) -> {
|
2022-04-21 23:02:59 +02:00
|
|
|
TextView textView = (TextView) LayoutInflater.from(ctx).inflate(R.layout.layout_tab_text, findViewById(android.R.id.content), false);
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
switch(position) {
|
|
|
|
case 0:
|
2022-04-21 23:02:59 +02:00
|
|
|
textView.setText(R.string.navRepos);
|
2022-02-22 07:23:46 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-04-21 23:02:59 +02:00
|
|
|
textView.setText(R.string.orgTabMembers);
|
2022-02-22 07:23:46 +01:00
|
|
|
break;
|
2022-04-21 23:02:59 +02:00
|
|
|
case 2:
|
|
|
|
textView.setText(R.string.teamPermissions);
|
|
|
|
break;
|
2022-02-22 07:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tab.setCustomView(textView);
|
|
|
|
}).attach();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2022-04-18 09:10:54 +02:00
|
|
|
OrganizationPermissions permissions = (OrganizationPermissions) getIntent().getSerializableExtra("permissions");
|
|
|
|
if(permissions == null || permissions.isIsOwner()) {
|
2022-02-22 07:23:46 +01:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
if(id == android.R.id.home) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(id == R.id.genericMenu) {
|
|
|
|
BottomSheetOrganizationTeamsFragment bottomSheet = new BottomSheetOrganizationTeamsFragment();
|
2022-04-21 23:02:59 +02:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("showRepo", !team.isIncludesAllRepositories());
|
|
|
|
bottomSheet.setArguments(args);
|
2022-02-22 07:23:46 +01:00
|
|
|
bottomSheet.show(getSupportFragmentManager(), "orgTeamsBottomSheet");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onButtonClicked(String text) {
|
|
|
|
if("newMember".equals(text)) {
|
|
|
|
Intent intent = new Intent(OrganizationTeamInfoActivity.this, AddNewTeamMemberActivity.class);
|
2022-04-18 09:10:54 +02:00
|
|
|
intent.putExtra("teamId", team.getId());
|
2022-02-22 07:23:46 +01:00
|
|
|
startActivity(intent);
|
2022-04-21 23:02:59 +02:00
|
|
|
} else if("newRepo".equals(text)) {
|
|
|
|
Intent intent = new Intent(OrganizationTeamInfoActivity.this, AddNewTeamRepoActivity.class);
|
|
|
|
intent.putExtra("teamId", team.getId());
|
|
|
|
intent.putExtra("teamName", team.getName());
|
|
|
|
intent.putExtra("orgName", getIntent().getStringExtra("orgName"));
|
|
|
|
startActivity(intent);
|
2022-02-22 07:23:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|