1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-06-05 21:09:11 +02:00
This commit is contained in:
Thomas
2020-12-18 14:31:36 +01:00
parent bdd12de34d
commit 6820344750
62 changed files with 122 additions and 548 deletions

View File

@@ -74,6 +74,7 @@ import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistAdapter.AllPlaylistRemoved {
private static final int PICK_AVATAR = 467;
PlaylistAdapter playlistAdapter;
private HashMap<Integer, String> privacyToSend;
private String idChannel;
@@ -81,7 +82,6 @@ public class AllPlaylistsActivity extends AppCompatActivity implements PlaylistA
private Playlist playlistToEdit;
private List<ChannelData.Channel> myChannels;
private ChannelData.Channel selectedChannel;
private static final int PICK_AVATAR = 467;
private AddPlaylistBinding bindingDialog;
private Uri inputData;
private ActivityAllPlaylistBinding binding;

View File

@@ -111,16 +111,53 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
public static UserMe userMe;
public static InstanceData.InstanceConfig instanceConfig;
public static TypeOfConnection typeOfConnection;
public static List<ChromeCast> chromeCasts;
public static ChromeCast chromeCast;
public static boolean chromecastActivated = false;
private DisplayVideosFragment recentFragment, locaFragment, trendingFragment, subscriptionFragment, mostLikedFragment;
private DisplayOverviewFragment overviewFragment;
private ActivityMainBinding binding;
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
int itemId = item.getItemId();
String type = null;
if (itemId == R.id.navigation_discover) {
setTitleCustom(R.string.title_discover);
binding.viewpager.setCurrentItem(0);
type = HelperAcadInstance.DISCOVER;
} else if (itemId == R.id.navigation_subscription) {
binding.viewpager.setCurrentItem(1);
setTitleCustom(R.string.subscriptions);
type = HelperAcadInstance.SUBSCRIPTIONS;
} else if (itemId == R.id.navigation_trending) {
setTitleCustom(R.string.title_trending);
if (Helper.isLoggedIn(MainActivity.this)) {
binding.viewpager.setCurrentItem(2);
} else {
binding.viewpager.setCurrentItem(1);
}
type = HelperAcadInstance.TRENDING;
} else if (itemId == R.id.navigation_most_liked) {
setTitleCustom(R.string.title_most_liked);
binding.viewpager.setCurrentItem(2);
type = HelperAcadInstance.MOSTLIKED;
} else if (itemId == R.id.navigation_recently_added) {
setTitleCustom(R.string.title_recently_added);
binding.viewpager.setCurrentItem(3);
type = HelperAcadInstance.RECENTLY_ADDED;
} else if (itemId == R.id.navigation_local) {
setTitleCustom(R.string.title_local);
binding.viewpager.setCurrentItem(4);
type = HelperAcadInstance.LOCAL;
}
if (type != null) {
Matomo.sendScreen(MainActivity.this, "TIMELINE", type);
}
return true;
};
private BroadcastReceiver manage_chromecast;
public static List<ChromeCast> chromeCasts;
public static ChromeCast chromeCast;
private VideoData.Video castedTube;
public static boolean chromecastActivated = false;
@SuppressLint("ApplySharedPref")
public static void showRadioButtonDialogFullInstances(Activity activity, boolean storeInDb) {
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@@ -194,45 +231,6 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
}
}
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
int itemId = item.getItemId();
String type = null;
if (itemId == R.id.navigation_discover) {
setTitleCustom(R.string.title_discover);
binding.viewpager.setCurrentItem(0);
type = HelperAcadInstance.DISCOVER;
} else if (itemId == R.id.navigation_subscription) {
binding.viewpager.setCurrentItem(1);
setTitleCustom(R.string.subscriptions);
type = HelperAcadInstance.SUBSCRIPTIONS;
} else if (itemId == R.id.navigation_trending) {
setTitleCustom(R.string.title_trending);
if (Helper.isLoggedIn(MainActivity.this)) {
binding.viewpager.setCurrentItem(2);
} else {
binding.viewpager.setCurrentItem(1);
}
type = HelperAcadInstance.TRENDING;
} else if (itemId == R.id.navigation_most_liked) {
setTitleCustom(R.string.title_most_liked);
binding.viewpager.setCurrentItem(2);
type = HelperAcadInstance.MOSTLIKED;
} else if (itemId == R.id.navigation_recently_added) {
setTitleCustom(R.string.title_recently_added);
binding.viewpager.setCurrentItem(3);
type = HelperAcadInstance.RECENTLY_ADDED;
} else if (itemId == R.id.navigation_local) {
setTitleCustom(R.string.title_local);
binding.viewpager.setCurrentItem(4);
type = HelperAcadInstance.LOCAL;
}
if (type != null) {
Matomo.sendScreen(MainActivity.this, "TIMELINE", type);
}
return true;
};
@Override
public void newChromeCastDiscovered(ChromeCast chromeCast) {
if (chromeCasts == null) {
@@ -417,7 +415,6 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
});
toolbar.setOnClickListener(v -> {
if (binding.viewpager.getAdapter() == null) {
return;
@@ -939,6 +936,12 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
}
}
public enum TypeOfConnection {
UNKNOWN,
NORMAL,
SURFING
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
ScreenSlidePagerAdapter(FragmentManager fm) {
@@ -983,10 +986,4 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
return 5;
}
}
public enum TypeOfConnection {
UNKNOWN,
NORMAL,
SURFING
}
}

