From 8ff3b81112f92b1ae9691b4771f41e52559aa146 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 19 Nov 2020 12:00:39 +0100 Subject: [PATCH] Some fixes --- .../fedilab/fedilabtube/PeertubeActivity.java | 51 ++-- .../PeertubeEditUploadActivity.java | 111 +++---- .../fedilabtube/drawer/MenuItemAdapter.java | 8 +- .../fedilabtube/drawer/PeertubeAdapter.java | 146 ++++++--- .../fedilabtube/viewmodel/CommentVM.java | 15 +- app/src/main/res/layout/activity_peertube.xml | 281 +++++++++--------- .../res/layout/activity_peertube_edit.xml | 1 + 7 files changed, 337 insertions(+), 276 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index ba16393..41ccb8d 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -233,7 +233,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - binding = ActivityPeertubeBinding.inflate(getLayoutInflater()); View view = binding.getRoot(); setContentView(view); @@ -407,7 +406,17 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd if (autoFullscreen && autoPlay) { openFullscreenDialog(); } - binding.postCommentButton.setOnClickListener(v -> openPostComment(null, 0)); + binding.postCommentButton.setOnClickListener(v -> { + if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { + openPostComment(null, 0); + } else { + if (sepiaSearch) { + Toasty.info(PeertubeActivity.this, getString(R.string.federation_issue), Toasty.LENGTH_SHORT).show(); + } else { + Toasty.error(PeertubeActivity.this, getString(R.string.not_logged_in), Toast.LENGTH_SHORT).show(); + } + } + }); } @@ -591,21 +600,22 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd VideoData.Description description = api.getVideoDescription(videoUuid); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { - if (description == null) { - binding.peertubeDescriptionMore.setVisibility(View.GONE); - show_more_content = null; - } else { - if (!PeertubeActivity.this.isFinishing()) { - if ((peertube.getDescription() == null && description.getDescription() != null) || (peertube.getDescription() != null && description.getDescription() != null && description.getDescription().compareTo(peertube.getDescription()) > 0)) { - binding.peertubeDescriptionMore.setVisibility(View.VISIBLE); - show_more_content = description.getDescription(); - } else { - binding.peertubeDescriptionMore.setVisibility(View.GONE); - show_more_content = null; + if (!isFinishing()) { + if (description == null) { + binding.peertubeDescriptionMore.setVisibility(View.GONE); + show_more_content = null; + } else { + if (!PeertubeActivity.this.isFinishing()) { + if ((peertube.getDescription() == null && description.getDescription() != null) || (peertube.getDescription() != null && description.getDescription() != null && description.getDescription().compareTo(peertube.getDescription()) > 0)) { + binding.peertubeDescriptionMore.setVisibility(View.VISIBLE); + show_more_content = description.getDescription(); + } else { + binding.peertubeDescriptionMore.setVisibility(View.GONE); + show_more_content = null; + } } } } - }; mainHandler.post(myRunnable); } catch (Exception e) { @@ -614,6 +624,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd }).start(); } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { @@ -768,7 +779,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd binding.peertubeDislikeCount.setText(Helper.withSuffix(peertube.getDislikes())); binding.peertubeLikeCount.setText(Helper.withSuffix(peertube.getLikes())); binding.peertubeViewCount.setText(Helper.withSuffix(peertube.getViews())); - loadGiF(PeertubeActivity.this, peertube.getChannel().getAvatar() != null ? peertube.getChannel().getAvatar().getPath() : null, binding.ppChannel); + String ppChannelURL; + if (sepiaSearch) { + ppChannelURL = peertube.getChannel().getAvatar() != null ? "https://" + peertubeInstance + peertube.getChannel().getAvatar().getPath() : null; + } else { + ppChannelURL = peertube.getChannel().getAvatar() != null ? peertube.getChannel().getAvatar().getPath() : null; + } + loadGiF(PeertubeActivity.this, ppChannelURL, binding.ppChannel); binding.ppChannel.setOnClickListener(v -> { Intent intent = new Intent(PeertubeActivity.this, ShowChannelActivity.class); Bundle b = new Bundle(); @@ -1194,7 +1211,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); binding.peertubeReply.setVisibility(View.GONE); - commentViewModel.getRepliesComment(videoUuid, comment.getId()).observe(PeertubeActivity.this, apiResponse -> manageVIewCommentReply(comment, apiResponse)); + commentViewModel.getRepliesComment(sepiaSearch ? peertubeInstance : null, videoUuid, comment.getId()).observe(PeertubeActivity.this, apiResponse -> manageVIewCommentReply(comment, apiResponse)); binding.replyThread.setVisibility(View.VISIBLE); TranslateAnimation animate = new TranslateAnimation( @@ -1225,7 +1242,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int height = displayMetrics.heightPixels; - + binding.doubleTapPlayerView.hideController(); List menuItemVideos = new ArrayList<>(); if (peertube.getFiles() != null && peertube.getFiles().size() > 0) { MenuItemVideo resolutionItem = new MenuItemVideo(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java index 5420404..b996eea 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeEditUploadActivity.java @@ -28,11 +28,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.Spinner; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; @@ -65,13 +60,13 @@ import app.fedilab.fedilabtube.client.data.VideoData.Video; import app.fedilab.fedilabtube.client.entities.Item; import app.fedilab.fedilabtube.client.entities.ItemStr; import app.fedilab.fedilabtube.client.entities.VideoParams; +import app.fedilab.fedilabtube.databinding.ActivityPeertubeEditBinding; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.viewmodel.ChannelsVM; import app.fedilab.fedilabtube.viewmodel.MyVideoVM; import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import app.fedilab.fedilabtube.viewmodel.TimelineVM; import es.dmoral.toasty.Toasty; -import mabbas007.tagsedittext.TagsEditText; import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.PEERTUBEDELETEVIDEO; @@ -85,23 +80,20 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724; Item licenseToSend, privacyToSend, categoryToSend; ItemStr languageToSend; - private Button set_upload_submit; - private Spinner set_upload_privacy, set_upload_categories, set_upload_licenses, set_upload_languages, set_upload_channel; - private EditText p_video_title, p_video_description; - private TagsEditText p_video_tags; - private CheckBox set_upload_nsfw, set_upload_enable_comments; private LinkedHashMap channels; private String videoId; private Channel channel; - private ImageView p_video_preview; - private Button set_preview; private VideoParams videoParams; private Video video; private String channelToSendId; + private ActivityPeertubeEditBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + binding = ActivityPeertubeEditBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); @@ -116,23 +108,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.activity_peertube_edit); - set_upload_submit = findViewById(R.id.set_upload_submit); - Button set_upload_delete = findViewById(R.id.set_upload_delete); - set_upload_privacy = findViewById(R.id.set_upload_privacy); - set_upload_channel = findViewById(R.id.set_upload_channel); - set_upload_categories = findViewById(R.id.set_upload_categories); - set_upload_licenses = findViewById(R.id.set_upload_licenses); - set_upload_languages = findViewById(R.id.set_upload_languages); - p_video_title = findViewById(R.id.p_video_title); - p_video_description = findViewById(R.id.p_video_description); - p_video_tags = findViewById(R.id.p_video_tags); - p_video_preview = findViewById(R.id.p_video_preview); - set_upload_nsfw = findViewById(R.id.set_upload_nsfw); - set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments); - set_preview = findViewById(R.id.set_preview); - set_upload_delete.setOnClickListener(v -> { + binding.setUploadDelete.setOnClickListener(v -> { AlertDialog.Builder builderInner; builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this); builderInner.setMessage(getString(R.string.delete_video_confirmation)); @@ -168,7 +145,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } ArrayAdapter adapterCatgories = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, categoriesA); - set_upload_categories.setAdapter(adapterCatgories); + binding.setUploadCategories.setAdapter(adapterCatgories); //Populate licenses @@ -186,7 +163,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } ArrayAdapter adapterLicenses = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, licensesA); - set_upload_licenses.setAdapter(adapterLicenses); + binding.setUploadLicenses.setAdapter(adapterLicenses); //Populate languages @@ -204,7 +181,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } ArrayAdapter adapterLanguages = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, languagesA); - set_upload_languages.setAdapter(adapterLanguages); + binding.setUploadLanguages.setAdapter(adapterLanguages); //Populate languages @@ -223,7 +200,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { ArrayAdapter adapterPrivacies = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, privaciesA); - set_upload_privacy.setAdapter(adapterPrivacies); + binding.setUploadPrivacy.setAdapter(adapterPrivacies); TimelineVM feedsViewModel = new ViewModelProvider(PeertubeEditUploadActivity.this).get(TimelineVM.class); @@ -235,7 +212,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } public void manageUpdate(APIResponse apiResponse) { - set_upload_submit.setEnabled(true); + binding.setUploadSubmit.setEnabled(true); if (apiResponse.getError() != null) { if (apiResponse.getError() != null && apiResponse.getError().getError() != null) Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); @@ -251,7 +228,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { Toasty.error(PeertubeEditUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); else Toasty.error(PeertubeEditUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - set_upload_submit.setEnabled(true); + binding.setUploadSubmit.setEnabled(true); return; } @@ -267,11 +244,11 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { categoryToSend = video.getCategory(); if (video.getThumbnailPath() != null) { - Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(), p_video_preview); + Helper.loadGiF(PeertubeEditUploadActivity.this, video.getThumbnailPath(), binding.pVideoPreview); } - set_preview.setOnClickListener(v -> { + binding.setPreview.setOnClickListener(v -> { if (ContextCompat.checkSelfPermission(PeertubeEditUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(PeertubeEditUploadActivity.this, @@ -328,11 +305,11 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { boolean commentEnabled = video.isCommentsEnabled(); boolean isNSFW = video.isNsfw(); - set_upload_enable_comments.setChecked(commentEnabled); - set_upload_nsfw.setChecked(isNSFW); + binding.setUploadEnableComments.setChecked(commentEnabled); + binding.setUploadNsfw.setChecked(isNSFW); - p_video_title.setText(title); - p_video_description.setText(video.getDescription()); + binding.pVideoTitle.setText(title); + binding.pVideoDescription.setText(video.getDescription()); new Thread(() -> { try { @@ -341,8 +318,8 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { VideoData.Description description = api.getVideoDescription(video.getUuid()); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { - if (description == null) { - p_video_description.setText(description.getDescription()); + if (description != null) { + binding.pVideoDescription.setText(description.getDescription()); } }; mainHandler.post(myRunnable); @@ -403,7 +380,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } } //Manage privacies - set_upload_privacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.setUploadPrivacy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { updatePrivacyPosition(position); @@ -414,7 +391,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } }); - set_upload_licenses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.setUploadLicenses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { updateLicensePosition(position); @@ -426,7 +403,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } }); //Manage categories - set_upload_categories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.setUploadCategories.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { updateCategoryPosition(position); @@ -439,7 +416,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { }); //Manage languages - set_upload_languages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.setUploadLanguages.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { updateLanguagesPosition(position); @@ -451,7 +428,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } }); //Manage languages - set_upload_channel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + binding.setUploadChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { @@ -468,11 +445,11 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { Item finalLicenseToSend = licenseToSend; ItemStr finalLanguageToSend = languageToSend; Item finalPrivacyToSend = privacyToSend; - set_upload_submit.setOnClickListener(v -> { - String title1 = p_video_title.getText().toString().trim(); - String description = p_video_description.getText().toString().trim(); - boolean isNSFW1 = set_upload_nsfw.isChecked(); - boolean commentEnabled1 = set_upload_enable_comments.isChecked(); + binding.setUploadSubmit.setOnClickListener(v -> { + String title1 = binding.pVideoTitle.getText().toString().trim(); + String description = binding.pVideoDescription.getText().toString().trim(); + boolean isNSFW1 = binding.setUploadNsfw.isChecked(); + boolean commentEnabled1 = binding.setUploadEnableComments.isChecked(); videoParams = new VideoParams(); videoParams.setName(title1); videoParams.setDescription(description); @@ -484,25 +461,25 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { videoParams.setChannelId(channelToSendId); videoParams.setPrivacy(finalPrivacyToSend.getId()); - List tags = p_video_tags.getTags(); + List tags = binding.pVideoTags.getTags(); videoParams.setTags(tags); - set_upload_submit.setEnabled(false); + binding.setUploadSubmit.setEnabled(false); MyVideoVM myVideoVM = new ViewModelProvider(PeertubeEditUploadActivity.this).get(MyVideoVM.class); myVideoVM.updateVideo(videoId, videoParams, null, null).observe(PeertubeEditUploadActivity.this, this::manageUpdate); }); - set_upload_privacy.setSelection(privacyPosition, false); + binding.setUploadPrivacy.setSelection(privacyPosition, false); updatePrivacyPosition(privacyPosition); - set_upload_languages.setSelection(languagePosition, false); + binding.setUploadLanguages.setSelection(languagePosition, false); updateLanguagesPosition(languagePosition); - set_upload_licenses.setSelection(licensePosition, false); + binding.setUploadLicenses.setSelection(licensePosition, false); updateLicensePosition(licensePosition); - set_upload_categories.setSelection(categoryPosition, false); + binding.setUploadCategories.setSelection(categoryPosition, false); updateCategoryPosition(categoryPosition); List tags = video.getTags(); if (tags != null && tags.size() > 0) { - p_video_tags.setTags(tags.toArray(new String[0])); + binding.pVideoTags.setTags(tags.toArray(new String[0])); } } @@ -623,7 +600,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { Glide.with(PeertubeEditUploadActivity.this) .load(uri) - .into(p_video_preview); + .into(binding.pVideoPreview); } @Override @@ -672,7 +649,7 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { } ArrayAdapter adapterChannel = new ArrayAdapter<>(PeertubeEditUploadActivity.this, android.R.layout.simple_spinner_dropdown_item, channelName); - set_upload_channel.setAdapter(adapterChannel); + binding.setUploadChannel.setAdapter(adapterChannel); int channelPosition = 0; if (channels.containsKey(channel.getName())) { LinkedHashMap channelsIterator = new LinkedHashMap<>(channels); @@ -687,9 +664,15 @@ public class PeertubeEditUploadActivity extends AppCompatActivity { channelPosition++; } } - set_upload_channel.setSelection(channelPosition, false); + binding.setUploadChannel.setSelection(channelPosition, false); updateUploadChannel(channelPosition); - set_upload_submit.setEnabled(true); + binding.setUploadSubmit.setEnabled(true); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + finish(); } @SuppressWarnings({"unused", "RedundantSuppression"}) diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/MenuItemAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/MenuItemAdapter.java index f883217..05e09dd 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/MenuItemAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/MenuItemAdapter.java @@ -26,7 +26,6 @@ import java.util.List; import app.fedilab.fedilabtube.client.MenuItemVideo; import app.fedilab.fedilabtube.client.entities.MenuItemView; import app.fedilab.fedilabtube.databinding.DrawerMenuItemBinding; -import app.fedilab.fedilabtube.helper.Helper; public class MenuItemAdapter extends RecyclerView.Adapter { @@ -68,11 +67,8 @@ public class MenuItemAdapter extends RecyclerView.Adapter { - itemAction.which(actionType, item); - - }); - + holder.binding.itemMenuContainer.setOnClickListener(v -> itemAction.which(actionType, item)); + holder.binding.radio.setOnClickListener(v -> itemAction.which(actionType, item)); } public interface ItemAction { diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java index 8e95316..84a3422 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/PeertubeAdapter.java @@ -14,10 +14,12 @@ package app.fedilab.fedilabtube.drawer; * You should have received a copy of the GNU General Public License along with TubeLab; if not, * see . */ +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -25,17 +27,24 @@ import android.view.ViewGroup; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; -import androidx.constraintlayout.widget.ConstraintLayout; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.CustomTarget; +import com.bumptech.glide.request.transition.Transition; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -50,11 +59,13 @@ import app.fedilab.fedilabtube.client.data.PlaylistData; import app.fedilab.fedilabtube.client.data.VideoData; import app.fedilab.fedilabtube.client.entities.PlaylistExist; import app.fedilab.fedilabtube.client.entities.Report; +import app.fedilab.fedilabtube.databinding.DrawerPeertubeBinding; import app.fedilab.fedilabtube.helper.Helper; import app.fedilab.fedilabtube.viewmodel.PlaylistsVM; import app.fedilab.fedilabtube.viewmodel.PostActionsVM; import app.fedilab.fedilabtube.viewmodel.TimelineVM; import es.dmoral.toasty.Toasty; +import jp.wasabeef.glide.transformations.BlurTransformation; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.FOLLOW; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFOLLOW; @@ -87,8 +98,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter { + holder.binding.peertubeProfile.setOnClickListener(v -> { Intent intent = new Intent(context, ShowChannelActivity.class); Bundle b = new Bundle(); b.putParcelable("channel", video.getChannel()); @@ -170,8 +181,8 @@ public class PeertubeAdapter extends RecyclerView.Adapter { - PopupMenu popup = new PopupMenu(context, holder.more_actions); + holder.binding.moreActions.setOnClickListener(view -> { + PopupMenu popup = new PopupMenu(context, holder.binding.moreActions); popup.getMenuInflater() .inflate(R.menu.video_drawer_menu, popup.getMenu()); if (timelineType == MY_VIDEOS) { @@ -256,7 +267,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter { + holder.binding.bottomContainer.setOnClickListener(v -> { Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); b.putString("video_id", video.getId()); @@ -270,7 +281,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter { + holder.binding.peertubeVideoImage.setOnClickListener(v -> { Intent intent = new Intent(context, PeertubeActivity.class); Bundle b = new Bundle(); b.putString("video_id", video.getId()); @@ -385,29 +396,74 @@ public class PeertubeAdapter extends RecyclerView.Adapter> getPlaylist(); } + @SuppressLint("CheckResult") + private void loadImage(ImageView target, String instance, String urlPreview, String thumbnail, boolean blur) { + if (urlPreview == null || urlPreview.startsWith("null")) { + urlPreview = thumbnail; + } + if (instance != null) { + urlPreview = "https://" + instance + urlPreview; + thumbnail = "https://" + instance + thumbnail; + } else { + urlPreview = "https://" + Helper.getLiveInstance(context) + urlPreview; + thumbnail = "https://" + Helper.getLiveInstance(context) + thumbnail; + } + RequestBuilder requestBuilder = Glide.with(context) + .asDrawable(); + if (blur) { + requestBuilder.apply(new RequestOptions().transform(new BlurTransformation(50, 3), new CenterCrop(), new RoundedCorners(10))); + } else { + requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))); + } + final Drawable[] initialResource = new Drawable[1]; + String finalUrlPreview = urlPreview; + requestBuilder.load(thumbnail).into( + new CustomTarget() { + @Override + public void onResourceReady(@NonNull final Drawable resource, Transition transition) { + target.setImageDrawable(resource); + initialResource[0] = resource; + RequestBuilder requestBuilder = Glide.with(context) + .asDrawable(); + if (blur) { + requestBuilder.apply(new RequestOptions().transform(new BlurTransformation(50, 3), new CenterCrop(), new RoundedCorners(10))); + } else { + requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))); + } + requestBuilder.load(finalUrlPreview).into( + new CustomTarget() { + @Override + public void onResourceReady(@NonNull final Drawable resource, Transition transition) { + target.setImageDrawable(resource); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + } + + @Override + public void onLoadFailed(@Nullable Drawable errorDrawable) { + target.setImageDrawable(initialResource[0]); + } + } + ); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + } + ); + + } static class ViewHolder extends RecyclerView.ViewHolder { - LinearLayout main_container, bottom_container; - ImageView peertube_profile, peertube_video_image, peertube_video_image_small; - TextView peertube_account_name, peertube_views, peertube_duration; - TextView peertube_title, peertube_date, header_title, more_actions; - ConstraintLayout preview_container; + DrawerPeertubeBinding binding; - public ViewHolder(@NonNull View itemView) { - super(itemView); - peertube_account_name = itemView.findViewById(R.id.peertube_account_name); - peertube_video_image_small = itemView.findViewById(R.id.peertube_video_image_small); - peertube_title = itemView.findViewById(R.id.peertube_title); - peertube_video_image = itemView.findViewById(R.id.peertube_video_image); - peertube_profile = itemView.findViewById(R.id.peertube_profile); - peertube_date = itemView.findViewById(R.id.peertube_date); - peertube_views = itemView.findViewById(R.id.peertube_views); - peertube_duration = itemView.findViewById(R.id.peertube_duration); - main_container = itemView.findViewById(R.id.main_container); - header_title = itemView.findViewById(R.id.header_title); - bottom_container = itemView.findViewById(R.id.bottom_container); - more_actions = itemView.findViewById(R.id.more_actions); - preview_container = itemView.findViewById(R.id.preview_container); + ViewHolder(DrawerPeertubeBinding itemView) { + super(itemView.getRoot()); + binding = itemView; } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java index d6f833d..97d947d 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java +++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/CommentVM.java @@ -41,9 +41,9 @@ public class CommentVM extends AndroidViewModel { return apiResponseMutableLiveData; } - public LiveData getRepliesComment(String videoId, String commentId) { + public LiveData getRepliesComment(String instance, String videoId, String commentId) { apiResponseMutableLiveData = new MutableLiveData<>(); - getThreadRepliesComments(videoId, commentId); + getThreadRepliesComments(instance, videoId, commentId); return apiResponseMutableLiveData; } @@ -69,12 +69,17 @@ public class CommentVM extends AndroidViewModel { } - private void getThreadRepliesComments(String videoId, String commentId) { + private void getThreadRepliesComments(String instance, String videoId, String commentId) { Context _mContext = getApplication().getApplicationContext(); new Thread(() -> { try { - RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(_mContext); - APIResponse apiResponse = api.getComments(action.GET_REPLIES, videoId, commentId, null); + RetrofitPeertubeAPI retrofitPeertubeAPI; + if (instance == null) { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext); + } else { + retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, instance, null); + } + APIResponse apiResponse = retrofitPeertubeAPI.getComments(action.GET_REPLIES, videoId, commentId, null); Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse); mainHandler.post(myRunnable); diff --git a/app/src/main/res/layout/activity_peertube.xml b/app/src/main/res/layout/activity_peertube.xml index 4b9f641..cf924e6 100644 --- a/app/src/main/res/layout/activity_peertube.xml +++ b/app/src/main/res/layout/activity_peertube.xml @@ -110,146 +110,155 @@ - - - - - - - - - - - - - - + android:layout_height="wrap_content"> + android:orientation="vertical" + android:padding="10dp"> + + + + + + + + + + + + + + + + + + - + - + - - + + + + +