Android: Convert CustomFilePickerActivity to Kotlin

This commit is contained in:
Charles Lombardo 2023-06-03 22:23:47 -04:00
parent 03675f7677
commit cbca383bd2
2 changed files with 47 additions and 51 deletions

View File

@ -1,51 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.activities;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import androidx.annotation.Nullable;
import com.nononsenseapps.filepicker.AbstractFilePickerFragment;
import com.nononsenseapps.filepicker.FilePickerActivity;
import org.dolphinemu.dolphinemu.fragments.CustomFilePickerFragment;
import java.io.File;
import java.util.HashSet;
public class CustomFilePickerActivity extends FilePickerActivity
{
public static final String EXTRA_EXTENSIONS = "dolphinemu.org.filepicker.extensions";
private HashSet<String> mExtensions;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent != null)
{
mExtensions = (HashSet<String>) intent.getSerializableExtra(EXTRA_EXTENSIONS);
}
}
@Override
protected AbstractFilePickerFragment<File> getFragment(
@Nullable final String startPath, final int mode, final boolean allowMultiple,
final boolean allowCreateDir, final boolean allowExistingFile,
final boolean singleClick)
{
CustomFilePickerFragment fragment = new CustomFilePickerFragment();
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(
startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
fragment.setExtensions(mExtensions);
return fragment;
}
}

View File

@ -0,0 +1,47 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.activities
import android.os.Bundle
import android.os.Environment
import com.nononsenseapps.filepicker.AbstractFilePickerFragment
import com.nononsenseapps.filepicker.FilePickerActivity
import org.dolphinemu.dolphinemu.fragments.CustomFilePickerFragment
import java.io.File
class CustomFilePickerActivity : FilePickerActivity() {
private var extensions: HashSet<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (intent != null) {
extensions = intent.getSerializableExtra(EXTRA_EXTENSIONS) as HashSet<String>?
}
}
override fun getFragment(
startPath: String?,
mode: Int,
allowMultiple: Boolean,
allowCreateDir: Boolean,
allowExistingFile: Boolean,
singleClick: Boolean
): AbstractFilePickerFragment<File> {
val fragment = CustomFilePickerFragment()
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
fragment.setArgs(
startPath ?: Environment.getExternalStorageDirectory().path,
mode,
allowMultiple,
allowCreateDir,
allowExistingFile,
singleClick
)
fragment.setExtensions(extensions)
return fragment
}
companion object {
const val EXTRA_EXTENSIONS = "dolphinemu.org.filepicker.extensions"
}
}