View File

@@ -235,7 +235,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override
public void onStreamStarted(Torrent torrent) {
startStream(torrent.getVideoFile().getAbsolutePath(), null, autoPlay, -1, null, null, true);
startStream(peertube, torrent.getVideoFile().getAbsolutePath(), null, autoPlay, -1, null, null, true);
}
@Override
@@ -961,7 +961,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.loader.setVisibility(View.GONE);
return;
}
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this) == null) {
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || (!apiResponse.getPeertubes().get(0).isLive() && apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this) == null)) {
Toasty.error(PeertubeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
binding.loader.setVisibility(View.GONE);
return;
@@ -1191,8 +1191,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.doubleTapPlayerView.setPlayer(player);
binding.loader.setVisibility(View.GONE);
startStream(
apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this),
apiResponse.getPeertubes().get(0).getStreamingPlaylists().size() > 0 ? apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl() : null,
apiResponse.getPeertubes().get(0),
null,
null,
autoPlay, position, null, null, true);
player.prepare();
player.setPlayWhenReady(autoPlay);
@@ -1281,7 +1282,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
private void stream(String videoURL, String streamingPlaylistsURLS, boolean autoPlay, long position, Uri subtitles, String lang) {
private void stream(VideoData.Video video, String resolution, boolean autoPlay, long position, Uri subtitles, String lang) {
String videoURL = video.getFileUrl(resolution, PeertubeActivity.this);
if (videoURL != null && !videoURL.endsWith("m3u8")) {
if (videoURL.endsWith(".torrent")) {
torrentStream.startStream(videoURL);
@@ -1320,10 +1322,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
} else {
if (streamingPlaylistsURLS == null && videoURL != null) {
streamingPlaylistsURLS = videoURL;
}
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(streamingPlaylistsURLS)).build();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build();
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
.createMediaSource(mediaItem);
player.setMediaSource(hlsMediaSource);
@@ -1362,10 +1361,15 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
private void startStream(String videoURL, String streamingPlaylistsURLS, boolean autoPlay, long position, Uri subtitles, String lang, boolean promptNSFW) {
private void startStream(VideoData.Video video, String torrentLocal, String resolution, boolean autoPlay, long position, Uri subtitles, String lang, boolean promptNSFW) {
if (peertube != null && peertube.isWaitTranscoding()) {
String videoURL;
if (torrentLocal != null) {
videoURL = torrentLocal;
} else {
videoURL = peertube.getFileUrl(resolution, PeertubeActivity.this);
}
if (peertube != null && peertube.isWaitTranscoding() && peertube.isLive()) {
View parentLayout = findViewById(android.R.id.content);
Snackbar snackbar = Snackbar.make(parentLayout, R.string.live_not_started, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.close, view -> finish());
@@ -1387,13 +1391,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
finish();
});
dialogBuilder.setPositiveButton(R.string.play, (dialog, id) -> {
stream(videoURL, streamingPlaylistsURLS, autoPlay, position, subtitles, lang);
stream(video, resolution, autoPlay, position, subtitles, lang);
dialog.dismiss();
});
alertDialog = dialogBuilder.create();
alertDialog.show();
} else {
stream(videoURL, streamingPlaylistsURLS, autoPlay, position, subtitles, lang);
stream(video, resolution, autoPlay, position, subtitles, lang);
}
@@ -1621,6 +1625,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
binding.peertubeInformationContainer.setVisibility(View.GONE);
@@ -1773,8 +1778,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.doubleTapPlayerView.setPlayer(player);
binding.loader.setVisibility(View.GONE);
startStream(
peertube.getFileUrl(res, PeertubeActivity.this),
peertube.getStreamingPlaylists().size() > 0 ? peertube.getStreamingPlaylists().get(0).getPlaylistUrl() : null,
peertube,
null,
res,
true, position, null, null, false);
}
break;
@@ -1813,7 +1819,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
binding.mediaVideo.player(player);
binding.doubleTapPlayerView.setPlayer(player);
startStream(
peertube.getFileUrl(null, PeertubeActivity.this),
peertube,
null,
null,
true,
newPosition,
@@ -1872,7 +1879,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
public void closeSubMenuMenuOptions() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
@@ -2303,8 +2309,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
enum videoOrientation {
LANDSCAPE,
PORTRAIT

View File

@@ -37,7 +37,6 @@ import androidx.core.content.ContextCompat;
import androidx.documentfile.provider.DocumentFile;
import androidx.lifecycle.ViewModelProvider;
import net.gotev.uploadservice.data.UploadNotificationAction;
import net.gotev.uploadservice.data.UploadNotificationConfig;
import net.gotev.uploadservice.data.UploadNotificationStatusConfig;

View File

@@ -160,16 +160,14 @@ public class ShowChannelActivity extends AppCompatActivity {
if (accounts != null && accounts.size() > 0) {
if (accounts.size() > 1) {
final OwnAccountsAdapter accountsListAdapter = new OwnAccountsAdapter(ShowChannelActivity.this, accounts);
builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> {
new Thread(() -> {
try {
RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(ShowChannelActivity.this, accounts.get(which).getHost(), accounts.get(which).getToken());
peertubeAPI.post(FOLLOW, channel.getAcct(), null);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
});
builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> new Thread(() -> {
try {
RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(ShowChannelActivity.this, accounts.get(which).getHost(), accounts.get(which).getToken());
peertubeAPI.post(FOLLOW, channel.getAcct(), null);
} catch (Exception e) {
e.printStackTrace();
}
}).start());
} else {
RetrofitPeertubeAPI peertubeAPI = new RetrofitPeertubeAPI(ShowChannelActivity.this, accounts.get(0).getHost(), accounts.get(0).getToken());
peertubeAPI.post(FOLLOW, channel.getAcct(), null);
@@ -362,7 +360,11 @@ public class ShowChannelActivity extends AppCompatActivity {
public void manageVIewRelationship(APIResponse apiResponse) {
if (apiResponse.getError() != null) {
Toasty.error(ShowChannelActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
if (apiResponse.getError().getError().length() > 500) {
Toasty.info(ShowChannelActivity.this, getString(R.string.remote_account), Toast.LENGTH_LONG).show();
} else {
Toasty.error(ShowChannelActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}
return;
}
this.relationship = apiResponse.getRelationships();

View File

@@ -91,7 +91,7 @@ import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@SuppressWarnings({"unused", "RedundantSuppression"})
@SuppressWarnings({"unused", "RedundantSuppression", "ConstantConditions"})
public class RetrofitPeertubeAPI {
private final String finalUrl;
@@ -177,9 +177,6 @@ public class RetrofitPeertubeAPI {
}
private PeertubeService init() {
if (!URLUtil.isValidUrl(finalUrl)) {
return null;
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(finalUrl)
.addConverterFactory(GsonConverterFactory.create())

View File

@@ -197,18 +197,9 @@ public class VideoData {
public String getFileUrl(String resolution, Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
List<File> files = getAllFile(context);
if (files != null && files.size() > 0) {
return getFile(context, files, resolution, mode);
} else if (streamingPlaylists != null && streamingPlaylists.size() > 0) {
List<File> files = new ArrayList<>();
for (StreamingPlaylists streamingPlaylists : streamingPlaylists) {
if (streamingPlaylists.getFiles().size() > 0) {
files.addAll(streamingPlaylists.getFiles());
} else {
return streamingPlaylists.getPlaylistUrl();
}
}
return getFile(context, files, resolution, mode);
}
return null;
}
@@ -216,7 +207,7 @@ public class VideoData {
public List<File> getAllFile(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
if (files != null) {
if (files != null && files.size() > 0) {
return files;
} else if (streamingPlaylists != null) {
List<File> files = new ArrayList<>();
@@ -225,7 +216,7 @@ public class VideoData {
}
return files;
}
return null;
return files;
}

View File

@@ -23,7 +23,6 @@ import com.google.gson.annotations.SerializedName;
import java.util.List;
@SuppressWarnings({"unused", "RedundantSuppression"})
public class VideoPlaylistData {

View File

@@ -19,11 +19,14 @@ import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.databinding.DrawerHorizontalAccountBinding;
import app.fedilab.fedilabtube.helper.Helper;

View File

@@ -75,11 +75,11 @@ public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
private final List<Comment> comments;
private final CommentListAdapter commentListAdapter;
private final boolean isThread;
private final String instance;
private final boolean sepiaSearch;
public AllCommentRemoved allCommentRemoved;
boolean isVideoOwner;
private Context context;
private final String instance;
private final boolean sepiaSearch;
public CommentListAdapter(List<Comment> comments, boolean isVideoOwner, boolean isThread, String instance, boolean sepiaSearch) {
this.comments = comments;

View File

@@ -408,14 +408,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
}
public interface RelationShipListener {
Map<String, Boolean> getRelationShip();
}
public interface PlaylistListener {
Map<String, List<PlaylistExist>> getPlaylist();
}
@SuppressLint("CheckResult")
private void loadImage(ImageView target, String instance, String urlPreview, String thumbnail, boolean blur) {
if (urlPreview == null || urlPreview.startsWith("null")) {
@@ -478,6 +470,14 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
public interface RelationShipListener {
Map<String, Boolean> getRelationShip();
}
public interface PlaylistListener {
Map<String, List<PlaylistExist>> getPlaylist();
}
static class ViewHolder extends RecyclerView.ViewHolder {
DrawerPeertubeBinding binding;

View File

@@ -33,7 +33,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.app.ActivityCompat;

View File

@@ -68,8 +68,8 @@ import static app.fedilab.fedilabtube.PeertubeUploadActivity.MY_PERMISSIONS_REQU
public class DisplayChannelsFragment extends Fragment implements ChannelListAdapter.AllChannelRemoved, ChannelListAdapter.EditAlertDialog {
private Context context;
private static final int PICK_AVATAR = 467;
private Context context;
private ChannelListAdapter channelListAdapter;
private List<ChannelData.Channel> channels;
private String name;

View File

@@ -30,7 +30,6 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast;

View File

@@ -325,8 +325,13 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
if (this.peertubes == null || apiResponse == null || (apiResponse.getError() != null)) {
if (apiResponse == null)
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
else {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
else if (apiResponse.getError() != null) {
if (apiResponse.getError().getError().length() > 500) {
Toasty.info(context, getString(R.string.remote_account), Toast.LENGTH_LONG).show();
} else {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
}
}
binding.swipeContainer.setRefreshing(false);
flag_loading = false;
@@ -437,11 +442,9 @@ public class DisplayVideosFragment extends Fragment implements AccountsHorizonta
@Override
public void onDestroyView() {
if (binding.lvVideos != null) {
try {
binding.lvVideos.setAdapter(null);
} catch (Exception ignored) {
}
try {
binding.lvVideos.setAdapter(null);
} catch (Exception ignored) {
}
super.onDestroyView();
}

View File

@@ -16,6 +16,7 @@ package app.fedilab.fedilabtube.helper;
import java.util.List;
import app.fedilab.fedilabtube.client.data.CommentData;
public class CommentDecorationHelper {

View File

@@ -80,7 +80,6 @@ import static android.content.Context.DOWNLOAD_SERVICE;
public class Helper {
public static PeertubeInformation peertubeInformation;
public static final int RELOAD_MYVIDEOS = 10;
public static final String SET_VIDEO_MODE = "set_video_mode";
public static final String SET_QUALITY_MODE = "set_quality_mode";
@@ -132,8 +131,7 @@ public class Helper {
public static final int VIDEOS_PER_PAGE = 10;
public static final String RECEIVE_ACTION = "receive_action";
public static final String SET_UNFOLLOW_VALIDATION = "set_unfollow_validation";
public static PeertubeInformation peertubeInformation;
/**
* Convert a date in String -> format yyyy-MM-dd HH:mm:ss

View File

@@ -24,7 +24,6 @@ import app.fedilab.fedilabtube.BuildConfig;
public class HelperInstance {
/**
* Returns the instance of the authenticated user
*

View File

@@ -72,7 +72,12 @@ public class AccountsVM extends AndroidViewModel {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
try {
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
RetrofitPeertubeAPI retrofitPeertubeAPI;
if (acct.split("@").length > 1) {
retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext, acct.split("@")[1], null);
} else {
retrofitPeertubeAPI = new RetrofitPeertubeAPI(_mContext);
}
APIResponse apiResponse = retrofitPeertubeAPI.getAccount(acct);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> apiResponseMutableLiveData.setValue(apiResponse);

View File

@@ -445,4 +445,5 @@
<string name="set_video_language_description">Filter videos with different languages</string>
<string name="live">Live</string>
<string name="live_not_started">This live has not started!</string>
<string name="remote_account">Account from another network!</string>
</resources>