mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Add more link handlers (#948)
I can't implement every handler correctly, if there are no views that display them (e.g. a single milestone or release) - [X] Organization #915 - [X] Milestones - [X] Milestone - [X] New milestone - [X] Files - [ ] Lines *currently opens file viewer* - [X] Folders/directory's - [X] Branches list - [X] Branches - [X] Releases - [X] Release - [X] new Release - [X] Labels - [X] Explore (orgs/repos) - [X] Commits list - [X] New issue - [ ] Issue comments *currently opens the issue details* - [X] New PR - [ ] PR comments *currently opens the PR details* - [X] PR diff - [X] Your user profile - [ ] User profiles *blocked by #931* - [X] Gitea administration - [X] Notifications - [X] repository settings (only for repo admins) - [X] Login screen Commits: not possible, Gitea's API doesn't provide enough information to view the correct branch in the list and/or to display the diff. Closes #918 Closes #915 Co-authored-by: qwerty287 <ndev@web.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/948 Reviewed-by: 6543 <6543@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
0e696eb46f
commit
36f20bb1aa
@ -49,6 +49,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
|
||||
initCloseListener();
|
||||
viewBinding.close.setOnClickListener(onClickListener);
|
||||
viewBinding.instanceUrl.setText(getIntent().getStringExtra("instanceUrl"));
|
||||
|
||||
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(ctx, R.layout.list_spinner_items, Protocol.values());
|
||||
|
||||
|
@ -9,8 +9,11 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.gitnex.tea4j.models.Files;
|
||||
import org.gitnex.tea4j.models.Organization;
|
||||
import org.gitnex.tea4j.models.PullRequests;
|
||||
import org.gitnex.tea4j.models.UserRepositories;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.BaseApi;
|
||||
@ -20,13 +23,16 @@ import org.mian.gitnex.database.models.Repository;
|
||||
import org.mian.gitnex.database.models.UserAccount;
|
||||
import org.mian.gitnex.databinding.ActivityDeeplinksBinding;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.UrlHelper;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import io.mikael.urlbuilder.UrlBuilder;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -42,6 +48,8 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
private Intent mainIntent;
|
||||
private Intent issueIntent;
|
||||
private Intent repoIntent;
|
||||
private Intent orgIntent;
|
||||
private Intent userIntent;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -54,6 +62,9 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
mainIntent = new Intent(ctx, MainActivity.class);
|
||||
issueIntent = new Intent(ctx, IssueDetailActivity.class);
|
||||
repoIntent = new Intent(ctx, RepoDetailActivity.class);
|
||||
orgIntent = new Intent(ctx, OrganizationDetailActivity.class);
|
||||
// TODO: enable if UserProfile Activity exist
|
||||
//userIntent = new Intent(ctx, ProfileActivity.class)
|
||||
|
||||
Intent intent = getIntent();
|
||||
Uri data = intent.getData();
|
||||
@ -61,9 +72,10 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
|
||||
// check for login
|
||||
if(!tinyDB.getBoolean("loggedInMode")) {
|
||||
|
||||
Intent loginIntent = new Intent(ctx, LoginActivity.class);
|
||||
loginIntent.putExtra("instanceUrl", data.getHost());
|
||||
ctx.startActivity(loginIntent);
|
||||
finish();
|
||||
ctx.startActivity(new Intent(ctx, LoginActivity.class));
|
||||
}
|
||||
|
||||
// check for the links(URI) to be in the db
|
||||
@ -89,26 +101,83 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
|
||||
if(accountFound) {
|
||||
|
||||
// redirect to proper fragment/activity, If no action is there, show options where user to want to go like repos, profile, notifications etc
|
||||
if(data.getPathSegments().size() > 0) {
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
String[] restOfUrl = Objects.requireNonNull(data.getPath()).split("/");
|
||||
|
||||
if(data.getPathSegments().contains("issues")) { // issue
|
||||
// redirect to proper fragment/activity, if no action is there, show options where user to want to go like repos, profile, notifications etc
|
||||
if(data.getPathSegments().size() == 1) {
|
||||
if(data.getLastPathSegment().equals("notifications")) { // notifications
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(data.getLastPathSegment().equals("explore")) { // explore
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(data.getLastPathSegment().equals(tinyDB.getString("userLogin"))) { // your user profile
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "profile");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(data.getLastPathSegment().equals("admin")) {
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "admin");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
getUserOrOrg(currentInstance, instanceToken, data.getLastPathSegment()), 500);
|
||||
}
|
||||
}
|
||||
else if(data.getPathSegments().size() == 2) {
|
||||
if(data.getPathSegments().get(0).equals("explore")) { // specific explore tab
|
||||
if(data.getPathSegments().get(1).equals("organizations")) { // orgs
|
||||
mainIntent.putExtra("exploreOrgs", true);
|
||||
}
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(data.getPathSegments().get(0).equals("user") && data.getPathSegments().get(1).equals("login")) { // open login
|
||||
Intent loginIntent = new Intent(ctx, AddNewAccountActivity.class);
|
||||
loginIntent.putExtra("instanceUrl", data.getHost());
|
||||
loginIntent.putExtra("instanceProtocol", data.getScheme());
|
||||
ctx.startActivity(loginIntent);
|
||||
finish();
|
||||
}
|
||||
else if(data.getPathSegments().get(0).equals("admin")) {
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "admin");
|
||||
mainIntent.putExtra("giteaAdminAction", data.getLastPathSegment());
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(!data.getPathSegments().get(0).equals("") & !data.getLastPathSegment().equals("")) { // go to repo
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getLastPathSegment(), "repo"), 500);
|
||||
}
|
||||
else { // no action, show options
|
||||
showNoActionButtons();
|
||||
}
|
||||
}
|
||||
else if(data.getPathSegments().size() >= 3) {
|
||||
if(data.getPathSegments().get(2).equals("issues")) { // issue
|
||||
|
||||
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("issues") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
||||
|
||||
issueIntent.putExtra("issueNumber", data.getLastPathSegment());
|
||||
issueIntent.putExtra("openedFromLink", "true");
|
||||
|
||||
String[] urlSplitted = data.toString().split("#");
|
||||
if (urlSplitted.length == 2) {
|
||||
issueIntent.putExtra("issueComment", urlSplitted[1]);
|
||||
}
|
||||
|
||||
tinyDB.putString("issueNumber", data.getLastPathSegment());
|
||||
tinyDB.putString("issueType", "Issue");
|
||||
|
||||
tinyDB.putString("repoFullName", restOfUrl[restOfUrl.length - 4] + "/" + restOfUrl[restOfUrl.length - 3]);
|
||||
tinyDB.putString("repoFullName", data.getPathSegments().get(0) + "/" + data.getPathSegments().get(1));
|
||||
|
||||
final String repoOwner = restOfUrl[restOfUrl.length - 4];
|
||||
final String repoName = restOfUrl[restOfUrl.length - 3];
|
||||
final String repoOwner = data.getPathSegments().get(0);
|
||||
final String repoName = data.getPathSegments().get(1);
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||
@ -130,125 +199,121 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
finish();
|
||||
}
|
||||
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("issues")) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 3], restOfUrl[restOfUrl.length - 2], "issue");
|
||||
}, 500);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "issue"), 500);
|
||||
}
|
||||
else if(data.getLastPathSegment().equals("new")) {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "issueNew"), 500);
|
||||
}
|
||||
else {
|
||||
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
else if(data.getPathSegments().contains("pulls")) { // pr
|
||||
else if(data.getPathSegments().get(2).equals("pulls")) { // pr
|
||||
|
||||
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("pulls") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
getPullRequest(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 4], restOfUrl[restOfUrl.length - 3], Integer.parseInt(data.getLastPathSegment()));
|
||||
String[] urlSplitted = data.toString().split("#");
|
||||
if (urlSplitted.length == 2) {
|
||||
issueIntent.putExtra("issueComment", urlSplitted[1]);
|
||||
}
|
||||
|
||||
getPullRequest(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), Integer.parseInt(data.getLastPathSegment()));
|
||||
}, 500);
|
||||
|
||||
}
|
||||
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("pulls")) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
|
||||
}
|
||||
else if(data.getLastPathSegment().equals("files")) { // pr diff
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 3], restOfUrl[restOfUrl.length - 2], "pull");
|
||||
issueIntent.putExtra("openPrDiff", "true");
|
||||
getPullRequest(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), Integer.parseInt(data.getPathSegments().get(3)));
|
||||
}, 500);
|
||||
}
|
||||
else {
|
||||
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
else if(data.getPathSegments().contains("commit")) { // commits (no API yet to properly implement)
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 4], restOfUrl[restOfUrl.length - 3], "pull");
|
||||
}, 500);
|
||||
else if(data.getPathSegments().get(2).equals("compare")) { // new pull request
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pullNew"), 500);
|
||||
}
|
||||
else if(!restOfUrl[restOfUrl.length - 2].equals("") & !restOfUrl[restOfUrl.length - 1].equals("")) { // go to repo
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 2], restOfUrl[restOfUrl.length - 1], "repo");
|
||||
}, 500);
|
||||
else if(data.getPathSegments().get(2).equals("commit")) { // commits (no API yet to properly implement)
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("commits")) { // commits list
|
||||
String branch = data.getLastPathSegment();
|
||||
repoIntent.putExtra("branchName", branch);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "commitsList"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("milestones") && data.getLastPathSegment().equals("new")) { // new milestone
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestonesNew"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("milestones")) { // milestones
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestones"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("milestone")) { // milestone
|
||||
repoIntent.putExtra("milestoneId", data.getLastPathSegment());
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestones"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("releases") && data.getLastPathSegment().equals("new")) { // new release
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "newRelease"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("releases") && data.getPathSegments().get(3).equals("tag") && data.getPathSegments().size() == 5) { // release
|
||||
repoIntent.putExtra("releaseTagName", data.getLastPathSegment());
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "releases"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("releases")) { // releases
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "releases"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("labels")) { // labels
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "labels"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("settings")) { // repo settings
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "settings"), 500);
|
||||
}
|
||||
else if(data.getLastPathSegment().equals("branches")) { // branches list
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "branchesList"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().size() == 5 && data.getPathSegments().get(2).equals("src") && data.getPathSegments().get(3).equals("branch")) { // branch
|
||||
repoIntent.putExtra("selectedBranch", data.getLastPathSegment());
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "branch"), 500);
|
||||
}
|
||||
else if(data.getPathSegments().get(2).equals("src") && data.getPathSegments().get(3).equals("branch")) { // file/dir
|
||||
StringBuilder filePath = new StringBuilder();
|
||||
ArrayList<String> segments = new ArrayList<>(data.getPathSegments());
|
||||
segments.subList(0, 5).clear();
|
||||
for (String item : segments) {
|
||||
filePath.append(item);
|
||||
filePath.append("/");
|
||||
}
|
||||
filePath.deleteCharAt(filePath.toString().length() - 1);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||
getFile(currentInstance, instanceToken, data.getPathSegments().get(0),
|
||||
data.getPathSegments().get(1), filePath.toString(), data.getPathSegments().get(4)), 500);
|
||||
}
|
||||
else { // no action, show options
|
||||
|
||||
if(tinyDB.getInt("defaultScreenId") == 1) { // repos
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 2) { // org
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 3) { // notifications
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 4) { // explore
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 0) { // show options
|
||||
|
||||
viewBinding.noActionFrame.setVisibility(View.VISIBLE);
|
||||
viewBinding.addNewAccountFrame.setVisibility(View.GONE);
|
||||
|
||||
viewBinding.repository.setOnClickListener(repository -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 1);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.organization.setOnClickListener(organization -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 2);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.notification.setOnClickListener(notification -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 3);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.explore.setOnClickListener(explore -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 4);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.launchApp2.setOnClickListener(launchApp2 -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 0);
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
showNoActionButtons();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -267,6 +332,7 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
viewBinding.addNewAccount.setOnClickListener(addNewAccount -> {
|
||||
|
||||
Intent accountIntent = new Intent(ctx, AddNewAccountActivity.class);
|
||||
accountIntent.putExtra("instanceUrl", data.getHost());
|
||||
startActivity(accountIntent);
|
||||
finish();
|
||||
});
|
||||
@ -452,4 +518,184 @@ public class DeepLinksActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getUserOrOrg(String url, String instanceToken, String userOrgName) {
|
||||
Call<Organization> call = RetrofitClient.getApiInterface(ctx, url).getOrganization(instanceToken, userOrgName);
|
||||
|
||||
call.enqueue(new Callback<Organization>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<Organization> call, @NotNull Response<Organization> response) {
|
||||
if(response.code() == 404) { // org doesn't exist or it's a user user
|
||||
Log.d("getUserOrOrg-404", String.valueOf(response.code()));
|
||||
getUser(url, instanceToken, userOrgName);
|
||||
}
|
||||
else if(response.code() == 200) { // org
|
||||
assert response.body() != null;
|
||||
orgIntent.putExtra("orgName", response.body().getUsername());
|
||||
|
||||
|
||||
TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||
tinyDb.putString("orgName", response.body().getUsername());
|
||||
tinyDb.putString("organizationId", String.valueOf(response.body().getId()));
|
||||
tinyDb.putBoolean("organizationAction", true);
|
||||
ctx.startActivity(orgIntent);
|
||||
finish();
|
||||
}
|
||||
else {
|
||||
Log.e("getUserOrOrg-code", String.valueOf(response.code()));
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<Organization> call, @NotNull Throwable t) {
|
||||
Log.e("onFailure-getUserOrOrg", t.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getUser(String url, String instanceToken, String userName) {
|
||||
// TODO: enable if UserProfile Activity exist
|
||||
showNoActionButtons();
|
||||
/*Call<UserInfo> call = RetrofitClient.getApiInterface(ctx, url).getUserProfile(instanceToken, userName);
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<UserInfo> call, @NotNull Response<UserInfo> response) {
|
||||
if(response.code() == 200) {
|
||||
assert response.body() != null;
|
||||
userIntent.putExtra("username", response.body().getLogin());
|
||||
ctx.startActivity(userIntent);
|
||||
finish();
|
||||
}
|
||||
else {
|
||||
Log.e("getUser-code", String.valueOf(response.code()));
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<UserInfo> call, @NotNull Throwable t) {
|
||||
Log.e("onFailure-getUser", t.toString());
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
private void getFile(String url, String instanceToken, String owner, String repo, String filePath, String branch) {
|
||||
Call<Files> call = RetrofitClient.getApiInterface(ctx, url).getSingleFileContents(instanceToken, owner, repo, filePath, branch);
|
||||
|
||||
call.enqueue(new Callback<Files>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<Files> call, @NotNull Response<Files> response) {
|
||||
if(response.code() == 200) {
|
||||
// check if file and open file/dir
|
||||
Files file = response.body();
|
||||
assert file != null;
|
||||
if(file.getType().equals("file")) {
|
||||
repoIntent.putExtra("file", file);
|
||||
repoIntent.putExtra("branch", branch);
|
||||
goToRepoSection(url, instanceToken, owner, repo, "file");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.e("getFile-onFailure", String.valueOf(response.code()));
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<Files> call, @NotNull Throwable t) {
|
||||
Log.e("getFile-onFailure", t.toString());
|
||||
// maybe it's a directory
|
||||
getDir(url, instanceToken, owner, repo, filePath, branch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getDir(String url, String instanceToken, String owner, String repo, String filePath, String branch) {
|
||||
repoIntent.putExtra("branch", branch);
|
||||
repoIntent.putExtra("dir", filePath);
|
||||
goToRepoSection(url, instanceToken, owner, repo, "dir");
|
||||
}
|
||||
|
||||
private void showNoActionButtons() {
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
|
||||
if(tinyDB.getInt("defaultScreenId") == 1) { // repos
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 2) { // org
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 3) { // notifications
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 4) { // explore
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 0) { // show options
|
||||
|
||||
viewBinding.noActionFrame.setVisibility(View.VISIBLE);
|
||||
viewBinding.addNewAccountFrame.setVisibility(View.GONE);
|
||||
|
||||
viewBinding.repository.setOnClickListener(repository -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 1);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.organization.setOnClickListener(organization -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 2);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.notification.setOnClickListener(notification -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 3);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.explore.setOnClickListener(explore -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 4);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.launchApp2.setOnClickListener(launchApp2 -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 0);
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,6 +196,10 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
getSingleIssue(repoOwner, repoName, issueIndex);
|
||||
fetchDataAsync(repoOwner, repoName, issueIndex);
|
||||
|
||||
if(getIntent().getStringExtra("openPrDiff") != null && getIntent().getStringExtra("openPrDiff").equals("true")) {
|
||||
startActivity(new Intent(ctx, FileDiffActivity.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,6 +77,8 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.list_spinner_items, Protocol.values());
|
||||
|
||||
instanceUrlET.setText(getIntent().getStringExtra("instanceUrl"));
|
||||
|
||||
protocolSpinner.setAdapter(adapterProtocols);
|
||||
protocolSpinner.setSelection(0);
|
||||
protocolSpinner.setOnItemClickListener((parent, view, position, id) -> {
|
||||
|
@ -380,12 +380,24 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
case "notification":
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_notifications);
|
||||
setActionBarTitle(getResources().getString(R.string.pageTitleNotifications));
|
||||
return;
|
||||
|
||||
case "explore":
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_explore);
|
||||
return;
|
||||
|
||||
case "profile":
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_profile);
|
||||
return;
|
||||
|
||||
case "admin":
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_administration);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,13 +232,84 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
mainIntent.removeExtra("goToSection");
|
||||
mainIntent.removeExtra("goToSectionType");
|
||||
|
||||
if(goToSectionType.equals("issue")) {
|
||||
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(2);
|
||||
}
|
||||
else if(goToSectionType.equals("pull")) {
|
||||
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(3);
|
||||
switch(goToSectionType) {
|
||||
case "branchesList":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||
chooseBranch();
|
||||
break;
|
||||
case "branch":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||
String selectedBranch = mainIntent.getStringExtra("selectedBranch");
|
||||
tinyDB.putString("repoBranch", selectedBranch);
|
||||
if(getFragmentRefreshListenerFiles() != null) {
|
||||
getFragmentRefreshListenerFiles().onRefresh(selectedBranch);
|
||||
}
|
||||
break;
|
||||
case "file":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||
String branch1 = mainIntent.getStringExtra("branch");
|
||||
tinyDB.putString("repoBranch", branch1);
|
||||
if(getFragmentRefreshListenerFiles() != null) {
|
||||
getFragmentRefreshListenerFiles().onRefresh(branch1);
|
||||
}
|
||||
Intent intent = new Intent(ctx, FileViewActivity.class);
|
||||
intent.putExtra("file", mainIntent.getSerializableExtra("file"));
|
||||
startActivity(intent);
|
||||
break;
|
||||
case "dir":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||
String branch2 = mainIntent.getStringExtra("branch");
|
||||
tinyDB.putString("repoBranch", branch2);
|
||||
if(getFragmentRefreshListenerFiles() != null) {
|
||||
getFragmentRefreshListenerFiles().onRefresh(branch2);
|
||||
}
|
||||
//((SectionsPagerAdapter) Objects.requireNonNull(RepoDetailActivity.mViewPager.getAdapter())).getItem(1);
|
||||
break;
|
||||
case "commitsList":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||
String branch = mainIntent.getStringExtra("branchName");
|
||||
tinyDB.putString("repoBranch", branch);
|
||||
if(getFragmentRefreshListenerFiles() != null) {
|
||||
getFragmentRefreshListenerFiles().onRefresh(branch);
|
||||
}
|
||||
Intent intent1 = new Intent(ctx, CommitsActivity.class);
|
||||
intent1.putExtra("branchName", branch);
|
||||
ctx.startActivity(intent1);
|
||||
break;
|
||||
case "issue":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(2);
|
||||
break;
|
||||
case "issueNew":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(2);
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
|
||||
break;
|
||||
case "pull":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(3);
|
||||
break;
|
||||
case "pullNew":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(3);
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreatePullRequestActivity.class));
|
||||
break;
|
||||
case "releases":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(4);
|
||||
break;
|
||||
case "newRelease":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(4);
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
|
||||
break;
|
||||
case "milestones":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(5);
|
||||
break;
|
||||
case "milestonesNew":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(5);
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
|
||||
break;
|
||||
case "labels":
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(6);
|
||||
break;
|
||||
case "settings":
|
||||
startActivity(new Intent(RepoDetailActivity.this, RepositorySettingsActivity.class));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,16 @@ public class AdministrationFragment extends Fragment {
|
||||
|
||||
fragmentAdministrationBinding.adminCron.setOnClickListener(v1 -> startActivity(new Intent(getContext(), AdminCronTasksActivity.class)));
|
||||
|
||||
String action = requireActivity().getIntent().getStringExtra("giteaAdminAction");
|
||||
if(action != null) {
|
||||
if(action.equals("users")) {
|
||||
startActivity(new Intent(getContext(), AdminGetUsersActivity.class));
|
||||
}
|
||||
else if(action.equals("monitor")) {
|
||||
startActivity(new Intent(getContext(), AdminCronTasksActivity.class));
|
||||
}
|
||||
}
|
||||
|
||||
return fragmentAdministrationBinding.getRoot();
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,10 @@ public class ExploreFragment extends Fragment {
|
||||
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
if(requireActivity().getIntent().getBooleanExtra("exploreOrgs", false)) {
|
||||
mViewPager.setCurrentItem(2);
|
||||
}
|
||||
|
||||
return view;
|
||||
|
||||
}
|
||||
|
@ -130,7 +130,17 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
|
||||
|
||||
});
|
||||
|
||||
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName, ref);
|
||||
String dir = requireActivity().getIntent().getStringExtra("dir");
|
||||
if(dir != null) {
|
||||
fetchDataAsyncSub(Authorization.get(getContext()), repoOwner, repoName, dir, ref);
|
||||
for(String segment: dir.split("/")) {
|
||||
binding.breadcrumbsView.addItem(new BreadcrumbItem(Collections.singletonList(segment)));
|
||||
path.add(segment);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName, ref);
|
||||
}
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ public class MilestonesFragment extends Fragment {
|
||||
private String TAG = Constants.tagMilestonesFragment;
|
||||
private int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||
|
||||
private String milestoneId;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
@ -63,6 +65,9 @@ public class MilestonesFragment extends Fragment {
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
milestoneId = requireActivity().getIntent().getStringExtra("milestoneId");
|
||||
requireActivity().getIntent().removeExtra("milestoneId");
|
||||
|
||||
viewBinding.recyclerView.setHasFixedSize(true);
|
||||
viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
@ -188,6 +193,10 @@ public class MilestonesFragment extends Fragment {
|
||||
adapter.notifyDataChanged();
|
||||
viewBinding.noDataMilestone.setVisibility(View.GONE);
|
||||
|
||||
if(milestoneId != null) {
|
||||
viewBinding.recyclerView.scrollToPosition(getMilestoneIndex(Integer.parseInt(milestoneId), response.body()));
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -216,6 +225,15 @@ public class MilestonesFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
private static int getMilestoneIndex(int milestoneId, List<Milestones> milestones) {
|
||||
for (Milestones milestone : milestones) {
|
||||
if(milestone.getId() == milestoneId) {
|
||||
return milestones.indexOf(milestone);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void loadMore(String token, String repoOwner, String repoName, int page, int resultLimit, String milestoneState) {
|
||||
|
||||
viewBinding.progressLoadMore.setVisibility(View.VISIBLE);
|
||||
|
@ -29,7 +29,7 @@ import retrofit2.Callback;
|
||||
|
||||
public class OrganizationInfoFragment extends Fragment {
|
||||
|
||||
private Context ctx = getContext();
|
||||
private Context ctx;
|
||||
private ProgressBar mProgressBar;
|
||||
private static String orgNameF = "param1";
|
||||
|
||||
@ -67,6 +67,8 @@ public class OrganizationInfoFragment extends Fragment {
|
||||
|
||||
FragmentOrganizationInfoBinding fragmentOrganizationInfoBinding = FragmentOrganizationInfoBinding.inflate(inflater, container, false);
|
||||
|
||||
ctx = getContext();
|
||||
|
||||
mProgressBar = fragmentOrganizationInfoBinding.progressBar;
|
||||
orgAvatar = fragmentOrganizationInfoBinding.orgAvatar;
|
||||
TextView orgNameInfo = fragmentOrganizationInfoBinding.orgNameInfo;
|
||||
|
@ -18,6 +18,7 @@ import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import org.gitnex.tea4j.models.IssueComments;
|
||||
import org.gitnex.tea4j.models.Releases;
|
||||
import org.mian.gitnex.adapters.ReleasesAdapter;
|
||||
import org.mian.gitnex.databinding.FragmentReleasesBinding;
|
||||
@ -41,6 +42,7 @@ public class ReleasesFragment extends Fragment {
|
||||
|
||||
private String repoName;
|
||||
private String repoOwner;
|
||||
private String releaseTag;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
@ -63,6 +65,7 @@ public class ReleasesFragment extends Fragment {
|
||||
repoName = getArguments().getString(repoNameF);
|
||||
repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
releaseTag = requireActivity().getIntent().getStringExtra("releaseTagName");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,6 +140,13 @@ public class ReleasesFragment extends Fragment {
|
||||
adapter = new ReleasesAdapter(getContext(), releasesListMain);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
if(releasesListMain != null && releaseTag != null) {
|
||||
int index = getReleaseIndex(releaseTag, releasesListMain);
|
||||
releaseTag = null;
|
||||
if(index != -1) {
|
||||
mRecyclerView.scrollToPosition(index);
|
||||
}
|
||||
}
|
||||
noDataReleases.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
@ -150,4 +160,13 @@ public class ReleasesFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
private static int getReleaseIndex(String tag, List<Releases> releases) {
|
||||
for (Releases release : releases) {
|
||||
if(release.getTag_name().equals(tag)) {
|
||||
return releases.indexOf(release);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user