Add torrent
This commit is contained in:
parent
4457259dfd
commit
c8fc98ee71
|
@ -97,7 +97,7 @@ dependencies {
|
|||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.3.1'
|
||||
implementation "androidx.fragment:fragment:1.2.5"
|
||||
|
@ -127,6 +127,8 @@ dependencies {
|
|||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||
implementation 'com.github.mancj:MaterialSearchBar:0.8.5'
|
||||
|
||||
implementation "com.github.TorrentStream:TorrentStream-Android:2.7.0"
|
||||
|
||||
implementation "io.github.kobakei:ratethisapp:1.2.0"
|
||||
implementation 'com.github.HITGIF:TextFieldBoxes:1.4.5'
|
||||
implementation 'com.github.vkay94:DoubleTapPlayerView:1.0.0'
|
||||
|
|
|
@ -271,8 +271,9 @@
|
|||
<string name="report_account">Signaler le compte</string>
|
||||
<string-array name="settings_video_mode">
|
||||
<item>Normal</item>
|
||||
<item>Streaming</item>
|
||||
<item>Flux direct</item>
|
||||
<item>Navigateur</item>
|
||||
<item>Magnet</item>
|
||||
<item>Torrent</item>
|
||||
</string-array>
|
||||
<string-array name="settings_video_quality">
|
||||
<item>Élevée</item>
|
||||
|
|
|
@ -305,7 +305,8 @@
|
|||
<string-array name="settings_video_mode">
|
||||
<item>Normal</item>
|
||||
<item>Webview</item>
|
||||
<item>Direct stream</item>
|
||||
<item>Magnet</item>
|
||||
<item>Torrent</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
|
|
|
@ -214,6 +214,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (token == null && Helper.instanceOnline(instance)) {
|
||||
runOnUiThread(() -> Helper.logoutCurrentUser(MainActivity.this, finalAccount));
|
||||
return;
|
||||
}else if(token == null) {
|
||||
return;
|
||||
}
|
||||
runOnUiThread(() -> {
|
||||
//To avoid a token issue with subscriptions, adding fragment is done when the token is refreshed.
|
||||
|
|
|
@ -66,6 +66,11 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.github.se_bastiaan.torrentstream.StreamStatus;
|
||||
import com.github.se_bastiaan.torrentstream.Torrent;
|
||||
import com.github.se_bastiaan.torrentstream.TorrentOptions;
|
||||
import com.github.se_bastiaan.torrentstream.TorrentStream;
|
||||
import com.github.se_bastiaan.torrentstream.listeners.TorrentListener;
|
||||
import com.github.vkay94.dtpv.youtube.YouTubeOverlay;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
|
@ -74,7 +79,6 @@ import com.google.android.exoplayer2.MediaItem;
|
|||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.MergingMediaSource;
|
||||
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
|
||||
import com.google.android.exoplayer2.source.SingleSampleMediaSource;
|
||||
|
@ -142,7 +146,7 @@ import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
|||
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO;
|
||||
|
||||
|
||||
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener {
|
||||
public class PeertubeActivity extends AppCompatActivity implements CommentListAdapter.AllCommentRemoved, Player.EventListener, VideoListener, TorrentListener {
|
||||
|
||||
public static String video_id;
|
||||
private String peertubeInstance, videoUuid;
|
||||
|
@ -171,6 +175,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
private Intent urlIntent;
|
||||
public static List<String> playedVideos = new ArrayList<>();
|
||||
private VideoData.Video nextVideo;
|
||||
private TorrentStream torrentStream;
|
||||
|
||||
@Override
|
||||
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
|
||||
|
@ -181,6 +186,32 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamPrepared(Torrent torrent) {
|
||||
torrent.startDownload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamStarted(Torrent torrent) {
|
||||
startStream(torrent.getVideoFile().getAbsolutePath(), null, autoPlay, -1, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamError(Torrent torrent, Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamReady(Torrent torrent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamProgress(Torrent torrent, StreamStatus status) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamStopped() {}
|
||||
|
||||
enum videoOrientation {
|
||||
LANDSCAPE,
|
||||
PORTRAIT
|
||||
|
@ -217,6 +248,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPpReply);
|
||||
}
|
||||
|
||||
TorrentOptions torrentOptions = new TorrentOptions.Builder()
|
||||
.saveLocation(getCacheDir())
|
||||
.autoDownload(true)
|
||||
.removeFilesAfterStop(true)
|
||||
.build();
|
||||
|
||||
torrentStream = TorrentStream.init(torrentOptions);
|
||||
torrentStream.addListener(PeertubeActivity.this);
|
||||
|
||||
if (Helper.isTablet(PeertubeActivity.this)) {
|
||||
|
||||
|
@ -776,35 +815,16 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
|
||||
if (mode == Helper.VIDEO_MODE_NORMAL) {
|
||||
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
|
||||
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).build();
|
||||
player.addVideoListener(PeertubeActivity.this);
|
||||
player.addListener(this);
|
||||
binding.mediaVideo.player(player);
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
binding.loader.setVisibility(View.GONE);
|
||||
|
||||
if (apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
}
|
||||
player.setMediaSource(videoSource);
|
||||
} else {
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(apiResponse.getPeertubes().get(0).getStreamingPlaylists().get(0).getPlaylistUrl())).build();
|
||||
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
|
||||
.createMediaSource(mediaItem);
|
||||
player.setMediaSource(hlsMediaSource);
|
||||
}
|
||||
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,
|
||||
autoPlay,-1, null, null);
|
||||
player.prepare();
|
||||
player.setPlayWhenReady(autoPlay);
|
||||
}
|
||||
|
@ -900,9 +920,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath());
|
||||
}
|
||||
}
|
||||
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
|
||||
long position = player.getCurrentPosition();
|
||||
|
||||
if (player != null)
|
||||
|
@ -911,43 +928,15 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
TrackSelector trackSelector = new DefaultTrackSelector(PeertubeActivity.this, new AdaptiveTrackSelection.Factory());
|
||||
player = new SimpleExoPlayer.Builder(PeertubeActivity.this).setTrackSelector(trackSelector).build();
|
||||
binding.mediaVideo.player(player);
|
||||
ProgressiveMediaSource videoSource;
|
||||
MediaSource subtitleSource = null;
|
||||
if (apiResponse.getPeertubes().get(0).getFiles() != null && apiResponse.getPeertubes().get(0).getFiles().size() > 0) {
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
if (uri != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(uri, MimeTypes.TEXT_VTT, itemsKeyLanguage[which]);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
if (uri != null) {
|
||||
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(uri, MimeTypes.TEXT_VTT, itemsKeyLanguage[which], Format.NO_VALUE);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
}
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
if (which > 0 && subtitleSource != null) {
|
||||
MergingMediaSource mergedSource =
|
||||
new MergingMediaSource(videoSource, subtitleSource);
|
||||
player.setMediaSource(mergedSource);
|
||||
}
|
||||
player.prepare();
|
||||
player.seekTo(0, position);
|
||||
player.setPlayWhenReady(true);
|
||||
}
|
||||
|
||||
|
||||
startStream(
|
||||
apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this),
|
||||
null,
|
||||
true,
|
||||
position,
|
||||
uri,
|
||||
itemsKeyLanguage[which]
|
||||
);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
|
@ -977,8 +966,59 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
});
|
||||
popup.show();
|
||||
});
|
||||
}
|
||||
|
||||
private void startStream(String videoURL, String streamingPlaylistsURLS, boolean autoPlay, long position, Uri subtitles, String lang) {
|
||||
|
||||
if (videoURL != null) {
|
||||
if( videoURL.endsWith(".torrent")) {
|
||||
|
||||
torrentStream.startStream(videoURL);
|
||||
return;
|
||||
}else {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
SingleSampleMediaSource subtitleSource = null;
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
|
||||
if (subtitles != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
if (subtitles != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang, Format.NO_VALUE);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
}
|
||||
if (lang != null && subtitleSource != null) {
|
||||
MergingMediaSource mergedSource =
|
||||
new MergingMediaSource(videoSource, subtitleSource);
|
||||
player.setMediaSource(mergedSource);
|
||||
}else {
|
||||
player.setMediaSource(videoSource);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(streamingPlaylistsURLS)).build();
|
||||
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
|
||||
.createMediaSource(mediaItem);
|
||||
player.setMediaSource(hlsMediaSource);
|
||||
}
|
||||
player.prepare();
|
||||
if( position > 0) {
|
||||
player.seekTo(0, position);
|
||||
}
|
||||
player.setPlayWhenReady(autoPlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1006,6 +1046,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
if (player != null) {
|
||||
player.release();
|
||||
}
|
||||
if( torrentStream != null && torrentStream.isStreaming()) {
|
||||
torrentStream.stopStream();
|
||||
}
|
||||
unregisterReceiver();
|
||||
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
|
||||
fullScreenDialog.dismiss();
|
||||
|
@ -1129,8 +1172,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
|
||||
|
||||
public void displayResolution() {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
|
||||
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this);
|
||||
builderSingle.setTitle(R.string.pickup_resolution);
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(PeertubeActivity.this, android.R.layout.select_dialog_item);
|
||||
|
@ -1157,24 +1198,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
binding.mediaVideo.player(player);
|
||||
binding.doubleTapPlayerView.setPlayer(player);
|
||||
binding.loader.setVisibility(View.GONE);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(peertube.getFileUrl(res, PeertubeActivity.this))).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(peertube.getFileUrl(res, PeertubeActivity.this))).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
}
|
||||
player.setMediaSource(videoSource);
|
||||
player.prepare();
|
||||
player.seekTo(0, position);
|
||||
player.setPlayWhenReady(true);
|
||||
startStream(
|
||||
peertube.getFileUrl(res, PeertubeActivity.this),
|
||||
peertube.getStreamingPlaylists().size()>0?peertube.getStreamingPlaylists().get(0).getPlaylistUrl():null,
|
||||
true, position, null, null);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1483,6 +1510,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateHistory(long position) {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
boolean storeInHistory = sharedpreferences.getBoolean(getString(R.string.set_store_in_history), true);
|
||||
|
|
|
@ -54,7 +54,6 @@ import app.fedilab.fedilabtube.client.entities.AccountCreation;
|
|||
import app.fedilab.fedilabtube.client.entities.ChannelParams;
|
||||
import app.fedilab.fedilabtube.client.entities.Error;
|
||||
import app.fedilab.fedilabtube.client.entities.InstanceParams;
|
||||
import app.fedilab.fedilabtube.client.entities.NotificationSettings;
|
||||
import app.fedilab.fedilabtube.client.entities.Oauth;
|
||||
import app.fedilab.fedilabtube.client.entities.OauthParams;
|
||||
import app.fedilab.fedilabtube.client.entities.OverviewVideo;
|
||||
|
|
|
@ -186,27 +186,29 @@ public class VideoData {
|
|||
|
||||
public String getFileUrl(String resolution, Context context) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean streamService = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL) == Helper.VIDEO_MODE_STREAMING;
|
||||
int mode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
|
||||
if (files != null && files.size() > 0) {
|
||||
if (resolution != null) {
|
||||
for (File file : files) {
|
||||
if (file.getResolutions().getLabel().compareTo(resolution) == 0) {
|
||||
if (streamService) {
|
||||
if (mode == Helper.VIDEO_MODE_MAGNET) {
|
||||
return file.getMagnetUri();
|
||||
} else if (mode == Helper.VIDEO_MODE_TORRENT) {
|
||||
return file.getTorrentUrl();
|
||||
}else {
|
||||
return file.getFileUrl();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File file = Helper.defaultFile(context, files);
|
||||
if (file != null) {
|
||||
if (streamService) {
|
||||
if (mode == Helper.VIDEO_MODE_MAGNET) {
|
||||
return file.getMagnetUri();
|
||||
} else if (mode == Helper.VIDEO_MODE_TORRENT) {
|
||||
return file.getTorrentUrl();
|
||||
} else {
|
||||
return file.getFileUrl();
|
||||
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
|
|
|
@ -96,11 +96,14 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
|
||||
break;
|
||||
case "1":
|
||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_STREAMING);
|
||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_MAGNET);
|
||||
break;
|
||||
case "2":
|
||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
|
||||
break;
|
||||
case "3":
|
||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -232,6 +235,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
//****** My Account ******
|
||||
|
||||
Preference my_account = findPreference("my_account");
|
||||
assert my_account != null;
|
||||
if(!Helper.isLoggedIn(getActivity()) || userMe == null) {
|
||||
my_account.setVisible(false);
|
||||
} else {
|
||||
|
@ -276,11 +280,12 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
|||
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
|
||||
List<String> array = Arrays.asList(getResources().getStringArray(R.array.settings_video_mode));
|
||||
CharSequence[] entries = array.toArray(new CharSequence[0]);
|
||||
CharSequence[] entryValues = new CharSequence[3];
|
||||
CharSequence[] entryValues = new CharSequence[4];
|
||||
int video_mode = sharedpref.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
|
||||
entryValues[0] = String.valueOf(Helper.VIDEO_MODE_NORMAL);
|
||||
entryValues[1] = String.valueOf(Helper.VIDEO_MODE_STREAMING);
|
||||
entryValues[1] = String.valueOf(Helper.VIDEO_MODE_MAGNET);
|
||||
entryValues[2] = String.valueOf(Helper.VIDEO_MODE_WEBVIEW);
|
||||
entryValues[3] = String.valueOf(Helper.VIDEO_MODE_TORRENT);
|
||||
if (set_video_mode_choice != null) {
|
||||
set_video_mode_choice.setEntries(entries);
|
||||
set_video_mode_choice.setEntryValues(entryValues);
|
||||
|
|
|
@ -85,7 +85,8 @@ public class Helper {
|
|||
public static final int DEFAULT_MODE = 2;
|
||||
public static final String TIMELINE_TYPE = "timeline_type";
|
||||
public static final int VIDEO_MODE_NORMAL = 0;
|
||||
public static final int VIDEO_MODE_STREAMING = 2;
|
||||
public static final int VIDEO_MODE_MAGNET = 2;
|
||||
public static final int VIDEO_MODE_TORRENT = 3;
|
||||
public static final int VIDEO_MODE_WEBVIEW = 1;
|
||||
public static final int QUALITY_HIGH = 0;
|
||||
public static final int QUALITY_MEDIUM = 1;
|
||||
|
|
|
@ -53,10 +53,10 @@ public class NotificationHelper {
|
|||
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, FETCH_NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_notification_tubelab).setTicker(message)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setAutoCancel(true);
|
||||
.setWhen(System.currentTimeMillis());
|
||||
notificationBuilder.setGroup(account.getAcct())
|
||||
.setContentIntent(pIntent)
|
||||
.setAutoCancel(true)
|
||||
.setContentText(message);
|
||||
|
||||
|
||||
|
@ -76,6 +76,7 @@ public class NotificationHelper {
|
|||
.setContentText(context.getApplicationContext().getString(R.string.fetch_notification_channel_name))
|
||||
.setContentIntent(pIntent)
|
||||
.setLargeIcon(icon)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_notification_tubelab)
|
||||
.setGroup(account.getAcct())
|
||||
.setGroupSummary(true)
|
||||
|
|
|
@ -98,13 +98,18 @@ public class NotificationsWorker extends Worker {
|
|||
for(AccountData.Account account: accounts) {
|
||||
RetrofitPeertubeAPI retrofitPeertubeAPI = new RetrofitPeertubeAPI(getApplicationContext(), account.getHost(), account.getToken());
|
||||
APIResponse apiResponse = retrofitPeertubeAPI.getNotifications();
|
||||
if( apiResponse == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
UserMe userMe = retrofitPeertubeAPI.verifyCredentials();
|
||||
if( userMe != null) {
|
||||
List<NotificationData.Notification> notifications = apiResponse.getPeertubeNotifications();
|
||||
NotificationSettings notificationSettings = userMe.getNotificationSettings();
|
||||
if( apiResponse != null && apiResponse.getPeertubeNotifications() != null && apiResponse.getPeertubeNotifications().size() > 0 ) {
|
||||
if( apiResponse.getPeertubeNotifications() != null && apiResponse.getPeertubeNotifications().size() > 0 ) {
|
||||
String last_read = sharedpreferences.getString(Helper.LAST_NOTIFICATION_READ + account.getId() + account.getHost(), null);
|
||||
editor.putString(Helper.LAST_NOTIFICATION_READ + account.getId() + account.getHost(), apiResponse.getPeertubeNotifications().get(0).getId());
|
||||
editor.apply();
|
||||
if( last_read != null) {
|
||||
for(NotificationData.Notification notification: notifications) {
|
||||
String title = "";
|
||||
|
@ -121,7 +126,7 @@ public class NotificationsWorker extends Worker {
|
|||
}
|
||||
|
||||
Intent intent = null;
|
||||
if( last_read == null || notification.getId().compareTo(last_read) > 0) {
|
||||
if(notification.getId().compareTo(last_read) > 0) {
|
||||
switch (notification.getType()) {
|
||||
case DisplayNotificationsFragment.NEW_VIDEO_FROM_SUBSCRIPTION:
|
||||
if(notificationSettings.getNewVideoFromSubscription() == 1 || notificationSettings.getNewVideoFromSubscription() == 3) {
|
||||
|
@ -281,8 +286,6 @@ public class NotificationsWorker extends Worker {
|
|||
}
|
||||
}
|
||||
}
|
||||
editor.putString(Helper.LAST_NOTIFICATION_READ + account.getId() + account.getHost(), apiResponse.getPeertubeNotifications().get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,7 +303,7 @@ public class NotificationsWorker extends Worker {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(FETCH_NOTIFICATION_CHANNEL_ID,
|
||||
getApplicationContext().getString(R.string.fetch_notification_channel_name),
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
channel.setSound(null, null);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
@ -317,6 +320,8 @@ public class NotificationsWorker extends Worker {
|
|||
.setOnlyAlertOnce(true)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setSmallIcon(R.drawable.ic_notification_tubelab)
|
||||
.setSound(null)
|
||||
.setAutoCancel(true)
|
||||
.setOngoing(true);
|
||||
return new ForegroundInfo(pendingNotificationID, notificationBuilder.build());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue