· 5 years ago · Jun 01, 2020, 07:24 PM
1package com.cristian.rocopelis;
2
3import android.annotation.SuppressLint;
4import android.app.AlertDialog;
5import android.content.BroadcastReceiver;
6import android.content.ComponentName;
7import android.content.ContentResolver;
8import android.content.Context;
9import android.content.Intent;
10import android.content.SharedPreferences;
11import android.content.pm.ActivityInfo;
12import android.content.pm.PackageManager;
13import android.content.pm.ResolveInfo;
14import android.graphics.Point;
15import android.media.AudioManager;
16import android.net.ConnectivityManager;
17import android.net.NetworkInfo;
18import android.net.Uri;
19import android.os.Build;
20import android.os.Bundle;
21
22import androidx.annotation.RequiresApi;
23import androidx.core.app.ActivityCompat;
24import androidx.core.content.ContextCompat;
25import androidx.mediarouter.app.MediaRouteButton;
26import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
27import androidx.appcompat.app.AppCompatActivity;
28import androidx.recyclerview.widget.LinearLayoutManager;
29import androidx.recyclerview.widget.RecyclerView;
30import androidx.work.Data;
31import androidx.work.OneTimeWorkRequest;
32import androidx.work.WorkManager;
33
34import at.huber.youtubeExtractor.VideoMeta;
35import at.huber.youtubeExtractor.YouTubeExtractor;
36import at.huber.youtubeExtractor.YtFile;
37import retrofit2.Call;
38import retrofit2.Callback;
39import retrofit2.Retrofit;
40
41import android.os.Environment;
42import android.os.Handler;
43import android.os.PersistableBundle;
44import android.provider.Settings;
45import android.util.Log;
46import android.util.SparseArray;
47import android.view.Display;
48import android.view.GestureDetector;
49import android.view.KeyEvent;
50import android.view.LayoutInflater;
51import android.view.MotionEvent;
52import android.view.OrientationEventListener;
53import android.view.View;
54import android.view.ViewGroup;
55import android.view.Window;
56import android.view.WindowManager;
57import android.webkit.WebChromeClient;
58import android.webkit.WebSettings;
59import android.webkit.WebView;
60import android.widget.AdapterView;
61import android.widget.ArrayAdapter;
62import android.widget.Button;
63import android.widget.EditText;
64import android.widget.ImageView;
65import android.widget.LinearLayout;
66import android.widget.ListView;
67import android.widget.ProgressBar;
68import android.widget.RelativeLayout;
69import android.widget.SeekBar;
70import android.widget.Spinner;
71import android.widget.TextView;
72import android.widget.Toast;
73
74import com.balysv.materialripple.MaterialRippleLayout;
75import com.cristian.rocopelis.listener.MyGestureListener;
76import com.cristian.rocopelis.models.AppDetail;
77import com.facebook.shimmer.ShimmerFrameLayout;
78import com.google.android.exoplayer2.C;
79import com.google.android.exoplayer2.ExoPlayerFactory;
80import com.google.android.exoplayer2.Format;
81import com.google.android.exoplayer2.Player;
82import com.google.android.exoplayer2.SimpleExoPlayer;
83import com.google.android.exoplayer2.ext.cast.CastPlayer;
84import com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory;
85import com.google.android.exoplayer2.source.ExtractorMediaSource;
86import com.google.android.exoplayer2.source.MediaSource;
87import com.google.android.exoplayer2.source.MergingMediaSource;
88import com.google.android.exoplayer2.source.SingleSampleMediaSource;
89import com.google.android.exoplayer2.source.hls.HlsMediaSource;
90import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
91import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
92import com.google.android.exoplayer2.trackselection.TrackSelection;
93import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
94import com.google.android.exoplayer2.ui.PlaybackControlView;
95import com.google.android.exoplayer2.ui.PlayerControlView;
96import com.google.android.exoplayer2.ui.PlayerView;
97import com.google.android.exoplayer2.ui.SubtitleView;
98import com.google.android.exoplayer2.upstream.BandwidthMeter;
99import com.google.android.exoplayer2.upstream.DataSource;
100import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
101import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
102import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
103import com.google.android.exoplayer2.util.MimeTypes;
104import com.google.android.exoplayer2.util.Util;
105import com.google.android.gms.cast.MediaInfo;
106import com.google.android.gms.cast.MediaMetadata;
107import com.google.android.gms.cast.MediaQueueItem;
108import com.google.android.gms.cast.MediaStatus;
109import com.google.android.gms.cast.framework.CastButtonFactory;
110import com.google.android.gms.cast.framework.CastContext;
111import com.google.android.gms.cast.framework.CastSession;
112import com.google.android.gms.cast.framework.CastState;
113import com.google.android.gms.cast.framework.media.RemoteMediaClient;
114import com.google.android.gms.common.images.WebImage;
115import com.google.android.material.bottomsheet.BottomSheetDialog;
116import com.google.firebase.analytics.FirebaseAnalytics;
117import com.cristian.rocopelis.adapters.CastCrewAdapter;
118import com.cristian.rocopelis.adapters.CommentsAdapter;
119import com.cristian.rocopelis.adapters.EpisodeAdapter;
120import com.cristian.rocopelis.adapters.DownloadAdapter;
121import com.cristian.rocopelis.adapters.HomePageAdapter;
122import com.cristian.rocopelis.adapters.ProgramAdapter;
123import com.cristian.rocopelis.adapters.RelatedTvAdapter;
124import com.cristian.rocopelis.adapters.ServerAdapter;
125import com.cristian.rocopelis.database.DatabaseHelper;
126import com.cristian.rocopelis.models.CastCrew;
127import com.cristian.rocopelis.models.GetCommentsModel;
128import com.cristian.rocopelis.models.CommonModels;
129import com.cristian.rocopelis.models.EpiModel;
130import com.cristian.rocopelis.models.PostCommentModel;
131import com.cristian.rocopelis.models.Program;
132import com.cristian.rocopelis.models.SubtitleModel;
133import com.cristian.rocopelis.models.single_details.Cast;
134import com.cristian.rocopelis.models.single_details.Director;
135import com.cristian.rocopelis.models.single_details.DownloadLink;
136import com.cristian.rocopelis.models.single_details.Episode;
137import com.cristian.rocopelis.models.single_details.Genre;
138import com.cristian.rocopelis.models.single_details.RelatedMovie;
139import com.cristian.rocopelis.models.single_details.Season;
140import com.cristian.rocopelis.models.single_details.SingleDetails;
141import com.cristian.rocopelis.models.single_details.Subtitle;
142import com.cristian.rocopelis.models.single_details.Video;
143import com.cristian.rocopelis.models.single_details_tv.AdditionalMediaSource;
144import com.cristian.rocopelis.models.single_details_tv.AllTvChannel;
145import com.cristian.rocopelis.models.single_details_tv.ProgramGuide;
146import com.cristian.rocopelis.models.single_details_tv.SingleDetailsTV;
147import com.cristian.rocopelis.network.RetrofitClient;
148import com.cristian.rocopelis.network.apis.CommentApi;
149import com.cristian.rocopelis.network.apis.FavouriteApi;
150import com.cristian.rocopelis.network.apis.SingleDetailsApi;
151import com.cristian.rocopelis.network.apis.SingleDetailsTVApi;
152import com.cristian.rocopelis.network.apis.SubscriptionApi;
153import com.cristian.rocopelis.network.model.ActiveStatus;
154import com.cristian.rocopelis.network.model.config.AdsConfig;
155import com.cristian.rocopelis.network.model.FavoriteModel;
156import com.cristian.rocopelis.service.DownloadWorkManager;
157import com.cristian.rocopelis.utils.PreferenceUtils;
158import com.cristian.rocopelis.utils.RtlUtils;
159import com.cristian.rocopelis.utils.ads.BannerAds;
160import com.cristian.rocopelis.utils.Constants;
161import com.cristian.rocopelis.utils.ads.PopUpAds;
162import com.cristian.rocopelis.utils.ToastMsg;
163import com.cristian.rocopelis.utils.Tools;
164import com.squareup.picasso.Picasso;
165
166import org.jetbrains.annotations.NotNull;
167
168import java.io.File;
169import java.util.ArrayList;
170import java.util.List;
171import java.util.Random;
172
173import static android.view.View.GONE;
174import static android.view.View.VISIBLE;
175import static com.google.android.gms.ads.AdActivity.CLASS_NAME;
176
177public class DetailsActivity extends AppCompatActivity implements CastPlayer.SessionAvailabilityListener, ProgramAdapter.OnProgramClickListener, EpisodeAdapter.OnTVSeriesEpisodeItemClickListener,
178 RelatedTvAdapter.RelatedTvClickListener {
179 private static final int PERMISSION_REQUEST_CODE = 1;
180 private static final int PRELOAD_TIME_S = 20;
181 public static final String TAG = DetailsActivity.class.getSimpleName();
182 private TextView tvName, tvDirector, tvRelease, tvCast, tvDes, tvGenre, tvRelated;
183 private RecyclerView rvDirector, rvServer, rvRelated, rvComment, castRv;
184 private Spinner seasonSpinner;
185 private LinearLayout seasonSpinnerContainer;
186 public static RelativeLayout lPlay;
187 private RelativeLayout contentDetails;
188 private LinearLayout subscriptionLayout, topbarLayout;
189 private Button subscribeBt;
190 private ImageView backIv, subBackIv;
191
192 private ServerAdapter serverAdapter;
193 private DownloadAdapter internalDownloadAdapter, externalDownloadAdapter;
194 private HomePageAdapter relatedAdapter;
195 private RelatedTvAdapter relatedTvAdapter;
196 private CastCrewAdapter castCrewAdapter;
197
198 int start = 0;
199 private List<CommonModels> listServer = new ArrayList<>();
200 private List<CommonModels> listRelated = new ArrayList<>();
201 private List<GetCommentsModel> listComment = new ArrayList<>();
202 private List<CommonModels> listDownload = new ArrayList<>();
203 private List<CommonModels> listInternalDownload = new ArrayList<>();
204 private List<CommonModels> listExternalDownload = new ArrayList<>();
205 private List<CastCrew> castCrews = new ArrayList<>();
206 private String strDirector = "", strCast = "", strGenre = "";
207 public static LinearLayout llBottom, llBottomParent;
208 public static RelativeLayout llcomment;
209 private SwipeRefreshLayout swipeRefreshLayout;
210 private String type = "", id = "";
211 private ImageView imgAddFav, shareIv2;
212 public static ImageView imgBack, serverIv;
213 private Button watchNowBt, downloadBt;
214 private ImageView posterIv, thumbIv, descriptionBackIv;
215 private String V_URL = "";
216 public static WebView webView;
217 public static ProgressBar progressBar;
218 private boolean isFav = false;
219 private TextView chromeCastTv;
220 private ShimmerFrameLayout shimmerFrameLayout;
221 private Button btnComment;
222 private EditText etComment;
223 private CommentsAdapter commentsAdapter;
224 private RelativeLayout adView;
225
226 public static SimpleExoPlayer player;
227 public static PlayerView simpleExoPlayerView;
228 public PlayerControlView castControlView;
229 public static SubtitleView subtitleView;
230
231 public static ImageView imgFull;
232 public ImageView aspectRatioIv, externalPlayerIv, volumControlIv;
233 private LinearLayout volumnControlLayout;
234 private SeekBar volumnSeekbar;
235 private ImageView volumeMute;
236 private boolean isMute=false;
237 private TextView volumnTv;
238 public MediaRouteButton mediaRouteButton;
239 private CastContext castContext;
240
241 public static boolean isPlaying, isFullScr;
242 public static View playerLayout;
243
244 private int playerHeight;
245 public static boolean isVideo = true;
246 private FirebaseAnalytics mFirebaseAnalytics;
247 private String strSubtitle = "Null";
248 public static MediaSource mediaSource = null;
249 public static ImageView imgSubtitle;
250 public ImageView radioPlayImage;
251 private List<SubtitleModel> listSub = new ArrayList<>();
252 private AlertDialog alertDialog;
253 private String mediaUrl;
254 private boolean tv = false;
255 private String download_check = "";
256
257 private String season;
258 private String episod;
259 private String movieTitle;
260 private String seriesTitle;
261
262 private CastPlayer castPlayer;
263 private boolean castSession;
264 private String title;
265 String castImageUrl;
266
267 private LinearLayout tvLayout, sheduleLayout, tvTopLayout;
268 private TextView tvTitleTv, watchStatusTv, timeTv, programTv, proGuideTv, watchLiveTv;
269 private ProgramAdapter programAdapter;
270 List<Program> programs = new ArrayList<>();
271 private RecyclerView programRv;
272 private ImageView tvThumbIv, shareIv;
273 ///my var Ly
274 private LinearLayout exoRewind, exoForward, seekbarLayout,btnCast,btnCloseCast;
275 private SeekBar seekBrightnessControl;
276 private int brightness;
277 private ContentResolver cResolver;
278 private Window window;
279 private CustomViewTouch lyControlGestureLeft;
280 GestureDetector mDetector;
281 List<ResolveInfo> playerList;//
282 ImageView btnlockUi,btnUnlockUi;
283 TextView txtRwd, txtFwd,txtMovieTitle;
284 LinearLayout lyTouchControl2;
285 String selectedUrl="";
286 private static String PREFER_NAME="history_pelis";
287 private PackageManager manager;
288 private List<AppDetail> apps;
289 private ListView list;
290
291
292 //my vars end
293
294
295 ImageView exoDownloadIv;
296 private TextView liveTv;
297
298
299 boolean isDark;
300 private OrientationEventListener myOrientationEventListener;
301 private String serverType;
302
303 private boolean fullScreenByClick;
304 private String currentProgramTime;
305 private String currentProgramTitle;
306 private String userId;
307
308 private String youtubeDownloadUr;
309 private String urlType = "";
310 private RelativeLayout descriptionLayout;
311 private MaterialRippleLayout descriptionContatainer;
312 private TextView dGenryTv;
313 private RecyclerView internalServerRv, externalServerRv, serverRv;
314 private LinearLayout internalDownloadLayout, externalDownloadLayout;
315 private boolean activeMovie;
316
317 private TextView sereisTitleTv;
318 private RelativeLayout seriestLayout;
319 private ImageView favIv;
320
321 private RelativeLayout mRlTouch;
322 private boolean intLeft, intRight;
323 private int sWidth, sHeight;
324 private long diffX, diffY;
325 private Display display;
326 private Point size;
327 private float downX, downY;
328 private AudioManager mAudioManager;
329 private int aspectClickCount = 1;
330
331 private DatabaseHelper db;
332
333 //------------------
334
335 //------------------
336 @Override
337 protected void onCreate(Bundle savedInstanceState) {
338 RtlUtils.setScreenDirection(this);
339 SharedPreferences sharedPreferences = getSharedPreferences("push", MODE_PRIVATE);
340 isDark = sharedPreferences.getBoolean("dark", false);
341 if (isDark) {
342 setTheme(R.style.AppThemeDark);
343 } else {
344 setTheme(R.style.AppThemeLight);
345 }
346 super.onCreate(savedInstanceState);
347 setContentView(R.layout.activity_details);
348
349 db = new DatabaseHelper(DetailsActivity.this);
350
351 mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
352
353 //---analytics-----------
354 mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
355 Bundle bundle = new Bundle();
356 bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "id");
357 bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "details_activity");
358 bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "activity");
359 mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
360
361 adView = findViewById(R.id.adView);
362 llBottom = findViewById(R.id.llbottom);
363 tvDes = findViewById(R.id.tv_details);
364 tvCast = findViewById(R.id.tv_cast);
365 tvRelease = findViewById(R.id.tv_release_date);
366 tvName = findViewById(R.id.text_name);
367 tvDirector = findViewById(R.id.tv_director);
368 tvGenre = findViewById(R.id.tv_genre);
369 swipeRefreshLayout = findViewById(R.id.swipe_layout);
370 imgAddFav = findViewById(R.id.add_fav);
371 imgBack = findViewById(R.id.img_back);
372 radioPlayImage = findViewById(R.id.radioPlayImage);
373 webView = findViewById(R.id.webView);
374 progressBar = findViewById(R.id.progressBar);
375 llBottomParent = findViewById(R.id.llbottomparent);
376 lPlay = findViewById(R.id.play);
377 rvRelated = findViewById(R.id.rv_related);
378 tvRelated = findViewById(R.id.tv_related);
379 shimmerFrameLayout = findViewById(R.id.shimmer_view_container);
380 btnComment = findViewById(R.id.btn_comment);
381 etComment = findViewById(R.id.et_comment);
382 rvComment = findViewById(R.id.recyclerView_comment);
383 llcomment = findViewById(R.id.llcomments);
384 simpleExoPlayerView = findViewById(R.id.video_view);
385 subtitleView = findViewById(R.id.subtitle);
386 playerLayout = findViewById(R.id.player_layout);
387 imgFull = findViewById(R.id.img_full_scr);
388 aspectRatioIv = findViewById(R.id.aspect_ratio_iv);
389 externalPlayerIv = findViewById(R.id.external_player_iv);
390 volumControlIv = findViewById(R.id.volumn_control_iv);
391 volumnControlLayout = findViewById(R.id.volumn_layout);
392 volumeMute=(ImageView) findViewById(R.id.volumn_icon);
393 volumnSeekbar = findViewById(R.id.volumn_seekbar);
394 volumnTv = findViewById(R.id.volumn_tv);
395 rvServer = findViewById(R.id.rv_server_list);
396 seasonSpinner = findViewById(R.id.season_spinner);
397 seasonSpinnerContainer = findViewById(R.id.spinner_container);
398 imgSubtitle = findViewById(R.id.img_subtitle);
399 mediaRouteButton = findViewById(R.id.media_route_button);
400 chromeCastTv = findViewById(R.id.chrome_cast_tv);
401 castControlView = findViewById(R.id.cast_control_view);
402 tvLayout = findViewById(R.id.tv_layout);
403 sheduleLayout = findViewById(R.id.p_shedule_layout);
404 tvTitleTv = findViewById(R.id.tv_title_tv);
405 programRv = findViewById(R.id.program_guide_rv);
406 tvTopLayout = findViewById(R.id.tv_top_layout);
407 tvThumbIv = findViewById(R.id.tv_thumb_iv);
408 shareIv = findViewById(R.id.share_iv);
409 watchStatusTv = findViewById(R.id.watch_status_tv);
410 timeTv = findViewById(R.id.time_tv);
411 programTv = findViewById(R.id.program_type_tv);
412 exoRewind = findViewById(R.id.rewind_layout);
413 exoForward = findViewById(R.id.forward_layout);
414 seekbarLayout = findViewById(R.id.seekbar_layout);
415 liveTv = findViewById(R.id.live_tv);
416 castRv = findViewById(R.id.cast_rv);
417 proGuideTv = findViewById(R.id.pro_guide_tv);
418 watchLiveTv = findViewById(R.id.watch_live_tv);
419
420 contentDetails = findViewById(R.id.content_details);
421 subscriptionLayout = findViewById(R.id.subscribe_layout);
422 subscribeBt = findViewById(R.id.subscribe_bt);
423 backIv = findViewById(R.id.des_back_iv);
424 subBackIv = findViewById(R.id.back_iv);
425 topbarLayout = findViewById(R.id.topbar);
426
427 descriptionLayout = findViewById(R.id.description_layout);
428 descriptionContatainer = findViewById(R.id.lyt_parent);
429 watchNowBt = findViewById(R.id.watch_now_bt);
430 downloadBt = findViewById(R.id.download_bt);
431 posterIv = findViewById(R.id.poster_iv);
432 thumbIv = findViewById(R.id.image_thumb);
433 descriptionBackIv = findViewById(R.id.back_iv);
434 dGenryTv = findViewById(R.id.genre_tv);
435 serverIv = findViewById(R.id.img_server);
436
437 seriestLayout = findViewById(R.id.series_layout);
438 favIv = findViewById(R.id.add_fav2);
439 sereisTitleTv = findViewById(R.id.seriest_title_tv);
440 shareIv2 = findViewById(R.id.share_iv2);
441
442 //mi codigo **********************************************
443
444 btnCast=(LinearLayout)findViewById(R.id.exo_cast);
445 btnCloseCast=(LinearLayout)findViewById(R.id.exocast_close);
446 seekBrightnessControl=(SeekBar)findViewById(R.id.exo_brigness);
447 lyControlGestureLeft =(CustomViewTouch)findViewById(R.id.exo_lytouchcontrol);
448 lyTouchControl2=(LinearLayout)findViewById(R.id.exo_lytouchcontrol2);
449 txtFwd=(TextView)findViewById(R.id.exo_settimeRigth);
450 txtRwd=(TextView)findViewById(R.id.exo_settimeleft);
451 txtMovieTitle=(TextView)findViewById(R.id.exo_movietitle);
452 btnlockUi=(ImageView)findViewById(R.id.exo_lockui);
453 btnUnlockUi=(ImageView)findViewById(R.id.exo_unlockui);
454
455 cResolver = getContentResolver();
456 window = getWindow();
457 seekBrightnessControl.setMax(255);
458 seekBrightnessControl.setKeyProgressIncrement(1);
459
460
461 btnlockUi.setOnClickListener(new View.OnClickListener() {
462 @Override
463 public void onClick(View v) {
464 btnUnlockUi.setVisibility(VISIBLE);
465 simpleExoPlayerView.setUseController(false);
466 v.setVisibility(GONE);
467 }
468 });
469 btnUnlockUi.setOnClickListener(new View.OnClickListener() {
470 @Override
471 public void onClick(View v) {
472 btnlockUi.setVisibility(VISIBLE);
473 simpleExoPlayerView.setUseController(true);
474 v.setVisibility(GONE);
475 }
476 });
477 btnCloseCast.setOnClickListener(new View.OnClickListener() {
478 @Override
479 public void onClick(View v) {
480
481 }
482 });
483 btnCast.setOnClickListener(new View.OnClickListener() {
484 @Override
485 public void onClick(View v) {
486 //action chromecast buttom
487 Log.i("juacosoft","Click in cast buttom");
488 //onCastSessionAvailable();
489 //playNextCast(getMediaInfo());
490 }
491 });
492
493 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
494 if (Settings.System.canWrite(this)) {
495 // Do stuff here
496 Log.i("juacosoft","permiso concedido");
497 brightness =
498 Settings.System.getInt(cResolver,
499 Settings.System.SCREEN_BRIGHTNESS, 0);
500 seekBrightnessControl.setProgress(brightness);
501 }
502 else {
503 Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
504 intent.setData(Uri.parse("package:" + this.getPackageName()));
505 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
506 startActivity(intent);
507 }
508 }
509
510 mAudioManager.registerMediaButtonEventReceiver(
511 new ComponentName(getPackageName(), AudioReciever.class.getName())
512 );
513 seekBrightnessControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
514 @Override
515 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
516 Settings.System.putInt(cResolver,
517 Settings.System.SCREEN_BRIGHTNESS, progress);
518 Log.i("juacosoft","progress"+progress);
519 }
520
521 @Override
522 public void onStartTrackingTouch(SeekBar seekBar) {
523
524 }
525
526 @Override
527 public void onStopTrackingTouch(SeekBar seekBar) {
528
529 }
530 });
531
532 lyTouchControl2.setOnTouchListener(touchListener);
533
534 //fin mi codigo
535 if (isDark) {
536 tvTopLayout.setBackgroundColor(getResources().getColor(R.color.black_window_light));
537 sheduleLayout.setBackground(getResources().getDrawable(R.drawable.rounded_black_transparent));
538 etComment.setBackground(getResources().getDrawable(R.drawable.round_grey_transparent));
539 btnComment.setTextColor(getResources().getColor(R.color.grey_20));
540 topbarLayout.setBackgroundColor(getResources().getColor(R.color.dark));
541 subscribeBt.setBackground(getResources().getDrawable(R.drawable.btn_rounded_dark));
542
543 descriptionContatainer.setBackground(getResources().getDrawable(R.drawable.gradient_black_transparent));
544 }
545 // chrome cast
546 CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton);
547 castContext = CastContext.getSharedInstance(this);
548 castPlayer = new CastPlayer(castContext);
549 castPlayer.setSessionAvailabilityListener(this);
550
551 // cast button will show if the cast device will be available
552 if (castContext.getCastState() != CastState.NO_DEVICES_AVAILABLE)
553 mediaRouteButton.setVisibility(View.VISIBLE);
554 // start the shimmer effect
555 shimmerFrameLayout.startShimmer();
556 playerHeight = lPlay.getLayoutParams().height;
557 progressBar.setMax(100); // 100 maximum value for the progress value
558 progressBar.setProgress(50);
559
560 WebSettings webSettings = webView.getSettings();
561 webSettings.setJavaScriptEnabled(true);
562 webView.setWebChromeClient(new WebChromeClient());
563
564 imgBack.setOnClickListener(new View.OnClickListener() {
565 @Override
566 public void onClick(View v) {
567 if (activeMovie) {
568 setPlayerNormalScreen();
569 if (player != null){
570
571 SharedPreferences pref=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
572 SharedPreferences.Editor editor=pref.edit();
573 editor.putLong(mediaUrl,player.getCurrentPosition());
574 editor.apply();
575
576
577 player.setPlayWhenReady(false);
578 player.stop();
579 }
580 showDescriptionLayout();
581 activeMovie = false;
582 } else {
583 finish();
584 }
585 }
586 });
587
588
589 type = getIntent().getStringExtra("vType");
590 id = getIntent().getStringExtra("id");
591 castSession = getIntent().getBooleanExtra("castSession", false);
592
593 // getting user login info for favourite button visibility
594 userId = db.getUserData().getUserId();
595 if (PreferenceUtils.isLoggedIn(DetailsActivity.this)) {
596 imgAddFav.setVisibility(VISIBLE);
597 } else {
598 imgAddFav.setVisibility(GONE);
599 }
600
601 commentsAdapter = new CommentsAdapter(this, listComment);
602 rvComment.setLayoutManager(new LinearLayoutManager(this));
603 rvComment.setHasFixedSize(true);
604 rvComment.setNestedScrollingEnabled(false);
605 rvComment.setAdapter(commentsAdapter);
606 getComments();
607 imgFull.setOnClickListener(new View.OnClickListener() {
608 @Override
609 public void onClick(View v) {
610
611 controlFullScreenPlayer();
612
613 }
614 });
615 imgSubtitle.setOnClickListener(new View.OnClickListener() {
616 @Override
617 public void onClick(View v) {
618 showSubtitleDialog(DetailsActivity.this, listSub);
619 }
620 });
621 btnComment.setOnClickListener(new View.OnClickListener() {
622 @Override
623 public void onClick(View v) {
624 if (!PreferenceUtils.isLoggedIn(DetailsActivity.this)) {
625 startActivity(new Intent(DetailsActivity.this, LoginActivity.class));
626 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.login_first));
627 } else if (etComment.getText().toString().equals("")) {
628 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.comment_empty));
629 } else {
630 String comment = etComment.getText().toString();
631 addComment( id, PreferenceUtils.getUserId(DetailsActivity.this), comment);
632 }
633 }
634 });
635
636 imgAddFav.setOnClickListener(new View.OnClickListener() {
637 @Override
638 public void onClick(View v) {
639 if (isFav) {
640 removeFromFav();
641 } else {
642 addToFav();
643 }
644 }
645 });
646
647 // its for tv series only when description layout visibility gone.
648 favIv.setOnClickListener(new View.OnClickListener() {
649 @Override
650 public void onClick(View v) {
651 if (isFav) {
652 removeFromFav();
653 } else {
654 addToFav();
655 }
656 }
657 });
658
659
660 if (!isNetworkAvailable()) {
661 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.no_internet));
662 }
663 swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
664 @Override
665 public void onRefresh() {
666 clear_previous();
667 initGetData();
668 }
669 });
670
671 loadAd();
672 }
673 //*********************************************
674 View.OnTouchListener touchListener = new View.OnTouchListener() {
675 @Override
676 public boolean onTouch(View v, MotionEvent event) {
677
678 //playerLayout.callOnClick();
679 Log.i("juacosoft","this event" + event.toString());
680 return mDetector.onTouchEvent(event);
681
682 }
683 };
684
685
686
687
688 //*******************************************
689 @SuppressLint("SourceLockedOrientationActivity")
690 public void controlFullScreenPlayer() {
691 if (isFullScr) {
692 fullScreenByClick = false;
693 isFullScr = false;
694 swipeRefreshLayout.setVisibility(VISIBLE);
695 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
696 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
697
698 if (isVideo) {
699 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, playerHeight));
700 } else {
701 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, playerHeight));
702 }
703
704 // reset the orientation
705 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
706
707 } else {
708
709 fullScreenByClick = true;
710 isFullScr = true;
711 swipeRefreshLayout.setVisibility(GONE);
712 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
713 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
714
715 if (isVideo) {
716 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
717
718 } else {
719 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
720
721 }
722
723 // reset the orientation
724 //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
725 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
726
727 }
728 }//***********************************************************************
729 public class AudioReciever extends BroadcastReceiver{
730
731 @Override
732 public void onReceive(Context context, Intent intent) {
733 Log.i("juacosoft",""+intent.getAction());
734 if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
735 KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
736 if (KeyEvent.KEYCODE_MEDIA_PLAY == event.getKeyCode()) {
737 // Handle key press.
738
739 int currentVolum=mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
740 volumnSeekbar.setProgress(currentVolum);
741
742 }
743 }
744 }
745 }
746
747
748 @Override
749 protected void onStart() {
750 super.onStart();
751
752 if (!Config.ENABLE_EXTERNAL_PLAYER){
753 externalPlayerIv.setVisibility(GONE);
754 }
755 externalPlayerIv.setVisibility(VISIBLE);
756 initGetData();
757 setVolumeControlStream(AudioManager.STREAM_MUSIC);//*************
758 if (mAudioManager != null) {
759 volumnSeekbar.setMax(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
760 int currentVolumn = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
761 volumnSeekbar.setProgress(currentVolumn);
762 }
763 volumeMute.setOnClickListener(new View.OnClickListener() {
764 @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
765 @Override
766 public void onClick(View v) {
767 if(!isMute) {
768 volumeMute.setImageResource(R.drawable.ic_volume_mute_white);
769 //volumeMute.setImageDrawable(getDrawable(R.drawable.ic_volume_mute_white) );
770 mAudioManager.setStreamMute(player.getAudioStreamType(),true);
771 isMute=true;
772
773 }else{
774 volumeMute.setImageResource(R.drawable.ic_volume_up_white);
775 //volumeMute.setImageDrawable(getDrawable(R.drawable.ic_volume_up_white));
776 mAudioManager.setStreamMute(player.getAudioStreamType(),false);
777 isMute=false;
778 }
779 }
780 });
781
782 volumnSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
783 @Override
784 public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
785 if (b) {
786 //volumnTv.setText(i+"");
787 if (i == 0) {
788 volumeMute.setImageResource(R.drawable.ic_volume_mute_white);
789 }else{
790 volumeMute.setImageResource(R.drawable.ic_volume_up_white);
791 }
792
793 mAudioManager.setStreamVolume(player.getAudioStreamType(), i, 0);
794 }
795 }
796
797 @Override
798 public void onStartTrackingTouch(SeekBar seekBar) {
799
800 }
801
802 @Override
803 public void onStopTrackingTouch(SeekBar seekBar) {
804
805 }
806 });
807
808 volumControlIv.setOnClickListener(new View.OnClickListener() {
809 @Override
810 public void onClick(View view) {
811
812 //volumnControlLayout.setVisibility(VISIBLE);
813
814 }
815 });
816
817 aspectRatioIv.setOnClickListener(new View.OnClickListener() {
818 @Override
819 public void onClick(View view) {
820 if (aspectClickCount == 1) {
821 //Toast.makeText(DetailsActivity.this, "Fill", Toast.LENGTH_SHORT).show();
822 simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
823 player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
824 aspectClickCount = 2;
825 } else if (aspectClickCount == 2) {
826 //Toast.makeText(DetailsActivity.this, "Fit", Toast.LENGTH_SHORT).show();
827 simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
828 player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
829 aspectClickCount = 3;
830 } else if (aspectClickCount == 3) {
831 //Toast.makeText(DetailsActivity.this, "Zoom", Toast.LENGTH_SHORT).show();
832 simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
833 player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
834 aspectClickCount = 1;
835 }
836
837 }
838 });
839
840 externalPlayerIv.setOnClickListener(new View.OnClickListener() {
841 @Override
842 public void onClick(View view) {
843
844 if (mediaUrl != null) {
845 if (!tv) {
846 // set player normal/ potrait screen if not tv
847 descriptionLayout.setVisibility(VISIBLE);
848 setPlayerNormalScreen();
849 }
850//**********************************************************
851
852 manager = getPackageManager();
853 apps = new ArrayList<AppDetail>();
854
855 final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
856 DetailsActivity.this, R.style.BottomSheetDialogTheme
857 );
858 View bottomSheetView = LayoutInflater.from(getApplicationContext())
859 .inflate(
860 R.layout.bottom_sheet,
861 (LinearLayout) findViewById(R.id.bottom_sheet_container)
862 );
863
864 list=bottomSheetView.findViewById(R.id.apps_list);
865 Intent i = new Intent(Intent.ACTION_VIEW, null);
866 //i.setType("video/*");
867 i.setDataAndType(Uri.parse(mediaUrl), "video/*");
868 //i.addCategory(Intent.CATEGORY_);
869
870 List<ResolveInfo> availableActivities = manager.queryIntentActivities(i, 0);
871 for(ResolveInfo ri:availableActivities){
872 AppDetail app = new AppDetail();
873 app.label = ri.loadLabel(manager);
874 app.name = ri.activityInfo.packageName;
875 app.icon = ri.activityInfo.loadIcon(manager);
876 apps.add(app);
877 }
878
879 ArrayAdapter<AppDetail> adapter = new ArrayAdapter<AppDetail>(getApplicationContext(),
880 R.layout.list_item,
881 apps) {
882 @Override
883 public View getView(int position, View convertView, ViewGroup parent) {
884 if(convertView == null){
885 convertView = getLayoutInflater().inflate(R.layout.list_item, null);
886 }
887
888 ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon);
889 appIcon.setImageDrawable(apps.get(position).icon);
890
891 TextView appLabel = (TextView)convertView.findViewById(R.id.item_app_label);
892 appLabel.setText(apps.get(position).label);
893
894 TextView appName = (TextView)convertView.findViewById(R.id.item_app_name);
895 if(apps.get(position).name.equals("com.mxtech.videoplayer.ad")){
896 String addRecomended=apps.get(position).label+" (Recomendado)";
897 appLabel.setText(addRecomended);
898 appName.setVisibility(VISIBLE);
899 }
900 appName.setText(apps.get(position).name);
901
902 return convertView;
903 }
904 };
905
906 list.setAdapter(adapter);
907
908 list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
909 @Override
910 public void onItemClick(AdapterView<?> av, View v, int pos,
911 long id) {
912 Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());
913
914
915 //i.setData(Uri.parse(mediaUrl));
916 Log.i("juacosoft",mediaUrl);
917 //DetailsActivity.this.startActivity(i);
918 Intent intent=new Intent(Intent.ACTION_VIEW);
919 intent.setPackage(apps.get(pos).name.toString());
920 intent.setDataAndType(Uri.parse(mediaUrl),"video/*");
921 startActivity(intent);
922
923 }
924 });
925 bottomSheetView.findViewById(R.id.bs_lyclose).setOnClickListener(new View.OnClickListener() {
926 @Override
927 public void onClick(View v) {
928 bottomSheetDialog.dismiss();
929 }
930 });
931
932
933
934 bottomSheetDialog.setContentView(bottomSheetView);
935 bottomSheetDialog.show();
936
937
938//*********************************************************************************
939
940 //Intent intent = new Intent(Intent.ACTION_VIEW);
941 //intent.setDataAndType(Uri.parse(mediaUrl), "video/*");
942 //startActivity(Intent.createChooser(intent, "Complete action using"));
943 releasePlayer();
944 resetCastPlayer();
945 }
946
947 }
948 });
949
950 watchNowBt.setOnClickListener(new View.OnClickListener() {
951 @Override
952 public void onClick(View v) {
953 if (!listServer.isEmpty()) {
954 if (listServer.size() == 1) {
955 releasePlayer();
956 resetCastPlayer();
957 preparePlayer(listServer.get(0));
958 descriptionLayout.setVisibility(GONE);
959 lPlay.setVisibility(VISIBLE);
960 }else {
961 openServerDialog();
962 }
963 }else{
964 Toast.makeText(DetailsActivity.this, R.string.no_video_found, Toast.LENGTH_SHORT).show();
965 }
966 }
967 });
968
969 downloadBt.setOnClickListener(new View.OnClickListener() {
970 @Override
971 public void onClick(View v) {
972 if (!listInternalDownload.isEmpty() || !listExternalDownload.isEmpty()) {
973 if (Config.ENABLE_DOWNLOAD_TO_ALL) {
974 openDownloadServerDialog();
975 } else {
976 if (PreferenceUtils.isLoggedIn(DetailsActivity.this) && PreferenceUtils.isActivePlan(DetailsActivity.this)) {
977 openDownloadServerDialog();
978 } else {
979 Toast.makeText(DetailsActivity.this, R.string.download_not_permitted, Toast.LENGTH_SHORT).show();
980 Log.e("Download", "not permitted");
981 }
982 }
983 } else {
984 Toast.makeText(DetailsActivity.this, R.string.no_download_server_found, Toast.LENGTH_SHORT).show();
985 }
986 }
987 });
988
989 watchLiveTv.setOnClickListener(new View.OnClickListener() {
990 @Override
991 public void onClick(View v) {
992 hideExoControlForTv();
993 initMoviePlayer(mediaUrl, serverType, DetailsActivity.this);
994
995 watchStatusTv.setText(getString(R.string.watching_on) + " " + getString(R.string.app_name));
996 watchLiveTv.setVisibility(GONE);
997
998 timeTv.setText(currentProgramTime);
999 programTv.setText(currentProgramTitle);
1000 }
1001 });
1002
1003 shareIv.setOnClickListener(new View.OnClickListener() {
1004 @Override
1005 public void onClick(View v) {
1006 Tools.share(DetailsActivity.this, title);
1007 }
1008 });
1009
1010 shareIv2.setOnClickListener(new View.OnClickListener() {
1011 @Override
1012 public void onClick(View v) {
1013 if (title == null) {
1014 new ToastMsg(DetailsActivity.this).toastIconError("Title should not be empty.");
1015 return;
1016 }
1017 Tools.share(DetailsActivity.this, title);
1018 }
1019 });
1020
1021 castPlayer.addListener(new Player.DefaultEventListener() {
1022 @Override
1023 public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
1024
1025 if (playWhenReady && playbackState == CastPlayer.STATE_READY) {
1026 progressBar.setVisibility(View.GONE);
1027
1028 Log.e("STATE PLAYER:::", String.valueOf(isPlaying));
1029
1030 } else if (playbackState == CastPlayer.STATE_READY) {
1031 progressBar.setVisibility(View.GONE);
1032 Log.e("STATE PLAYER:::", String.valueOf(isPlaying));
1033 } else if (playbackState == CastPlayer.STATE_BUFFERING) {
1034 progressBar.setVisibility(VISIBLE);
1035
1036 Log.e("STATE PLAYER:::", String.valueOf(isPlaying));
1037 } else {
1038 Log.e("STATE PLAYER:::", String.valueOf(isPlaying));
1039 }
1040
1041 }
1042 });
1043
1044 serverIv.setOnClickListener(new View.OnClickListener() {
1045 @Override
1046 public void onClick(View v) {
1047 openServerDialog();
1048 }
1049 });
1050
1051 simpleExoPlayerView.setControllerVisibilityListener(new PlayerControlView.VisibilityListener() {
1052 @Override
1053 public void onVisibilityChange(int visibility) {
1054
1055 if (visibility == 0) {
1056 imgBack.setVisibility(VISIBLE);
1057 int currentVolum=mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
1058 Log.i("juacosoft","visible: "+currentVolum);//mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
1059
1060 volumnSeekbar.setProgress(currentVolum);
1061
1062
1063 if(currentVolum==0){
1064 volumeMute.setImageResource(R.drawable.ic_volume_mute_white);
1065 }else{
1066 volumeMute.setImageResource(R.drawable.ic_volume_up_white);
1067 }
1068
1069 if (type.equals("tv") || type.equals("tvseries")) {
1070 imgFull.setVisibility(VISIBLE);
1071 } else {
1072 imgFull.setVisibility(GONE);
1073 }
1074
1075 // invisible download icon for live tv
1076 if (download_check.equals("1")) {
1077 if (!tv) {
1078 if (activeMovie) {
1079 serverIv.setVisibility(VISIBLE);
1080 }
1081 } else {
1082 }
1083 } else {
1084 }
1085
1086 if (listSub.size() != 0) {
1087 imgSubtitle.setVisibility(VISIBLE);
1088 }
1089 //imgSubtitle.setVisibility(VISIBLE);
1090 } else {
1091 imgBack.setVisibility(GONE);
1092 imgFull.setVisibility(GONE);
1093 imgSubtitle.setVisibility(GONE);
1094 //volumnControlLayout.setVisibility(GONE);
1095 }
1096 }
1097 });
1098
1099 subscribeBt.setOnClickListener(new View.OnClickListener() {
1100 @Override
1101 public void onClick(View v) {
1102
1103 if (userId == null) {
1104 new ToastMsg(DetailsActivity.this).toastIconError(getResources().getString(R.string.subscribe_error));
1105 startActivity(new Intent(DetailsActivity.this, LoginActivity.class));
1106 finish();
1107 } else {
1108 startActivity(new Intent(DetailsActivity.this, PurchasePlanActivity.class));
1109 }
1110
1111 }
1112 });
1113 backIv.setOnClickListener(new View.OnClickListener() {
1114 @Override
1115 public void onClick(View v) {
1116 finish();
1117 }
1118 });
1119
1120 subBackIv.setOnClickListener(new View.OnClickListener() {
1121 @Override
1122 public void onClick(View v) {
1123 finish();
1124 }
1125 });
1126
1127 }
1128
1129 @SuppressLint("SourceLockedOrientationActivity")
1130 public void setPlayerNormalScreen() {
1131 swipeRefreshLayout.setVisibility(VISIBLE);
1132 lPlay.setVisibility(GONE);
1133 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
1134 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
1135 //close embed link playing
1136 if (webView.getVisibility() == VISIBLE){
1137 if (webView != null){
1138 Intent intent = new Intent(DetailsActivity.this, DetailsActivity.class);
1139 intent.putExtra("vType",type);
1140 intent.putExtra("id",id);
1141 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
1142 startActivity(intent);
1143 }
1144 }
1145
1146 if (isVideo) {
1147 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, playerHeight));
1148
1149 } else {
1150 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, playerHeight));
1151 }
1152 }
1153
1154 @SuppressLint("SourceLockedOrientationActivity")
1155 public void setPlayerFullScreen() {
1156 swipeRefreshLayout.setVisibility(GONE);
1157 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
1158 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
1159
1160 if (isVideo) {
1161 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
1162 } else {
1163 lPlay.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
1164 }
1165 }
1166
1167 private void openDownloadServerDialog() {
1168 AlertDialog.Builder builder = new AlertDialog.Builder(this);
1169 View view = LayoutInflater.from(this).inflate(R.layout.layout_download_server_dialog, null);
1170 internalDownloadLayout = view.findViewById(R.id.internal_download_layout);
1171 externalDownloadLayout = view.findViewById(R.id.external_download_layout);
1172 if (listExternalDownload.isEmpty()) {
1173 externalDownloadLayout.setVisibility(GONE);
1174 }
1175 if (listInternalDownload.isEmpty()) {
1176 internalDownloadLayout.setVisibility(GONE);
1177 }
1178 internalServerRv = view.findViewById(R.id.internal_download_rv);
1179 externalServerRv = view.findViewById(R.id.external_download_rv);
1180 internalDownloadAdapter = new DownloadAdapter(this, listInternalDownload, true);
1181 internalServerRv.setLayoutManager(new LinearLayoutManager(this));
1182 internalServerRv.setHasFixedSize(true);
1183 internalServerRv.setAdapter(internalDownloadAdapter);
1184
1185 externalDownloadAdapter = new DownloadAdapter(this, listExternalDownload, true);
1186 externalServerRv.setLayoutManager(new LinearLayoutManager(this));
1187 externalServerRv.setHasFixedSize(true);
1188 externalServerRv.setAdapter(externalDownloadAdapter);
1189
1190 builder.setView(view);
1191
1192 final AlertDialog dialog = builder.create();
1193 dialog.show();
1194 }
1195
1196 private void openServerDialog() {
1197 AlertDialog.Builder builder = new AlertDialog.Builder(this);
1198 View view = LayoutInflater.from(this).inflate(R.layout.layout_server_dialog, null);
1199 serverRv = view.findViewById(R.id.serverRv);
1200 serverAdapter = new ServerAdapter(this, listServer, "movie");
1201 serverRv.setLayoutManager(new LinearLayoutManager(this));
1202 serverRv.setHasFixedSize(true);
1203 serverRv.setAdapter(serverAdapter);
1204
1205 ImageView closeIv = view.findViewById(R.id.close_iv);
1206 builder.setView(view);
1207
1208 final AlertDialog dialog = builder.create();
1209 dialog.show();
1210
1211 closeIv.setOnClickListener(new View.OnClickListener() {
1212 @Override
1213 public void onClick(View v) {
1214 dialog.dismiss();
1215 }
1216 });
1217
1218 final ServerAdapter.OriginalViewHolder[] viewHolder = {null};
1219 serverAdapter.setOnItemClickListener(new ServerAdapter.OnItemClickListener() {
1220 @Override
1221 public void onItemClick(View view, CommonModels obj, int position, ServerAdapter.OriginalViewHolder holder) {
1222 releasePlayer();
1223 resetCastPlayer();
1224 preparePlayer(obj);
1225
1226 //serverAdapter.chanColor(viewHolder[0], position);
1227 //holder.name.setTextColor(getResources().getColor(R.color.colorPrimary));
1228 //viewHolder[0] = holder;
1229 }
1230
1231 @Override
1232 public void getFirstUrl(String url) {
1233 mediaUrl = url;
1234 }
1235
1236 @Override
1237 public void hideDescriptionLayout() {
1238 descriptionLayout.setVisibility(GONE);
1239 lPlay.setVisibility(VISIBLE);
1240 dialog.dismiss();
1241
1242 }
1243 });
1244
1245 }
1246
1247 public void preparePlayer(CommonModels obj){
1248 activeMovie = true;
1249 setPlayerFullScreen();
1250 mediaUrl = obj.getStremURL();
1251 Log.i("juacosoft",obj.getStremURL());
1252 if (!castSession) {
1253 initMoviePlayer(obj.getStremURL(), obj.getServerType(), DetailsActivity.this);
1254
1255 listSub.clear();
1256 if (obj.getListSub() != null) {
1257 listSub.addAll(obj.getListSub());
1258 }
1259
1260 if (listSub.size() != 0) {
1261 imgSubtitle.setVisibility(VISIBLE);
1262 }else {
1263 imgSubtitle.setVisibility(GONE);
1264 }
1265
1266 } else {
1267 if (obj.getServerType().toLowerCase().equals("embed")) {
1268
1269 castSession = false;
1270 castPlayer.setSessionAvailabilityListener(null);
1271 castPlayer.release();
1272
1273 // invisible control ui of exoplayer
1274 player.setPlayWhenReady(true);
1275 simpleExoPlayerView.setUseController(true);
1276
1277 // invisible control ui of casting
1278 castControlView.setVisibility(GONE);
1279 chromeCastTv.setVisibility(GONE);
1280
1281
1282 } else {
1283 showQueuePopup(DetailsActivity.this, null, getMediaInfo());
1284 }
1285 }
1286 }
1287
1288 void clear_previous() {
1289
1290 strCast = "";
1291 strDirector = "";
1292 strGenre = "";
1293 listDownload.clear();
1294 listInternalDownload.clear();
1295 listExternalDownload.clear();
1296 programs.clear();
1297 castCrews.clear();
1298 }
1299
1300 private void prepareSubtitleList(Context context, List<SubtitleModel> list){
1301
1302 }
1303
1304
1305 public void showSubtitleDialog(Context context, List<SubtitleModel> list) {
1306 ViewGroup viewGroup = findViewById(android.R.id.content);
1307 View dialogView = LayoutInflater.from(this).inflate(R.layout.custom_dialog_subtitle, viewGroup, false);
1308 ImageView cancel = dialogView.findViewById(R.id.cancel);
1309
1310 RecyclerView recyclerView = dialogView.findViewById(R.id.recyclerView);
1311 SubtitleAdapter adapter = new SubtitleAdapter(context, list);
1312 recyclerView.setLayoutManager(new LinearLayoutManager(this));
1313 recyclerView.setAdapter(adapter);
1314
1315 AlertDialog.Builder builder = new AlertDialog.Builder(this);
1316 builder.setView(dialogView);
1317
1318 alertDialog = builder.create();
1319 alertDialog.show();
1320
1321 cancel.setOnClickListener(new View.OnClickListener() {
1322 @Override
1323 public void onClick(View v) {
1324 alertDialog.cancel();
1325 }
1326 });
1327
1328 }
1329
1330 @Override
1331 public void onCastSessionAvailable() {
1332 castSession = true;
1333
1334 MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
1335 movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
1336 //movieMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, "Test Artist");
1337 movieMetadata.addImage(new WebImage(Uri.parse(castImageUrl)));
1338 MediaInfo mediaInfo = new MediaInfo.Builder(mediaUrl)
1339 .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
1340 .setContentType(MimeTypes.VIDEO_UNKNOWN)
1341 .setMetadata(movieMetadata).build();
1342
1343 //array of media sources
1344 final MediaQueueItem[] mediaItems = {new MediaQueueItem.Builder(mediaInfo).build()};
1345
1346 castPlayer.loadItems(mediaItems, 0, 3000, Player.REPEAT_MODE_OFF);
1347
1348 // visible control ui of casting
1349 castControlView.setVisibility(VISIBLE);
1350 castControlView.setPlayer(castPlayer);
1351
1352 castControlView.setVisibilityListener(new PlaybackControlView.VisibilityListener() {
1353 @Override
1354 public void onVisibilityChange(int visibility) {
1355 if (visibility == GONE) {
1356
1357 castControlView.setVisibility(VISIBLE);
1358 chromeCastTv.setVisibility(VISIBLE);
1359 }
1360 }
1361 });
1362
1363 // invisible control ui of exoplayer
1364 player.setPlayWhenReady(false);
1365 simpleExoPlayerView.setUseController(false);
1366 }
1367
1368 @Override
1369 public void onCastSessionUnavailable() {
1370 // make cast session false
1371 castSession = false;
1372 // invisible control ui of exoplayer
1373 player.setPlayWhenReady(true);
1374 simpleExoPlayerView.setUseController(true);
1375
1376 // invisible control ui of casting
1377 castControlView.setVisibility(GONE);
1378 chromeCastTv.setVisibility(GONE);
1379 }
1380
1381 public void initServerTypeForTv(String serverType) {
1382 this.serverType = serverType;
1383 }
1384
1385 @Override
1386 public void onProgramClick(Program program) {
1387 if (program.getProgramStatus().equals("onaired")) {
1388 showExoControlForTv();
1389 initMoviePlayer(program.getVideoUrl(), "tv", this);
1390 timeTv.setText(program.getTime());
1391 programTv.setText(program.getTitle());
1392 } else {
1393 new ToastMsg(DetailsActivity.this).toastIconError("Not Yet");
1394 }
1395 }
1396
1397
1398 //this method will be called when related tv channel is clicked
1399 @Override
1400 public void onRelatedTvClicked(CommonModels obj) {
1401 type = obj.getVideoType();
1402 id = obj.getId();
1403 initGetData();
1404 }
1405
1406 // this will call when any episode is clicked
1407 //if it is embed player will go full screen
1408 @Override
1409 public void onEpisodeItemClickTvSeries(String type, View view, EpiModel obj, int position, EpisodeAdapter.OriginalViewHolder holder) {
1410 if (type.equalsIgnoreCase("embed")){
1411 CommonModels model = new CommonModels();
1412 model.setStremURL(obj.getStreamURL());
1413 model.setServerType(obj.getServerType());
1414 model.setListSub(null);
1415 releasePlayer();
1416 resetCastPlayer();
1417 preparePlayer(model);
1418 }else {
1419 if (obj != null){
1420 if (obj.getSubtitleList().size() != 0){
1421 listSub.clear();
1422 listSub.addAll(obj.getSubtitleList());
1423 imgSubtitle.setVisibility(VISIBLE);
1424 }else {
1425 listSub.clear();
1426 imgSubtitle.setVisibility(GONE);
1427 }
1428
1429 initMoviePlayer(obj.getStreamURL(), obj.getServerType(), DetailsActivity.this);
1430 }
1431 }
1432 }
1433
1434 private class SubtitleAdapter extends RecyclerView.Adapter<SubtitleAdapter.OriginalViewHolder> {
1435 private List<SubtitleModel> items = new ArrayList<>();
1436 private Context ctx;
1437
1438 public SubtitleAdapter(Context context, List<SubtitleModel> items) {
1439 this.items = items;
1440 ctx = context;
1441 }
1442
1443 @Override
1444 public SubtitleAdapter.OriginalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
1445 SubtitleAdapter.OriginalViewHolder vh;
1446 View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_subtitle, parent, false);
1447 vh = new SubtitleAdapter.OriginalViewHolder(v);
1448 return vh;
1449 }
1450
1451 @Override
1452 public void onBindViewHolder(SubtitleAdapter.OriginalViewHolder holder, final int position) {
1453 final SubtitleModel obj = items.get(position);
1454 holder.name.setText(obj.getLanguage());
1455
1456 holder.lyt_parent.setOnClickListener(new View.OnClickListener() {
1457 @Override
1458 public void onClick(View v) {
1459 setSelectedSubtitle(mediaSource, obj.getUrl(), ctx);
1460 alertDialog.cancel();
1461 }
1462 });
1463
1464 }
1465
1466 @Override
1467 public int getItemCount() {
1468 return items.size();
1469 }
1470
1471 public class OriginalViewHolder extends RecyclerView.ViewHolder {
1472 public TextView name;
1473 private View lyt_parent;
1474
1475 public OriginalViewHolder(View v) {
1476 super(v);
1477 name = v.findViewById(R.id.name);
1478 lyt_parent = v.findViewById(R.id.lyt_parent);
1479 }
1480 }
1481
1482 }
1483
1484 private void loadAd() {
1485 AdsConfig adsConfig = db.getConfigurationData().getAdsConfig();
1486 if (adsConfig.getAdsEnable().equals("1")) {
1487
1488 if (adsConfig.getMobileAdsNetwork().equalsIgnoreCase(Constants.ADMOB)) {
1489 BannerAds.ShowAdmobBannerAds(this, adView);
1490 PopUpAds.ShowAdmobInterstitialAds(this);
1491
1492 } else if (adsConfig.getMobileAdsNetwork().equalsIgnoreCase(Constants.START_APP)) {
1493 BannerAds.showStartAppBanner(DetailsActivity.this, adView);
1494 PopUpAds.showStartappInterstitialAds(DetailsActivity.this);
1495
1496 } else if (adsConfig.getMobileAdsNetwork().equalsIgnoreCase(Constants.NETWORK_AUDIENCE)) {
1497 BannerAds.showFANBanner(this, adView);
1498 PopUpAds.showFANInterstitialAds(DetailsActivity.this);
1499 }
1500
1501 }
1502
1503 }
1504
1505 private void initGetData() {
1506 if (!type.equals("tv")) {
1507
1508 //----related rv----------
1509 relatedAdapter = new HomePageAdapter(this, listRelated);
1510 rvRelated.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,
1511 false));
1512 rvRelated.setHasFixedSize(true);
1513 rvRelated.setAdapter(relatedAdapter);
1514
1515 if (type.equals("tvseries")) {
1516
1517 seasonSpinnerContainer.setVisibility(VISIBLE);
1518
1519 rvServer.setVisibility(VISIBLE);
1520 serverIv.setVisibility(GONE);
1521
1522 rvRelated.removeAllViews();
1523 listRelated.clear();
1524 rvServer.removeAllViews();
1525 listServer.clear();
1526 listServer.clear();
1527
1528 downloadBt.setVisibility(GONE);
1529 watchNowBt.setVisibility(GONE);
1530
1531 // cast & crew adapter
1532 castCrewAdapter = new CastCrewAdapter(this, castCrews);
1533 castRv.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
1534 castRv.setHasFixedSize(true);
1535 castRv.setAdapter(castCrewAdapter);
1536
1537 getSeriesData(type, id);
1538
1539 if (listSub.size() == 0) {
1540 imgSubtitle.setVisibility(GONE);
1541 }
1542
1543 } else {
1544 imgFull.setVisibility(GONE);
1545 listServer.clear();
1546 rvRelated.removeAllViews();
1547 listRelated.clear();
1548 if (listSub.size() == 0) {
1549 imgSubtitle.setVisibility(GONE);
1550 }
1551
1552 // cast & crew adapter
1553 castCrewAdapter = new CastCrewAdapter(this, castCrews);
1554 castRv.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
1555 castRv.setHasFixedSize(true);
1556 castRv.setAdapter(castCrewAdapter);
1557
1558 getMovieData(type, id);
1559
1560 final ServerAdapter.OriginalViewHolder[] viewHolder = {null};
1561 }
1562
1563 if (PreferenceUtils.isLoggedIn(DetailsActivity.this)) {
1564 getFavStatus();
1565 }
1566
1567 } else {
1568 tv = true;
1569 imgSubtitle.setVisibility(GONE);
1570 llcomment.setVisibility(GONE);
1571 serverIv.setVisibility(GONE);
1572
1573 rvServer.setVisibility(VISIBLE);
1574 descriptionLayout.setVisibility(GONE);
1575 lPlay.setVisibility(VISIBLE);
1576
1577 // hide exo player some control
1578 hideExoControlForTv();
1579
1580 tvLayout.setVisibility(VISIBLE);
1581
1582 // hide program guide if its disable from api
1583 if (!PreferenceUtils.isProgramGuideEnabled(DetailsActivity.this)) {
1584 proGuideTv.setVisibility(GONE);
1585 programRv.setVisibility(GONE);
1586
1587 }
1588
1589 watchStatusTv.setText(getString(R.string.watching_on) + " " + getString(R.string.app_name));
1590
1591 tvRelated.setText(getString(R.string.all_tv_channel));
1592
1593 rvServer.removeAllViews();
1594 listServer.clear();
1595 rvRelated.removeAllViews();
1596 listRelated.clear();
1597
1598 programAdapter = new ProgramAdapter(programs, this);
1599 programAdapter.setOnProgramClickListener(this);
1600 programRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
1601 programRv.setHasFixedSize(true);
1602 programRv.setAdapter(programAdapter);
1603
1604 //----related rv----------
1605 //relatedTvAdapter = new LiveTvHomeAdapter(this, listRelated, TAG);
1606 relatedTvAdapter = new RelatedTvAdapter(listRelated, DetailsActivity.this);
1607 rvRelated.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
1608 rvRelated.setHasFixedSize(true);
1609 rvRelated.setAdapter(relatedTvAdapter);
1610 relatedTvAdapter.setListener(DetailsActivity.this);
1611
1612 imgAddFav.setVisibility(GONE);
1613
1614 serverAdapter = new ServerAdapter(this, listServer, "tv");
1615 rvServer.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
1616 rvServer.setHasFixedSize(true);
1617 rvServer.setAdapter(serverAdapter);
1618 getTvData(type, id);
1619 llBottom.setVisibility(GONE);
1620
1621 final ServerAdapter.OriginalViewHolder[] viewHolder = {null};
1622 serverAdapter.setOnItemClickListener(new ServerAdapter.OnItemClickListener() {
1623 @Override
1624 public void onItemClick(View view, CommonModels obj, int position, ServerAdapter.OriginalViewHolder holder) {
1625 mediaUrl = obj.getStremURL();
1626
1627 if (!castSession) {
1628 initMoviePlayer(obj.getStremURL(), obj.getServerType(), DetailsActivity.this);
1629
1630 } else {
1631
1632 if (obj.getServerType().toLowerCase().equals("embed")) {
1633
1634 castSession = false;
1635 castPlayer.setSessionAvailabilityListener(null);
1636 castPlayer.release();
1637
1638 // invisible control ui of exoplayer
1639 player.setPlayWhenReady(true);
1640 simpleExoPlayerView.setUseController(true);
1641
1642 // invisible control ui of casting
1643 castControlView.setVisibility(GONE);
1644 chromeCastTv.setVisibility(GONE);
1645 } else {
1646 showQueuePopup(DetailsActivity.this, null, getMediaInfo());
1647 }
1648 }
1649
1650 serverAdapter.chanColor(viewHolder[0], position);
1651 holder.name.setTextColor(getResources().getColor(R.color.colorPrimary));
1652 viewHolder[0] = holder;
1653 }
1654
1655 @Override
1656 public void getFirstUrl(String url) {
1657 mediaUrl = url;
1658 }
1659
1660 @Override
1661 public void hideDescriptionLayout() {
1662
1663 }
1664 });
1665
1666
1667 }
1668 }
1669
1670 private void openWebActivity(String s, Context context, String videoType) {
1671
1672 if (isPlaying) {
1673 player.release();
1674 }
1675 progressBar.setVisibility(GONE);
1676 playerLayout.setVisibility(GONE);
1677
1678 webView.loadUrl(s);
1679 webView.setWebChromeClient(new WebChromeClient());
1680 WebSettings webSettings = webView.getSettings();
1681 webSettings.setJavaScriptEnabled(true);
1682 webView.setVisibility(VISIBLE);
1683
1684 }
1685
1686 public void initMoviePlayer(String url, String type, Context context) {
1687 Log.e("vTYpe :: ", type);
1688 urlType = type;
1689 if (type.equals("embed") || type.equals("vimeo") || type.equals("gdrive") || type.equals("youtube-live")) {
1690 isVideo = false;
1691
1692 openWebActivity(url, context, type);
1693 } else {
1694 isVideo = true;
1695 initVideoPlayer(url, context, type);
1696 }
1697 }
1698
1699 public void initVideoPlayer(String url, Context context, String type) {
1700 progressBar.setVisibility(VISIBLE);
1701
1702 if (player != null){
1703 player.stop();
1704 player.release();
1705 }
1706
1707 webView.setVisibility(GONE);
1708 playerLayout.setVisibility(VISIBLE);
1709
1710 BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
1711 TrackSelection.Factory videoTrackSelectionFactory = new
1712 AdaptiveTrackSelection.Factory(bandwidthMeter);
1713
1714 DefaultTrackSelector trackSelector = new
1715 DefaultTrackSelector(videoTrackSelectionFactory);
1716 player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
1717 // player.setPlayWhenReady(true);
1718 //simpleExoPlayerView.setPlayer(player);
1719
1720 Uri uri = Uri.parse(url);
1721
1722 if (type.equals("hls")) {
1723 mediaSource = hlsMediaSource(uri, context);
1724 } else if (type.equals("youtube")) {
1725 Log.e("youtube url :: ", url);
1726 extractYoutubeUrl(url, context, 18);
1727 } else if (type.equals("youtube-live")) {
1728 Log.e("youtube url :: ", url);
1729 extractYoutubeUrl(url, context, 133);
1730 } else if (type.equals("rtmp")) {
1731 mediaSource = rtmpMediaSource(uri);
1732 } else {
1733 mediaSource = mediaSource(uri, context);
1734 }
1735
1736 //Toast.makeText(context, "castSession:"+getCastSessionObj()+"", Toast.LENGTH_SHORT).show();
1737 player.prepare(mediaSource, true, false);
1738 simpleExoPlayerView.setPlayer(player);
1739 player.setPlayWhenReady(true);
1740
1741 player.addListener(new Player.DefaultEventListener() {
1742 @Override
1743 public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
1744 if (playWhenReady && playbackState == Player.STATE_READY) {
1745
1746 isPlaying = true;
1747 progressBar.setVisibility(View.GONE);
1748 } else if (playbackState == Player.STATE_READY) {
1749 progressBar.setVisibility(View.GONE);
1750 isPlaying = false;
1751 } else if (playbackState == Player.STATE_BUFFERING) {
1752 isPlaying = false;
1753 progressBar.setVisibility(VISIBLE);
1754 } else {
1755 // player paused in any state
1756 isPlaying = false;
1757 }
1758 }
1759 });
1760 //*****************************custom detector
1761 mDetector=null;
1762 mDetector=new GestureDetector(this, new MyGestureListener(player,txtFwd,txtRwd));
1763 SharedPreferences preferences=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
1764 //txtMovieTitle.setVisibility(VISIBLE);
1765 if(season!=null&&episod!=null) {
1766 txtMovieTitle.setTextSize(14f);
1767 txtMovieTitle.setText(title + " Season:" + season + "- " + episod);
1768 }else{
1769 txtMovieTitle.setTextSize(18f);
1770 txtMovieTitle.setText(title);
1771 }
1772
1773 long lastTime=preferences.getLong(url,0);
1774 player.seekTo(lastTime);//****************
1775 selectedUrl=url;
1776
1777
1778 }
1779
1780 @SuppressLint("StaticFieldLeak")
1781 private void extractYoutubeUrl(String url, final Context context, final int tag) {
1782 new YouTubeExtractor(context) {
1783 @Override
1784 public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {
1785 if (ytFiles != null) {
1786 int itag = tag;
1787 String downloadUrl = ytFiles.get(itag).getUrl();
1788 youtubeDownloadUr = downloadUrl;
1789 Log.e("YOUTUBE::", String.valueOf(downloadUrl));
1790 try {
1791
1792 MediaSource mediaSource = mediaSource(Uri.parse(downloadUrl), context);
1793 player.prepare(mediaSource, true, false);
1794 if (Config.YOUTUBE_VIDEO_AUTO_PLAY) {
1795 player.setPlayWhenReady(true);
1796 } else {
1797 player.setPlayWhenReady(false);
1798 }
1799 } catch (Exception e) {
1800 e.printStackTrace();
1801 }
1802
1803 }
1804 }
1805 }.extract(url, true, true);
1806 }
1807
1808 private MediaSource rtmpMediaSource(Uri uri) {
1809 MediaSource videoSource = null;
1810 RtmpDataSourceFactory dataSourceFactory = new RtmpDataSourceFactory();
1811 videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
1812 .createMediaSource(uri);
1813
1814 return videoSource;
1815 }
1816
1817 private MediaSource hlsMediaSource(Uri uri, Context context) {
1818 DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
1819 DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
1820 Util.getUserAgent(context, "oxoo"), bandwidthMeter);
1821
1822 MediaSource videoSource = new HlsMediaSource.Factory(dataSourceFactory)
1823 .createMediaSource(uri);
1824
1825
1826 return videoSource;
1827 }
1828
1829 private MediaSource mediaSource(Uri uri, Context context) {
1830 return new ExtractorMediaSource.Factory(
1831 new DefaultHttpDataSourceFactory("exoplayer")).
1832 createMediaSource(uri);
1833 }
1834
1835
1836 public void setSelectedSubtitle(MediaSource mediaSource, String subtitle, Context context) {
1837 MergingMediaSource mergedSource;
1838 if (subtitle != null) {
1839 Uri subtitleUri = Uri.parse(subtitle);
1840
1841 Format subtitleFormat = Format.createTextSampleFormat(
1842 null, // An identifier for the track. May be null.
1843 MimeTypes.TEXT_VTT, // The mime type. Must be set correctly.
1844 Format.NO_VALUE, // Selection flags for the track.
1845 "en"); // The subtitle language. May be null.
1846
1847 DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context,
1848 Util.getUserAgent(context, CLASS_NAME), new DefaultBandwidthMeter());
1849
1850
1851 MediaSource subtitleSource = new SingleSampleMediaSource
1852 .Factory(dataSourceFactory)
1853 .createMediaSource(subtitleUri, subtitleFormat, C.TIME_UNSET);
1854
1855
1856 mergedSource = new MergingMediaSource(mediaSource, subtitleSource);
1857 player.prepare(mergedSource, false, false);
1858 player.setPlayWhenReady(true);
1859 //resumePlayer();
1860
1861 } else {
1862 Toast.makeText(context, "there is no subtitle", Toast.LENGTH_SHORT).show();
1863 }
1864 }
1865
1866 private void addToFav() {
1867 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
1868 FavouriteApi api = retrofit.create(FavouriteApi.class);
1869 Call<FavoriteModel> call = api.addToFavorite(Config.API_KEY, userId, id);
1870 call.enqueue(new Callback<FavoriteModel>() {
1871 @Override
1872 public void onResponse(Call<FavoriteModel> call, retrofit2.Response<FavoriteModel> response) {
1873 if (response.code() == 200){
1874 if (response.body().getStatus().equalsIgnoreCase("success")){
1875 new ToastMsg(DetailsActivity.this).toastIconSuccess(response.body().getMessage());
1876 isFav = true;
1877 imgAddFav.setBackgroundResource(R.drawable.ic_favorite_white);
1878 } else {
1879 new ToastMsg(DetailsActivity.this).toastIconError(response.body().getMessage());
1880 }
1881 }else {
1882 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.error_toast));
1883 }
1884 }
1885
1886 @Override
1887 public void onFailure(Call<FavoriteModel> call, Throwable t) {
1888 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.error_toast));
1889
1890 }
1891 });
1892
1893 }
1894
1895 private void paidControl(String isPaid) {
1896 if (isPaid.equals("1")) {
1897 if (PreferenceUtils.isLoggedIn(DetailsActivity.this)) {
1898 if (PreferenceUtils.isActivePlan(DetailsActivity.this)) {
1899 if (PreferenceUtils.isValid(DetailsActivity.this)) {
1900 contentDetails.setVisibility(VISIBLE);
1901 subscriptionLayout.setVisibility(GONE);
1902 Log.e("SUBCHECK", "validity: " + PreferenceUtils.isValid(DetailsActivity.this));
1903
1904 } else {
1905 Log.e("SUBCHECK", "not valid");
1906 /*contentDetails.setVisibility(GONE);
1907 subscriptionLayout.setVisibility(VISIBLE);*/
1908 PreferenceUtils.updateSubscriptionStatus(DetailsActivity.this);
1909 //paidControl(isPaid);
1910 }
1911 } else {
1912 Log.e("SUBCHECK", "not active plan");
1913 contentDetails.setVisibility(GONE);
1914 subscriptionLayout.setVisibility(VISIBLE);
1915 }
1916 }else {
1917 startActivity(new Intent(DetailsActivity.this, FirebaseSignUpActivity.class));
1918 finish();
1919 }
1920
1921 } else {
1922 //free content
1923 contentDetails.setVisibility(VISIBLE);
1924 subscriptionLayout.setVisibility(GONE);
1925 }
1926 }
1927
1928 private void getActiveStatus(String userId) {
1929 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
1930 SubscriptionApi subscriptionApi = retrofit.create(SubscriptionApi.class);
1931
1932 Call<ActiveStatus> call = subscriptionApi.getActiveStatus(com.cristian.rocopelis.Config.API_KEY, userId);
1933 call.enqueue(new Callback<ActiveStatus>() {
1934 @Override
1935 public void onResponse(Call<ActiveStatus> call, retrofit2.Response<ActiveStatus> response) {
1936 ActiveStatus activeStatus = response.body();
1937 if (!activeStatus.getStatus().equals("active")) {
1938 contentDetails.setVisibility(GONE);
1939 subscriptionLayout.setVisibility(VISIBLE);
1940 } else {
1941 contentDetails.setVisibility(VISIBLE);
1942 subscriptionLayout.setVisibility(GONE);
1943 }
1944
1945 PreferenceUtils.updateSubscriptionStatus(DetailsActivity.this);
1946 }
1947
1948 @Override
1949 public void onFailure(Call<ActiveStatus> call, Throwable t) {
1950 t.printStackTrace();
1951 }
1952 });
1953
1954 }
1955
1956 private void getTvData(final String vtype, final String vId) {
1957 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
1958 SingleDetailsTVApi api = retrofit.create(SingleDetailsTVApi.class);
1959 Call<SingleDetailsTV> call = api.getSingleDetails(Config.API_KEY, vtype, vId);
1960 call.enqueue(new Callback<SingleDetailsTV>() {
1961 @Override
1962 public void onResponse(Call<SingleDetailsTV> call, retrofit2.Response<SingleDetailsTV> response) {
1963 if (response.code() == 200){
1964 if (response.body() != null){
1965 swipeRefreshLayout.setRefreshing(false);
1966 shimmerFrameLayout.stopShimmer();
1967 shimmerFrameLayout.setVisibility(GONE);
1968 paidControl(response.body().getIsPaid());
1969
1970 SingleDetailsTV detailsModel = response.body();
1971
1972 title = detailsModel.getTvName();
1973
1974
1975 tvName.setText(title);
1976 tvName.setVisibility(GONE);
1977 tvTitleTv.setText(title);
1978
1979 tvDes.setText(detailsModel.getDescription());
1980 V_URL = detailsModel.getStreamUrl();
1981 castImageUrl = detailsModel.getThumbnailUrl();
1982
1983 Picasso.get().load(detailsModel.getThumbnailUrl()).placeholder(R.drawable.album_art_placeholder)
1984 .into(tvThumbIv);
1985
1986 CommonModels model = new CommonModels();
1987 model.setTitle("HD");
1988 model.setStremURL(V_URL);
1989 model.setServerType(detailsModel.getStreamFrom());
1990 listServer.add(model);
1991
1992 currentProgramTime = detailsModel.getCurrentProgramTime();
1993 currentProgramTitle = detailsModel.getCurrentProgramTitle();
1994
1995 timeTv.setText(currentProgramTime);
1996 programTv.setText(currentProgramTitle);
1997 if (PreferenceUtils.isProgramGuideEnabled(DetailsActivity.this)) {
1998 List<ProgramGuide> programGuideList = response.body().getProgramGuide();
1999 for (int i = 0; i < programGuideList.size(); i++) {
2000 ProgramGuide programGuide = programGuideList.get(i);
2001 Program program = new Program();
2002 program.setId(programGuide.getId());
2003 program.setTitle(programGuide.getTitle());
2004 program.setProgramStatus(programGuide.getProgramStatus());
2005 program.setTime(programGuide.getTime());
2006 program.setVideoUrl(programGuide.getVideoUrl());
2007
2008 programs.add(program);
2009 }
2010
2011 if (programs.size() <= 0) {
2012 proGuideTv.setVisibility(GONE);
2013 programRv.setVisibility(GONE);
2014 } else {
2015 proGuideTv.setVisibility(VISIBLE);
2016 programRv.setVisibility(VISIBLE);
2017 programAdapter.notifyDataSetChanged();
2018 }
2019 }
2020 //all tv channel data
2021 List<AllTvChannel> allTvChannelList = response.body().getAllTvChannel();
2022 for (int i = 0; i < allTvChannelList.size(); i++) {
2023 AllTvChannel allTvChannel = allTvChannelList.get(i);
2024 CommonModels models = new CommonModels();
2025 models.setImageUrl(allTvChannel.getPosterUrl());
2026 models.setTitle(allTvChannel.getTvName());
2027 models.setVideoType("tv");
2028 models.setIsPaid(allTvChannel.getIsPaid());
2029 models.setId(allTvChannel.getLiveTvId());
2030 listRelated.add(models);
2031 }
2032 if (listRelated.size() == 0) {
2033 tvRelated.setVisibility(GONE);
2034 }
2035 relatedTvAdapter.notifyDataSetChanged();
2036
2037 //additional media source data
2038 List<AdditionalMediaSource> serverArray = response.body().getAdditionalMediaSource();
2039 for (int i = 0; i < serverArray.size(); i++) {
2040 AdditionalMediaSource jsonObject = serverArray.get(i);
2041 CommonModels models = new CommonModels();
2042 models.setTitle(jsonObject.getLabel());
2043 models.setStremURL(jsonObject.getUrl());
2044 models.setServerType(jsonObject.getSource());
2045
2046 listServer.add(models);
2047 }
2048 serverAdapter.notifyDataSetChanged();
2049 }
2050 }
2051 }
2052
2053 @Override
2054 public void onFailure(Call<SingleDetailsTV> call, Throwable t) {
2055 swipeRefreshLayout.setRefreshing(false);
2056 }
2057 });
2058
2059 }
2060
2061 private void getSeriesData(String vtype, String vId) {
2062 final List<String> seasonList = new ArrayList<>();
2063 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
2064 SingleDetailsApi api = retrofit.create(SingleDetailsApi.class);
2065 Call<SingleDetails> call = api.getSingleDetails(Config.API_KEY, vtype, vId);
2066 call.enqueue(new Callback<SingleDetails>() {
2067 @Override
2068 public void onResponse(Call<SingleDetails> call, retrofit2.Response<SingleDetails> response) {
2069 if (response.code() == 200){
2070 swipeRefreshLayout.setRefreshing(false);
2071 shimmerFrameLayout.stopShimmer();
2072 shimmerFrameLayout.setVisibility(GONE);
2073
2074 SingleDetails singleDetails = response.body();
2075 String isPaid = singleDetails.getIsPaid();
2076 paidControl(isPaid);
2077
2078 title = singleDetails.getTitle();
2079 sereisTitleTv.setText(title);
2080 castImageUrl = singleDetails.getThumbnailUrl();
2081 seriesTitle = title;
2082 tvName.setText(title);
2083 tvRelease.setText("Lanzamiento en " + singleDetails.getRelease());
2084 tvDes.setText(singleDetails.getDescription());
2085
2086 Picasso.get().load(singleDetails.getPosterUrl()).placeholder(R.drawable.album_art_placeholder_large)
2087 .into(posterIv);
2088 Picasso.get().load(singleDetails.getThumbnailUrl()).placeholder(R.drawable.poster_placeholder)
2089 .into(thumbIv);
2090
2091 download_check = singleDetails.getEnableDownload();
2092
2093 //----director---------------
2094 for (int i = 0; i < singleDetails.getDirector().size(); i++) {
2095 Director director = singleDetails.getDirector().get(i);
2096 if (i == singleDetails.getDirector().size() - 1) {
2097 strDirector = strDirector + director.getName();
2098 } else {
2099 strDirector = strDirector + director.getName() + ", ";
2100 }
2101 }
2102 tvDirector.setText(strDirector);
2103
2104 //----cast---------------
2105 for (int i = 0; i < singleDetails.getCast().size(); i++) {
2106 Cast cast = singleDetails.getCast().get(i);
2107
2108 CastCrew castCrew = new CastCrew();
2109 castCrew.setId(cast.getStarId());
2110 castCrew.setName(cast.getName());
2111 castCrew.setUrl(cast.getUrl());
2112 castCrew.setImageUrl(cast.getImageUrl());
2113 castCrews.add(castCrew);
2114 }
2115 castCrewAdapter.notifyDataSetChanged();
2116 //---genre---------------
2117 for (int i = 0; i < singleDetails.getGenre().size(); i++) {
2118 Genre genre = singleDetails.getGenre().get(i);
2119 if (i == singleDetails.getCast().size() - 1) {
2120 strGenre = strGenre + genre.getName();
2121 } else {
2122 if (i == singleDetails.getGenre().size() - 1) {
2123 strGenre = strGenre + genre.getName();
2124 } else {
2125 strGenre = strGenre + genre.getName() + ", ";
2126 }
2127 }
2128 }
2129 setGenreText();
2130
2131 //----related tv series---------------
2132 for (int i = 0; i < singleDetails.getRelatedTvseries().size(); i++) {
2133 RelatedMovie relatedTvSeries = singleDetails.getRelatedTvseries().get(i);
2134
2135 CommonModels models = new CommonModels();
2136 models.setTitle(relatedTvSeries.getTitle());
2137 models.setImageUrl(relatedTvSeries.getThumbnailUrl());
2138 models.setId(relatedTvSeries.getVideosId());
2139 models.setVideoType("tvseries");
2140 models.setIsPaid(relatedTvSeries.getIsPaid());
2141 listRelated.add(models);
2142 }
2143 if (listRelated.size() == 0) {
2144 tvRelated.setVisibility(GONE);
2145 }
2146 relatedAdapter.notifyDataSetChanged();
2147
2148 //----seasson------------
2149 for (int i = 0; i <singleDetails.getSeason().size(); i++) {
2150 Season season = singleDetails.getSeason().get(i);
2151
2152 CommonModels models = new CommonModels();
2153 String season_name = season.getSeasonsName();
2154 models.setTitle(season.getSeasonsName());
2155 seasonList.add("Temporada: " + season.getSeasonsName());
2156
2157 //----episode------
2158 List<EpiModel> epList = new ArrayList<>();
2159 epList.clear();
2160 for (int j = 0; j <singleDetails.getSeason().get(i).getEpisodes().size(); j++) {
2161 Episode episode = singleDetails.getSeason().get(i).getEpisodes().get(j);
2162
2163 EpiModel model = new EpiModel();
2164 model.setSeson(season_name);
2165 model.setEpi(episode.getEpisodesName());
2166 model.setStreamURL(episode.getFileUrl());
2167 model.setServerType(episode.getFileType());
2168 model.setImageUrl(episode.getImageUrl());
2169 model.setSubtitleList(episode.getSubtitle());
2170 epList.add(model);
2171 }
2172 models.setListEpi(epList);
2173 listServer.add(models);
2174
2175 setSeasonData(seasonList);
2176
2177 }
2178 }
2179 }
2180
2181 @Override
2182 public void onFailure(Call<SingleDetails> call, Throwable t) {
2183
2184 }
2185 });
2186 }
2187
2188 public void setSeasonData(List<String> seasonData) {
2189
2190 ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, seasonData);
2191 aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
2192 //Setting the ArrayAdapter data on the Spinner
2193 seasonSpinner.setAdapter(aa);
2194
2195 seasonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2196
2197 @Override
2198 public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
2199 rvServer.removeAllViewsInLayout();
2200 rvServer.setLayoutManager(new LinearLayoutManager(DetailsActivity.this,
2201 RecyclerView.HORIZONTAL, false));
2202 EpisodeAdapter episodeAdapter = new EpisodeAdapter(DetailsActivity.this,
2203 listServer.get(i).getListEpi());
2204 rvServer.setAdapter(episodeAdapter);
2205
2206 episodeAdapter.setOnEmbedItemClickListener(DetailsActivity.this);
2207
2208 }
2209
2210 @Override
2211 public void onNothingSelected(AdapterView<?> adapterView) {
2212
2213 }
2214 });
2215
2216 }
2217
2218 private void setGenreText() {
2219
2220 tvGenre.setText(strGenre);
2221
2222 dGenryTv.setText(strGenre);
2223
2224 }
2225
2226 private void getMovieData(String vtype, String vId) {
2227 strCast = "";
2228 strDirector = "";
2229 strGenre = "";
2230
2231 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
2232 SingleDetailsApi api = retrofit.create(SingleDetailsApi.class);
2233 Call<SingleDetails> call = api.getSingleDetails(Config.API_KEY, vtype, vId);
2234 call.enqueue(new Callback<SingleDetails>() {
2235 @Override
2236 public void onResponse(Call<SingleDetails> call, retrofit2.Response<SingleDetails> response) {
2237 if (response.code() == 200){
2238 shimmerFrameLayout.stopShimmer();
2239 shimmerFrameLayout.setVisibility(GONE);
2240 swipeRefreshLayout.setRefreshing(false);
2241
2242 SingleDetails singleDetails = response.body();
2243 paidControl(singleDetails.getIsPaid());
2244 download_check = singleDetails.getEnableDownload();
2245 castImageUrl = singleDetails.getThumbnailUrl();
2246 if (download_check.equals("1")) {
2247 downloadBt.setVisibility(VISIBLE);
2248 } else {
2249 downloadBt.setVisibility(GONE);
2250 }
2251 title = singleDetails.getTitle();
2252 movieTitle = title;
2253
2254 tvName.setText(title);
2255 tvRelease.setText("Lanzamiento en " + singleDetails.getRelease());
2256 tvDes.setText(singleDetails.getDescription());
2257
2258
2259 Picasso.get().load(singleDetails.getPosterUrl()).placeholder(R.drawable.album_art_placeholder_large)
2260 .into(posterIv);
2261 Picasso.get().load(singleDetails.getThumbnailUrl()).placeholder(R.drawable.poster_placeholder)
2262 .into(thumbIv);
2263
2264 //----director---------------
2265 for (int i = 0; i < singleDetails.getDirector().size(); i++) {
2266 Director director = response.body().getDirector().get(i);
2267 if (i == singleDetails.getDirector().size() - 1) {
2268 strDirector = strDirector + director.getName();
2269 } else {
2270 strDirector = strDirector + director.getName() + ", ";
2271 }
2272 }
2273 tvDirector.setText(strDirector);
2274
2275 //----cast---------------
2276 for (int i = 0; i < singleDetails.getCast().size(); i++) {
2277 Cast cast = singleDetails.getCast().get(i);
2278
2279 CastCrew castCrew = new CastCrew();
2280 castCrew.setId(cast.getStarId());
2281 castCrew.setName(cast.getName());
2282 castCrew.setUrl(cast.getUrl());
2283 castCrew.setImageUrl(cast.getImageUrl());
2284
2285 castCrews.add(castCrew);
2286
2287 }
2288 castCrewAdapter.notifyDataSetChanged();
2289
2290 //---genre---------------
2291 for (int i = 0; i < singleDetails.getGenre().size(); i++) {
2292 Genre genre = singleDetails.getGenre().get(i);
2293 if (i == singleDetails.getCast().size() - 1) {
2294 strGenre = strGenre + genre.getName();
2295 } else {
2296 if (i == singleDetails.getGenre().size() - 1) {
2297 strGenre = strGenre + genre.getName();
2298 } else {
2299 strGenre = strGenre + genre.getName() + ", ";
2300 }
2301 }
2302 }
2303 tvGenre.setText(strGenre);
2304 dGenryTv.setText(strGenre);
2305
2306 //-----server----------
2307 List<Video> serverList = new ArrayList<>();
2308 serverList.addAll(singleDetails.getVideos());
2309 for (int i = 0; i < serverList.size(); i++){
2310 Video video = serverList.get(i);
2311
2312 CommonModels models = new CommonModels();
2313 models.setTitle(video.getLabel());
2314 models.setStremURL(video.getFileUrl());
2315 models.setServerType(video.getFileType());
2316
2317 if (video.getFileType().equals("mp4")) {
2318 V_URL = video.getFileUrl();
2319 }
2320
2321 //----subtitle-----------
2322 List<Subtitle> subArray = new ArrayList<>();
2323 subArray.addAll(singleDetails.getVideos().get(i).getSubtitle());
2324 if (subArray.size() != 0) {
2325
2326 List<SubtitleModel> list = new ArrayList<>();
2327 for (int j = 0; j < subArray.size(); j++) {
2328 Subtitle subtitle = subArray.get(j);
2329 SubtitleModel subtitleModel = new SubtitleModel();
2330 subtitleModel.setUrl(subtitle.getUrl());
2331 subtitleModel.setLanguage(subtitle.getLanguage());
2332 list.add(subtitleModel);
2333 }
2334 if (i == 0) {
2335 listSub.addAll(list);
2336 }
2337 models.setListSub(list);
2338 } else {
2339 models.setSubtitleURL(strSubtitle);
2340 }
2341 listServer.add(models);
2342 }
2343
2344 if (serverAdapter != null) {
2345 serverAdapter.notifyDataSetChanged();
2346 }
2347
2348 //----related post---------------
2349 for (int i = 0; i < singleDetails.getRelatedMovie().size(); i++) {
2350 RelatedMovie relatedMovie = singleDetails.getRelatedMovie().get(i);
2351 CommonModels models = new CommonModels();
2352 models.setTitle(relatedMovie.getTitle());
2353 models.setImageUrl(relatedMovie.getThumbnailUrl());
2354 models.setId(relatedMovie.getVideosId());
2355 models.setVideoType("movie");
2356 models.setIsPaid(relatedMovie.getIsPaid());
2357 models.setIsPaid(relatedMovie.getIsPaid());
2358 listRelated.add(models);
2359 }
2360
2361 if (listRelated.size() == 0) {
2362 tvRelated.setVisibility(GONE);
2363 }
2364 relatedAdapter.notifyDataSetChanged();
2365
2366 //----download list---------
2367 listExternalDownload.clear();
2368 listInternalDownload.clear();
2369 for (int i = 0; i < singleDetails.getDownloadLinks().size(); i++) {
2370 DownloadLink downloadLink = singleDetails.getDownloadLinks().get(i);
2371
2372 CommonModels models = new CommonModels();
2373 models.setTitle(downloadLink.getLabel());
2374 models.setStremURL(downloadLink.getDownloadUrl());
2375 models.setFileSize(downloadLink.getFileSize());
2376 models.setResulation(downloadLink.getResolution());
2377 models.setInAppDownload(downloadLink.isInAppDownload());
2378 if (downloadLink.isInAppDownload()) {
2379 listInternalDownload.add(models);
2380 } else {
2381 listExternalDownload.add(models);
2382 }
2383 }
2384
2385 }else {
2386 swipeRefreshLayout.setRefreshing(false);
2387 }
2388 }
2389
2390 @Override
2391 public void onFailure(Call<SingleDetails> call, Throwable t) {
2392 swipeRefreshLayout.setRefreshing(false);
2393 }
2394 });
2395 }
2396
2397 private void getFavStatus() {
2398 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
2399 FavouriteApi api = retrofit.create(FavouriteApi.class);
2400 Call<FavoriteModel> call = api.verifyFavoriteList(Config.API_KEY, userId, id);
2401 call.enqueue(new Callback<FavoriteModel>() {
2402 @Override
2403 public void onResponse(Call<FavoriteModel> call, retrofit2.Response<FavoriteModel> response) {
2404 if (response.code() == 200){
2405 if (response.body().getStatus().equalsIgnoreCase("success")){
2406 isFav = true;
2407 imgAddFav.setBackgroundResource(R.drawable.ic_favorite_white);
2408 imgAddFav.setVisibility(VISIBLE);
2409 } else {
2410 isFav = false;
2411 imgAddFav.setBackgroundResource(R.drawable.ic_favorite_border_white);
2412 imgAddFav.setVisibility(VISIBLE);
2413 }
2414 }
2415 }
2416
2417 @Override
2418 public void onFailure(@NotNull Call<FavoriteModel> call, @NotNull Throwable t) {
2419
2420 }
2421 });
2422
2423 }
2424
2425 private void removeFromFav() {
2426 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
2427 FavouriteApi api = retrofit.create(FavouriteApi.class);
2428 Call<FavoriteModel> call = api.removeFromFavorite(Config.API_KEY, userId, id);
2429 call.enqueue(new Callback<FavoriteModel>() {
2430 @Override
2431 public void onResponse(Call<FavoriteModel> call, retrofit2.Response<FavoriteModel> response) {
2432 if (response.code() == 200){
2433 if (response.body().getStatus().equalsIgnoreCase("success")){
2434 isFav = false;
2435 new ToastMsg(DetailsActivity.this).toastIconSuccess(response.body().getMessage());
2436 imgAddFav.setBackgroundResource(R.drawable.ic_favorite_border_white);
2437 } else {
2438 isFav = true;
2439 new ToastMsg(DetailsActivity.this).toastIconError(response.body().getMessage());
2440 imgAddFav.setBackgroundResource(R.drawable.ic_favorite_white);
2441 }
2442 }
2443 }
2444
2445 @Override
2446 public void onFailure(Call<FavoriteModel> call, Throwable t) {
2447 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.fetch_error));
2448 }
2449 });
2450 }
2451
2452 private boolean isNetworkAvailable() {
2453 ConnectivityManager connectivityManager
2454 = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
2455 NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
2456 return activeNetworkInfo != null && activeNetworkInfo.isConnected();
2457 }
2458
2459 private void addComment(String videoId, String userId, final String comments) {
2460
2461 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
2462 CommentApi api = retrofit.create(CommentApi.class);
2463 Call<PostCommentModel> call = api.postComment(Config.API_KEY, videoId, userId, comments);
2464 call.enqueue(new Callback<PostCommentModel>() {
2465 @Override
2466 public void onResponse(Call<PostCommentModel> call, retrofit2.Response<PostCommentModel> response) {
2467 if (response.body().getStatus().equals("success")){
2468 rvComment.removeAllViews();
2469 listComment.clear();
2470 getComments();
2471 etComment.setText("");
2472 new ToastMsg(DetailsActivity.this).toastIconSuccess(response.body().getMessage());
2473 }else {
2474 new ToastMsg(DetailsActivity.this).toastIconError(response.body().getMessage());
2475 }
2476 }
2477
2478 @Override
2479 public void onFailure(Call<PostCommentModel> call, Throwable t) {
2480
2481 }
2482 });
2483 }
2484
2485 private void getComments() {
2486
2487 Retrofit retrofit = RetrofitClient.getRetrofitInstance();
2488 CommentApi api = retrofit.create(CommentApi.class);
2489 Call<List<GetCommentsModel>> call = api.getAllComments(Config.API_KEY, id);
2490 call.enqueue(new Callback<List<GetCommentsModel>>() {
2491 @Override
2492 public void onResponse(Call<List<GetCommentsModel>> call, retrofit2.Response<List<GetCommentsModel>> response) {
2493 if (response.code() == 200) {
2494 listComment.addAll(response.body());
2495
2496 commentsAdapter.notifyDataSetChanged();
2497 }
2498 }
2499
2500 @Override
2501 public void onFailure(Call<List<GetCommentsModel>> call, Throwable t) {
2502
2503 }
2504 });
2505
2506 }
2507
2508 public void hideDescriptionLayout() {
2509 descriptionLayout.setVisibility(GONE);
2510 lPlay.setVisibility(VISIBLE);
2511 }
2512
2513 public void showSeriesLayout() {
2514 seriestLayout.setVisibility(VISIBLE);
2515 }
2516
2517 public void showDescriptionLayout() {
2518 descriptionLayout.setVisibility(VISIBLE);
2519 lPlay.setVisibility(GONE);
2520 }
2521
2522 @Override
2523 protected void onPause() {
2524 super.onPause();
2525 Log.e("OnPause", "isPlaying: " + isPlaying);
2526 if (isPlaying && player != null) {
2527 //Log.e("PLAY:::","PAUSE");
2528
2529 SharedPreferences pref=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
2530 SharedPreferences.Editor editor=pref.edit();
2531 editor.putLong(mediaUrl,player.getCurrentPosition());
2532 editor.apply();
2533
2534 player.setPlayWhenReady(false);
2535 }
2536 }
2537
2538 @Override
2539 protected void onStop() {
2540 super.onStop();
2541
2542 //castManager.removeProgressWatcher(this);
2543
2544 if(player!=null){
2545 SharedPreferences pref=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
2546 SharedPreferences.Editor editor=pref.edit();
2547 editor.putLong(mediaUrl,player.getCurrentPosition());
2548 editor.apply();
2549 }
2550 Log.e("onStop", "isPlaying: " + isPlaying);
2551
2552 }
2553
2554 @Override
2555 protected void onDestroy() {
2556 super.onDestroy();
2557 if(player!=null){
2558 SharedPreferences pref=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
2559 SharedPreferences.Editor editor=pref.edit();
2560 editor.putLong(mediaUrl,player.getCurrentPosition());
2561 editor.apply();
2562 }
2563
2564
2565 resetCastPlayer();
2566 releasePlayer();
2567
2568
2569 }
2570
2571 @Override
2572 public void onBackPressed() {
2573 if(player!=null){
2574 SharedPreferences pref=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
2575 SharedPreferences.Editor editor=pref.edit();
2576 editor.putLong(mediaUrl,player.getCurrentPosition());
2577 editor.apply();
2578 }
2579 if (activeMovie) {
2580 setPlayerNormalScreen();
2581 if (player != null){
2582
2583
2584
2585
2586 player.setPlayWhenReady(false);
2587 player.stop();
2588
2589 Log.i("juacosoft","On back");
2590
2591 }
2592 showDescriptionLayout();
2593 activeMovie = false;
2594 } else {
2595 releasePlayer();
2596
2597 }
2598 super.onBackPressed();
2599 }
2600
2601 @Override
2602 protected void onResume() {
2603 super.onResume();
2604 //startPlayer();
2605 if (player != null) {
2606 setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);//***************
2607 if (type.equals("youtube") || type.equals("youtube-live")) {
2608 if (Config.YOUTUBE_VIDEO_AUTO_PLAY) {
2609 player.setPlayWhenReady(true);
2610 } else {
2611 player.setPlayWhenReady(false);
2612 }
2613 } else {
2614 player.setPlayWhenReady(true);
2615 }
2616
2617 SharedPreferences pref=getSharedPreferences(PREFER_NAME,Context.MODE_PRIVATE);
2618 long current=pref.getLong(selectedUrl,0);
2619 player.seekTo(current);
2620 }
2621 }
2622
2623 public void releasePlayer() {
2624 if (player != null) {
2625 player.setPlayWhenReady(true);
2626 player.stop();
2627 player.release();
2628 player = null;
2629
2630 simpleExoPlayerView.setPlayer(null);
2631 //simpleExoPlayerView = null;
2632 }
2633 }
2634
2635 public void setMediaUrlForTvSeries(String url, String season, String episod) {
2636 mediaUrl = url;
2637 this.season = season;
2638 this.episod = episod;
2639 }
2640
2641 public boolean getCastSession() {
2642 return castSession;
2643 }
2644
2645 public void resetCastPlayer() {
2646 if (castPlayer != null) {
2647 castPlayer.setPlayWhenReady(false);
2648 castPlayer.release();
2649 }
2650 }
2651
2652 public void showQueuePopup(final Context context, View view, final MediaInfo mediaInfo) {
2653 CastSession castSession =
2654 CastContext.getSharedInstance(context).getSessionManager().getCurrentCastSession();
2655 if (castSession == null || !castSession.isConnected()) {
2656 Log.w(TAG, "showQueuePopup(): not connected to a cast device");
2657 return;
2658 }
2659 final RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
2660 if (remoteMediaClient == null) {
2661 Log.w(TAG, "showQueuePopup(): null RemoteMediaClient");
2662 return;
2663 }
2664 MediaQueueItem queueItem = new MediaQueueItem.Builder(mediaInfo).setAutoplay(
2665 true).setPreloadTime(PRELOAD_TIME_S).build();
2666 MediaQueueItem[] newItemArray = new MediaQueueItem[]{queueItem};
2667 remoteMediaClient.queueLoad(newItemArray, 0,
2668 MediaStatus.REPEAT_MODE_REPEAT_OFF, null);
2669
2670 }
2671
2672 public void playNextCast(MediaInfo mediaInfo) {
2673
2674 //simpleExoPlayerView.setPlayer(castPlayer);
2675 simpleExoPlayerView.setUseController(false);
2676 castControlView.setVisibility(VISIBLE);
2677 castControlView.setPlayer(castPlayer);
2678 //simpleExoPlayerView.setDefaultArtwork();
2679 castControlView.setVisibilityListener(new PlaybackControlView.VisibilityListener() {
2680 @Override
2681 public void onVisibilityChange(int visibility) {
2682 if (visibility == GONE) {
2683 castControlView.setVisibility(VISIBLE);
2684 chromeCastTv.setVisibility(VISIBLE);
2685 }
2686 }
2687 });
2688 CastSession castSession =
2689 CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession();
2690
2691 if (castSession == null || !castSession.isConnected()) {
2692 Log.w(TAG, "showQueuePopup(): not connected to a cast device");
2693 return;
2694 }
2695
2696 final RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
2697
2698 if (remoteMediaClient == null) {
2699 Log.w(TAG, "showQueuePopup(): null RemoteMediaClient");
2700 return;
2701 }
2702 MediaQueueItem queueItem = new MediaQueueItem.Builder(mediaInfo).setAutoplay(
2703 true).setPreloadTime(PRELOAD_TIME_S).build();
2704 MediaQueueItem[] newItemArray = new MediaQueueItem[]{queueItem};
2705
2706 remoteMediaClient.queueLoad(newItemArray, 0,
2707 MediaStatus.REPEAT_MODE_REPEAT_OFF, null);
2708 castPlayer.setPlayWhenReady(true);
2709
2710 }
2711
2712 public MediaInfo getMediaInfo() {
2713 MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
2714 movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
2715 //movieMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, "Test Artist");
2716 movieMetadata.addImage(new WebImage(Uri.parse(castImageUrl)));
2717 MediaInfo mediaInfo = new MediaInfo.Builder(mediaUrl)
2718 .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
2719 .setContentType(MimeTypes.VIDEO_UNKNOWN)
2720 .setMetadata(movieMetadata).build();
2721
2722 return mediaInfo;
2723
2724 }
2725
2726 public void downloadVideo(final String url) {
2727
2728 if (Build.VERSION.SDK_INT >= 23) {
2729 if (checkPermission()) {
2730 // Code for above or equal 23 API Oriented Device
2731 // Your Permission granted already .Do next code
2732 Handler handler = new Handler();
2733 Runnable runnable = new Runnable() {
2734 public void run() {
2735 downloadFile(url);
2736 }
2737 };
2738 handler.post(runnable);
2739
2740 } else {
2741 requestPermission(); // Code for permission
2742 }
2743 } else {
2744
2745 // Code for Below 23 API Oriented Device
2746 // Do next code
2747
2748 Handler handler = new Handler();
2749 Runnable runnable = new Runnable() {
2750 public void run() {
2751 downloadFile(url);
2752 }
2753 };
2754 handler.post(runnable);
2755 }
2756 }
2757
2758 private boolean checkPermission() {
2759 int result = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
2760 if (result == PackageManager.PERMISSION_GRANTED) {
2761 return true;
2762 } else {
2763 return false;
2764 }
2765 }
2766
2767 private void requestPermission() {
2768
2769 if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
2770 Toast.makeText(this, "El permiso de escritura de almacenamiento externo nos permite almacenar imágenes. Permita este permiso en la Configuración de la aplicación.", Toast.LENGTH_LONG).show();
2771 } else {
2772 ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
2773 }
2774 }
2775
2776 @Override
2777 public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
2778 switch (requestCode) {
2779 case PERMISSION_REQUEST_CODE:
2780 if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
2781 new ToastMsg(DetailsActivity.this).toastIconSuccess("Ahora puedes descargar.");
2782 Log.e("value", "Permiso concedido, ahora puede usar la unidad local .");
2783 } else {
2784 Log.e("value", "Permiso denegado, no puede usar la unidad local .");
2785 }
2786 break;
2787 }
2788 }
2789
2790 public void downloadFile(String url) {
2791 String fileName = "";
2792 int notificationId = new Random().nextInt(100 - 1) - 1;
2793 Log.d("id:", notificationId + "");
2794
2795 if (url == null || url.isEmpty()) {
2796 return;
2797 }
2798
2799 if (type.equals("movie")) {
2800 fileName = tvName.getText().toString();
2801 } else {
2802 fileName = seriesTitle + "_" + season + "_" + episod;
2803 }
2804
2805 String path = Constants.getDownloadDir(DetailsActivity.this);
2806
2807 String fileExt = url.substring(url.lastIndexOf('.')); // output like .mkv
2808 fileName = fileName + fileExt;
2809
2810 fileName = fileName.replaceAll(" ", "_");
2811 fileName = fileName.replaceAll(":", "_");
2812
2813 File file = new File(path, "e_" + fileName); // e_ for encode
2814 if (file.exists()) {
2815 new ToastMsg(DetailsActivity.this).toastIconError(getString(R.string.file_already_downloaded));
2816 return;
2817 }
2818
2819 //download with workManager
2820 String dir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString();
2821 Data data = new Data.Builder()
2822 .putString("url", url)
2823 .putString("dir", dir)
2824 .putString("fileName", fileName)
2825 .build();
2826
2827 OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(DownloadWorkManager.class)
2828 .setInputData(data)
2829 .build();
2830
2831 String workId = request.getId().toString();
2832 Constants.workId = workId;
2833 WorkManager.getInstance().enqueue(request);
2834 }
2835
2836 public void hideExoControlForTv() {
2837 exoRewind.setVisibility(GONE);
2838 exoForward.setVisibility(GONE);
2839 liveTv.setVisibility(VISIBLE);
2840 seekbarLayout.setVisibility(GONE);
2841 }
2842
2843 public void showExoControlForTv() {
2844 exoRewind.setVisibility(VISIBLE);
2845 exoForward.setVisibility(VISIBLE);
2846 liveTv.setVisibility(GONE);
2847 seekbarLayout.setVisibility(VISIBLE);
2848 watchLiveTv.setVisibility(VISIBLE);
2849 liveTv.setVisibility(GONE);
2850 watchStatusTv.setText(getResources().getString(R.string.watching_catch_up_tv));
2851 }
2852
2853 private void getScreenSize() {
2854 display = getWindowManager().getDefaultDisplay();
2855 size = new Point();
2856 display.getSize(size);
2857 sWidth = size.x;
2858 sHeight = size.y;
2859 //Toast.makeText(this, "fjiaf", Toast.LENGTH_SHORT).show();
2860 }
2861
2862 public class RelativeLayoutTouchListener implements View.OnTouchListener {
2863 @Override
2864 public boolean onTouch(View v, MotionEvent event) {
2865 switch (event.getAction()) {
2866 case MotionEvent.ACTION_DOWN:
2867
2868 //touch is start
2869 downX = event.getX();
2870 downY = event.getY();
2871 if (event.getX() < (sWidth / 2)) {
2872
2873 //here check touch is screen left or right side
2874 intLeft = true;
2875 intRight = false;
2876
2877 } else if (event.getX() > (sWidth / 2)) {
2878
2879 //here check touch is screen left or right side
2880 intLeft = false;
2881 intRight = true;
2882 }
2883 break;
2884
2885 case MotionEvent.ACTION_UP:
2886
2887 case MotionEvent.ACTION_MOVE:
2888
2889 //finger move to screen
2890 float x2 = event.getX();
2891 float y2 = event.getY();
2892
2893 diffX = (long) (Math.ceil(event.getX() - downX));
2894 diffY = (long) (Math.ceil(event.getY() - downY));
2895
2896 if (Math.abs(diffY) > Math.abs(diffX)) {
2897 if (intLeft) {
2898 //if left its for brightness
2899
2900 if (downY < y2) {
2901 //down swipe brightness decrease
2902 } else if (downY > y2) {
2903 //up swipe brightness increase
2904 }
2905
2906 } else if (intRight) {
2907
2908 //if right its for audio
2909 if (downY < y2) {
2910 //down swipe volume decrease
2911 mAudioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);
2912
2913 } else if (downY > y2) {
2914 //up swipe volume increase
2915 mAudioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
2916 }
2917 }
2918 }
2919 }
2920 return true;
2921 }
2922
2923
2924 }
2925
2926 @Override
2927 public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
2928 super.onSaveInstanceState(outState, outPersistentState);
2929
2930 }
2931
2932 @Override
2933 protected void onRestoreInstanceState(Bundle savedInstanceState) {
2934 super.onRestoreInstanceState(savedInstanceState);
2935
2936 }
2937}