2016-08-02 21:17:54 +02:00
|
|
|
package org.schabi.newpipe.detail;
|
2015-09-04 02:15:03 +02:00
|
|
|
|
|
|
|
import android.content.Intent;
|
2016-02-01 09:59:28 +01:00
|
|
|
import android.media.AudioManager;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.os.Bundle;
|
2017-02-27 12:55:15 +01:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2015-11-29 13:06:27 +01:00
|
|
|
import android.util.Log;
|
2015-09-04 02:15:03 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
|
2016-08-02 21:17:54 +02:00
|
|
|
import org.schabi.newpipe.App;
|
|
|
|
import org.schabi.newpipe.R;
|
2017-02-18 21:59:48 +01:00
|
|
|
import org.schabi.newpipe.report.ErrorActivity;
|
|
|
|
import org.schabi.newpipe.util.NavStack;
|
2017-02-27 12:55:15 +01:00
|
|
|
import org.schabi.newpipe.util.ThemeHelper;
|
2015-11-17 00:32:00 +01:00
|
|
|
|
2015-09-04 02:15:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
2015-09-11 09:50:30 +02:00
|
|
|
* VideoItemDetailActivity.java is part of NewPipe.
|
2015-09-04 02:15:03 +02:00
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-02-27 12:55:15 +01:00
|
|
|
public class VideoItemDetailActivity extends AppCompatActivity {
|
2015-09-04 02:15:03 +02:00
|
|
|
private static final String TAG = VideoItemDetailActivity.class.toString();
|
|
|
|
|
2015-11-29 13:06:27 +01:00
|
|
|
private VideoItemDetailFragment fragment;
|
2015-10-29 17:56:35 +01:00
|
|
|
|
2015-09-04 02:15:03 +02:00
|
|
|
private String videoUrl;
|
|
|
|
private int currentStreamingService = -1;
|
|
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-02-27 12:55:15 +01:00
|
|
|
ThemeHelper.setTheme(this, true);
|
2015-09-04 02:15:03 +02:00
|
|
|
setContentView(R.layout.activity_videoitem_detail);
|
2016-01-29 15:46:57 +01:00
|
|
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
2015-09-04 02:15:03 +02:00
|
|
|
// Show the Up button in the action bar.
|
2015-11-29 13:06:27 +01:00
|
|
|
try {
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
} catch(Exception e) {
|
|
|
|
Log.d(TAG, "Could not get SupportActionBar");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-09-04 02:15:03 +02:00
|
|
|
|
|
|
|
// savedInstanceState is non-null when there is fragment state
|
|
|
|
// saved from previous configurations of this activity
|
|
|
|
// (e.g. when rotating the screen from portrait to landscape).
|
|
|
|
// In this case, the fragment will automatically be re-added
|
|
|
|
// to its container so we don't need to manually add it.
|
|
|
|
// For more information, see the Fragments API guide at:
|
|
|
|
//
|
|
|
|
// http://developer.android.com/guide/components/fragments.html
|
|
|
|
//
|
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
2016-09-28 06:09:42 +02:00
|
|
|
handleIntent(getIntent());
|
|
|
|
} else {
|
2017-02-18 21:59:48 +01:00
|
|
|
videoUrl = savedInstanceState.getString(NavStack.URL);
|
|
|
|
currentStreamingService = savedInstanceState.getInt(NavStack.SERVICE_ID);
|
2017-02-19 16:07:45 +01:00
|
|
|
NavStack.getInstance()
|
|
|
|
.restoreSavedInstanceState(savedInstanceState);
|
2016-09-28 06:09:42 +02:00
|
|
|
addFragment(savedInstanceState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
setIntent(intent);
|
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleIntent(Intent intent) {
|
|
|
|
Bundle arguments = new Bundle();
|
2016-12-25 19:28:40 +01:00
|
|
|
boolean autoplay = false;
|
2017-02-27 21:14:03 +01:00
|
|
|
|
|
|
|
videoUrl = intent.getStringExtra(NavStack.URL);
|
|
|
|
currentStreamingService = intent.getIntExtra(NavStack.SERVICE_ID, -1);
|
|
|
|
if(intent.hasExtra(VideoItemDetailFragment.AUTO_PLAY)) {
|
|
|
|
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY,
|
|
|
|
intent.getBooleanExtra(VideoItemDetailFragment.AUTO_PLAY, false));
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
2017-02-18 21:59:48 +01:00
|
|
|
arguments.putString(NavStack.URL, videoUrl);
|
|
|
|
arguments.putInt(NavStack.SERVICE_ID, currentStreamingService);
|
2016-09-28 06:09:42 +02:00
|
|
|
addFragment(arguments);
|
|
|
|
}
|
2015-10-29 17:56:35 +01:00
|
|
|
|
2016-09-28 06:09:42 +02:00
|
|
|
private void addFragment(final Bundle arguments) {
|
2015-10-29 17:56:35 +01:00
|
|
|
// Create the detail fragment and add it to the activity
|
|
|
|
// using a fragment transaction.
|
|
|
|
fragment = new VideoItemDetailFragment();
|
|
|
|
fragment.setArguments(arguments);
|
|
|
|
getSupportFragmentManager().beginTransaction()
|
2016-09-28 06:09:42 +02:00
|
|
|
.replace(R.id.videoitem_detail_container, fragment)
|
2015-10-29 17:56:35 +01:00
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
|
2016-01-01 23:04:29 +01:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
App.checkStartTor(this);
|
|
|
|
}
|
|
|
|
|
2015-10-29 17:56:35 +01:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
2017-01-16 16:06:54 +01:00
|
|
|
super.onSaveInstanceState(outState);
|
2017-02-18 21:59:48 +01:00
|
|
|
outState.putString(NavStack.URL, videoUrl);
|
|
|
|
outState.putInt(NavStack.SERVICE_ID, currentStreamingService);
|
2015-10-29 17:56:35 +01:00
|
|
|
outState.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
|
2017-02-19 16:07:45 +01:00
|
|
|
NavStack.getInstance()
|
|
|
|
.onSaveInstanceState(outState);
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2017-01-16 16:06:54 +01:00
|
|
|
super.onOptionsItemSelected(item);
|
2015-09-04 02:15:03 +02:00
|
|
|
int id = item.getItemId();
|
|
|
|
if (id == android.R.id.home) {
|
|
|
|
// This ID represents the Home or Up button. In the case of this
|
|
|
|
// activity, the Up button is shown. Use NavUtils to allow users
|
|
|
|
// to navigate up one level in the application structure. For
|
|
|
|
// more details, see the Navigation pattern on Android Design:
|
2015-11-02 16:03:11 +01:00
|
|
|
|
2015-09-04 02:15:03 +02:00
|
|
|
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
|
2015-11-02 16:03:11 +01:00
|
|
|
|
2017-02-19 16:07:45 +01:00
|
|
|
NavStack.getInstance()
|
|
|
|
.openMainActivity(this);
|
2015-09-04 02:15:03 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2017-01-19 19:38:33 +01:00
|
|
|
return super.onOptionsItemSelected(item);
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 21:59:48 +01:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
try {
|
|
|
|
NavStack.getInstance()
|
|
|
|
.navBack(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
ErrorActivity.reportUiError(this, e);
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 02:15:03 +02:00
|
|
|
}
|