package de.danoeh.antennapod.activity;

import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ProgressBar;

import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Shows the AntennaPod logo while waiting for the main activity to start.
 */
public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        ProgressBar progressBar = findViewById(R.id.progressBar);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable());
            DrawableCompat.setTint(wrapDrawable, 0xffffffff);
            progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
        } else {
            progressBar.getIndeterminateDrawable().setColorFilter(0xffffffff, PorterDuff.Mode.SRC_IN);
        }

        Completable.create(subscriber -> {
            // Trigger schema updates
            PodDBAdapter.getInstance().open();
            PodDBAdapter.getInstance().close();
            subscriber.onComplete();
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(() -> {
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                    finish();
                }, error -> {
                        error.printStackTrace();
                        Toast.makeText(this, error.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                        finish();
                    });
    }
}

@@ -486,16 +486,69 @@
 dapter;%0A
+import de.danoeh.antennapod.error.CrashReportWriter;%0A
 import i
@@ -634,52 +634,8 @@
 rs;%0A
-import io.reactivex.disposables.Disposable;%0A
 impo
@@ -1851,16 +1851,37 @@
 ibe(
+%0A                    
 () -%3E %7B%0A
     
@@ -1872,24 +1872,28 @@
     () -%3E %7B%0A
+    
             
@@ -1989,16 +1989,20 @@
         
+    
 startAct
@@ -2016,16 +2016,20 @@
 ntent);%0A
+    
         
@@ -2073,16 +2073,20 @@
 (0, 0);%0A
+    
         
@@ -2123,16 +2123,20 @@
         
+    
 %7D, error
@@ -2186,24 +2186,80 @@
 ackTrace();%0A
+                        CrashReportWriter.write(error);%0A
             

Write to crash report file if app is unable to open