Merge branch '136-watch-a-repo' of gitnex/GitNex into master
This commit is contained in:
commit
143d680627
@ -149,4 +149,132 @@ public class RepositoryActions {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void watchRepository(final Context context) {
|
||||||
|
|
||||||
|
final TinyDB tinyDb = new TinyDB(context);
|
||||||
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||||
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
final String repoOwner = parts[0];
|
||||||
|
final String repoName = parts[1];
|
||||||
|
|
||||||
|
Call<JsonElement> call;
|
||||||
|
|
||||||
|
call = RetrofitClient
|
||||||
|
.getInstance(instanceUrl)
|
||||||
|
.getApiInterface()
|
||||||
|
.watchRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
if(response.code() == 200) {
|
||||||
|
|
||||||
|
tinyDb.putBoolean("repoCreated", true);
|
||||||
|
Toasty.info(context, context.getString(R.string.watchRepositorySuccess));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
context.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
context.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
|
Toasty.info(context, context.getString(R.string.authorizeError));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
|
Toasty.info(context, context.getString(R.string.apiNotFound));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Toasty.info(context, context.getString(R.string.genericError));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unWatchRepository(final Context context) {
|
||||||
|
|
||||||
|
final TinyDB tinyDb = new TinyDB(context);
|
||||||
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||||
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
final String repoOwner = parts[0];
|
||||||
|
final String repoName = parts[1];
|
||||||
|
|
||||||
|
Call<JsonElement> call;
|
||||||
|
|
||||||
|
call = RetrofitClient
|
||||||
|
.getInstance(instanceUrl)
|
||||||
|
.getApiInterface()
|
||||||
|
.unWatchRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
|
if(response.code() == 204) {
|
||||||
|
|
||||||
|
tinyDb.putBoolean("repoCreated", true);
|
||||||
|
Toasty.info(context, context.getString(R.string.unWatchRepositorySuccess));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
context.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
context.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
|
Toasty.info(context, context.getString(R.string.authorizeError));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
|
Toasty.info(context, context.getString(R.string.apiNotFound));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Toasty.info(context, context.getString(R.string.genericError));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import org.mian.gitnex.fragments.RepoBottomSheetFragment;
|
|||||||
import org.mian.gitnex.fragments.RepoInfoFragment;
|
import org.mian.gitnex.fragments.RepoInfoFragment;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.mian.gitnex.models.UserRepositories;
|
||||||
|
import org.mian.gitnex.models.WatchRepository;
|
||||||
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;
|
||||||
@ -100,6 +101,7 @@ public class RepoDetailActivity extends AppCompatActivity implements RepoBottomS
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkRepositoryStarStatus(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName1);
|
checkRepositoryStarStatus(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName1);
|
||||||
|
checkRepositoryWatchStatus(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -297,4 +299,40 @@ public class RepoDetailActivity extends AppCompatActivity implements RepoBottomS
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkRepositoryWatchStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
||||||
|
|
||||||
|
Call<WatchRepository> call;
|
||||||
|
|
||||||
|
call = RetrofitClient
|
||||||
|
.getInstance(instanceUrl)
|
||||||
|
.getApiInterface()
|
||||||
|
.checkRepoWatchStatus(instanceToken, owner, repo);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<WatchRepository>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
||||||
|
|
||||||
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||||
|
|
||||||
|
if(response.code() == 200) {
|
||||||
|
assert response.body() != null;
|
||||||
|
if(response.body().getSubscribed()) {
|
||||||
|
tinyDb.putBoolean("repositoryWatchStatus", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tinyDb.putBoolean("repositoryWatchStatus", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@ public class RepoBottomSheetFragment extends BottomSheetDialogFragment {
|
|||||||
TextView newFile = v.findViewById(R.id.newFile);
|
TextView newFile = v.findViewById(R.id.newFile);
|
||||||
TextView starRepository = v.findViewById(R.id.starRepository);
|
TextView starRepository = v.findViewById(R.id.starRepository);
|
||||||
TextView unStarRepository = v.findViewById(R.id.unStarRepository);
|
TextView unStarRepository = v.findViewById(R.id.unStarRepository);
|
||||||
|
TextView watchRepository = v.findViewById(R.id.watchRepository);
|
||||||
|
TextView unWatchRepository = v.findViewById(R.id.unWatchRepository);
|
||||||
|
|
||||||
createLabel.setOnClickListener(new View.OnClickListener() {
|
createLabel.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -109,6 +111,7 @@ public class RepoBottomSheetFragment extends BottomSheetDialogFragment {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
RepositoryActions.unStarRepository(getContext());
|
RepositoryActions.unStarRepository(getContext());
|
||||||
|
tinyDb.putInt("repositoryStarStatus", 404);
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -124,6 +127,40 @@ public class RepoBottomSheetFragment extends BottomSheetDialogFragment {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
RepositoryActions.starRepository(getContext());
|
RepositoryActions.starRepository(getContext());
|
||||||
|
tinyDb.putInt("repositoryStarStatus", 204);
|
||||||
|
dismiss();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tinyDb.getBoolean("repositoryWatchStatus")) { // watch a repo
|
||||||
|
|
||||||
|
watchRepository.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
unWatchRepository.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
RepositoryActions.unWatchRepository(getContext());
|
||||||
|
tinyDb.putBoolean("repositoryWatchStatus", false);
|
||||||
|
dismiss();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
unWatchRepository.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
watchRepository.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
RepositoryActions.watchRepository(getContext());
|
||||||
|
tinyDb.putBoolean("repositoryWatchStatus", true);
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,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 java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.http.Body;
|
import retrofit2.http.Body;
|
||||||
@ -237,4 +238,13 @@ public interface ApiInterface {
|
|||||||
|
|
||||||
@DELETE("user/starred/{owner}/{repo}") // un star a repository
|
@DELETE("user/starred/{owner}/{repo}") // un star a repository
|
||||||
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
|
||||||
|
Call<WatchRepository> 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);
|
||||||
|
|
||||||
|
@DELETE("repos/{owner}/{repo}/subscription") // un watch a repository
|
||||||
|
Call<JsonElement> unWatchRepository(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
6
app/src/main/res/drawable/ic_unwatch.xml
Normal file
6
app/src/main/res/drawable/ic_unwatch.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<vector android:autoMirrored="true" android:height="24dp"
|
||||||
|
android:viewportHeight="511.999" android:viewportWidth="511.999"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FFFFFFFF" android:pathData="M508.745,246.041c-4.574,-6.257 -113.557,-153.206 -252.748,-153.206S7.818,239.784 3.249,246.035c-4.332,5.936 -4.332,13.987 0,19.923c4.569,6.257 113.557,153.206 252.748,153.206s248.174,-146.95 252.748,-153.201C513.083,260.028 513.083,251.971 508.745,246.041zM255.997,385.406c-102.529,0 -191.33,-97.533 -217.617,-129.418c26.253,-31.913 114.868,-129.395 217.617,-129.395c102.524,0 191.319,97.516 217.617,129.418C447.361,287.923 358.746,385.406 255.997,385.406z"/>
|
||||||
|
<path android:fillColor="#FFFFFFFF" android:pathData="M255.997,154.725c-55.842,0 -101.275,45.433 -101.275,101.275s45.433,101.275 101.275,101.275s101.275,-45.433 101.275,-101.275S311.839,154.725 255.997,154.725zM255.997,323.516c-37.23,0 -67.516,-30.287 -67.516,-67.516s30.287,-67.516 67.516,-67.516s67.516,30.287 67.516,67.516S293.227,323.516 255.997,323.516z"/>
|
||||||
|
</vector>
|
@ -115,6 +115,30 @@
|
|||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:padding="16dp" />
|
android:padding="16dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/watchRepository"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/watchRepository"
|
||||||
|
android:drawableStart="@drawable/ic_unwatch"
|
||||||
|
android:drawablePadding="24dp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:padding="16dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/unWatchRepository"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/unWatchRepository"
|
||||||
|
android:drawableStart="@drawable/ic_watchers"
|
||||||
|
android:drawablePadding="24dp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:padding="16dp" />
|
||||||
|
|
||||||
<View style="@style/lineDividerHorizontal" />
|
<View style="@style/lineDividerHorizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/linearLayoutFrame"
|
android:id="@+id/linearLayoutFrame"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_marginTop="0dp"
|
android:layout_marginTop="0dp"
|
||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
|
@ -506,7 +506,11 @@
|
|||||||
<string name="exploreTextBoxHint">Explore repositories</string>
|
<string name="exploreTextBoxHint">Explore repositories</string>
|
||||||
<string name="starRepository">Star Repository</string>
|
<string name="starRepository">Star Repository</string>
|
||||||
<string name="unStarRepository">Unstar Repository</string>
|
<string name="unStarRepository">Unstar Repository</string>
|
||||||
<string name="starRepositorySuccess">Repository starred</string>
|
<string name="starRepositorySuccess">Repository added to starred list</string>
|
||||||
<string name="unStarRepositorySuccess">Repository unstarred</string>
|
<string name="unStarRepositorySuccess">Repository removed from starred list</string>
|
||||||
|
<string name="watchRepository">Watch Repository</string>
|
||||||
|
<string name="unWatchRepository">Unwatch Repository</string>
|
||||||
|
<string name="watchRepositorySuccess">Repository added to watch list</string>
|
||||||
|
<string name="unWatchRepositorySuccess">Repository removed from watch list</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user