mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-09-20 11:20:52 +02:00
Compare commits
155 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2a45a13f73 | ||
![]() |
067b15c300 | ||
![]() |
8a1c283542 | ||
![]() |
93d1e8b2ff | ||
![]() |
c60d5b54fa | ||
![]() |
ef180f082e | ||
![]() |
f52741cc37 | ||
![]() |
2a2661f066 | ||
![]() |
b521903138 | ||
![]() |
acbd699d95 | ||
![]() |
6b8928becb | ||
![]() |
e393bdb1e5 | ||
![]() |
bba6b96765 | ||
![]() |
740116356c | ||
![]() |
2f6e4fa4a3 | ||
![]() |
fb3f6721b2 | ||
![]() |
4e7bd21e5c | ||
![]() |
219c2030b9 | ||
![]() |
b75fdb4566 | ||
![]() |
4584b14a31 | ||
![]() |
814ddb5932 | ||
![]() |
6ea0f6290a | ||
![]() |
c796fe1fe6 | ||
![]() |
a452a164e6 | ||
![]() |
0d9dd69b19 | ||
![]() |
d7b73c18f1 | ||
![]() |
07f66c0e45 | ||
![]() |
d449acbf86 | ||
![]() |
fce416ba76 | ||
![]() |
cb6bfe8556 | ||
![]() |
d7b31e1d25 | ||
![]() |
85057376d6 | ||
![]() |
c43ac7c869 | ||
![]() |
b2657315f1 | ||
![]() |
de5ed9717c | ||
![]() |
e17a6cbb9f | ||
![]() |
8e783b774b | ||
![]() |
733663f40d | ||
![]() |
4b2a792a62 | ||
![]() |
f7aa171d01 | ||
![]() |
5eafefb683 | ||
![]() |
5d1b02a856 | ||
![]() |
4acda3d9ae | ||
![]() |
643e10ace2 | ||
![]() |
7b64a232de | ||
![]() |
d7472d837d | ||
![]() |
94b473ab4b | ||
![]() |
4a05bbb6c8 | ||
![]() |
0343659b35 | ||
![]() |
f38eadbe30 | ||
![]() |
eb29a53ac5 | ||
![]() |
bc71e260e2 | ||
![]() |
ddf23a3443 | ||
![]() |
d41b248d1c | ||
![]() |
a025b25933 | ||
![]() |
c9a52a6088 | ||
![]() |
0276dca406 | ||
![]() |
3bb95ad44c | ||
![]() |
0a6572c282 | ||
![]() |
3937067be1 | ||
![]() |
48e4eb44f2 | ||
![]() |
c78cc6f2fd | ||
![]() |
73a71e0f5c | ||
![]() |
93605774f0 | ||
![]() |
2834e5d78f | ||
![]() |
dd467b4d63 | ||
![]() |
1fa541776b | ||
![]() |
f6f67c7b0a | ||
![]() |
9b3f19c19b | ||
![]() |
f4a9ec15e8 | ||
![]() |
006c4ecb02 | ||
![]() |
1c752b0e18 | ||
![]() |
f84aff63e3 | ||
![]() |
ae8121b680 | ||
![]() |
882fbf9275 | ||
![]() |
0a1743251e | ||
![]() |
3403a127c1 | ||
![]() |
9c5ca9f09d | ||
![]() |
73eea5608a | ||
![]() |
f48aeb91f4 | ||
![]() |
0bda964ece | ||
![]() |
14f5d54b50 | ||
![]() |
105ac2f6ff | ||
![]() |
160560f1fd | ||
![]() |
deeb667d6f | ||
![]() |
78123ff6f5 | ||
![]() |
9b1fdff22f | ||
![]() |
0275502796 | ||
![]() |
8af475e319 | ||
![]() |
2202c8f09e | ||
![]() |
adf309d3a8 | ||
![]() |
3071314586 | ||
![]() |
88e1df840d | ||
![]() |
23c1b66f6c | ||
![]() |
b0318a1cce | ||
![]() |
c130a66e4d | ||
![]() |
3386ba6d1b | ||
![]() |
9275569fa6 | ||
![]() |
2b23dfd0a6 | ||
![]() |
2a13d9990e | ||
![]() |
c9669b51c6 | ||
![]() |
486c180b3c | ||
![]() |
9eb5bf9b87 | ||
![]() |
953a89f3a1 | ||
![]() |
d638fa1434 | ||
![]() |
e6d700288c | ||
![]() |
371f14cdc9 | ||
![]() |
0733ae2404 | ||
![]() |
b1731ebd49 | ||
![]() |
342b3191ac | ||
![]() |
cd39445245 | ||
![]() |
92eac67367 | ||
![]() |
0e31a0c704 | ||
![]() |
d60c117a70 | ||
![]() |
69ccad5998 | ||
![]() |
b6d22320e6 | ||
![]() |
d3bf948dba | ||
![]() |
5de3d96b31 | ||
![]() |
d30dd64322 | ||
![]() |
386df10a5a | ||
![]() |
af147de547 | ||
![]() |
23cd0e5a5e | ||
![]() |
c5a566657c | ||
![]() |
ce2018c864 | ||
![]() |
472ab46af2 | ||
![]() |
7f87d45bb5 | ||
![]() |
e9f7ab18bb | ||
![]() |
fba83a8afe | ||
![]() |
05089abddc | ||
![]() |
ccd70aac51 | ||
![]() |
5df8445d04 | ||
![]() |
8c43674fa4 | ||
![]() |
f162316a6b | ||
![]() |
670596ed88 | ||
![]() |
6b3eb716c4 | ||
![]() |
6a5180d94c | ||
![]() |
83faaedfcc | ||
![]() |
d98d790a7a | ||
![]() |
36b5833a3a | ||
![]() |
5e86781a79 | ||
![]() |
6a780504b4 | ||
![]() |
a0d8212136 | ||
![]() |
0e1e6a9d62 | ||
![]() |
812282a332 | ||
![]() |
a8a4c9e97f | ||
![]() |
24c293e335 | ||
![]() |
0a596df497 | ||
![]() |
3d66c6572b | ||
![]() |
f45769cbb2 | ||
![]() |
ef51f93c6f | ||
![]() |
35af68f148 | ||
![]() |
646fa877ba | ||
![]() |
d1b0cd74be | ||
![]() |
dcdb2c323e | ||
![]() |
d9e616beee |
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -28,7 +28,7 @@ Do not report crashes in the GitHub issue tracker. NewPipe has an automated cras
|
||||
* Stick to NewPipe's style conventions (well, just look the other code and then do it the same way :))
|
||||
* Do not bring non-free software (e.g., binary blobs) into the project. Also, make sure you do not introduce Google libraries.
|
||||
* Stick to [F-Droid contribution guidelines](https://f-droid.org/wiki/page/Inclusion_Policy)
|
||||
* Make changes on a separate branch, not on the master branch. This is commonly known as *feature branch workflow*. You may then send your changes as a pull request on GitHub. Patches to the email address mentioned in this document might not be considered, GitHub is the primary platform.
|
||||
* Make changes on a separate branch, not on the master branch. This is commonly known as *feature branch workflow*. You may then send your changes as a pull request on GitHub. Patches to the email address mentioned in this document might not be considered, GitHub is the primary platform. (This only affects you if you are a member of TeamNewPipe)
|
||||
* When submitting changes, you confirm that your code is licensed under the terms of the [GNU General Public License v3](https://www.gnu.org/licenses/gpl-3.0.html).
|
||||
* Please test (compile and run) your code before you submit changes! Ideally, provide test feedback in the PR description. Untested code will **not** be merged!
|
||||
* Try to figure out yourself why builds on our CI fail.
|
||||
|
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "org.schabi.newpipe"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 27
|
||||
versionCode 62
|
||||
versionName "0.13.3"
|
||||
versionCode 64
|
||||
versionName "0.13.5"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
6
app/proguard-rules.pro
vendored
6
app/proguard-rules.pro
vendored
@@ -42,3 +42,9 @@
|
||||
-dontwarn javax.annotation.**
|
||||
# A resource is loaded with a relative path so the package of this class must be preserved.
|
||||
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
|
||||
-keepclassmembers class * implements java.io.Serializable {
|
||||
static final long serialVersionUID;
|
||||
!static !transient <fields>;
|
||||
private void writeObject(java.io.ObjectOutputStream);
|
||||
private void readObject(java.io.ObjectInputStream);
|
||||
}
|
||||
|
@@ -128,47 +128,31 @@ public class AboutActivity extends AppCompatActivity {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
Context context = this.getContext();
|
||||
|
||||
TextView version = rootView.findViewById(R.id.app_version);
|
||||
version.setText(BuildConfig.VERSION_NAME);
|
||||
|
||||
View githubLink = rootView.findViewById(R.id.github_link);
|
||||
githubLink.setOnClickListener(new OnGithubLinkClickListener());
|
||||
githubLink.setOnClickListener(nv -> openWebsite(context.getString(R.string.github_url), context));
|
||||
|
||||
View donationLink = rootView.findViewById(R.id.donation_link);
|
||||
donationLink.setOnClickListener(new OnDonationLinkClickListener());
|
||||
donationLink.setOnClickListener(v -> openWebsite(context.getString(R.string.donation_url), context));
|
||||
|
||||
View websiteLink = rootView.findViewById(R.id.website_link);
|
||||
websiteLink.setOnClickListener(new OnWebsiteLinkClickListener());
|
||||
websiteLink.setOnClickListener(nv -> openWebsite(context.getString(R.string.website_url), context));
|
||||
|
||||
View privacyPolicyLink = rootView.findViewById(R.id.privacy_policy_link);
|
||||
privacyPolicyLink.setOnClickListener(v -> openWebsite(context.getString(R.string.privacy_policy_url), context));
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private static class OnGithubLinkClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
final Context context = view.getContext();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.github_url)));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
private void openWebsite(String url, Context context) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
private static class OnDonationLinkClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
final Context context = view.getContext();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.donation_url)));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private static class OnWebsiteLinkClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
final Context context = view.getContext();
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.website_url)));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package org.schabi.newpipe.about;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@@ -39,7 +40,7 @@ public class LicenseFragment extends Fragment {
|
||||
* @param license the license to show
|
||||
*/
|
||||
public static void showLicense(Context context, License license) {
|
||||
new LicenseFragmentHelper().execute(context, license);
|
||||
new LicenseFragmentHelper((Activity) context).execute(license);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,8 +1,11 @@
|
||||
package org.schabi.newpipe.about;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.webkit.WebView;
|
||||
import org.schabi.newpipe.R;
|
||||
@@ -10,26 +13,46 @@ import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class LicenseFragmentHelper extends AsyncTask<Object, Void, Integer> {
|
||||
|
||||
private Context context;
|
||||
WeakReference<Activity> weakReference;
|
||||
private License license;
|
||||
|
||||
public LicenseFragmentHelper(@Nullable Activity activity) {
|
||||
weakReference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Activity getActivity() {
|
||||
Activity activity = weakReference.get();
|
||||
|
||||
if (activity != null && activity.isFinishing()) {
|
||||
return null;
|
||||
} else {
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Object... objects) {
|
||||
context = (Context) objects[0];
|
||||
license = (License) objects[1];
|
||||
license = (License) objects[0];
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer result){
|
||||
String webViewData = getFormattedLicense(context, license);
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
||||
protected void onPostExecute(Integer result) {
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String webViewData = getFormattedLicense(activity, license);
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
|
||||
alert.setTitle(license.getName());
|
||||
|
||||
WebView wv = new WebView(context);
|
||||
WebView wv = new WebView(activity);
|
||||
wv.loadData(webViewData, "text/html; charset=UTF-8", null);
|
||||
|
||||
alert.setView(wv);
|
||||
|
@@ -77,8 +77,7 @@ public class KioskFragment extends BaseListInfoFragment<KioskInfo> {
|
||||
UrlIdHandler kioskTypeUrlIdHandler = service.getKioskList()
|
||||
.getUrlIdHandlerByType(kioskId);
|
||||
instance.setInitialData(serviceId,
|
||||
kioskTypeUrlIdHandler.getUrl(kioskId),
|
||||
kioskId);
|
||||
kioskTypeUrlIdHandler.getUrl(kioskId), kioskId);
|
||||
instance.kioskId = kioskId;
|
||||
return instance;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import org.schabi.newpipe.info_list.holder.PlaylistInfoItemHolder;
|
||||
import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder;
|
||||
import org.schabi.newpipe.info_list.holder.StreamInfoItemHolder;
|
||||
import org.schabi.newpipe.info_list.holder.StreamMiniInfoItemHolder;
|
||||
import org.schabi.newpipe.util.FallbackViewHolder;
|
||||
import org.schabi.newpipe.util.OnClickGesture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -238,7 +239,7 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
||||
return new PlaylistInfoItemHolder(infoItemBuilder, parent);
|
||||
default:
|
||||
Log.e(TAG, "Trollolo");
|
||||
return null;
|
||||
return new FallbackViewHolder(new View(parent.getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@ import org.schabi.newpipe.local.holder.LocalPlaylistItemHolder;
|
||||
import org.schabi.newpipe.local.holder.LocalPlaylistStreamItemHolder;
|
||||
import org.schabi.newpipe.local.holder.LocalStatisticStreamItemHolder;
|
||||
import org.schabi.newpipe.local.holder.RemotePlaylistItemHolder;
|
||||
import org.schabi.newpipe.util.FallbackViewHolder;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
import org.schabi.newpipe.util.OnClickGesture;
|
||||
|
||||
@@ -225,7 +226,7 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
return new LocalStatisticStreamItemHolder(localItemBuilder, parent);
|
||||
default:
|
||||
Log.e(TAG, "No view type has been considered for holder: [" + type + "]");
|
||||
return null;
|
||||
return new FallbackViewHolder(new View(parent.getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -271,6 +271,7 @@ public abstract class BasePlayer implements
|
||||
if (audioReactor != null) audioReactor.dispose();
|
||||
if (playbackManager != null) playbackManager.dispose();
|
||||
if (databaseUpdateReactor != null) databaseUpdateReactor.dispose();
|
||||
if (mediaSessionManager != null) mediaSessionManager.dispose();
|
||||
|
||||
if (playQueueAdapter != null) {
|
||||
playQueueAdapter.unsetSelectedListener();
|
||||
|
@@ -25,6 +25,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -114,9 +115,14 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||
if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
|
||||
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
ThemeHelper.setTheme(this);
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.BLACK);
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
WindowManager.LayoutParams lp = getWindow().getAttributes();
|
||||
lp.screenBrightness = PlayerHelper.getScreenBrightness(getApplicationContext());
|
||||
getWindow().setAttributes(lp);
|
||||
|
||||
hideSystemUi();
|
||||
setContentView(R.layout.activity_main_player);
|
||||
playerImpl = new VideoPlayerImpl(this);
|
||||
@@ -203,6 +209,9 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||
if (DEBUG) Log.d(TAG, "onStop() called");
|
||||
super.onStop();
|
||||
playerImpl.destroy();
|
||||
|
||||
PlayerHelper.setScreenBrightness(getApplicationContext(),
|
||||
getWindow().getAttributes().screenBrightness);
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
@@ -645,7 +654,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||
@Override
|
||||
protected int getOverrideResolutionIndex(final List<VideoStream> sortedVideos,
|
||||
final String playbackQuality) {
|
||||
return ListHelper.getDefaultResolutionIndex(context, sortedVideos, playbackQuality);
|
||||
return ListHelper.getResolutionIndex(context, sortedVideos, playbackQuality);
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
@@ -882,7 +891,9 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||
private final boolean isPlayerGestureEnabled = PlayerHelper.isPlayerGestureEnabled(getApplicationContext());
|
||||
|
||||
private final float stepsBrightness = 15, stepBrightness = (1f / stepsBrightness), minBrightness = .01f;
|
||||
private float currentBrightness = .5f;
|
||||
private float currentBrightness = getWindow().getAttributes().screenBrightness > 0
|
||||
? getWindow().getAttributes().screenBrightness
|
||||
: 0.5f;
|
||||
|
||||
private int currentVolume, maxVolume = playerImpl.getAudioReactor().getMaxVolume();
|
||||
private final float stepsVolume = 15, stepVolume = (float) Math.ceil(maxVolume / stepsVolume), minVolume = 0;
|
||||
|
@@ -517,7 +517,7 @@ public final class PopupVideoPlayer extends Service {
|
||||
@Override
|
||||
protected int getOverrideResolutionIndex(final List<VideoStream> sortedVideos,
|
||||
final String playbackQuality) {
|
||||
return ListHelper.getPopupDefaultResolutionIndex(context, sortedVideos, playbackQuality);
|
||||
return ListHelper.getPopupResolutionIndex(context, sortedVideos, playbackQuality);
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -11,7 +11,6 @@ import android.view.KeyEvent;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
||||
|
||||
import org.schabi.newpipe.player.mediasession.DummyPlaybackPreparer;
|
||||
import org.schabi.newpipe.player.mediasession.MediaSessionCallback;
|
||||
import org.schabi.newpipe.player.mediasession.PlayQueueNavigator;
|
||||
import org.schabi.newpipe.player.mediasession.PlayQueuePlaybackController;
|
||||
@@ -26,10 +25,12 @@ public class MediaSessionManager {
|
||||
@NonNull final Player player,
|
||||
@NonNull final MediaSessionCallback callback) {
|
||||
this.mediaSession = new MediaSessionCompat(context, TAG);
|
||||
this.mediaSession.setActive(true);
|
||||
|
||||
this.sessionConnector = new MediaSessionConnector(mediaSession,
|
||||
new PlayQueuePlaybackController(callback));
|
||||
this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback));
|
||||
this.sessionConnector.setPlayer(player, new DummyPlaybackPreparer());
|
||||
this.sessionConnector.setPlayer(player, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -37,4 +38,11 @@ public class MediaSessionManager {
|
||||
public KeyEvent handleMediaButtonIntent(final Intent intent) {
|
||||
return MediaButtonReceiver.handleIntent(mediaSession, intent);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
this.sessionConnector.setPlayer(null, null);
|
||||
this.sessionConnector.setQueueNavigator(null);
|
||||
this.mediaSession.setActive(false);
|
||||
this.mediaSession.release();
|
||||
}
|
||||
}
|
||||
|
@@ -9,9 +9,9 @@ import android.support.annotation.Nullable;
|
||||
import android.view.accessibility.CaptioningManager;
|
||||
|
||||
import com.google.android.exoplayer2.SeekParameters;
|
||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
||||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
@@ -37,6 +37,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FILL;
|
||||
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIT;
|
||||
@@ -260,6 +261,16 @@ public class PlayerHelper {
|
||||
|
||||
return captioningManager.getFontScale();
|
||||
}
|
||||
|
||||
public static float getScreenBrightness(@NonNull final Context context) {
|
||||
//a value of less than 0, the default, means to use the preferred screen brightness
|
||||
return getScreenBrightness(context, -1);
|
||||
}
|
||||
|
||||
public static void setScreenBrightness(@NonNull final Context context, final float setScreenBrightness) {
|
||||
setScreenBrightness(context, setScreenBrightness, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Private helpers
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@@ -292,4 +303,23 @@ public class PlayerHelper {
|
||||
private static boolean isAutoQueueEnabled(@NonNull final Context context, final boolean b) {
|
||||
return getPreferences(context).getBoolean(context.getString(R.string.auto_queue_key), b);
|
||||
}
|
||||
|
||||
private static void setScreenBrightness(@NonNull final Context context, final float screenBrightness, final long timestamp) {
|
||||
SharedPreferences.Editor editor = getPreferences(context).edit();
|
||||
editor.putFloat(context.getString(R.string.screen_brightness_key), screenBrightness);
|
||||
editor.putLong(context.getString(R.string.screen_brightness_timestamp_key), timestamp);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private static float getScreenBrightness(@NonNull final Context context, final float screenBrightness) {
|
||||
SharedPreferences sp = getPreferences(context);
|
||||
long timestamp = sp.getLong(context.getString(R.string.screen_brightness_timestamp_key), 0);
|
||||
// hypothesis: 4h covers a viewing block, eg evening. External lightning conditions will change in the next
|
||||
// viewing block so we fall back to the default brightness
|
||||
if ((System.currentTimeMillis() - timestamp) > TimeUnit.HOURS.toMillis(4)) {
|
||||
return screenBrightness;
|
||||
} else {
|
||||
return sp.getFloat(context.getString(R.string.screen_brightness_key), screenBrightness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,45 +0,0 @@
|
||||
package org.schabi.newpipe.player.mediasession;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.ResultReceiver;
|
||||
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
||||
|
||||
public class DummyPlaybackPreparer implements MediaSessionConnector.PlaybackPreparer {
|
||||
@Override
|
||||
public long getSupportedPrepareActions() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepare() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareFromMediaId(String mediaId, Bundle extras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareFromSearch(String query, Bundle extras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareFromUri(Uri uri, Bundle extras) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCommands() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(Player player, String command, Bundle extras, ResultReceiver cb) {
|
||||
|
||||
}
|
||||
}
|
@@ -13,5 +13,4 @@ public interface MediaSessionCallback {
|
||||
|
||||
void onPlay();
|
||||
void onPause();
|
||||
void onSetShuffle(final boolean isShuffled);
|
||||
}
|
||||
|
@@ -1,7 +1,5 @@
|
||||
package org.schabi.newpipe.player.mediasession;
|
||||
|
||||
import android.support.v4.media.session.PlaybackStateCompat;
|
||||
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.ext.mediasession.DefaultPlaybackController;
|
||||
|
||||
@@ -22,10 +20,4 @@ public class PlayQueuePlaybackController extends DefaultPlaybackController {
|
||||
public void onPause(Player player) {
|
||||
callback.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetShuffleMode(Player player, int shuffleMode) {
|
||||
callback.onSetShuffle(shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_ALL
|
||||
|| shuffleMode == PlaybackStateCompat.SHUFFLE_MODE_GROUP);
|
||||
}
|
||||
}
|
||||
|
@@ -69,9 +69,4 @@ public class BasePlayerMediaSession implements MediaSessionCallback {
|
||||
public void onPause() {
|
||||
player.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetShuffle(boolean isShuffled) {
|
||||
player.onShuffleModeEnabledChanged(isShuffled);
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import org.schabi.newpipe.player.playqueue.events.MoveEvent;
|
||||
import org.schabi.newpipe.player.playqueue.events.PlayQueueEvent;
|
||||
import org.schabi.newpipe.player.playqueue.events.RemoveEvent;
|
||||
import org.schabi.newpipe.player.playqueue.events.SelectEvent;
|
||||
import org.schabi.newpipe.util.FallbackViewHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -188,7 +189,7 @@ public class PlayQueueAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||
return new PlayQueueItemHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.play_queue_item, parent, false));
|
||||
default:
|
||||
Log.e(TAG, "Attempting to create view holder with undefined type: " + type);
|
||||
return null;
|
||||
return new FallbackViewHolder(new View(parent.getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package org.schabi.newpipe.report;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
@@ -33,10 +35,8 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.schabi.newpipe.ActivityCommunicator;
|
||||
import org.schabi.newpipe.BuildConfig;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.MainActivity;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.utils.Parser;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
@@ -44,9 +44,9 @@ import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/*
|
||||
* Created by Christian Schabesberger on 24.10.15.
|
||||
@@ -210,12 +210,31 @@ public class ErrorActivity extends AppCompatActivity {
|
||||
currentTimeStamp = getCurrentTimeStamp();
|
||||
|
||||
reportButton.setOnClickListener((View v) -> {
|
||||
Intent i = new Intent(Intent.ACTION_SENDTO);
|
||||
i.setData(Uri.parse("mailto:" + ERROR_EMAIL_ADDRESS))
|
||||
.putExtra(Intent.EXTRA_SUBJECT, ERROR_EMAIL_SUBJECT)
|
||||
.putExtra(Intent.EXTRA_TEXT, buildJson());
|
||||
Context context = this;
|
||||
new AlertDialog.Builder(context)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setTitle(R.string.privacy_policy_title)
|
||||
.setMessage(R.string.start_accept_privacy_policy)
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(R.string.read_privacy_policy, (dialog, which) -> {
|
||||
Intent webIntent = new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse(context.getString(R.string.privacy_policy_url))
|
||||
);
|
||||
context.startActivity(webIntent);
|
||||
})
|
||||
.setPositiveButton(R.string.accept, (dialog, which) -> {
|
||||
Intent i = new Intent(Intent.ACTION_SENDTO);
|
||||
i.setData(Uri.parse("mailto:" + ERROR_EMAIL_ADDRESS))
|
||||
.putExtra(Intent.EXTRA_SUBJECT, ERROR_EMAIL_SUBJECT)
|
||||
.putExtra(Intent.EXTRA_TEXT, buildJson());
|
||||
|
||||
startActivity(Intent.createChooser(i, "Send Email"));
|
||||
})
|
||||
.setNegativeButton(R.string.decline, (dialog, which) -> {
|
||||
// do nothing
|
||||
})
|
||||
.show();
|
||||
|
||||
startActivity(Intent.createChooser(i, "Send Email"));
|
||||
});
|
||||
|
||||
// normal bugreport
|
||||
|
@@ -4,7 +4,9 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
@@ -30,15 +32,21 @@ import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
|
||||
private static final int REQUEST_IMPORT_PATH = 8945;
|
||||
@@ -48,6 +56,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
private File databasesDir;
|
||||
private File newpipe_db;
|
||||
private File newpipe_db_journal;
|
||||
private File newpipe_settings;
|
||||
|
||||
private String thumbnailLoadToggleKey;
|
||||
|
||||
@@ -79,6 +88,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
databasesDir = new File(homeDir + "/databases");
|
||||
newpipe_db = new File(homeDir + "/databases/newpipe.db");
|
||||
newpipe_db_journal = new File(homeDir + "/databases/newpipe.db-journal");
|
||||
newpipe_settings = new File(homeDir + "/databases/newpipe.settings");
|
||||
newpipe_settings.delete();
|
||||
|
||||
addPreferencesFromResource(R.xml.content_settings);
|
||||
|
||||
@@ -174,19 +185,19 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
|
||||
if ((requestCode == REQUEST_IMPORT_PATH || requestCode == REQUEST_EXPORT_PATH)
|
||||
&& resultCode == Activity.RESULT_OK && data.getData() != null) {
|
||||
String path = Utils.getFileForUri(data.getData()).getAbsolutePath();
|
||||
if (requestCode == REQUEST_EXPORT_PATH) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
|
||||
exportDatabase(path + "/NewPipeData-" + sdf.format(new Date()) + ".zip");
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(R.string.override_current_data)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
(DialogInterface d, int id) -> importDatabase(path))
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
(DialogInterface d, int id) -> d.cancel());
|
||||
builder.create().show();
|
||||
}
|
||||
String path = Utils.getFileForUri(data.getData()).getAbsolutePath();
|
||||
if (requestCode == REQUEST_EXPORT_PATH) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
|
||||
exportDatabase(path + "/NewPipeData-" + sdf.format(new Date()) + ".zip");
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(R.string.override_current_data)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
(DialogInterface d, int id) -> importDatabase(path))
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
(DialogInterface d, int id) -> d.cancel());
|
||||
builder.create().show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +208,8 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
new FileOutputStream(path)));
|
||||
ZipHelper.addFileToZip(outZip, newpipe_db.getPath(), "newpipe.db");
|
||||
ZipHelper.addFileToZip(outZip, newpipe_db_journal.getPath(), "newpipe.db-journal");
|
||||
saveSharedPreferencesToFile(newpipe_settings);
|
||||
ZipHelper.addFileToZip(outZip, newpipe_settings.getPath(), "newpipe.settings");
|
||||
|
||||
outZip.close();
|
||||
|
||||
@@ -207,6 +220,29 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSharedPreferencesToFile(File dst) {
|
||||
ObjectOutputStream output = null;
|
||||
try {
|
||||
output = new ObjectOutputStream(new FileOutputStream(dst));
|
||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
output.writeObject(pref.getAll());
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (output != null) {
|
||||
output.flush();
|
||||
output.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void importDatabase(String filePath) {
|
||||
// check if file is supported
|
||||
ZipFile zipFile = null;
|
||||
@@ -223,30 +259,83 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
}
|
||||
|
||||
try {
|
||||
ZipInputStream zipIn = new ZipInputStream(
|
||||
new BufferedInputStream(
|
||||
new FileInputStream(filePath)));
|
||||
|
||||
if (!databasesDir.exists() && !databasesDir.mkdir()) {
|
||||
throw new Exception("Could not create databases dir");
|
||||
}
|
||||
|
||||
if(!(ZipHelper.extractFileFromZip(zipIn, newpipe_db.getPath(), "newpipe.db")
|
||||
&& ZipHelper.extractFileFromZip(zipIn, newpipe_db_journal.getPath(), "newpipe.db-journal"))) {
|
||||
Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
if(!(ZipHelper.extractFileFromZip(filePath, newpipe_db.getPath(), "newpipe.db")
|
||||
&& ZipHelper.extractFileFromZip(filePath, newpipe_db_journal.getPath(), "newpipe.db-journal"))) {
|
||||
Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
|
||||
zipIn.close();
|
||||
//If settings file exist, ask if it should be imported.
|
||||
if(ZipHelper.extractFileFromZip(filePath, newpipe_settings.getPath(), "newpipe.settings")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
|
||||
alert.setTitle(R.string.import_settings);
|
||||
|
||||
alert.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
// restart app to properly load db
|
||||
System.exit(0);
|
||||
});
|
||||
alert.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
loadSharedPreferences(newpipe_settings);
|
||||
// restart app to properly load db
|
||||
System.exit(0);
|
||||
});
|
||||
alert.show();
|
||||
} else {
|
||||
// restart app to properly load db
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// restart app to properly load db
|
||||
//App.restart(getContext());
|
||||
System.exit(0);
|
||||
} catch (Exception e) {
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSharedPreferences(File src) {
|
||||
ObjectInputStream input = null;
|
||||
try {
|
||||
input = new ObjectInputStream(new FileInputStream(src));
|
||||
SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
|
||||
prefEdit.clear();
|
||||
Map<String, ?> entries = (Map<String, ?>) input.readObject();
|
||||
for (Map.Entry<String, ?> entry : entries.entrySet()) {
|
||||
Object v = entry.getValue();
|
||||
String key = entry.getKey();
|
||||
|
||||
if (v instanceof Boolean)
|
||||
prefEdit.putBoolean(key, ((Boolean) v).booleanValue());
|
||||
else if (v instanceof Float)
|
||||
prefEdit.putFloat(key, ((Float) v).floatValue());
|
||||
else if (v instanceof Integer)
|
||||
prefEdit.putInt(key, ((Integer) v).intValue());
|
||||
else if (v instanceof Long)
|
||||
prefEdit.putLong(key, ((Long) v).longValue());
|
||||
else if (v instanceof String)
|
||||
prefEdit.putString(key, ((String) v));
|
||||
}
|
||||
prefEdit.commit();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (input != null) {
|
||||
input.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@@ -159,7 +159,7 @@ public class SelectChannelFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable exception) {
|
||||
onError(exception);
|
||||
SelectChannelFragment.this.onError(exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
public class FallbackViewHolder extends RecyclerView.ViewHolder {
|
||||
public FallbackViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -62,7 +62,12 @@ public class ZipHelper {
|
||||
* @return will return true if the file was found within the zip file
|
||||
* @throws Exception
|
||||
*/
|
||||
public static boolean extractFileFromZip(ZipInputStream inZip, String file, String name) throws Exception {
|
||||
public static boolean extractFileFromZip(String filePath, String file, String name) throws Exception {
|
||||
|
||||
ZipInputStream inZip = new ZipInputStream(
|
||||
new BufferedInputStream(
|
||||
new FileInputStream(filePath)));
|
||||
|
||||
byte data[] = new byte[BUFFER_SIZE];
|
||||
|
||||
boolean found = false;
|
||||
@@ -89,6 +94,6 @@ public class ZipHelper {
|
||||
inZip.closeEntry();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
@@ -312,6 +313,13 @@ public class DownloadMission implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream inputStream)
|
||||
throws java.io.IOException, ClassNotFoundException
|
||||
{
|
||||
inputStream.defaultReadObject();
|
||||
mListeners = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void deleteThisFromFile() {
|
||||
new File(getMetaFilename()).delete();
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package us.shandian.giga.get;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -104,11 +103,11 @@ public class DownloadRunnable implements Runnable {
|
||||
|
||||
RandomAccessFile f = new RandomAccessFile(mMission.location + "/" + mMission.name, "rw");
|
||||
f.seek(start);
|
||||
BufferedInputStream ipt = new BufferedInputStream(conn.getInputStream());
|
||||
byte[] buf = new byte[512];
|
||||
java.io.InputStream ipt = conn.getInputStream();
|
||||
byte[] buf = new byte[64*1024];
|
||||
|
||||
while (start < end && mMission.running) {
|
||||
int len = ipt.read(buf, 0, 512);
|
||||
int len = ipt.read(buf, 0, buf.length);
|
||||
|
||||
if (len == -1) {
|
||||
break;
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package us.shandian.giga.ui.adapter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -24,6 +27,7 @@ import android.widget.Toast;
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -46,13 +50,13 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||
ALGORITHMS.put(R.id.sha1, "SHA1");
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private Activity mContext;
|
||||
private LayoutInflater mInflater;
|
||||
private DownloadManager mManager;
|
||||
private DownloadManagerService.DMBinder mBinder;
|
||||
private int mLayout;
|
||||
|
||||
public MissionAdapter(Context context, DownloadManagerService.DMBinder binder, DownloadManager manager, boolean isLinear) {
|
||||
public MissionAdapter(Activity context, DownloadManagerService.DMBinder binder, DownloadManager manager, boolean isLinear) {
|
||||
mContext = context;
|
||||
mManager = manager;
|
||||
mBinder = binder;
|
||||
@@ -247,7 +251,7 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||
case R.id.md5:
|
||||
case R.id.sha1:
|
||||
DownloadMission mission = mManager.getMission(h.position);
|
||||
new ChecksumTask().execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
|
||||
new ChecksumTask(mContext).execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -352,18 +356,26 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||
|
||||
}
|
||||
|
||||
private class ChecksumTask extends AsyncTask<String, Void, String> {
|
||||
private static class ChecksumTask extends AsyncTask<String, Void, String> {
|
||||
ProgressDialog prog;
|
||||
WeakReference<Activity> weakReference;
|
||||
|
||||
ChecksumTask(@NonNull Activity activity) {
|
||||
weakReference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
// Create dialog
|
||||
prog = new ProgressDialog(mContext);
|
||||
prog.setCancelable(false);
|
||||
prog.setMessage(mContext.getString(R.string.msg_wait));
|
||||
prog.show();
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
// Create dialog
|
||||
prog = new ProgressDialog(activity);
|
||||
prog.setCancelable(false);
|
||||
prog.setMessage(activity.getString(R.string.msg_wait));
|
||||
prog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -374,8 +386,24 @@ public class MissionAdapter extends RecyclerView.Adapter<MissionAdapter.ViewHold
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
super.onPostExecute(result);
|
||||
prog.dismiss();
|
||||
Utility.copyToClipboard(mContext, result);
|
||||
|
||||
if (prog != null) {
|
||||
Utility.copyToClipboard(prog.getContext(), result);
|
||||
if (getActivity() != null) {
|
||||
prog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Activity getActivity() {
|
||||
Activity activity = weakReference.get();
|
||||
|
||||
if (activity != null && activity.isFinishing()) {
|
||||
return null;
|
||||
} else {
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -129,7 +129,7 @@ public abstract class MissionsFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void updateList() {
|
||||
mAdapter = new MissionAdapter(mActivity, mBinder, mManager, mLinear);
|
||||
mAdapter = new MissionAdapter((Activity) mActivity, mBinder, mManager, mLinear);
|
||||
|
||||
if (mLinear) {
|
||||
mList.setLayoutManager(mLinearManager);
|
||||
|
@@ -12,6 +12,7 @@ import android.widget.Toast;
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -59,17 +60,17 @@ public class Utility {
|
||||
ObjectOutputStream objectOutputStream = null;
|
||||
|
||||
try {
|
||||
objectOutputStream = new ObjectOutputStream(new FileOutputStream(fileName));
|
||||
objectOutputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
|
||||
objectOutputStream.writeObject(serializable);
|
||||
} catch (Exception e) {
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
if(objectOutputStream != null) {
|
||||
try {
|
||||
objectOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
//nothing to do
|
||||
} finally {
|
||||
if(objectOutputStream != null) {
|
||||
try {
|
||||
objectOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
//nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="@android:color/black"
|
||||
android:gravity="center">
|
||||
|
||||
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||
|
@@ -49,7 +49,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/separator"
|
||||
android:background="?android:windowBackground"
|
||||
android:scrollbars="vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user