Allow to reblog/unreblog, favourite/unfavourite, bookmark/unbookmark videos from mastodon/pleroma Accounts
This commit is contained in:
parent
d446081331
commit
b5e9f70be6
|
@ -7,6 +7,8 @@
|
||||||
<color name="tag_color">#bbF2690D</color>
|
<color name="tag_color">#bbF2690D</color>
|
||||||
<color name="tag_color_text">#FAFAFA</color>
|
<color name="tag_color_text">#FAFAFA</color>
|
||||||
<color name="positive_thumbs">#2b90d9</color>
|
<color name="positive_thumbs">#2b90d9</color>
|
||||||
|
<color name="favorite">#ca8f04</color>
|
||||||
|
<color name="bookmark">#795548</color>
|
||||||
<color name="negative_thumbs">#F44336</color>
|
<color name="negative_thumbs">#F44336</color>
|
||||||
<color name="backgroundDark">#DD000000</color>
|
<color name="backgroundDark">#DD000000</color>
|
||||||
<color name="red_1">#F44336</color>
|
<color name="red_1">#F44336</color>
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
<color name="tag_color">#bbF2690D</color>
|
<color name="tag_color">#bbF2690D</color>
|
||||||
<color name="tag_color_text">#FAFAFA</color>
|
<color name="tag_color_text">#FAFAFA</color>
|
||||||
<color name="positive_thumbs">#2b90d9</color>
|
<color name="positive_thumbs">#2b90d9</color>
|
||||||
|
<color name="favorite">#ca8f04</color>
|
||||||
|
<color name="bookmark">#795548</color>
|
||||||
<color name="negative_thumbs">#F44336</color>
|
<color name="negative_thumbs">#F44336</color>
|
||||||
<color name="backgroundDark">#DD000000</color>
|
<color name="backgroundDark">#DD000000</color>
|
||||||
<color name="red_1">#F44336</color>
|
<color name="red_1">#F44336</color>
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
<color name="tag_color_text">#FAFAFA</color>
|
<color name="tag_color_text">#FAFAFA</color>
|
||||||
<color name="positive_thumbs">#2b90d9</color>
|
<color name="positive_thumbs">#2b90d9</color>
|
||||||
<color name="negative_thumbs">#F44336</color>
|
<color name="negative_thumbs">#F44336</color>
|
||||||
|
<color name="favorite">#ca8f04</color>
|
||||||
|
<color name="bookmark">#795548</color>
|
||||||
<color name="backgroundDark">#DD000000</color>
|
<color name="backgroundDark">#DD000000</color>
|
||||||
<color name="red_1">#F44336</color>
|
<color name="red_1">#F44336</color>
|
||||||
<color name="gray_light">#80808080</color>
|
<color name="gray_light">#80808080</color>
|
||||||
|
|
|
@ -943,7 +943,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
NORMAL,
|
NORMAL,
|
||||||
SURFING,
|
SURFING,
|
||||||
REMOTE_ACCOUNT
|
REMOTE_ACCOUNT,
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
|
@ -142,6 +142,7 @@ import app.fedilab.fedilabtube.client.entities.MenuItemView;
|
||||||
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
import app.fedilab.fedilabtube.client.entities.PlaylistExist;
|
||||||
import app.fedilab.fedilabtube.client.entities.Report;
|
import app.fedilab.fedilabtube.client.entities.Report;
|
||||||
import app.fedilab.fedilabtube.client.entities.UserSettings;
|
import app.fedilab.fedilabtube.client.entities.UserSettings;
|
||||||
|
import app.fedilab.fedilabtube.client.mastodon.RetrofitMastodonAPI;
|
||||||
import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding;
|
import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding;
|
||||||
import app.fedilab.fedilabtube.drawer.CommentListAdapter;
|
import app.fedilab.fedilabtube.drawer.CommentListAdapter;
|
||||||
import app.fedilab.fedilabtube.drawer.MenuAdapter;
|
import app.fedilab.fedilabtube.drawer.MenuAdapter;
|
||||||
|
@ -218,6 +219,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
private boolean isRemote;
|
private boolean isRemote;
|
||||||
private boolean willPlayFromIntent;
|
private boolean willPlayFromIntent;
|
||||||
private String chromeCastVideoURL;
|
private String chromeCastVideoURL;
|
||||||
|
private app.fedilab.fedilabtube.client.mastodon.Status status;
|
||||||
|
|
||||||
public static void hideKeyboard(Activity activity) {
|
public static void hideKeyboard(Activity activity) {
|
||||||
if (activity != null && activity.getWindow() != null) {
|
if (activity != null && activity.getWindow() != null) {
|
||||||
|
@ -366,6 +368,15 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
|
|
||||||
willPlayFromIntent = manageIntentUrl(intent);
|
willPlayFromIntent = manageIntentUrl(intent);
|
||||||
|
|
||||||
|
if (BuildConfig.allow_remote_connections && Helper.isLoggedInType(PeertubeActivity.this) == MainActivity.TypeOfConnection.REMOTE_ACCOUNT) {
|
||||||
|
binding.peertubeLikeCount.setVisibility(View.GONE);
|
||||||
|
binding.peertubeDislikeCount.setVisibility(View.GONE);
|
||||||
|
binding.peertubePlaylist.setVisibility(View.GONE);
|
||||||
|
binding.peertubeReblog.setVisibility(View.VISIBLE);
|
||||||
|
binding.peertubeFavorite.setVisibility(View.VISIBLE);
|
||||||
|
binding.peertubeBookmark.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
binding.peertubeDescriptionMore.setOnClickListener(v -> {
|
binding.peertubeDescriptionMore.setOnClickListener(v -> {
|
||||||
if (show_more_content != null && peertube != null) {
|
if (show_more_content != null && peertube != null) {
|
||||||
if (binding.peertubeDescriptionMore.getText().toString().compareTo(getString(R.string.show_more)) == 0) {
|
if (binding.peertubeDescriptionMore.getText().toString().compareTo(getString(R.string.show_more)) == 0) {
|
||||||
|
@ -1088,6 +1099,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
binding.writeCommentContainer.setVisibility(View.GONE);
|
binding.writeCommentContainer.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (peertube.isNsfw()) {
|
if (peertube.isNsfw()) {
|
||||||
binding.videoSensitive.setVisibility(View.VISIBLE);
|
binding.videoSensitive.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1209,6 +1221,24 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
changeColor();
|
changeColor();
|
||||||
initResolution();
|
initResolution();
|
||||||
|
|
||||||
|
binding.peertubeReblog.setOnClickListener(v -> {
|
||||||
|
MastodonPostActionsVM mastodonPostActionsVM = new ViewModelProvider(PeertubeActivity.this).get(MastodonPostActionsVM.class);
|
||||||
|
RetrofitMastodonAPI.actionType type = status.isReblogged() ? RetrofitMastodonAPI.actionType.UNBOOST : RetrofitMastodonAPI.actionType.BOOST;
|
||||||
|
mastodonPostActionsVM.post(type, status).observe(PeertubeActivity.this, this::manageVIewPostActionsMastodon);
|
||||||
|
});
|
||||||
|
|
||||||
|
binding.peertubeFavorite.setOnClickListener(v -> {
|
||||||
|
MastodonPostActionsVM mastodonPostActionsVM = new ViewModelProvider(PeertubeActivity.this).get(MastodonPostActionsVM.class);
|
||||||
|
RetrofitMastodonAPI.actionType type = status.isFavourited() ? RetrofitMastodonAPI.actionType.UNFAVOURITE : RetrofitMastodonAPI.actionType.FAVOURITE;
|
||||||
|
mastodonPostActionsVM.post(type, status).observe(PeertubeActivity.this, this::manageVIewPostActionsMastodon);
|
||||||
|
});
|
||||||
|
|
||||||
|
binding.peertubeBookmark.setOnClickListener(v -> {
|
||||||
|
MastodonPostActionsVM mastodonPostActionsVM = new ViewModelProvider(PeertubeActivity.this).get(MastodonPostActionsVM.class);
|
||||||
|
RetrofitMastodonAPI.actionType type = status.isBookmarked() ? RetrofitMastodonAPI.actionType.UNBOOKMARK : RetrofitMastodonAPI.actionType.BOOKMARK;
|
||||||
|
mastodonPostActionsVM.post(type, status).observe(PeertubeActivity.this, this::manageVIewPostActionsMastodon);
|
||||||
|
});
|
||||||
|
|
||||||
binding.peertubeLikeCount.setOnClickListener(v -> {
|
binding.peertubeLikeCount.setOnClickListener(v -> {
|
||||||
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
||||||
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
|
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
|
||||||
|
@ -1260,6 +1290,11 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (BuildConfig.allow_remote_connections && Helper.isLoggedInType(PeertubeActivity.this) == MainActivity.TypeOfConnection.REMOTE_ACCOUNT) {
|
||||||
|
String url = "https://" + peertube.getChannel().getHost() + "/videos/watch/" + peertube.getUuid();
|
||||||
|
MastodonPostActionsVM postActionsVM = new ViewModelProvider(PeertubeActivity.this).get(MastodonPostActionsVM.class);
|
||||||
|
postActionsVM.searchRemoteStatus(url).observe(PeertubeActivity.this, this::retrieveRemoteStatus);
|
||||||
|
}
|
||||||
|
|
||||||
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
|
||||||
|
|
||||||
|
@ -2173,6 +2208,17 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
binding.postComment.startAnimation(animateComment);
|
binding.postComment.startAnimation(animateComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void manageVIewPostActionsMastodon(app.fedilab.fedilabtube.client.mastodon.Status status) {
|
||||||
|
if (status != null) {
|
||||||
|
this.status = status;
|
||||||
|
changeColorMastodon();
|
||||||
|
binding.peertubeFavorite.setText(String.valueOf(status.getFavouriteCount()));
|
||||||
|
binding.peertubeReblog.setText(String.valueOf(status.getReblogsCount()));
|
||||||
|
} else {
|
||||||
|
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void manageVIewPostActionsMastodon(RetrofitPeertubeAPI.ActionType statusAction, int position, app.fedilab.fedilabtube.client.mastodon.Status status) {
|
public void manageVIewPostActionsMastodon(RetrofitPeertubeAPI.ActionType statusAction, int position, app.fedilab.fedilabtube.client.mastodon.Status status) {
|
||||||
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
|
if (peertube.isCommentsEnabled() && statusAction == ADD_COMMENT) {
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
|
@ -2192,6 +2238,15 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void retrieveRemoteStatus(app.fedilab.fedilabtube.client.mastodon.Status status) {
|
||||||
|
this.status = status;
|
||||||
|
if (status != null) {
|
||||||
|
changeColorMastodon();
|
||||||
|
binding.peertubeFavorite.setText(String.valueOf(status.getFavouriteCount()));
|
||||||
|
binding.peertubeReblog.setText(String.valueOf(status.getReblogsCount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "RedundantSuppression"})
|
@SuppressWarnings({"unused", "RedundantSuppression"})
|
||||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int position, APIResponse apiResponse) {
|
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, int position, APIResponse apiResponse) {
|
||||||
|
|
||||||
|
@ -2269,6 +2324,47 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void changeColorMastodon() {
|
||||||
|
Drawable reblog = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_repeat_24);
|
||||||
|
Drawable favorite = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_star_24);
|
||||||
|
Drawable bookmark = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_bookmark_24);
|
||||||
|
|
||||||
|
int color = getAttColor(this, android.R.attr.colorControlNormal);
|
||||||
|
|
||||||
|
if (reblog != null) {
|
||||||
|
reblog.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
DrawableCompat.setTint(reblog, color);
|
||||||
|
}
|
||||||
|
if (favorite != null) {
|
||||||
|
favorite.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
DrawableCompat.setTint(favorite, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bookmark != null) {
|
||||||
|
bookmark.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||||
|
DrawableCompat.setTint(bookmark, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.isReblogged()) {
|
||||||
|
reblog.setColorFilter(getResources().getColor(R.color.positive_thumbs), PorterDuff.Mode.SRC_ATOP);
|
||||||
|
DrawableCompat.setTint(reblog, getResources().getColor(R.color.positive_thumbs));
|
||||||
|
}
|
||||||
|
if (status.isFavourited()) {
|
||||||
|
favorite.setColorFilter(getResources().getColor(R.color.favorite), PorterDuff.Mode.SRC_ATOP);
|
||||||
|
DrawableCompat.setTint(favorite, getResources().getColor(R.color.favorite));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.isBookmarked()) {
|
||||||
|
bookmark.setColorFilter(getResources().getColor(R.color.bookmark), PorterDuff.Mode.SRC_ATOP);
|
||||||
|
DrawableCompat.setTint(bookmark, getResources().getColor(R.color.bookmark));
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.peertubeReblog.setCompoundDrawablesWithIntrinsicBounds(null, reblog, null, null);
|
||||||
|
binding.peertubeFavorite.setCompoundDrawablesWithIntrinsicBounds(null, favorite, null, null);
|
||||||
|
binding.peertubeBookmark.setCompoundDrawablesWithIntrinsicBounds(null, bookmark, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
private void changeColor() {
|
private void changeColor() {
|
||||||
|
|
||||||
Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24);
|
Drawable thumbUp = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_baseline_thumb_up_alt_24);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import retrofit2.http.FormUrlEncoded;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Header;
|
import retrofit2.http.Header;
|
||||||
import retrofit2.http.POST;
|
import retrofit2.http.POST;
|
||||||
|
import retrofit2.http.Path;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
interface MastodonService {
|
interface MastodonService {
|
||||||
|
@ -60,4 +61,42 @@ interface MastodonService {
|
||||||
@Query("visibility") String visibility
|
@Query("visibility") String visibility
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@POST("statuses/{id}/reblog")
|
||||||
|
Call<Status> boost(
|
||||||
|
@Header("Authorization") String credentials,
|
||||||
|
@Path("id") String id
|
||||||
|
);
|
||||||
|
|
||||||
|
@POST("statuses/{id}/unreblog")
|
||||||
|
Call<Status> unBoost(
|
||||||
|
@Header("Authorization") String credentials,
|
||||||
|
@Path("id") String id
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@POST("statuses/{id}/favourite")
|
||||||
|
Call<Status> favourite(
|
||||||
|
@Header("Authorization") String credentials,
|
||||||
|
@Path("id") String id
|
||||||
|
);
|
||||||
|
|
||||||
|
@POST("statuses/{id}/unfavourite")
|
||||||
|
Call<Status> unfavourite(
|
||||||
|
@Header("Authorization") String credentials,
|
||||||
|
@Path("id") String id
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@POST("statuses/{id}/bookmark")
|
||||||
|
Call<Status> bookmark(
|
||||||
|
@Header("Authorization") String credentials,
|
||||||
|
@Path("id") String id
|
||||||
|
);
|
||||||
|
|
||||||
|
@POST("statuses/{id}/unbookmark")
|
||||||
|
Call<Status> unbookmark(
|
||||||
|
@Header("Authorization") String credentials,
|
||||||
|
@Path("id") String id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,30 @@ public class RetrofitMastodonAPI {
|
||||||
private String instance;
|
private String instance;
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
|
public Status search(String url) throws Error {
|
||||||
|
MastodonService mastodonService2 = init2();
|
||||||
|
Call<Results> statusCall = mastodonService2.searchMessage(getToken(), url);
|
||||||
|
Response<Results> response;
|
||||||
|
try {
|
||||||
|
response = statusCall.execute();
|
||||||
|
if (response.isSuccessful() && response.body() != null && response.body().getStatuses() != null && response.body().getStatuses().size() > 0) {
|
||||||
|
return response.body().getStatuses().get(0);
|
||||||
|
} else {
|
||||||
|
Error error = new Error();
|
||||||
|
error.setStatusCode(response.code());
|
||||||
|
if (response.errorBody() != null) {
|
||||||
|
error.setError(response.errorBody().string());
|
||||||
|
} else {
|
||||||
|
error.setError(_context.getString(R.string.toast_error));
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public RetrofitMastodonAPI(Context context) {
|
public RetrofitMastodonAPI(Context context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
|
@ -231,13 +255,7 @@ public class RetrofitMastodonAPI {
|
||||||
|
|
||||||
public Status commentAction(String url, String content) throws Error {
|
public Status commentAction(String url, String content) throws Error {
|
||||||
MastodonService mastodonService = init();
|
MastodonService mastodonService = init();
|
||||||
MastodonService mastodonService2 = init2();
|
Status status = search(url);
|
||||||
Call<Results> statusCall = mastodonService2.searchMessage(getToken(), url);
|
|
||||||
Response<Results> response;
|
|
||||||
try {
|
|
||||||
response = statusCall.execute();
|
|
||||||
if (response.isSuccessful() && response.body() != null && response.body().getStatuses() != null && response.body().getStatuses().size() > 0) {
|
|
||||||
Status status = response.body().getStatuses().get(0);
|
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
Call<Status> postReplyCall = mastodonService.postReply(getToken(), status.getId(), content, null);
|
Call<Status> postReplyCall = mastodonService.postReply(getToken(), status.getId(), content, null);
|
||||||
try {
|
try {
|
||||||
|
@ -253,23 +271,61 @@ public class RetrofitMastodonAPI {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
return null;
|
||||||
Error error = new Error();
|
}
|
||||||
error.setStatusCode(response.code());
|
|
||||||
if (response.errorBody() != null) {
|
public Status postAction(actionType type, Status status) throws Error {
|
||||||
error.setError(response.errorBody().string());
|
MastodonService mastodonService = init();
|
||||||
} else {
|
Call<Status> postAction = null;
|
||||||
error.setError(_context.getString(R.string.toast_error));
|
if (status != null) {
|
||||||
|
switch (type) {
|
||||||
|
case BOOST:
|
||||||
|
postAction = mastodonService.boost(getToken(), status.getId());
|
||||||
|
break;
|
||||||
|
case UNBOOST:
|
||||||
|
postAction = mastodonService.unBoost(getToken(), status.getId());
|
||||||
|
break;
|
||||||
|
case FAVOURITE:
|
||||||
|
postAction = mastodonService.favourite(getToken(), status.getId());
|
||||||
|
break;
|
||||||
|
case UNFAVOURITE:
|
||||||
|
postAction = mastodonService.unfavourite(getToken(), status.getId());
|
||||||
|
break;
|
||||||
|
case BOOKMARK:
|
||||||
|
postAction = mastodonService.bookmark(getToken(), status.getId());
|
||||||
|
break;
|
||||||
|
case UNBOOKMARK:
|
||||||
|
postAction = mastodonService.unbookmark(getToken(), status.getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (postAction != null) {
|
||||||
|
Response<Status> responsePost = postAction.execute();
|
||||||
|
if (responsePost.isSuccessful()) {
|
||||||
|
Status statusReturned = responsePost.body();
|
||||||
|
if (statusReturned != null && statusReturned.getAccount() != null) {
|
||||||
|
statusReturned.getAccount().setHost(instance);
|
||||||
|
}
|
||||||
|
return statusReturned;
|
||||||
}
|
}
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum actionType {
|
||||||
|
BOOST,
|
||||||
|
UNBOOST,
|
||||||
|
FAVOURITE,
|
||||||
|
UNFAVOURITE,
|
||||||
|
BOOKMARK,
|
||||||
|
UNBOOKMARK
|
||||||
|
}
|
||||||
|
|
||||||
private String getToken() {
|
private String getToken() {
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
return "Bearer " + token;
|
return "Bearer " + token;
|
||||||
|
|
|
@ -16,13 +16,12 @@ package app.fedilab.fedilabtube.client.mastodon;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import org.w3c.dom.Comment;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.client.data.CommentData;
|
import app.fedilab.fedilabtube.client.data.CommentData;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Status {
|
public class Status {
|
||||||
|
|
||||||
@SerializedName("id")
|
@SerializedName("id")
|
||||||
|
@ -37,6 +36,16 @@ public class Status {
|
||||||
private String text;
|
private String text;
|
||||||
@SerializedName("created_at")
|
@SerializedName("created_at")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
|
@SerializedName("reblogs_count")
|
||||||
|
private int reblogsCount;
|
||||||
|
@SerializedName("favourites_count")
|
||||||
|
private int favouritesCount;
|
||||||
|
@SerializedName("favourited")
|
||||||
|
private boolean favourited;
|
||||||
|
@SerializedName("reblogged")
|
||||||
|
private boolean reblogged;
|
||||||
|
@SerializedName("bookmarked")
|
||||||
|
private boolean bookmarked;
|
||||||
|
|
||||||
public static CommentData.Comment convertStatusToComment(Status status) {
|
public static CommentData.Comment convertStatusToComment(Status status) {
|
||||||
CommentData.Comment comment = new CommentData.Comment();
|
CommentData.Comment comment = new CommentData.Comment();
|
||||||
|
@ -93,4 +102,48 @@ public class Status {
|
||||||
public void setCreatedAt(Date createdAt) {
|
public void setCreatedAt(Date createdAt) {
|
||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getReblogsCount() {
|
||||||
|
return reblogsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReblogsCount(int reblogsCount) {
|
||||||
|
this.reblogsCount = reblogsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFavouriteCount() {
|
||||||
|
return favouritesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFavourited() {
|
||||||
|
return favourited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFavourited(boolean favourited) {
|
||||||
|
this.favourited = favourited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReblogged() {
|
||||||
|
return reblogged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReblogged(boolean reblogged) {
|
||||||
|
this.reblogged = reblogged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFavouritesCount() {
|
||||||
|
return favouritesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFavouritesCount(int favouritesCount) {
|
||||||
|
this.favouritesCount = favouritesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBookmarked() {
|
||||||
|
return bookmarked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBookmarked(boolean bookmarked) {
|
||||||
|
this.bookmarked = bookmarked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,44 @@ public class MastodonPostActionsVM extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public LiveData<Status> post(RetrofitMastodonAPI.actionType type, Status status) {
|
||||||
|
statusMutableLiveData = new MutableLiveData<>();
|
||||||
|
postAction(type, status);
|
||||||
|
return statusMutableLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
public LiveData<Status> comment(String url, String content) {
|
public LiveData<Status> comment(String url, String content) {
|
||||||
statusMutableLiveData = new MutableLiveData<>();
|
statusMutableLiveData = new MutableLiveData<>();
|
||||||
postComment(url, content);
|
postComment(url, content);
|
||||||
return statusMutableLiveData;
|
return statusMutableLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Status> searchRemoteStatus(String url) {
|
||||||
|
statusMutableLiveData = new MutableLiveData<>();
|
||||||
|
search(url);
|
||||||
|
return statusMutableLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void search(String videoURL) {
|
||||||
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
RetrofitMastodonAPI mastodonAPI = new RetrofitMastodonAPI(_mContext);
|
||||||
|
Status status = null;
|
||||||
|
try {
|
||||||
|
status = mastodonAPI.search(videoURL);
|
||||||
|
} catch (Error error) {
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Status finalStatus = status;
|
||||||
|
Runnable myRunnable = () -> statusMutableLiveData.setValue(finalStatus);
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
private void postComment(String videoURL, String content) {
|
private void postComment(String videoURL, String content) {
|
||||||
Context _mContext = getApplication().getApplicationContext();
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
|
@ -65,4 +97,20 @@ public class MastodonPostActionsVM extends AndroidViewModel {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void postAction(RetrofitMastodonAPI.actionType type, Status status) {
|
||||||
|
Context _mContext = getApplication().getApplicationContext();
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
RetrofitMastodonAPI mastodonAPI = new RetrofitMastodonAPI(_mContext);
|
||||||
|
Status statusReply = mastodonAPI.postAction(type, status);
|
||||||
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||||
|
Runnable myRunnable = () -> statusMutableLiveData.setValue(statusReply);
|
||||||
|
mainHandler.post(myRunnable);
|
||||||
|
} catch (Exception | Error e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:width="24dp"
|
android:width="24dp"
|
||||||
android:height="24dp"
|
android:height="24dp"
|
||||||
android:tint="?attr/colorControlNormal"
|
|
||||||
android:viewportWidth="24"
|
android:viewportWidth="24"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
android:viewportHeight="24">
|
android:viewportHeight="24">
|
||||||
<path
|
<path
|
||||||
android:fillColor="@android:color/white"
|
android:fillColor="@android:color/white"
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z" />
|
||||||
|
</vector>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z" />
|
||||||
|
</vector>
|
|
@ -272,6 +272,54 @@
|
||||||
app:drawableTopCompat="@drawable/ic_baseline_thumb_down_alt_24"
|
app:drawableTopCompat="@drawable/ic_baseline_thumb_down_alt_24"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/peertube_reblog"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:drawablePadding="5dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text="0"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:drawableTopCompat="@drawable/ic_baseline_repeat_24"
|
||||||
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/peertube_favorite"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:drawablePadding="5dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text="0"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:drawableTopCompat="@drawable/ic_baseline_star_24"
|
||||||
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/peertube_bookmark"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:drawablePadding="5dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text=""
|
||||||
|
android:visibility="gone"
|
||||||
|
app:drawableTopCompat="@drawable/ic_baseline_bookmark_24"
|
||||||
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/peertube_playlist"
|
android:id="@+id/peertube_playlist"
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
<color name="tag_color">#bb864692</color>
|
<color name="tag_color">#bb864692</color>
|
||||||
<color name="tag_color_text">#FAFAFA</color>
|
<color name="tag_color_text">#FAFAFA</color>
|
||||||
<color name="positive_thumbs">#2b90d9</color>
|
<color name="positive_thumbs">#2b90d9</color>
|
||||||
|
<color name="favorite">#ca8f04</color>
|
||||||
|
<color name="bookmark">#795548</color>
|
||||||
<color name="negative_thumbs">#F44336</color>
|
<color name="negative_thumbs">#F44336</color>
|
||||||
<color name="backgroundDark">#DD000000</color>
|
<color name="backgroundDark">#DD000000</color>
|
||||||
<color name="red_1">#F44336</color>
|
<color name="red_1">#F44336</color>
|
||||||
|
|
Loading…
Reference in New Issue