GitNex-Android-App/app/src/main/java/org/mian/gitnex/activities/OrganizationTeamInfoActivit...

141 lines
4.6 KiB
Java
Raw Normal View History

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;
import org.gitnex.tea4j.v2.models.OrganizationPermissions;
import org.gitnex.tea4j.v2.models.Team;
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;
import org.mian.gitnex.fragments.OrganizationTeamInfoReposFragment;
import org.mian.gitnex.structs.BottomSheetListener;
/**
* Author M M Arif
*/
public class OrganizationTeamInfoActivity extends BaseActivity implements BottomSheetListener {
private Team team;
@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());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
team = (Team) getIntent().getSerializableExtra("team");
if(team.getName() != null && !team.getName().isEmpty()) {
binding.toolbarTitle.setText(team.getName());
}
else {
binding.toolbarTitle.setText(R.string.orgTeamMembers);
}
binding.close.setOnClickListener(view -> finish());
binding.pager.setOffscreenPageLimit(1);
binding.pager.setAdapter(new FragmentStateAdapter(getSupportFragmentManager(), getLifecycle()) {
@NonNull
@Override
public Fragment createFragment(int position) {
switch(position) {
case 0:
return OrganizationTeamInfoReposFragment.newInstance(team);
case 1:
return OrganizationTeamInfoMembersFragment.newInstance(team);
case 2:
return OrganizationTeamInfoPermissionsFragment.newInstance(team);
}
return null;
}
@Override
public int getItemCount() {
return 3;
}
});
new TabLayoutMediator(binding.tabs, binding.pager, (tab, position) -> {
TextView textView = (TextView) LayoutInflater.from(ctx).inflate(R.layout.layout_tab_text, findViewById(android.R.id.content), false);
switch(position) {
case 0:
textView.setText(R.string.navRepos);
break;
case 1:
textView.setText(R.string.orgTabMembers);
break;
case 2:
textView.setText(R.string.teamPermissions);
break;
}
tab.setCustomView(textView);
}).attach();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
OrganizationPermissions permissions = (OrganizationPermissions) getIntent().getSerializableExtra("permissions");
if(permissions == null || permissions.isIsOwner()) {
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();
Bundle args = new Bundle();
args.putBoolean("showRepo", !team.isIncludesAllRepositories());
bottomSheet.setArguments(args);
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);
intent.putExtra("teamId", team.getId());
startActivity(intent);
} 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);
}
}
}