mirror of
https://codeberg.org/gitnex/GitNex
synced 2025-03-13 01:50:07 +01:00
Some fixes and cleanups for PRs (#1146)
1. improve menu time (show when loading finished) 2. fix crashes from deleted forks I mainly tried to fix issue https://codeberg.org/gitnex/GitNex/issues/1137, but: 1. the missing UI options are Gitea's issue (the permission values are not correct when using notification endpoints) 2. the comments crash is an `SQLiteConstraintException` which we had already in #1084 but it seems that it wasn't fixed Closes https://codeberg.org/gitnex/GitNex/issues/1137 closes https://codeberg.org/gitnex/GitNex/issues/1144 Co-authored-by: qwerty287 <ndev@web.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1146 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
parent
7e9d494a49
commit
6916989ec1
@ -93,7 +93,7 @@ public class IssueActions {
|
||||
IssuesFragment.resumeIssues = issue.getIssue().getPullRequest() == null;
|
||||
PullRequestsFragment.resumePullRequests = issue.getIssue().getPullRequest() != null;
|
||||
}
|
||||
if(issue.getIssueType().equals("Pull")) {
|
||||
if(issue.getIssueType().equalsIgnoreCase("Pull")) {
|
||||
if(issueState.equals("closed")) {
|
||||
Toasty.success(ctx, ctx.getString(R.string.prClosed));
|
||||
}
|
||||
|
@ -180,23 +180,9 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
"Issue"
|
||||
);
|
||||
|
||||
final String repoOwner = data.getPathSegments().get(0);
|
||||
final String repoName = data.getPathSegments().get(1);
|
||||
issue.getRepository().saveToDB(ctx);
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||
assert repositoryData != null;
|
||||
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
int repoId;
|
||||
if(count == 0) {
|
||||
repoId = (int) repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
}
|
||||
else {
|
||||
repoId = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName).getRepositoryId();
|
||||
}
|
||||
issue.getRepository().setRepositoryId(repoId);
|
||||
issueIntent.putExtra(IssueContext.INTENT_EXTRA, issueIntent);
|
||||
|
||||
ctx.startActivity(issueIntent);
|
||||
finish();
|
||||
@ -384,20 +370,7 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
|
||||
IssueContext issue = new IssueContext(prInfo, new RepositoryContext(repoOwner, repoName, ctx));
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||
assert repositoryData != null;
|
||||
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
int id;
|
||||
if(count == 0) {
|
||||
id = (int) repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
}
|
||||
else {
|
||||
id = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName).getRepositoryId();
|
||||
}
|
||||
issue.getRepository().setRepositoryId(id);
|
||||
issue.getRepository().saveToDB(ctx);
|
||||
|
||||
issueIntent.putExtra(IssueContext.INTENT_EXTRA, issue);
|
||||
ctx.startActivity(issueIntent);
|
||||
@ -442,20 +415,7 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
repoIntent.putExtra("goToSection", "yes");
|
||||
repoIntent.putExtra("goToSectionType", type);
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
int id;
|
||||
if(count == 0) {
|
||||
id = (int) repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
}
|
||||
else {
|
||||
id = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName).getRepositoryId();
|
||||
}
|
||||
|
||||
repo.setRepositoryId(id);
|
||||
repo.saveToDB(ctx);
|
||||
repoIntent.putExtra(RepositoryContext.INTENT_EXTRA, repo);
|
||||
|
||||
ctx.startActivity(repoIntent);
|
||||
|
@ -116,7 +116,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
public static boolean singleIssueUpdate = false;
|
||||
public boolean commentEdited = false;
|
||||
public boolean commentPosted = false;
|
||||
public static boolean commentPosted = false;
|
||||
|
||||
private IssueCommentsViewModel issueCommentsModel;
|
||||
|
||||
@ -415,18 +415,28 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
});
|
||||
}
|
||||
|
||||
private Runnable showMenu = () -> {};
|
||||
private boolean loadingFinishedIssue = false;
|
||||
private boolean loadingFinishedPr = false;
|
||||
private boolean loadingFinishedRepo = false;
|
||||
private void updateMenuState() {
|
||||
if(loadingFinishedIssue && loadingFinishedPr && loadingFinishedRepo) showMenu.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
new Handler().postDelayed(() -> {
|
||||
showMenu = () -> {
|
||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||
if(issue.getIssueType() != null) {
|
||||
if(issue.getIssueType().equalsIgnoreCase("pull")) {
|
||||
inflater.inflate(R.menu.pr_info_menu, menu);
|
||||
}
|
||||
}
|
||||
}, 800);
|
||||
showMenu = () -> {}; // reset Runnable
|
||||
};
|
||||
updateMenuState();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -437,7 +447,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
if(id == android.R.id.home) {
|
||||
|
||||
if(getIntent().getStringExtra("openedFromLink") != null && getIntent().getStringExtra("openedFromLink").equals("true")) {
|
||||
if(issue.hasIssue() && getIntent().getStringExtra("openedFromLink") != null &&
|
||||
getIntent().getStringExtra("openedFromLink").equals("true")) {
|
||||
Intent intent = issue.getRepository().getIntent(ctx, RepoDetailActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
@ -455,20 +466,22 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
}
|
||||
else if(id == R.id.prInfo) {
|
||||
|
||||
View view = LayoutInflater.from(ctx).inflate(R.layout.custom_pr_info_dialog, null);
|
||||
if(issue.getPullRequest() != null) {
|
||||
View view = LayoutInflater.from(ctx).inflate(R.layout.custom_pr_info_dialog, null);
|
||||
|
||||
TextView baseBranch = view.findViewById(R.id.baseBranch);
|
||||
TextView headBranch = view.findViewById(R.id.headBranch);
|
||||
TextView baseBranch = view.findViewById(R.id.baseBranch);
|
||||
TextView headBranch = view.findViewById(R.id.headBranch);
|
||||
|
||||
baseBranch.setText(issue.getPullRequest().getBase().getRef());
|
||||
headBranch.setText(issue.getPullRequest().getHead().getRef());
|
||||
baseBranch.setText(issue.getPullRequest().getBase().getRef());
|
||||
headBranch.setText(issue.getPullRequest().getHead().getRef());
|
||||
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctx);
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctx);
|
||||
|
||||
alertDialog.setTitle(getResources().getString(R.string.prMergeInfo));
|
||||
alertDialog.setView(view);
|
||||
alertDialog.setPositiveButton(getString(R.string.okButton), null);
|
||||
alertDialog.create().show();
|
||||
alertDialog.setTitle(getResources().getString(R.string.prMergeInfo));
|
||||
alertDialog.setView(view);
|
||||
alertDialog.setPositiveButton(getString(R.string.okButton), null);
|
||||
alertDialog.create().show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@ -623,7 +636,11 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
private void initWithIssue() {
|
||||
if(!issue.getRepository().hasRepository()) {
|
||||
getRepoInfo();
|
||||
} else {
|
||||
loadingFinishedRepo = true;
|
||||
}
|
||||
loadingFinishedIssue = true;
|
||||
updateMenuState();
|
||||
|
||||
viewBinding.issuePrState.setVisibility(View.VISIBLE);
|
||||
|
||||
@ -646,10 +663,13 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
}
|
||||
}
|
||||
else if(issue.getIssue().getState().equals("closed")) { // issue closed
|
||||
|
||||
loadingFinishedPr = true;
|
||||
updateMenuState();
|
||||
viewBinding.issuePrState.setImageResource(R.drawable.ic_issue);
|
||||
ImageViewCompat.setImageTintList(viewBinding.issuePrState, ColorStateList.valueOf(ctx.getResources().getColor(R.color.iconIssuePrClosedColor)));
|
||||
} else {
|
||||
loadingFinishedPr = true;
|
||||
updateMenuState();
|
||||
viewBinding.issuePrState.setImageResource(R.drawable.ic_issue);
|
||||
ImageViewCompat.setImageTintList(viewBinding.issuePrState, ColorStateList.valueOf(ctx.getResources().getColor(R.color.darkGreen)));
|
||||
}
|
||||
@ -878,6 +898,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
public void onResponse(@NonNull Call<PullRequest> call, @NonNull Response<PullRequest> response) {
|
||||
if(response.isSuccessful() && response.body() != null) {
|
||||
issue.setPullRequest(response.body());
|
||||
loadingFinishedPr = true;
|
||||
updateMenuState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -899,6 +921,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
if(response.code() == 200) {
|
||||
assert repoInfo != null;
|
||||
issue.getRepository().setRepository(repoInfo);
|
||||
loadingFinishedRepo = true;
|
||||
updateMenuState();
|
||||
}
|
||||
else {
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
|
@ -99,7 +99,7 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
viewBinding.mergeButton.setOnClickListener(mergePullRequest);
|
||||
}
|
||||
|
||||
if(!issue.getPullRequest().getHead().getRepo().getPermissions().isPush()) {
|
||||
if(!(issue.getPullRequest().getHead().getRepo() != null ? issue.getPullRequest().getHead().getRepo().getPermissions().isPush() : false)) {
|
||||
viewBinding.deleteBranch.setVisibility(View.GONE);
|
||||
viewBinding.deleteBranchForkInfo.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class DiffAdapter extends BaseAdapter {
|
||||
|
||||
}
|
||||
|
||||
if(type.equals("pull")) {
|
||||
if(type.equalsIgnoreCase("pull")) {
|
||||
convertView.setOnClickListener(v -> {
|
||||
|
||||
if(selectedLines.contains(position)) {
|
||||
|
@ -119,22 +119,9 @@ public class ExploreIssuesAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
int currentActiveAccountId = ((BaseActivity) context).getAccount().getAccount().getAccountId();
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
RepositoryContext repo = new RepositoryContext(repoOwner, repoName, context);
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
repo.saveToDB(context);
|
||||
|
||||
Intent intentIssueDetail = new IssueContext(issue, repo).getIntent(context, IssueDetailActivity.class);
|
||||
intentIssueDetail.putExtra("openedFromLink", "true");
|
||||
|
@ -102,23 +102,9 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<RecyclerVie
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
@ -179,26 +179,10 @@ public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||
Context context = v.getContext();
|
||||
|
||||
String[] parts = userRepositories.getFullName().split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
|
||||
});
|
||||
|
@ -110,23 +110,9 @@ public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
int currentActiveAccountId = TinyDB.getInstance(context).getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
@ -99,23 +99,9 @@ public class RepositoriesAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
int currentActiveAccountId = TinyDB.getInstance(context).getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
org.mian.gitnex.database.models.Repository data = repositoryData.getRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
|
@ -99,23 +99,9 @@ public class StarredRepositoriesAdapter extends RecyclerView.Adapter<RecyclerVie
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
int currentActiveAccountId = TinyDB.getInstance(context).getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import org.mian.gitnex.activities.IssueDetailActivity;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.database.api.BaseApi;
|
||||
import org.mian.gitnex.database.api.DraftsApi;
|
||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||
import org.mian.gitnex.database.models.Repository;
|
||||
import org.mian.gitnex.databinding.BottomSheetReplyLayoutBinding;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
@ -186,10 +188,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
if(status == ActionResult.Status.SUCCESS) {
|
||||
|
||||
FragmentActivity activity = requireActivity();
|
||||
if(activity instanceof IssueDetailActivity) {
|
||||
((IssueDetailActivity) activity).commentPosted = true;
|
||||
}
|
||||
IssueDetailActivity.commentPosted = true;
|
||||
|
||||
Toasty.success(getContext(), getString(R.string.commentSuccess));
|
||||
|
||||
@ -284,7 +283,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
if(draftId == 0) {
|
||||
|
||||
draftId = draftsApi.insertDraft(issue.getRepository().getRepositoryId(), currentActiveAccountId, issue.getIssueIndex(), text, draftType, "TODO", issue.getIssueType());
|
||||
draftId = draftsApi.insertDraft(issue.getRepository().saveToDB(requireContext()), currentActiveAccountId, issue.getIssueIndex(), text, draftType, "TODO", issue.getIssueType());
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -83,7 +83,8 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
|
||||
binding.editIssue.setText(R.string.menuEditText);
|
||||
|
||||
boolean canPushPullSource = issue.getPullRequest().getHead().getRepo().getPermissions().isPush();
|
||||
boolean canPushPullSource = issue.getPullRequest().getHead().getRepo() != null ?
|
||||
issue.getPullRequest().getHead().getRepo().getPermissions().isPush() : false;
|
||||
if(issue.getPullRequest().isMerged() || issue.getIssue().getState().equals("closed")) {
|
||||
binding.updatePullRequest.setVisibility(View.GONE);
|
||||
binding.mergePullRequest.setVisibility(View.GONE);
|
||||
|
@ -54,7 +54,7 @@ public class DiffFilesFragment extends Fragment {
|
||||
|
||||
binding.diffFiles.setOnItemClickListener((parent, view, position, id) -> requireActivity().getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position), issue.getIssueType().toLowerCase()))
|
||||
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position), issue))
|
||||
.commit());
|
||||
|
||||
getPullDiffFiles(issue.getRepository().getOwner(), issue.getRepository().getName(), String.valueOf(issue.getIssueIndex()));
|
||||
|
@ -44,6 +44,7 @@ public class DiffFragment extends Fragment {
|
||||
DiffFragment fragment = new DiffFragment();
|
||||
fragment.setFileDiffView(fileDiffView);
|
||||
fragment.setIssue(issue);
|
||||
fragment.type = "pull";
|
||||
return fragment;
|
||||
|
||||
}
|
||||
|
@ -247,25 +247,14 @@ public class NotificationsFragment extends Fragment implements NotificationsAdap
|
||||
|
||||
if(StringUtils.containsAny(notificationThread.getSubject().getType().toLowerCase(), "pull", "issue")) {
|
||||
|
||||
RepositoryContext repo = new RepositoryContext(notificationThread.getRepository(), context);
|
||||
RepositoryContext repo = new RepositoryContext(notificationThread.getRepository().getOwner().getLogin(),
|
||||
notificationThread.getRepository().getName(), context); // we can't use the repository object here directly because the permissions are missing
|
||||
String issueUrl = notificationThread.getSubject().getUrl();
|
||||
|
||||
int currentActiveAccountId = TinyDB.getInstance(requireContext()).getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId((int) id);
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repo.getOwner(), repo.getName());
|
||||
repo.setRepositoryId(data.getRepositoryId());
|
||||
}
|
||||
repo.saveToDB(context);
|
||||
|
||||
Intent intent = new IssueContext(
|
||||
new RepositoryContext(notificationThread.getRepository(), context),
|
||||
repo,
|
||||
Integer.parseInt(issueUrl.substring(issueUrl.lastIndexOf("/") + 1)),
|
||||
notificationThread.getSubject().getType()
|
||||
).getIntent(context, IssueDetailActivity.class);
|
||||
|
@ -235,4 +235,23 @@ public class RepositoryContext implements Serializable {
|
||||
repository = null;
|
||||
}
|
||||
|
||||
public int saveToDB(Context context) {
|
||||
int currentActiveAccountId = TinyDB.getInstance(context).getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, getOwner(), getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, getOwner(), getName());
|
||||
setRepositoryId((int) id);
|
||||
return (int) id;
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, getOwner(), getName());
|
||||
setRepositoryId(data.getRepositoryId());
|
||||
return data.getRepositoryId();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user