@@ -104,8 +104,9 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
104104
105105 fun onCreate () {
106106 // Ask the user to grant write permission if relevant and not already granted
107- if (DirectoryInitialization .isWaitingForWriteAccess(activity))
108- PermissionsHandler .requestWritePermission(activity)
107+ if (DirectoryInitialization .isWaitingForWriteAccess(activity)) PermissionsHandler .requestWritePermission(
108+ activity
109+ )
109110
110111 val versionName = BuildConfig .VERSION_NAME
111112 mainView.setVersionString(versionName)
@@ -118,85 +119,83 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
118119 }
119120
120121 fun launchFileListActivity () {
121- val intent =
122- if (DirectoryInitialization .preferOldFolderPicker(activity)) {
123- FileBrowserHelper .createDirectoryPickerIntent(
124- activity,
125- FileBrowserHelper .GAME_EXTENSIONS ,
126- )
127- } else {
128- Intent (Intent .ACTION_OPEN_DOCUMENT_TREE )
129- }
122+ val intent = if (DirectoryInitialization .preferOldFolderPicker(activity)) {
123+ FileBrowserHelper .createDirectoryPickerIntent(
124+ activity,
125+ FileBrowserHelper .GAME_EXTENSIONS ,
126+ )
127+ } else {
128+ Intent (Intent .ACTION_OPEN_DOCUMENT_TREE )
129+ }
130130 requestDirectory.launch(intent)
131131 }
132132
133- fun handleOptionSelection (itemId : Int , activity : ComponentActivity ): Boolean =
134- when (itemId) {
135- R .id.menu_settings -> {
136- mainView.launchSettingsActivity(MenuTag .SETTINGS )
137- true
138- }
139-
140- R .id.menu_grid_options -> {
141- mainView.showGridOptions()
142- true
143- }
133+ fun handleOptionSelection (itemId : Int , activity : ComponentActivity ): Boolean = when (itemId) {
134+ R .id.menu_settings -> {
135+ mainView.launchSettingsActivity(MenuTag .SETTINGS )
136+ true
137+ }
144138
145- R .id.menu_refresh -> {
146- mainView.setRefreshing(true )
147- GameFileCacheManager .startRescan()
148- true
149- }
139+ R .id.menu_grid_options -> {
140+ mainView.showGridOptions()
141+ true
142+ }
150143
151- R .id.button_add_directory -> {
152- AfterDirectoryInitializationRunner ().runWithLifecycle(activity) { launchFileListActivity() }
153- true
154- }
144+ R .id.menu_refresh -> {
145+ mainView.setRefreshing(true )
146+ GameFileCacheManager .startRescan()
147+ true
148+ }
155149
156- R .id.menu_open_file -> {
157- requestGameFile.launch( " */* " )
158- true
159- }
150+ R .id.button_add_directory -> {
151+ AfterDirectoryInitializationRunner ().runWithLifecycle(activity) { launchFileListActivity() }
152+ true
153+ }
160154
161- R .id.menu_load_wii_system_menu -> {
162- launchWiiSystemMenu( )
163- true
164- }
155+ R .id.menu_open_file -> {
156+ requestGameFile.launch( " */* " )
157+ true
158+ }
165159
166- R .id.menu_online_system_update -> {
167- AfterDirectoryInitializationRunner ().runWithLifecycle(activity) { launchOnlineUpdate() }
168- true
169- }
160+ R .id.menu_load_wii_system_menu -> {
161+ launchWiiSystemMenu()
162+ true
163+ }
170164
171- R .id.menu_install_wad -> {
172- AfterDirectoryInitializationRunner ().runWithLifecycle(
173- activity
174- ) { requestWadFile.launch(" */*" ) }
175- true
176- }
165+ R .id.menu_online_system_update -> {
166+ AfterDirectoryInitializationRunner ().runWithLifecycle(activity) { launchOnlineUpdate() }
167+ true
168+ }
177169
178- R .id.menu_import_wii_save -> {
179- AfterDirectoryInitializationRunner ().runWithLifecycle(
180- activity
181- ) { requestWiiSaveFile .launch(" */*" ) }
182- true
183- }
170+ R .id.menu_install_wad -> {
171+ AfterDirectoryInitializationRunner ().runWithLifecycle(
172+ activity
173+ ) { requestWadFile .launch(" */*" ) }
174+ true
175+ }
184176
185- R .id.menu_import_nand_backup -> {
186- AfterDirectoryInitializationRunner ().runWithLifecycle(
187- activity
188- ) { requestNandBinFile .launch(" */*" ) }
189- true
190- }
177+ R .id.menu_import_wii_save -> {
178+ AfterDirectoryInitializationRunner ().runWithLifecycle(
179+ activity
180+ ) { requestWiiSaveFile .launch(" */*" ) }
181+ true
182+ }
191183
192- R .id.menu_about -> {
193- showAboutDialog()
194- false
195- }
184+ R .id.menu_import_nand_backup -> {
185+ AfterDirectoryInitializationRunner ().runWithLifecycle(
186+ activity
187+ ) { requestNandBinFile.launch(" */*" ) }
188+ true
189+ }
196190
197- else -> false
191+ R .id.menu_about -> {
192+ showAboutDialog()
193+ false
198194 }
199195
196+ else -> false
197+ }
198+
200199 fun onResume () {
201200 if (dirToAdd != null ) {
202201 GameFileCache .addGameFolder(dirToAdd!! )
@@ -226,24 +225,24 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
226225 val recursive = BooleanSetting .MAIN_RECURSIVE_ISO_PATHS .boolean
227226 val childNames = ContentHandler .getChildNames(uri, recursive)
228227 if (Arrays .stream(childNames).noneMatch {
229- FileBrowserHelper .GAME_EXTENSIONS
230- .contains(FileBrowserHelper .getExtension(it, false ))
228+ FileBrowserHelper .GAME_EXTENSIONS .contains(
229+ FileBrowserHelper .getExtension(
230+ it,
231+ false
232+ )
233+ )
231234 }) {
232- MaterialAlertDialogBuilder (activity)
233- .setMessage(
235+ MaterialAlertDialogBuilder (activity).setMessage(
234236 activity.getString(
235237 R .string.wrong_file_extension_in_directory,
236238 FileBrowserHelper .setToSortedDelimitedString(FileBrowserHelper .GAME_EXTENSIONS )
237239 )
238- )
239- .setPositiveButton(android.R .string.ok, null )
240- .show()
240+ ).setPositiveButton(android.R .string.ok, null ).show()
241241 }
242242
243243 val contentResolver = activity.contentResolver
244244 val canonicalizedUri = contentResolver.canonicalize(uri)
245- if (canonicalizedUri != null )
246- uri = canonicalizedUri
245+ if (canonicalizedUri != null ) uri = canonicalizedUri
247246
248247 val takeFlags = result.flags and Intent .FLAG_GRANT_READ_URI_PERMISSION
249248 activity.contentResolver.takePersistableUriPermission(uri, takeFlags)
@@ -253,10 +252,7 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
253252
254253 fun installWAD (path : String? ) {
255254 ThreadUtil .runOnThreadAndShowResult(
256- activity,
257- R .string.import_in_progress,
258- 0 ,
259- {
255+ activity, R .string.import_in_progress, 0 , {
260256 val success = WiiUtils .installWAD(path!! )
261257 val message =
262258 if (success) R .string.wad_install_success else R .string.wad_install_failure
@@ -266,26 +262,20 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
266262
267263 fun importWiiSave (path : String? ) {
268264 ThreadUtil .runOnThreadAndShowResult(
269- activity,
270- R .string.import_in_progress,
271- 0 ,
272- {
265+ activity, R .string.import_in_progress, 0 , {
273266 val canOverwrite = BooleanSupplier {
274267 val latch = CountDownLatch (1 )
275268 val decision = AtomicReference <Boolean >()
276269 activity.runOnUiThread {
277- MaterialAlertDialogBuilder (activity)
278- .setMessage(R .string.wii_save_exists)
270+ MaterialAlertDialogBuilder (activity).setMessage(R .string.wii_save_exists)
279271 .setCancelable(false )
280272 .setPositiveButton(R .string.yes) { _: DialogInterface ? , _: Int ->
281273 decision.set(true )
282274 latch.countDown()
283- }
284- .setNegativeButton(R .string.no) { _: DialogInterface ? , _: Int ->
275+ }.setNegativeButton(R .string.no) { _: DialogInterface ? , _: Int ->
285276 decision.set(false )
286277 latch.countDown()
287- }
288- .show()
278+ }.show()
289279 }
290280 try {
291281 latch.await()
@@ -307,23 +297,18 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
307297 }
308298
309299 fun importNANDBin (path : String? ) {
310- MaterialAlertDialogBuilder (activity)
311- .setMessage(R .string.nand_import_warning)
300+ MaterialAlertDialogBuilder (activity).setMessage(R .string.nand_import_warning)
312301 .setNegativeButton(R .string.no) { dialog: DialogInterface , _: Int -> dialog.dismiss() }
313302 .setPositiveButton(R .string.yes) { dialog: DialogInterface , _: Int ->
314303 dialog.dismiss()
315304 ThreadUtil .runOnThreadAndShowResult(
316- activity,
317- R .string.import_in_progress,
318- R .string.do_not_close_app,
319- {
305+ activity, R .string.import_in_progress, R .string.do_not_close_app, {
320306 // ImportNANDBin unfortunately doesn't provide any result value...
321307 // It does however show a panic alert if something goes wrong.
322308 WiiUtils .importNANDBin(path!! )
323309 null
324310 })
325- }
326- .show()
311+ }.show()
327312 }
328313
329314 private fun launchOnlineUpdate () {
@@ -333,8 +318,7 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
333318 launchUpdateProgressBarFragment(activity)
334319 } else {
335320 SystemMenuNotInstalledDialogFragment ().show(
336- activity.supportFragmentManager,
337- SystemMenuNotInstalledDialogFragment .TAG
321+ activity.supportFragmentManager, SystemMenuNotInstalledDialogFragment .TAG
338322 )
339323 }
340324 }
@@ -345,8 +329,7 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
345329 EmulationActivity .launchSystemMenu(activity)
346330 } else {
347331 SystemMenuNotInstalledDialogFragment ().show(
348- activity.supportFragmentManager,
349- SystemMenuNotInstalledDialogFragment .TAG
332+ activity.supportFragmentManager, SystemMenuNotInstalledDialogFragment .TAG
350333 )
351334 }
352335 }
@@ -373,8 +356,10 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
373356
374357 private fun launchUpdateProgressBarFragment (activity : FragmentActivity ) {
375358 val progressBarFragment = SystemUpdateProgressBarDialogFragment ()
376- progressBarFragment
377- .show(activity.supportFragmentManager, SystemUpdateProgressBarDialogFragment .TAG )
359+ progressBarFragment.show(
360+ activity.supportFragmentManager,
361+ SystemUpdateProgressBarDialogFragment .TAG
362+ )
378363 progressBarFragment.isCancelable = false
379364 }
380365 }
0 commit comments