diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 47ea79148..6e2854fa4 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -1352,6 +1352,12 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } else if (id == R.id.nav_cache) { Intent intent = new Intent(BaseMainActivity.this, CacheActivity.class); startActivity(intent); + } else if (id == R.id.nav_peertube) { + Intent intent = new Intent(BaseMainActivity.this, PeertubeMainActivity.class); + Bundle bundle = new Bundle(); + bundle.putBoolean(Helper.ARG_PEERTUBE_NAV_REMOTE, true); + intent.putExtras(bundle); + startActivity(intent); } else if (id == R.id.nav_about_instance) { (new InstanceActivity()).show(getSupportFragmentManager(), null); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index 3e367f503..ad5e36304 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -203,6 +203,8 @@ public class Helper { public static final String RECEIVE_REDRAW_PROFILE = "RECEIVE_REDRAW_PROFILE"; public static final String ARG_TIMELINE_TYPE = "ARG_TIMELINE_TYPE"; + public static final String ARG_PEERTUBE_NAV_REMOTE = "ARG_PEERTUBE_NAV_REMOTE"; + public static final String ARG_REMOTE_INSTANCE_STRING = "ARG_REMOTE_INSTANCE_STRING"; public static final String ARG_NOTIFICATION_TYPE = "ARG_NOTIFICATION_TYPE"; diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java index d656fdee5..3e29b1a0c 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java @@ -17,11 +17,13 @@ package app.fedilab.android.peertube.activities; import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO; import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; +import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.REPLY; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT; import static app.fedilab.android.peertube.client.RetrofitPeertubeAPI.ActionType.REPORT_VIDEO; +import static app.fedilab.android.peertube.helper.Helper.canMakeAction; import static app.fedilab.android.peertube.helper.Helper.getAttColor; import static app.fedilab.android.peertube.helper.Helper.isLoggedIn; import static app.fedilab.android.peertube.helper.Helper.loadAvatar; @@ -111,6 +113,7 @@ import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.video.VideoSize; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; +import com.varunest.sparkbutton.SparkButton; import org.jetbrains.annotations.NotNull; @@ -124,13 +127,16 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.activities.BasePeertubeActivity; import app.fedilab.android.databinding.ActivityPeertubeBinding; import app.fedilab.android.databinding.PopupVideoInfoPeertubeBinding; +import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.app.BaseAccount; import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.helper.CacheDataSourceFactory; +import app.fedilab.android.mastodon.viewmodel.mastodon.StatusesVM; import app.fedilab.android.peertube.client.APIResponse; import app.fedilab.android.peertube.client.MenuItemVideo; import app.fedilab.android.peertube.client.RetrofitPeertubeAPI; @@ -198,6 +204,8 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis private boolean isRemote; private boolean willPlayFromIntent; + private Status status; + public static void hideKeyboard(Activity activity) { if (activity != null && activity.getWindow() != null) { activity.getWindow().getDecorView(); @@ -218,24 +226,24 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis max_id = "0"; SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeActivity.this); String token = sharedpreferences.getString(PREF_USER_TOKEN, null); - if (Helper.isLoggedIn() && !sepiaSearch) { + if (Helper.canMakeAction() && !sepiaSearch) { BaseAccount account = null; try { account = new app.fedilab.android.mastodon.client.entities.app.Account(PeertubeActivity.this).getAccountByToken(token); } catch (DBException e) { e.printStackTrace(); } - if (account != null) { + if (account != null && account.peertube_account != null) { loadAvatar(PeertubeActivity.this, account.peertube_account, binding.myPp); + } else if (account != null && account.mastodon_account != null) { + app.fedilab.android.mastodon.helper.Helper.loadPP(PeertubeActivity.this, binding.myPp, account); } } isRemote = false; - fullScreenMode = false; initialOrientation = getResources().getConfiguration().orientation; if (Helper.isTablet(PeertubeActivity.this)) { - LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, @@ -276,6 +284,13 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis if (Helper.isLoggedIn()) { binding.peertubePlaylist.setVisibility(View.VISIBLE); + } else if (typeOfConnection == PeertubeMainActivity.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 -> { @@ -289,7 +304,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis } } }); - if (!Helper.isLoggedIn() || sepiaSearch) { + if (!Helper.canMakeAction() || sepiaSearch) { binding.writeCommentContainer.setVisibility(View.GONE); } playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true); @@ -397,7 +412,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis openFullscreenDialog(); } binding.postCommentButton.setOnClickListener(v -> { - if (Helper.isLoggedIn() && !sepiaSearch) { + if (canMakeAction() && !sepiaSearch) { openPostComment(null, 0); } else { if (sepiaSearch) { @@ -489,6 +504,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis return comments; } + @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -573,6 +589,15 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis } private void playVideo() { + if (status == null && typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) { + app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM searchVM = new ViewModelProvider(PeertubeActivity.this).get(app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM.class); + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, videoUuid, null, "statuses", false, true, false, 0, null, null, 1) + .observe(PeertubeActivity.this, results -> { + if (results != null && results.statuses != null && results.statuses.size() > 0) { + status = results.statuses.get(0); + } + }); + } if (player != null) { player.release(); player = new ExoPlayer.Builder(PeertubeActivity.this).build(); @@ -862,7 +887,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class); viewModel.videoExists(videoIds).observe(this, this::manageVIewPlaylist); - if (!Helper.isLoggedIn() || sepiaSearch) { + if (!Helper.canMakeAction() || sepiaSearch) { binding.writeCommentContainer.setVisibility(View.GONE); } @@ -1002,6 +1027,147 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis } } }); + + binding.peertubeReblog.setOnClickListener(v -> { + if (status != null) { + boolean confirmBoost = sharedpreferences.getBoolean(getString(R.string.SET_NOTIF_VALIDATION), true); + StatusesVM statusesVM = new ViewModelProvider(PeertubeActivity.this).get(StatusesVM.class); + if (confirmBoost) { + AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(this); + if (status.reblogged) { + alt_bld.setMessage(getString(R.string.reblog_remove)); + } else { + alt_bld.setMessage(getString(R.string.reblog_add)); + } + alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { + if (status.reblogged) { + statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } else { + ((SparkButton) v).playAnimation(); + statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } + dialog.dismiss(); + }); + alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); + AlertDialog alert = alt_bld.create(); + alert.show(); + } else { + if (status.reblogged) { + statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } else { + ((SparkButton) v).playAnimation(); + statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } + } + } + }); + + binding.peertubeFavorite.setOnClickListener(v -> { + if (status != null) { + boolean confirmFav = sharedpreferences.getBoolean(getString(R.string.SET_NOTIF_VALIDATION_FAV), false); + StatusesVM statusesVM = new ViewModelProvider(PeertubeActivity.this).get(StatusesVM.class); + if (confirmFav) { + AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(PeertubeActivity.this); + if (status.favourited) { + alt_bld.setMessage(getString(R.string.favourite_remove)); + } else { + alt_bld.setMessage(getString(R.string.favourite_add)); + } + alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { + if (status.favourited) { + statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } else { + ((SparkButton) v).playAnimation(); + statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } + dialog.dismiss(); + }); + alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); + AlertDialog alert = alt_bld.create(); + alert.show(); + } else { + if (status.favourited) { + statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } else { + ((SparkButton) v).playAnimation(); + statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } + } + } + }); + + binding.peertubeBookmark.setOnClickListener(v -> { + if (status != null) { + StatusesVM statusesVM = new ViewModelProvider(PeertubeActivity.this).get(StatusesVM.class); + if (status.bookmarked) { + statusesVM.unBookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } else { + ((SparkButton) v).playAnimation(); + statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) + .observe(PeertubeActivity.this, _status -> { + if (_status != null) { + status = _status; + } + manageVIewPostActionsMastodon(status); + }); + } + } + }); + binding.peertubeDislikeCount.setOnClickListener(v -> { if (isLoggedIn() && !sepiaSearch) { String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike"; @@ -1127,6 +1293,58 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis } + public void manageVIewPostActionsMastodon(Status status) { + if (status != null) { + this.status = status; + changeColorMastodon(); + binding.peertubeFavorite.setText(String.valueOf(status.favourites_count)); + binding.peertubeReblog.setText(String.valueOf(status.reblogs_count)); + } else { + Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toasty.LENGTH_LONG).show(); + } + } + + + 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 (reblog != null && status.reblogged) { + reblog.setColorFilter(getResources().getColor(R.color.boost_icon), PorterDuff.Mode.SRC_ATOP); + DrawableCompat.setTint(reblog, getResources().getColor(R.color.boost_icon)); + } + if (favorite != null && status.favourited) { + favorite.setColorFilter(getResources().getColor(R.color.marked_icon), PorterDuff.Mode.SRC_ATOP); + DrawableCompat.setTint(favorite, getResources().getColor(R.color.marked_icon)); + } + + if (bookmark != null && status.bookmarked) { + bookmark.setColorFilter(getResources().getColor(R.color.marked_icon), PorterDuff.Mode.SRC_ATOP); + DrawableCompat.setTint(bookmark, getResources().getColor(R.color.marked_icon)); + } + + binding.peertubeReblog.setCompoundDrawablesWithIntrinsicBounds(null, reblog, null, null); + binding.peertubeFavorite.setCompoundDrawablesWithIntrinsicBounds(null, favorite, null, null); + binding.peertubeBookmark.setCompoundDrawablesWithIntrinsicBounds(null, bookmark, null, null); + } + /** * Manage video to play with different factors * @@ -1203,14 +1421,14 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis private void fetchComments() { if (peertube.isCommentsEnabled()) { - if (Helper.isLoggedIn()) { + if (Helper.canMakeAction()) { binding.postCommentButton.setVisibility(View.VISIBLE); } else { binding.postCommentButton.setVisibility(View.GONE); } CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); commentViewModel.getThread(sepiaSearch ? peertubeInstance : null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); - if (Helper.isLoggedIn() && !sepiaSearch) { + if (Helper.canMakeAction() && !sepiaSearch) { binding.writeCommentContainer.setVisibility(View.VISIBLE); } binding.peertubeComments.setVisibility(View.VISIBLE); @@ -1765,7 +1983,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis private void sendComment(Comment comment, int position) { - if (Helper.isLoggedIn() && !sepiaSearch) { + if (Helper.canMakeAction() && !sepiaSearch) { if (comment == null) { String commentStr = binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().toString() : ""; if (commentStr.trim().length() > 0) { @@ -1857,7 +2075,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis public void onAnimationEnd(Animation animation) { binding.peertubeInformationContainer.setVisibility(View.GONE); InputMethodManager inputMethodManager = - (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInputFromWindow( binding.addCommentWrite.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java index 066d978ec..709b3afce 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java @@ -158,6 +158,17 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { super.onCreate(savedInstanceState); binding = super.binding; + + Intent intentActvity = getIntent(); + if (intentActvity != null) { + Bundle extras = intentActvity.getExtras(); + String userIdIntent, instanceIntent, urlOfMessage; + if (extras != null && extras.containsKey(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) { + if (extras.getBoolean(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) { + typeOfConnection = PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT; + } + } + } Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); @@ -274,7 +285,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { if (typeOfConnection == TypeOfConnection.SURFING) { switchDialog(PeertubeMainActivity.this, false); } else { - if (Helper.isLoggedIn()) { + if (Helper.canMakeAction()) { intent = new Intent(PeertubeMainActivity.this, AccountActivity.class); startActivity(intent); overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); @@ -571,6 +582,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { MenuItem incognitoItem = menu.findItem(R.id.action_incognito); switch (typeOfConnection) { + case REMOTE_ACCOUNT: case NORMAL: if (Helper.isLoggedIn()) { incognitoItem.setVisible(true); @@ -729,7 +741,8 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { public enum TypeOfConnection { NORMAL, - SURFING + SURFING, + REMOTE_ACCOUNT } private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { diff --git a/app/src/main/java/app/fedilab/android/peertube/drawer/CommentListAdapter.java b/app/src/main/java/app/fedilab/android/peertube/drawer/CommentListAdapter.java index a3bf3ad06..afb5b5e17 100644 --- a/app/src/main/java/app/fedilab/android/peertube/drawer/CommentListAdapter.java +++ b/app/src/main/java/app/fedilab/android/peertube/drawer/CommentListAdapter.java @@ -297,7 +297,7 @@ public class CommentListAdapter extends RecyclerView.Adapter { - if (Helper.isLoggedIn() && !sepiaSearch) { + if (Helper.canMakeAction() && !sepiaSearch) { ((PeertubeActivity) context).openPostComment(comment, i); } else { if (sepiaSearch) { @@ -308,7 +308,7 @@ public class CommentListAdapter extends RecyclerView.Adapter + + diff --git a/app/src/main/res/layouts/peertube/layout/activity_peertube.xml b/app/src/main/res/layouts/peertube/layout/activity_peertube.xml index eaaa551f9..80c380331 100644 --- a/app/src/main/res/layouts/peertube/layout/activity_peertube.xml +++ b/app/src/main/res/layouts/peertube/layout/activity_peertube.xml @@ -229,6 +229,55 @@ app:drawableTopCompat="@drawable/ic_baseline_thumb_down_alt_24" tools:ignore="HardcodedText" /> + + + + + + + +