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:
		| @@ -2,8 +2,6 @@ package org.mian.gitnex.actions; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.util.Log; | ||||
| import android.view.View; | ||||
| import android.widget.TextView; | ||||
| import androidx.annotation.NonNull; | ||||
| import com.google.gson.JsonElement; | ||||
| 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 String instanceUrl = tinyDB.getString("instanceUrl"); | ||||
| 		String repoFullName = tinyDB.getString("repoFullName"); | ||||
| 		String[] parts = repoFullName.split("/"); | ||||
| 		final String repoOwner = parts[0]; | ||||
| 		final String repoName = parts[1]; | ||||
| 		final String loginUid = tinyDB.getString("loginUid"); | ||||
| 		String[] repoFullName = tinyDB.getString("repoFullName").split("/"); | ||||
| 		if(repoFullName.length != 2) { | ||||
| 			return; | ||||
| 		} | ||||
| 		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")); | ||||
|  | ||||
| 		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>() { | ||||
|  | ||||
| @@ -187,10 +184,14 @@ public class IssueActions { | ||||
|  | ||||
| 					if(response.code() == 201) { | ||||
|  | ||||
| 						unsubscribeIssue.setVisibility(View.VISIBLE); | ||||
| 						subscribeIssue.setVisibility(View.GONE); | ||||
| 						Toasty.info(ctx, ctx.getString(R.string.issueSubscribtion)); | ||||
| 						tinyDB.putString("issueSubscriptionState", "unsubscribeToIssue"); | ||||
| 						Toasty.info(ctx, ctx.getString(R.string.subscribedSuccessfully)); | ||||
| 						tinyDB.putBoolean("issueSubscribed", true); | ||||
|  | ||||
| 					} | ||||
| 					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 { | ||||
|  | ||||
| 					Toasty.info(ctx, ctx.getString(R.string.issueSubscribtionError)); | ||||
| 					Toasty.info(ctx, ctx.getString(R.string.subscribtionError)); | ||||
|  | ||||
| 				} | ||||
|  | ||||
| @@ -211,29 +212,28 @@ public class IssueActions { | ||||
| 			@Override | ||||
| 			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 String instanceUrl = tinyDB.getString("instanceUrl"); | ||||
| 		String repoFullName = tinyDB.getString("repoFullName"); | ||||
| 		String[] parts = repoFullName.split("/"); | ||||
| 		final String repoOwner = parts[0]; | ||||
| 		final String repoName = parts[1]; | ||||
| 		final String loginUid = tinyDB.getString("loginUid"); | ||||
| 		String[] repoFullName = tinyDB.getString("repoFullName").split("/"); | ||||
| 		if(repoFullName.length != 2) { | ||||
| 			return; | ||||
| 		} | ||||
| 		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")); | ||||
|  | ||||
| 		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>() { | ||||
|  | ||||
| @@ -244,10 +244,14 @@ public class IssueActions { | ||||
|  | ||||
| 					if(response.code() == 201) { | ||||
|  | ||||
| 						unsubscribeIssue.setVisibility(View.GONE); | ||||
| 						subscribeIssue.setVisibility(View.VISIBLE); | ||||
| 						Toasty.info(ctx, ctx.getString(R.string.issueUnsubscribtion)); | ||||
| 						tinyDB.putString("issueSubscriptionState", "subscribeToIssue"); | ||||
| 						Toasty.info(ctx, ctx.getString(R.string.unsubscribedSuccessfully)); | ||||
| 						tinyDB.putBoolean("issueSubscribed", false); | ||||
|  | ||||
| 					} | ||||
| 					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 { | ||||
|  | ||||
| 					Toasty.info(ctx, ctx.getString(R.string.issueUnsubscribtionError)); | ||||
| 					Toasty.info(ctx, ctx.getString(R.string.unsubscribtionError)); | ||||
|  | ||||
| 				} | ||||
|  | ||||
| @@ -268,7 +272,7 @@ public class IssueActions { | ||||
| 			@Override | ||||
| 			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.TimeHelper; | ||||
| import org.mian.gitnex.helpers.UserMentions; | ||||
| import org.mian.gitnex.helpers.Version; | ||||
| import org.mian.gitnex.models.IssueComments; | ||||
| import org.mian.gitnex.models.Issues; | ||||
| import org.mian.gitnex.models.WatchInfo; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
| import org.mian.gitnex.viewmodels.IssueCommentsViewModel; | ||||
| 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() { | ||||
|   | ||||
| @@ -40,7 +40,7 @@ import org.mian.gitnex.fragments.RepoInfoFragment; | ||||
| import org.mian.gitnex.helpers.Authorization; | ||||
| import org.mian.gitnex.helpers.Version; | ||||
| 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.TinyDB; | ||||
| 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) { | ||||
|  | ||||
| 		Call<WatchRepository> call; | ||||
| 		Call<WatchInfo> call; | ||||
|  | ||||
| 		call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoWatchStatus(instanceToken, owner, repo); | ||||
|  | ||||
| 		call.enqueue(new Callback<WatchRepository>() { | ||||
| 		call.enqueue(new Callback<WatchInfo>() { | ||||
|  | ||||
| 			@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); | ||||
|  | ||||
| @@ -510,7 +510,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF | ||||
| 			} | ||||
|  | ||||
| 			@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()); | ||||
| 			} | ||||
|   | ||||
| @@ -25,7 +25,7 @@ import org.mian.gitnex.clients.RetrofitClient; | ||||
| import org.mian.gitnex.helpers.RoundedTransformation; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| 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 java.util.List; | ||||
| import retrofit2.Call; | ||||
| @@ -95,16 +95,16 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo | ||||
| 					final String repoName = parts[1]; | ||||
| 					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.enqueue(new Callback<WatchRepository>() { | ||||
| 					call.enqueue(new Callback<WatchInfo>() { | ||||
|  | ||||
| 						@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()) { | ||||
|  | ||||
| @@ -126,7 +126,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo | ||||
| 						} | ||||
|  | ||||
| 						@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); | ||||
| 							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.Toasty; | ||||
| 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 java.util.ArrayList; | ||||
| import java.util.List; | ||||
| @@ -88,16 +88,16 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter. | ||||
|                     final String repoName = parts[1]; | ||||
|                     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.enqueue(new Callback<WatchRepository>() { | ||||
|                     call.enqueue(new Callback<WatchInfo>() { | ||||
|  | ||||
|                         @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()) { | ||||
|  | ||||
| @@ -119,7 +119,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter. | ||||
|                         } | ||||
|  | ||||
|                         @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); | ||||
|                             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.Toasty; | ||||
| 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 java.util.ArrayList; | ||||
| import java.util.List; | ||||
| @@ -95,16 +95,16 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo | ||||
| 					final String repoName = parts[1]; | ||||
| 					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.enqueue(new Callback<WatchRepository>() { | ||||
| 					call.enqueue(new Callback<WatchInfo>() { | ||||
|  | ||||
| 						@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()) { | ||||
|  | ||||
| @@ -126,7 +126,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo | ||||
| 						} | ||||
|  | ||||
| 						@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); | ||||
| 							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.Toasty; | ||||
| 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 java.util.ArrayList; | ||||
| import java.util.List; | ||||
| @@ -92,16 +92,16 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB | ||||
|                     final String repoName = parts[1]; | ||||
|                     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.enqueue(new Callback<WatchRepository>() { | ||||
|                     call.enqueue(new Callback<WatchInfo>() { | ||||
|  | ||||
|                         @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()) { | ||||
|  | ||||
| @@ -123,7 +123,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB | ||||
|                         } | ||||
|  | ||||
|                         @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); | ||||
|                             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.Toasty; | ||||
| 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 java.util.ArrayList; | ||||
| import java.util.List; | ||||
| @@ -92,16 +92,16 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi | ||||
|                     final String repoName = parts[1]; | ||||
|                     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.enqueue(new Callback<WatchRepository>() { | ||||
|                     call.enqueue(new Callback<WatchInfo>() { | ||||
|  | ||||
|                         @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()) { | ||||
|  | ||||
| @@ -123,7 +123,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi | ||||
|                         } | ||||
|  | ||||
|                         @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); | ||||
|                             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.MergePullRequestActivity; | ||||
| import org.mian.gitnex.helpers.Toasty; | ||||
| import org.mian.gitnex.helpers.Version; | ||||
| import org.mian.gitnex.util.TinyDB; | ||||
| import java.util.Objects; | ||||
|  | ||||
| @@ -222,24 +223,30 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment { | ||||
|  | ||||
| 		subscribeIssue.setOnClickListener(subscribeToIssue -> { | ||||
|  | ||||
| 			IssueActions.subscribe(ctx, subscribeIssue, unsubscribeIssue); | ||||
| 			//dismiss(); | ||||
| 			IssueActions.subscribe(ctx); | ||||
| 			dismiss(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		unsubscribeIssue.setOnClickListener(unsubscribeToIssue -> { | ||||
|  | ||||
| 			IssueActions.unsubscribe(ctx, subscribeIssue, unsubscribeIssue); | ||||
| 			//dismiss(); | ||||
| 			IssueActions.unsubscribe(ctx); | ||||
| 			dismiss(); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| 		//if RepoWatch True Provide Unsubscribe first | ||||
| 		// ToDo: API to check if user is subscribed to an issue (do not exist can be guessed by many api endpoints :/) | ||||
| 		if(tinyDB.getBoolean("repoWatch")) { | ||||
| 		if(new Version(tinyDB.getString("giteaVersion")).less("1.12.0")) { | ||||
| 			subscribeIssue.setVisibility(View.GONE); | ||||
| 			unsubscribeIssue.setVisibility(View.GONE); | ||||
| 		} | ||||
| 		else if(tinyDB.getBoolean("issueSubscribed")) { | ||||
| 			subscribeIssue.setVisibility(View.GONE); | ||||
| 			unsubscribeIssue.setVisibility(View.VISIBLE); | ||||
| 		} | ||||
| 		else { | ||||
| 			subscribeIssue.setVisibility(View.VISIBLE); | ||||
| 			unsubscribeIssue.setVisibility(View.GONE); | ||||
| 		} | ||||
|  | ||||
| 		return v; | ||||
| 	} | ||||
|   | ||||
| @@ -31,7 +31,7 @@ import org.mian.gitnex.models.UserOrganizations; | ||||
| import org.mian.gitnex.models.UserRepositories; | ||||
| import org.mian.gitnex.models.UserSearch; | ||||
| import org.mian.gitnex.models.UserTokens; | ||||
| import org.mian.gitnex.models.WatchRepository; | ||||
| import org.mian.gitnex.models.WatchInfo; | ||||
| import java.util.List; | ||||
| import okhttp3.ResponseBody; | ||||
| 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); | ||||
|  | ||||
|     @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 | ||||
|     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 | ||||
|     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 | ||||
|     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; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user