Fix Playing
This commit is contained in:
parent
a8a5028852
commit
1bc99b3c46
|
@ -1000,7 +1000,7 @@ public class PeertubeActivity extends AppCompatActivity {
|
|||
private void initResolution() {
|
||||
PlayerControlView controlView = playerView.findViewById(R.id.exo_controller);
|
||||
resolution = controlView.findViewById(R.id.resolution);
|
||||
resolution.setText(String.format("%sp", peertube.getFiles().get(0).getResolutions().getLabel()));
|
||||
resolution.setText(String.format("%s", peertube.getFiles().get(0).getResolutions().getLabel()));
|
||||
resolution.setOnClickListener(v -> displayResolution());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,440 @@
|
|||
package app.fedilab.fedilabtube;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of TubeLab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* TubeLab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.client.data.ChannelData.Channel;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment;
|
||||
import app.fedilab.fedilabtube.fragment.DisplayVideosFragment;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PostActionsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.RelationshipVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.TimelineVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.FOLLOW;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFOLLOW;
|
||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.CHANNEL;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
||||
|
||||
|
||||
public class ShowAccountActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private Button account_follow;
|
||||
private ViewPager mPager;
|
||||
private TabLayout tabLayout;
|
||||
private TextView account_note, subscriber_count;
|
||||
private List<Map<String, Boolean>> relationship;
|
||||
private ImageView account_pp;
|
||||
private TextView account_dn;
|
||||
private Channel channel;
|
||||
private action doAction;
|
||||
private String channelAcct;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_show_account);
|
||||
setTitle("");
|
||||
Bundle b = getIntent().getExtras();
|
||||
account_follow = findViewById(R.id.account_follow);
|
||||
subscriber_count = findViewById(R.id.subscriber_count);
|
||||
account_follow.setEnabled(false);
|
||||
account_pp = findViewById(R.id.account_pp);
|
||||
account_dn = findViewById(R.id.account_dn);
|
||||
account_pp.setBackgroundResource(R.drawable.account_pp_border);
|
||||
if (b != null) {
|
||||
channel = b.getParcelable("channel");
|
||||
channelAcct = b.getString("channelId");
|
||||
} else {
|
||||
Toasty.error(ShowAccountActivity.this, getString(R.string.toast_error_loading_account), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
tabLayout = findViewById(R.id.account_tabLayout);
|
||||
account_note = findViewById(R.id.account_note);
|
||||
|
||||
|
||||
ChannelsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(ChannelsVM.class);
|
||||
|
||||
manageChannel();
|
||||
viewModel.get(CHANNEL, channelAcct==null?channel.getName()+"@"+channel.getHost():channelAcct).observe(ShowAccountActivity.this, this::manageViewAccounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main_account, menu);
|
||||
if (!Helper.isLoggedIn(ShowAccountActivity.this)) {
|
||||
menu.findItem(R.id.action_mute).setVisible(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_mute) {
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(MUTE, channel.getOwnerAccount() != null ? channel.getOwnerAccount().getAcct() : channel.getAcct(), null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(MUTE, apiResponse));
|
||||
} else if (item.getItemId() == R.id.action_report) {
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ShowAccountActivity.this);
|
||||
LayoutInflater inflater1 = getLayoutInflater();
|
||||
View dialogView = inflater1.inflate(R.layout.popup_report, new LinearLayout(ShowAccountActivity.this), false);
|
||||
dialogBuilder.setView(dialogView);
|
||||
EditText report_content = dialogView.findViewById(R.id.report_content);
|
||||
dialogBuilder.setNeutralButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
dialogBuilder.setPositiveButton(R.string.report, (dialog, id) -> {
|
||||
if (report_content.getText().toString().trim().length() == 0) {
|
||||
Toasty.info(ShowAccountActivity.this, getString(R.string.report_comment_size), Toasty.LENGTH_LONG).show();
|
||||
} else {
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(REPORT_ACCOUNT, channel.getId(), report_content.getText().toString()).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(REPORT_ACCOUNT, apiResponse));
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.show();
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void manageChannel() {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
|
||||
String accountIdRelation = channel.getAcct();
|
||||
if (isLoggedIn(ShowAccountActivity.this)) {
|
||||
RelationshipVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(RelationshipVM.class);
|
||||
List<String> uids = new ArrayList<>();
|
||||
uids.add(accountIdRelation);
|
||||
viewModel.get(uids).observe(ShowAccountActivity.this, this::manageVIewRelationship);
|
||||
}
|
||||
|
||||
setTitle(channel.getAcct());
|
||||
|
||||
|
||||
mPager = findViewById(R.id.account_viewpager);
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.videos)));
|
||||
mPager.setOffscreenPageLimit(1);
|
||||
|
||||
|
||||
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
mPager.setAdapter(mPagerAdapter);
|
||||
ViewGroup.LayoutParams params = tabLayout.getLayoutParams();
|
||||
params.height = 0;
|
||||
tabLayout.setLayoutParams(params);
|
||||
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
TabLayout.Tab tab = tabLayout.getTabAt(position);
|
||||
if (tab != null)
|
||||
tab.select();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
mPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
Fragment fragment = null;
|
||||
if (mPager.getAdapter() != null)
|
||||
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
|
||||
switch (tab.getPosition()) {
|
||||
case 0:
|
||||
if (fragment != null) {
|
||||
DisplayVideosFragment displayVideosFragment = ((DisplayVideosFragment) fragment);
|
||||
displayVideosFragment.scrollToTop();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (fragment != null) {
|
||||
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
|
||||
displayAccountsFragment.scrollToTop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
account_dn.setText(channel.getDisplayName());
|
||||
|
||||
|
||||
manageNotes(channel);
|
||||
Helper.loadGiF(ShowAccountActivity.this, channel.getAvatar()!=null?channel.getAvatar().getPath():null, account_pp);
|
||||
//Follow button
|
||||
String target = channel.getAcct();
|
||||
|
||||
account_follow.setOnClickListener(v -> {
|
||||
if (doAction == action.NOTHING) {
|
||||
Toasty.info(ShowAccountActivity.this, getString(R.string.nothing_to_do), Toast.LENGTH_LONG).show();
|
||||
} else if (doAction == action.FOLLOW) {
|
||||
account_follow.setEnabled(false);
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(FOLLOW, target, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(FOLLOW, apiResponse));
|
||||
} else if (doAction == action.UNFOLLOW) {
|
||||
boolean confirm_unfollow = sharedpreferences.getBoolean(Helper.SET_UNFOLLOW_VALIDATION, true);
|
||||
if (confirm_unfollow) {
|
||||
AlertDialog.Builder unfollowConfirm = new AlertDialog.Builder(ShowAccountActivity.this);
|
||||
unfollowConfirm.setTitle(getString(R.string.unfollow_confirm));
|
||||
unfollowConfirm.setMessage(channel.getAcct());
|
||||
unfollowConfirm.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
unfollowConfirm.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
account_follow.setEnabled(false);
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(UNFOLLOW, target, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse));
|
||||
dialog.dismiss();
|
||||
});
|
||||
unfollowConfirm.show();
|
||||
} else {
|
||||
account_follow.setEnabled(false);
|
||||
PostActionsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(PostActionsVM.class);
|
||||
viewModel.post(UNFOLLOW, target, null).observe(ShowAccountActivity.this, apiResponse -> manageVIewPostActions(UNFOLLOW, apiResponse));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void manageVIewRelationship(APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
this.relationship = apiResponse.getRelationships();
|
||||
manageButtonVisibility();
|
||||
|
||||
invalidateOptionsMenu();
|
||||
|
||||
}
|
||||
|
||||
//Manages the visibility of the button
|
||||
private void manageButtonVisibility() {
|
||||
if (relationship == null)
|
||||
return;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
int[][] states = new int[][]{
|
||||
new int[]{android.R.attr.state_enabled}, // enabled
|
||||
new int[]{-android.R.attr.state_enabled}, // disabled
|
||||
new int[]{-android.R.attr.state_checked}, // unchecked
|
||||
new int[]{android.R.attr.state_pressed} // pressed
|
||||
};
|
||||
|
||||
int[] colors = new int[]{
|
||||
ContextCompat.getColor(ShowAccountActivity.this, Helper.getColorAccent()),
|
||||
ContextCompat.getColor(ShowAccountActivity.this, Helper.getColorAccent()),
|
||||
ContextCompat.getColor(ShowAccountActivity.this, Helper.getColorAccent()),
|
||||
ContextCompat.getColor(ShowAccountActivity.this, Helper.getColorAccent())
|
||||
};
|
||||
account_follow.setBackgroundTintList(new ColorStateList(states, colors));
|
||||
}
|
||||
account_follow.setEnabled(true);
|
||||
|
||||
boolean isFollowing = relationship.get(0).get(channel.getAcct());
|
||||
if (isFollowing) {
|
||||
account_follow.setText(R.string.action_unfollow);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowAccountActivity.this, R.color.red_1)));
|
||||
}
|
||||
doAction = action.UNFOLLOW;
|
||||
account_follow.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
account_follow.setText(R.string.action_follow);
|
||||
doAction = action.FOLLOW;
|
||||
account_follow.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
||||
public void manageVIewPostActions(RetrofitPeertubeAPI.ActionType statusAction, APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse.getError() != null) {
|
||||
Toasty.error(ShowAccountActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
String target = channel.getAcct();
|
||||
//IF action is unfollow or mute, sends an intent to remove statuses
|
||||
if (statusAction == RetrofitPeertubeAPI.ActionType.UNFOLLOW) {
|
||||
Bundle b = new Bundle();
|
||||
b.putString("receive_action", apiResponse.getTargetedId());
|
||||
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
|
||||
intentBC.putExtras(b);
|
||||
}
|
||||
if (statusAction == RetrofitPeertubeAPI.ActionType.UNFOLLOW || statusAction == RetrofitPeertubeAPI.ActionType.FOLLOW) {
|
||||
RelationshipVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(RelationshipVM.class);
|
||||
List<String> uris = new ArrayList<>();
|
||||
uris.add(target);
|
||||
viewModel.get(uris).observe(ShowAccountActivity.this, this::manageVIewRelationship);
|
||||
} else if (statusAction == RetrofitPeertubeAPI.ActionType.MUTE) {
|
||||
Toasty.info(ShowAccountActivity.this, getString(R.string.muted_done), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void manageViewAccounts(APIResponse apiResponse) {
|
||||
if (apiResponse.getChannels() != null && apiResponse.getChannels().size() == 1) {
|
||||
Channel channel = apiResponse.getChannels().get(0);
|
||||
if (this.channel == null) {
|
||||
this.channel = channel;
|
||||
manageChannel();
|
||||
}
|
||||
if (channel.getOwnerAccount() != null) {
|
||||
this.channel.setOwnerAccount(channel.getOwnerAccount());
|
||||
}
|
||||
subscriber_count.setText(getString(R.string.followers_count, Helper.withSuffix(channel.getFollowersCount())));
|
||||
subscriber_count.setVisibility(View.VISIBLE);
|
||||
manageNotes(channel);
|
||||
}
|
||||
}
|
||||
|
||||
private void manageNotes(Channel channel) {
|
||||
if (channel.getDescription() != null && channel.getDescription().compareTo("null") != 0 && channel.getDescription().trim().length() > 0) {
|
||||
SpannableString spannableString;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
spannableString = new SpannableString(Html.fromHtml(channel.getDescription(), FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
spannableString = new SpannableString(Html.fromHtml(channel.getDescription()));
|
||||
|
||||
account_note.setText(spannableString, TextView.BufferType.SPANNABLE);
|
||||
account_note.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
account_note.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
account_note.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public enum action {
|
||||
FOLLOW,
|
||||
UNFOLLOW,
|
||||
NOTHING
|
||||
}
|
||||
|
||||
/**
|
||||
* Pager adapter for the 2 fragments
|
||||
*/
|
||||
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
ScreenSlidePagerAdapter(FragmentManager fm) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
if (position == 0) {
|
||||
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
|
||||
bundle = new Bundle();
|
||||
bundle.putSerializable("type", TimelineVM.TimelineType.USER_VIDEOS);
|
||||
bundle.putString("channelId", channel.getAcct());
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
return displayVideosFragment;
|
||||
}
|
||||
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
|
||||
bundle.putString("targetedid", channel.getId());
|
||||
bundle.putString("instance", getLiveInstance(ShowAccountActivity.this));
|
||||
bundle.putString("name", channel.getAcct());
|
||||
displayAccountsFragment.setArguments(bundle);
|
||||
return displayAccountsFragment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -117,9 +117,8 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
ChannelsVM viewModel = new ViewModelProvider(ShowChannelActivity.this).get(ChannelsVM.class);
|
||||
|
||||
manageChannel();
|
||||
viewModel.get(CHANNEL, channelAcct==null?channel.getAcct():channelAcct).observe(ShowChannelActivity.this, this::manageViewAccounts);
|
||||
manageChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -371,9 +370,9 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||
this.channel = channel;
|
||||
manageChannel();
|
||||
}
|
||||
if (channel.getOwnerAccount() != null) {
|
||||
/*if (channel.getOwnerAccount() != null) {
|
||||
this.channel.setOwnerAccount(channel.getOwnerAccount());
|
||||
}
|
||||
}*/
|
||||
subscriber_count.setText(getString(R.string.followers_count, Helper.withSuffix(channel.getFollowersCount())));
|
||||
subscriber_count.setVisibility(View.VISIBLE);
|
||||
manageNotes(channel);
|
||||
|
@ -418,7 +417,7 @@ public class ShowChannelActivity extends AppCompatActivity {
|
|||
if (position == 0) {
|
||||
DisplayVideosFragment displayVideosFragment = new DisplayVideosFragment();
|
||||
bundle = new Bundle();
|
||||
bundle.putSerializable("type", TimelineVM.TimelineType.USER_VIDEOS);
|
||||
bundle.putSerializable("timelineType", TimelineVM.TimelineType.USER_VIDEOS);
|
||||
bundle.putString("channelId", channel.getAcct());
|
||||
displayVideosFragment.setArguments(bundle);
|
||||
return displayVideosFragment;
|
||||
|
|
|
@ -167,7 +167,7 @@ public interface PeertubeService {
|
|||
Call<List<ChannelData.Channel>> getMyChannels(@Header("Authorization") String credentials);
|
||||
|
||||
@GET("video-channels/{channelHandle}/videos")
|
||||
Call<List<VideoData.Video>> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId);
|
||||
Call<VideoData> getChannelVideos(@Path("channelHandle") String channelHandle, @Query("start") String maxId);
|
||||
|
||||
@POST("video-channels")
|
||||
Call<String> addChannel(@Header("Authorization") String credentials, @Body ChannelParams channelParams);
|
||||
|
@ -209,7 +209,7 @@ public interface PeertubeService {
|
|||
|
||||
//Get/Update/Delete captions
|
||||
@GET("videos/{id}/captions")
|
||||
Call<List<CaptionData.Caption>> getCaptions(@Path("id") String videoId);
|
||||
Call<CaptionData> getCaptions(@Path("id") String videoId);
|
||||
|
||||
@PUT("videos/{id}/captions/{captionLanguage}")
|
||||
Call<String> updateCaptions(@Header("Authorization") String credentials, @Path("id") String videoId, @Path("captionLanguage") String captionLanguage, @Body CaptionsParams captionsParams, @Part MultipartBody.Part captionfile);
|
||||
|
@ -255,10 +255,10 @@ public interface PeertubeService {
|
|||
|
||||
//Comment
|
||||
@GET("videos/{id}/comment-threads")
|
||||
Call<List<CommentData.Comment>> getComments(String credentials, @Path("id") String id);
|
||||
Call<CommentData> getComments(@Path("id") String id);
|
||||
|
||||
@GET("videos/{id}/comment-threads/{threadId}")
|
||||
Call<List<CommentData.Comment>> getReplies(String credentials, @Path("id") String id, @Path("threadId") String threadId);
|
||||
Call<CommentData> getReplies(@Path("id") String id, @Path("threadId") String threadId);
|
||||
|
||||
@POST("videos/{id}/comment-threads")
|
||||
Call<String> postComment(@Header("Authorization") String credentials, @Path("id") String id, @Query("text") String text);
|
||||
|
|
|
@ -217,12 +217,12 @@ public class RetrofitPeertubeAPI {
|
|||
public APIResponse getVideosForChannel(String channelId, String max_id) {
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<List<VideoData.Video>> videoCall = peertubeService.getChannelVideos(channelId, max_id);
|
||||
Call<VideoData> videoCall = peertubeService.getChannelVideos(channelId, max_id);
|
||||
if (videoCall != null) {
|
||||
try {
|
||||
Response<List<VideoData.Video>> response = videoCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setPeertubes(response.body());
|
||||
Response<VideoData> response = videoCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setPeertubes(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
|
@ -371,11 +371,11 @@ public class RetrofitPeertubeAPI {
|
|||
|
||||
APIResponse apiResponse = new APIResponse();
|
||||
PeertubeService peertubeService = init();
|
||||
Call<List<CaptionData.Caption>> captions = peertubeService.getCaptions(videoId);
|
||||
Call<CaptionData> captions = peertubeService.getCaptions(videoId);
|
||||
try {
|
||||
Response<List<CaptionData.Caption>> response = captions.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setCaptions(response.body());
|
||||
Response<CaptionData> response = captions.execute();
|
||||
if (response.isSuccessful() && response.body() !=null) {
|
||||
apiResponse.setCaptions(response.body().data);
|
||||
} else {
|
||||
Error error = new Error();
|
||||
error.setStatusCode(response.code());
|
||||
|
@ -1109,19 +1109,19 @@ public class RetrofitPeertubeAPI {
|
|||
APIResponse apiResponse = new APIResponse();
|
||||
try {
|
||||
if (type == CommentVM.action.GET_THREAD) {
|
||||
Call<List<CommentData.Comment>> commentsCall = peertubeService.getComments(token, videoId);
|
||||
Response<List<CommentData.Comment>> response = commentsCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setComments(response.body());
|
||||
Call<CommentData> commentsCall = peertubeService.getComments(videoId);
|
||||
Response<CommentData> response = commentsCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setComments(response.body().data);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
}
|
||||
} else if (type == CommentVM.action.GET_REPLIES) {
|
||||
Call<List<CommentData.Comment>> commentsCall = peertubeService.getReplies(token, videoId, forCommentId);
|
||||
Response<List<CommentData.Comment>> response = commentsCall.execute();
|
||||
if (response.isSuccessful()) {
|
||||
apiResponse.setComments(response.body());
|
||||
Call<CommentData> commentsCall = peertubeService.getReplies(videoId, forCommentId);
|
||||
Response<CommentData> response = commentsCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
apiResponse.setComments(response.body().data);
|
||||
} else {
|
||||
Error error = generateError(response.code(), response.message());
|
||||
apiResponse.setError(error);
|
||||
|
|
|
@ -171,7 +171,7 @@ public class ChannelData {
|
|||
}
|
||||
|
||||
public String getAcct() {
|
||||
return acct;
|
||||
return name+"@"+host;
|
||||
}
|
||||
|
||||
public void setAcct(String acct) {
|
||||
|
|
|
@ -16,7 +16,7 @@ public class File {
|
|||
private String magnetUri;
|
||||
@SerializedName("metadataUrl")
|
||||
private String metadataUrl;
|
||||
@SerializedName("resolutions")
|
||||
@SerializedName("resolution")
|
||||
private Item resolutions;
|
||||
@SerializedName("size")
|
||||
private long size;
|
||||
|
|
|
@ -14,11 +14,15 @@ package app.fedilab.fedilabtube.client.entities;
|
|||
* You should have received a copy of the GNU General Public License along with TubeLab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ViewsPerDay {
|
||||
|
||||
@SerializedName("date")
|
||||
private Date date;
|
||||
@SerializedName("views")
|
||||
private int views;
|
||||
|
||||
public Date getDate() {
|
||||
|
|
|
@ -105,7 +105,6 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
holder.account_action.setImageResource(R.drawable.ic_baseline_volume_mute_24);
|
||||
}
|
||||
|
||||
|
||||
holder.account_pp.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
|
|
|
@ -105,7 +105,7 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
holder.peertube_profile.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, ShowChannelActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putParcelable("channel", peertube.getAccount());
|
||||
b.putParcelable("channel", peertube.getChannel());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
|
|
@ -98,12 +98,12 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
accounts = new ArrayList<>();
|
||||
context = getContext();
|
||||
Bundle bundle = this.getArguments();
|
||||
|
||||
if (bundle != null) {
|
||||
search_peertube = bundle.getString("search_peertube", null);
|
||||
channelId = bundle.getString("channelId", null);
|
||||
type = (TimelineVM.TimelineType) bundle.get("timelineType");
|
||||
}
|
||||
max_id = "0";
|
||||
|
||||
if (getArguments() != null && type == null) {
|
||||
type = DisplayVideosFragmentArgs.fromBundle(getArguments()).getType();
|
||||
|
@ -154,12 +154,6 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
viewModelFeeds = new ViewModelProvider(DisplayVideosFragment.this).get(TimelineVM.class);
|
||||
viewModelSearch = new ViewModelProvider(DisplayVideosFragment.this).get(SearchVM.class);
|
||||
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
|
||||
//Load data depending of the value
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
viewModelFeeds.getVideos(type, "0").observe(DisplayVideosFragment.this.requireActivity(), this::manageVIewVideos);
|
||||
} else {
|
||||
viewModelSearch.getVideos("0", search_peertube).observe(DisplayVideosFragment.this.requireActivity(), this::manageVIewVideos);
|
||||
}
|
||||
|
||||
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
|
@ -230,7 +224,7 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
|
|||
AccountsVM viewModel = new ViewModelProvider(this).get(AccountsVM.class);
|
||||
viewModel.getAccounts(RetrofitPeertubeAPI.DataType.SUBSCRIBER, max_id).observe(DisplayVideosFragment.this.requireActivity(), this::manageViewAccounts);
|
||||
}
|
||||
|
||||
loadTimeline(max_id);
|
||||
display_all.setOnClickListener(v -> {
|
||||
forAccount = null;
|
||||
pullToRefresh();
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import app.fedilab.fedilabtube.client.APIResponse;
|
||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
|
||||
|
||||
public class TimelineVM extends AndroidViewModel {
|
||||
|
@ -81,10 +82,12 @@ public class TimelineVM extends AndroidViewModel {
|
|||
try {
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getVideos(videoId);
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);
|
||||
if (response != null)
|
||||
apiResponse.getPeertubes().get(0).setMyRating(response.getRating().getRating());
|
||||
if(Helper.isLoggedIn(_mContext)) {
|
||||
if (apiResponse.getPeertubes() != null && apiResponse.getPeertubes().size() > 0 && apiResponse.getPeertubes().get(0) != null) {
|
||||
APIResponse response = new RetrofitPeertubeAPI(_mContext).getRating(videoId);
|
||||
if (response != null)
|
||||
apiResponse.getPeertubes().get(0).setMyRating(response.getRating().getRating());
|
||||
}
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);
|
||||
|
|
Loading…
Reference in New Issue