mirror of
https://codeberg.org/gitnex/GitNex
synced 2025-03-12 17:40:11 +01:00
Check Issue Subscription and display button based on that (#445)
update string names Update strings Merge branch 'master' into imprufe-issue-subscription-checking switch icon as per @mmarif Migrate to new Version Check & disable IssueSubscription function for gitea < 1.12.0 Merge branch 'master' into imprufe-issue-subscription-checking Merge branch 'master' into imprufe-issue-subscription-checking Merge branch 'master' into imprufe-issue-subscription-checking refactor & use dismiss() realy check If issue is subscribed add 200 http Status check and handle it Rename WatchRepository to WatchInfo & add checkIssueWatchStatus Co-authored-by: M M Arif <mmarif@swatian.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/445 Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
parent
ad7c3696d5
commit
e83b9eb736
@ -2,8 +2,6 @@ package org.mian.gitnex.actions;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
@ -160,23 +158,22 @@ public class IssueActions {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void subscribe(final Context ctx, final TextView subscribeIssue, final TextView unsubscribeIssue) {
|
public static void subscribe(final Context ctx) {
|
||||||
|
|
||||||
final TinyDB tinyDB = new TinyDB(ctx);
|
final TinyDB tinyDB = new TinyDB(ctx);
|
||||||
|
|
||||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
final String instanceUrl = tinyDB.getString("instanceUrl");
|
||||||
String repoFullName = tinyDB.getString("repoFullName");
|
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||||
String[] parts = repoFullName.split("/");
|
if(repoFullName.length != 2) {
|
||||||
final String repoOwner = parts[0];
|
return;
|
||||||
final String repoName = parts[1];
|
}
|
||||||
final String loginUid = tinyDB.getString("loginUid");
|
|
||||||
final String userLogin = tinyDB.getString("userLogin");
|
final String userLogin = tinyDB.getString("userLogin");
|
||||||
final String token = "token " + tinyDB.getString(loginUid + "-token");
|
final String token = "token " + tinyDB.getString(tinyDB.getString("loginUid") + "-token");
|
||||||
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||||
|
|
||||||
Call<Void> call;
|
Call<Void> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().addIssueSubscriber(token, repoOwner, repoName, issueNr, userLogin);
|
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().addIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||||
|
|
||||||
call.enqueue(new Callback<Void>() {
|
call.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
@ -187,10 +184,14 @@ public class IssueActions {
|
|||||||
|
|
||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
unsubscribeIssue.setVisibility(View.VISIBLE);
|
Toasty.info(ctx, ctx.getString(R.string.subscribedSuccessfully));
|
||||||
subscribeIssue.setVisibility(View.GONE);
|
tinyDB.putBoolean("issueSubscribed", true);
|
||||||
Toasty.info(ctx, ctx.getString(R.string.issueSubscribtion));
|
|
||||||
tinyDB.putString("issueSubscriptionState", "unsubscribeToIssue");
|
}
|
||||||
|
else if(response.code() == 200) {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("issueSubscribed", true);
|
||||||
|
Toasty.info(ctx, ctx.getString(R.string.alreadySubscribed));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +203,7 @@ public class IssueActions {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.info(ctx, ctx.getString(R.string.issueSubscribtionError));
|
Toasty.info(ctx, ctx.getString(R.string.subscribtionError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,29 +212,28 @@ public class IssueActions {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.info(ctx, ctx.getString(R.string.issueSubscribtionError));
|
Toasty.info(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unsubscribe(final Context ctx, final TextView subscribeIssue, final TextView unsubscribeIssue) {
|
public static void unsubscribe(final Context ctx) {
|
||||||
|
|
||||||
final TinyDB tinyDB = new TinyDB(ctx);
|
final TinyDB tinyDB = new TinyDB(ctx);
|
||||||
|
|
||||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
final String instanceUrl = tinyDB.getString("instanceUrl");
|
||||||
String repoFullName = tinyDB.getString("repoFullName");
|
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||||
String[] parts = repoFullName.split("/");
|
if(repoFullName.length != 2) {
|
||||||
final String repoOwner = parts[0];
|
return;
|
||||||
final String repoName = parts[1];
|
}
|
||||||
final String loginUid = tinyDB.getString("loginUid");
|
|
||||||
final String userLogin = tinyDB.getString("userLogin");
|
final String userLogin = tinyDB.getString("userLogin");
|
||||||
final String token = "token " + tinyDB.getString(loginUid + "-token");
|
final String token = "token " + tinyDB.getString(tinyDB.getString("loginUid") + "-token");
|
||||||
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||||
|
|
||||||
Call<Void> call;
|
Call<Void> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().delIssueSubscriber(token, repoOwner, repoName, issueNr, userLogin);
|
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().delIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||||
|
|
||||||
call.enqueue(new Callback<Void>() {
|
call.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
@ -244,10 +244,14 @@ public class IssueActions {
|
|||||||
|
|
||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
unsubscribeIssue.setVisibility(View.GONE);
|
Toasty.info(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
|
||||||
subscribeIssue.setVisibility(View.VISIBLE);
|
tinyDB.putBoolean("issueSubscribed", false);
|
||||||
Toasty.info(ctx, ctx.getString(R.string.issueUnsubscribtion));
|
|
||||||
tinyDB.putString("issueSubscriptionState", "subscribeToIssue");
|
}
|
||||||
|
else if(response.code() == 200) {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("issueSubscribed", false);
|
||||||
|
Toasty.info(ctx, ctx.getString(R.string.alreadyUnsubscribed));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +263,7 @@ public class IssueActions {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.info(ctx, ctx.getString(R.string.issueUnsubscribtionError));
|
Toasty.info(ctx, ctx.getString(R.string.unsubscribtionError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +272,7 @@ public class IssueActions {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.info(ctx, ctx.getString(R.string.issueUnsubscribtionError));
|
Toasty.info(ctx, ctx.getString(R.string.unsubscribtionError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,10 @@ import org.mian.gitnex.helpers.LabelWidthCalculator;
|
|||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.UserMentions;
|
import org.mian.gitnex.helpers.UserMentions;
|
||||||
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.IssueComments;
|
import org.mian.gitnex.models.IssueComments;
|
||||||
import org.mian.gitnex.models.Issues;
|
import org.mian.gitnex.models.Issues;
|
||||||
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import org.mian.gitnex.viewmodels.IssueCommentsViewModel;
|
import org.mian.gitnex.viewmodels.IssueCommentsViewModel;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
@ -550,6 +552,38 @@ public class IssueDetailActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
|
|
||||||
|
Call<WatchInfo> call2 = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkIssueWatchStatus(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
||||||
|
|
||||||
|
call2.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull Response<WatchInfo> response) {
|
||||||
|
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
|
tinyDb.putBoolean("issueSubscribed", response.body().getSubscribed());
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
tinyDb.putBoolean("issueSubscribed", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
tinyDb.putBoolean("issueSubscribed", false);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
@ -40,7 +40,7 @@ import org.mian.gitnex.fragments.RepoInfoFragment;
|
|||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.AppUtil;
|
import org.mian.gitnex.util.AppUtil;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -486,14 +486,14 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
private void checkRepositoryWatchStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
private void checkRepositoryWatchStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
||||||
|
|
||||||
Call<WatchRepository> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoWatchStatus(instanceToken, owner, repo);
|
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoWatchStatus(instanceToken, owner, repo);
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchRepository>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = new TinyDB(appCtx);
|
||||||
|
|
||||||
@ -510,7 +510,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
|||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -95,16 +95,16 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
|
|||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||||
|
|
||||||
WatchRepository watch = new WatchRepository();
|
WatchInfo watch = new WatchInfo();
|
||||||
|
|
||||||
Call<WatchRepository> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchRepository>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
@ -24,7 +24,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
|||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -88,16 +88,16 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.
|
|||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||||
|
|
||||||
WatchRepository watch = new WatchRepository();
|
WatchInfo watch = new WatchInfo();
|
||||||
|
|
||||||
Call<WatchRepository> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchRepository>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
@ -27,7 +27,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
|||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -95,16 +95,16 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
|
|||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||||
|
|
||||||
WatchRepository watch = new WatchRepository();
|
WatchInfo watch = new WatchInfo();
|
||||||
|
|
||||||
Call<WatchRepository> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchRepository>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
@ -25,7 +25,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
|||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -92,16 +92,16 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
|||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||||
|
|
||||||
WatchRepository watch = new WatchRepository();
|
WatchInfo watch = new WatchInfo();
|
||||||
|
|
||||||
Call<WatchRepository> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchRepository>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
@ -25,7 +25,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
|||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -92,16 +92,16 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
|||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||||
|
|
||||||
WatchRepository watch = new WatchRepository();
|
WatchInfo watch = new WatchInfo();
|
||||||
|
|
||||||
Call<WatchRepository> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchRepository>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
@ -20,6 +20,7 @@ import org.mian.gitnex.activities.EditIssueActivity;
|
|||||||
import org.mian.gitnex.activities.FileDiffActivity;
|
import org.mian.gitnex.activities.FileDiffActivity;
|
||||||
import org.mian.gitnex.activities.MergePullRequestActivity;
|
import org.mian.gitnex.activities.MergePullRequestActivity;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.util.TinyDB;
|
import org.mian.gitnex.util.TinyDB;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -222,24 +223,30 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
|||||||
|
|
||||||
subscribeIssue.setOnClickListener(subscribeToIssue -> {
|
subscribeIssue.setOnClickListener(subscribeToIssue -> {
|
||||||
|
|
||||||
IssueActions.subscribe(ctx, subscribeIssue, unsubscribeIssue);
|
IssueActions.subscribe(ctx);
|
||||||
//dismiss();
|
dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
unsubscribeIssue.setOnClickListener(unsubscribeToIssue -> {
|
unsubscribeIssue.setOnClickListener(unsubscribeToIssue -> {
|
||||||
|
|
||||||
IssueActions.unsubscribe(ctx, subscribeIssue, unsubscribeIssue);
|
IssueActions.unsubscribe(ctx);
|
||||||
//dismiss();
|
dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//if RepoWatch True Provide Unsubscribe first
|
if(new Version(tinyDB.getString("giteaVersion")).less("1.12.0")) {
|
||||||
// ToDo: API to check if user is subscribed to an issue (do not exist can be guessed by many api endpoints :/)
|
subscribeIssue.setVisibility(View.GONE);
|
||||||
if(tinyDB.getBoolean("repoWatch")) {
|
unsubscribeIssue.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
else if(tinyDB.getBoolean("issueSubscribed")) {
|
||||||
subscribeIssue.setVisibility(View.GONE);
|
subscribeIssue.setVisibility(View.GONE);
|
||||||
unsubscribeIssue.setVisibility(View.VISIBLE);
|
unsubscribeIssue.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
subscribeIssue.setVisibility(View.VISIBLE);
|
||||||
|
unsubscribeIssue.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import org.mian.gitnex.models.UserOrganizations;
|
|||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
import org.mian.gitnex.models.UserSearch;
|
import org.mian.gitnex.models.UserSearch;
|
||||||
import org.mian.gitnex.models.UserTokens;
|
import org.mian.gitnex.models.UserTokens;
|
||||||
import org.mian.gitnex.models.WatchRepository;
|
import org.mian.gitnex.models.WatchInfo;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -247,7 +247,7 @@ public interface ApiInterface {
|
|||||||
Call<JsonElement> unStarRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
Call<JsonElement> unStarRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
|
|
||||||
@GET("repos/{owner}/{repo}/subscription") // check watch status of a repository
|
@GET("repos/{owner}/{repo}/subscription") // check watch status of a repository
|
||||||
Call<WatchRepository> checkRepoWatchStatus(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
Call<WatchInfo> checkRepoWatchStatus(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
|
|
||||||
@PUT("repos/{owner}/{repo}/subscription") // watch a repository
|
@PUT("repos/{owner}/{repo}/subscription") // watch a repository
|
||||||
Call<JsonElement> watchRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
Call<JsonElement> watchRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
@ -255,6 +255,9 @@ public interface ApiInterface {
|
|||||||
@DELETE("repos/{owner}/{repo}/subscription") // un watch a repository
|
@DELETE("repos/{owner}/{repo}/subscription") // un watch a repository
|
||||||
Call<JsonElement> unWatchRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
Call<JsonElement> unWatchRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
|
|
||||||
|
@GET("repos/{owner}/{repo}/issues/{index}/subscriptions/check")
|
||||||
|
Call<WatchInfo> checkIssueWatchStatus(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("index") int issueIndex);
|
||||||
|
|
||||||
@PUT("repos/{owner}/{repo}/issues/{index}/subscriptions/{user}") // subscribe user to issue
|
@PUT("repos/{owner}/{repo}/issues/{index}/subscriptions/{user}") // subscribe user to issue
|
||||||
Call<Void> addIssueSubscriber(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("index") int issueIndex, @Path("user") String issueSubscriber);
|
Call<Void> addIssueSubscriber(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("index") int issueIndex, @Path("user") String issueSubscriber);
|
||||||
|
|
||||||
|
40
app/src/main/java/org/mian/gitnex/models/WatchInfo.java
Normal file
40
app/src/main/java/org/mian/gitnex/models/WatchInfo.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package org.mian.gitnex.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class WatchInfo {
|
||||||
|
|
||||||
|
private Boolean subscribed;
|
||||||
|
private Boolean ignored; // = !subscribed
|
||||||
|
private String reason; // not used by gitea jet
|
||||||
|
private String created_at;
|
||||||
|
private String url;
|
||||||
|
private String repository_url;
|
||||||
|
|
||||||
|
public Boolean getSubscribed() {
|
||||||
|
|
||||||
|
return subscribed;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreated_at() {
|
||||||
|
|
||||||
|
return created_at;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
|
||||||
|
return url;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepository_url() {
|
||||||
|
|
||||||
|
return repository_url;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,39 +0,0 @@
|
|||||||
package org.mian.gitnex.models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class WatchRepository {
|
|
||||||
|
|
||||||
private Boolean subscribed;
|
|
||||||
private Boolean ignored;
|
|
||||||
private String reason;
|
|
||||||
private String created_at;
|
|
||||||
private String url;
|
|
||||||
private String repository_url;
|
|
||||||
|
|
||||||
public Boolean getSubscribed() {
|
|
||||||
return subscribed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getIgnored() {
|
|
||||||
return ignored;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReason() {
|
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCreated_at() {
|
|
||||||
return created_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRepository_url() {
|
|
||||||
return repository_url;
|
|
||||||
}
|
|
||||||
}
|
|
@ -84,7 +84,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:text="@string/singleIssueSubscribe"
|
android:text="@string/singleIssueSubscribe"
|
||||||
android:drawableStart="@drawable/ic_watchers"
|
android:drawableStart="@drawable/ic_unwatch"
|
||||||
android:drawablePadding="24dp"
|
android:drawablePadding="24dp"
|
||||||
android:textColor="?attr/primaryTextColor"
|
android:textColor="?attr/primaryTextColor"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
@ -96,7 +96,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:drawableStart="@drawable/ic_unwatch"
|
android:drawableStart="@drawable/ic_watchers"
|
||||||
android:drawablePadding="24dp"
|
android:drawablePadding="24dp"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:text="@string/singleIssueUnSubscribe"
|
android:text="@string/singleIssueUnSubscribe"
|
||||||
|
@ -632,10 +632,12 @@
|
|||||||
<string name="mtm_decision_once">Once</string>
|
<string name="mtm_decision_once">Once</string>
|
||||||
<string name="mtm_decision_abort">Abort</string>
|
<string name="mtm_decision_abort">Abort</string>
|
||||||
|
|
||||||
<string name="issueSubscribtion">Issue Subscribed</string>
|
<string name="subscribedSuccessfully">Subscribed successfully</string>
|
||||||
<string name="issueSubscribtionError">Issue Subscription failed</string>
|
<string name="alreadySubscribed">You have already subscribed</string>
|
||||||
<string name="issueUnsubscribtion">Issue Unsubscribed</string>
|
<string name="subscribtionError">Subscription failed</string>
|
||||||
<string name="issueUnsubscribtionError">Issue Un-Subscription failed</string>
|
<string name="unsubscribedSuccessfully">Unsubscribed successfully</string>
|
||||||
|
<string name="alreadyUnsubscribed">You have already Unsubscribed</string>
|
||||||
|
<string name="unsubscribtionError">Un-Subscription failed</string>
|
||||||
|
|
||||||
<string name="closeMilestone">Close Milestone</string>
|
<string name="closeMilestone">Close Milestone</string>
|
||||||
<string name="openMilestone">Open Milestone</string>
|
<string name="openMilestone">Open Milestone</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user