mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Fix crash on startup without internet: Cbservable callable returning null
Use Maybe instead
This commit is contained in:
		| @@ -8,6 +8,7 @@ import android.os.Build; | |||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  |  | ||||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||||
|  | import androidx.annotation.Nullable; | ||||||
| import androidx.multidex.MultiDexApplication; | import androidx.multidex.MultiDexApplication; | ||||||
| import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||||
|  |  | ||||||
| @@ -67,7 +68,7 @@ public class App extends MultiDexApplication { | |||||||
|     protected static final String TAG = App.class.toString(); |     protected static final String TAG = App.class.toString(); | ||||||
|     private static App app; |     private static App app; | ||||||
|  |  | ||||||
|     private Disposable disposable = null; |     @Nullable private Disposable disposable = null; | ||||||
|  |  | ||||||
|     @NonNull |     @NonNull | ||||||
|     public static App getApp() { |     public static App getApp() { | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ import android.net.Uri; | |||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  |  | ||||||
| import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||||
|  | import androidx.annotation.Nullable; | ||||||
| import androidx.core.app.NotificationCompat; | import androidx.core.app.NotificationCompat; | ||||||
| import androidx.core.app.NotificationManagerCompat; | import androidx.core.app.NotificationManagerCompat; | ||||||
| import androidx.core.content.ContextCompat; | import androidx.core.content.ContextCompat; | ||||||
| @@ -36,10 +37,9 @@ import java.security.cert.CertificateException; | |||||||
| import java.security.cert.CertificateFactory; | import java.security.cert.CertificateFactory; | ||||||
| import java.security.cert.X509Certificate; | import java.security.cert.X509Certificate; | ||||||
|  |  | ||||||
| import io.reactivex.Observable; | import io.reactivex.Maybe; | ||||||
| import io.reactivex.android.schedulers.AndroidSchedulers; | import io.reactivex.android.schedulers.AndroidSchedulers; | ||||||
| import io.reactivex.disposables.Disposable; | import io.reactivex.disposables.Disposable; | ||||||
| import io.reactivex.disposables.Disposables; |  | ||||||
| import io.reactivex.schedulers.Schedulers; | import io.reactivex.schedulers.Schedulers; | ||||||
|  |  | ||||||
| public final class CheckForNewAppVersion { | public final class CheckForNewAppVersion { | ||||||
| @@ -174,18 +174,18 @@ public final class CheckForNewAppVersion { | |||||||
|         return getCertificateSHA1Fingerprint(app).equals(GITHUB_APK_SHA1); |         return getCertificateSHA1Fingerprint(app).equals(GITHUB_APK_SHA1); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @NonNull |     @Nullable | ||||||
|     public static Disposable checkNewVersion(@NonNull final App app) { |     public static Disposable checkNewVersion(@NonNull final App app) { | ||||||
|         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app); |         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app); | ||||||
|  |  | ||||||
|         // Check if user has enabled/disabled update checking |         // Check if user has enabled/disabled update checking | ||||||
|         // and if the current apk is a github one or not. |         // and if the current apk is a github one or not. | ||||||
|         if (!prefs.getBoolean(app.getString(R.string.update_app_key), true) |         if (!prefs.getBoolean(app.getString(R.string.update_app_key), true) || !isGithubApk(app)) { | ||||||
|                 || !isGithubApk(app)) { |             return null; | ||||||
|             return Disposables.empty(); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return Observable.fromCallable(() -> { |         return Maybe | ||||||
|  |                 .fromCallable(() -> { | ||||||
|                     if (!isConnected(app)) { |                     if (!isConnected(app)) { | ||||||
|                         return null; |                         return null; | ||||||
|                     } |                     } | ||||||
| @@ -198,15 +198,13 @@ public final class CheckForNewAppVersion { | |||||||
|                         if (DEBUG) { |                         if (DEBUG) { | ||||||
|                             Log.w(TAG, Log.getStackTraceString(e)); |                             Log.w(TAG, Log.getStackTraceString(e)); | ||||||
|                         } |                         } | ||||||
|             } |  | ||||||
|  |  | ||||||
|                         return null; |                         return null; | ||||||
|  |                     } | ||||||
|                 }) |                 }) | ||||||
|                 .subscribeOn(Schedulers.io()) |                 .subscribeOn(Schedulers.io()) | ||||||
|                 .observeOn(AndroidSchedulers.mainThread()) |                 .observeOn(AndroidSchedulers.mainThread()) | ||||||
|                 .subscribe(response -> { |                 .subscribe(response -> { | ||||||
|                     // Parse the json from the response. |                     // Parse the json from the response. | ||||||
|                     if (response != null) { |  | ||||||
|                     try { |                     try { | ||||||
|                         final JsonObject githubStableObject = JsonParser.object().from(response) |                         final JsonObject githubStableObject = JsonParser.object().from(response) | ||||||
|                                 .getObject("flavors").getObject("github").getObject("stable"); |                                 .getObject("flavors").getObject("github").getObject("stable"); | ||||||
| @@ -223,7 +221,6 @@ public final class CheckForNewAppVersion { | |||||||
|                             Log.w(TAG, Log.getStackTraceString(e)); |                             Log.w(TAG, Log.getStackTraceString(e)); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     } |  | ||||||
|                 }); |                 }); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Stypox
					Stypox