Refactor onCreate: extract initTaskRetainerFragment method

This commit extracts the logic to initialize a fragment without UI on a seperate method called `initTaskRetainerFragment`.
This commit is contained in:
DESKTOP-EMSE65H\Archontis 2023-02-25 01:39:52 +02:00
parent 23c8f86b7b
commit 2e6fca0c04

View file

@ -255,17 +255,7 @@ public class FileDisplayActivity extends FileActivity
/// USER INTERFACE
initLayout();
initUI();
// Init Fragment without UI to retain AsyncTask across configuration changes
FragmentManager fm = getSupportFragmentManager();
TaskRetainerFragment taskRetainerFragment =
(TaskRetainerFragment) fm.findFragmentByTag(TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT);
if (taskRetainerFragment == null) {
taskRetainerFragment = new TaskRetainerFragment();
fm.beginTransaction()
.add(taskRetainerFragment, TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT).commit();
} // else, Fragment already created and retained across configuration change
initTaskRetainerFragment();
if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
handleOpenFileViaIntent(getIntent());
@ -305,6 +295,18 @@ public class FileDisplayActivity extends FileActivity
fastScrollUtils.fixAppBarForFastScroll(binding.appbar.appbar, binding.rootLayout);
}
private void initTaskRetainerFragment() {
// Init Fragment without UI to retain AsyncTask across configuration changes
FragmentManager fm = getSupportFragmentManager();
TaskRetainerFragment taskRetainerFragment =
(TaskRetainerFragment) fm.findFragmentByTag(TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT);
if (taskRetainerFragment == null) {
taskRetainerFragment = new TaskRetainerFragment();
fm.beginTransaction()
.add(taskRetainerFragment, TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT).commit();
} // else, Fragment already created and retained across configuration change
}
private void checkStoragePath() {
String newStorage = Environment.getExternalStorageDirectory().getAbsolutePath();
String storagePath = preferences.getStoragePath(newStorage);