mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Show snackbar error when settings import fails
This commit is contained in:
		| @@ -6,6 +6,7 @@ package org.schabi.newpipe.error; | ||||
| public enum UserAction { | ||||
|     USER_REPORT("user report"), | ||||
|     UI_ERROR("ui error"), | ||||
|     DATABASE_IMPORT_EXPORT("database import or export"), | ||||
|     SUBSCRIPTION_CHANGE("subscription change"), | ||||
|     SUBSCRIPTION_UPDATE("subscription update"), | ||||
|     SUBSCRIPTION_GET("get subscription"), | ||||
|   | ||||
| @@ -23,7 +23,9 @@ import androidx.preference.PreferenceManager; | ||||
|  | ||||
| import org.schabi.newpipe.NewPipeDatabase; | ||||
| import org.schabi.newpipe.R; | ||||
| import org.schabi.newpipe.error.ErrorInfo; | ||||
| import org.schabi.newpipe.error.ErrorUtil; | ||||
| import org.schabi.newpipe.error.UserAction; | ||||
| import org.schabi.newpipe.settings.export.ImportExportManager; | ||||
| import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard; | ||||
| import org.schabi.newpipe.streams.io.StoredFileHelper; | ||||
| @@ -166,7 +168,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { | ||||
|             Toast.makeText(requireContext(), R.string.export_complete_toast, Toast.LENGTH_SHORT) | ||||
|                     .show(); | ||||
|         } catch (final Exception e) { | ||||
|             ErrorUtil.showUiErrorSnackbar(this, "Exporting database", e); | ||||
|             showErrorSnackbar(e, "Exporting database and settings"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -202,7 +204,12 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { | ||||
|                             final Context context = requireContext(); | ||||
|                             final SharedPreferences prefs = PreferenceManager | ||||
|                                     .getDefaultSharedPreferences(context); | ||||
|                             try { | ||||
|                                 manager.loadSharedPreferences(prefs); | ||||
|                             } catch (IOException | ClassNotFoundException e) { | ||||
|                                 showErrorSnackbar(e, "Importing preferences"); | ||||
|                                 return; | ||||
|                             } | ||||
|                             cleanImport(context, prefs); | ||||
|                             finishImport(importDataUri); | ||||
|                         }) | ||||
| @@ -211,7 +218,7 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { | ||||
|                 finishImport(importDataUri); | ||||
|             } | ||||
|         } catch (final Exception e) { | ||||
|             ErrorUtil.showUiErrorSnackbar(this, "Importing database", e); | ||||
|             showErrorSnackbar(e, "Importing database and settings"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -269,4 +276,8 @@ public class BackupRestoreSettingsFragment extends BasePreferenceFragment { | ||||
|                 .putString(importExportDataPathKey, importExportDataUri.toString()); | ||||
|         editor.apply(); | ||||
|     } | ||||
|  | ||||
|     private void showErrorSnackbar(final Throwable e, final String request) { | ||||
|         ErrorUtil.showSnackbar(this, new ErrorInfo(e, UserAction.DATABASE_IMPORT_EXPORT, request)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -73,8 +73,8 @@ class ImportExportManager(private val fileLocator: NewPipeFileLocator) { | ||||
|     /** | ||||
|      * Remove all shared preferences from the app and load the preferences supplied to the manager. | ||||
|      */ | ||||
|     @Throws(IOException::class, ClassNotFoundException::class) | ||||
|     fun loadSharedPreferences(preferences: SharedPreferences) { | ||||
|         try { | ||||
|         val preferenceEditor = preferences.edit() | ||||
|  | ||||
|         PreferencesObjectInputStream( | ||||
| @@ -109,14 +109,5 @@ class ImportExportManager(private val fileLocator: NewPipeFileLocator) { | ||||
|             } | ||||
|             preferenceEditor.commit() | ||||
|         } | ||||
|         } catch (e: IOException) { | ||||
|             if (DEBUG) { | ||||
|                 Log.e(TAG, "Unable to loadSharedPreferences", e) | ||||
|             } | ||||
|         } catch (e: ClassNotFoundException) { | ||||
|             if (DEBUG) { | ||||
|                 Log.e(TAG, "Unable to loadSharedPreferences", e) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stypox
					Stypox