ytdlnis/app/src/main/java/com/deniscerri/ytdl/App.java
Denis Çerri 709a3778a2
other new features
- check for updates when app launches
- remove scrollview so that recyclerview can recycle. It wont hide the top bar but thats a sacrifice for the greater good.
- remove download all mini card and made it into a floating action button
- made video loading from playlists as fast as possible even if you have thousands of videos in a list. It adds videos in recyclerview in a form of pagination
- fixed preferences when you just installed the app and you never opened the preference screen you can still download without erroring out
2022-09-18 00:27:36 +02:00

83 lines
2.8 KiB
Java

package com.deniscerri.ytdl;
import android.app.Application;
import android.os.Environment;
import android.provider.ContactsContract;
import android.util.Log;
import android.widget.Toast;
import androidx.preference.PreferenceManager;
import com.deniscerri.ytdl.util.NotificationUtil;
import com.deniscerri.ytdl.util.UpdateUtil;
import com.google.android.material.color.DynamicColors;
import com.yausername.ffmpeg.FFmpeg;
import com.yausername.youtubedl_android.YoutubeDL;
import com.yausername.youtubedl_android.YoutubeDLException;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.observers.DisposableCompletableObserver;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
public class App extends Application {
private static final String TAG = "App";
public static NotificationUtil notificationUtil;
@Override
public void onCreate() {
super.onCreate();
DynamicColors.applyToActivitiesIfAvailable(this);
notificationUtil = new NotificationUtil(this);
createNotificationChannels();
PreferenceManager.setDefaultValues(this, "root_preferences", this.MODE_PRIVATE, R.xml.root_preferences, false);
configureRxJavaErrorHandler();
Completable.fromAction(this::initLibraries).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
// it worked
}
@Override
public void onError(Throwable e) {
if(BuildConfig.DEBUG) Log.e(TAG, "failed to initialize youtubedl-android", e);
Toast.makeText(getApplicationContext(), "initialization failed: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void configureRxJavaErrorHandler() {
RxJavaPlugins.setErrorHandler(e -> {
if (e instanceof UndeliverableException) {
// As UndeliverableException is a wrapper, get the cause of it to get the "real" exception
e = e.getCause();
}
if (e instanceof InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
return;
}
Log.e(TAG, "Undeliverable exception received, not sure what to do", e);
});
}
private void initLibraries() throws YoutubeDLException {
YoutubeDL.getInstance().init(this);
FFmpeg.getInstance().init(this);
}
private void createNotificationChannels() {
notificationUtil.createNotificationChannel();
}
}