mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 04:47:53 +00:00
android: Convert AddDirectoryHelper to Kotlin
This commit is contained in:
parent
e83de8eefb
commit
8710c6e14c
2 changed files with 27 additions and 38 deletions
|
@ -1,38 +0,0 @@
|
||||||
package org.yuzu.yuzu_emu.utils;
|
|
||||||
|
|
||||||
import android.content.AsyncQueryHandler;
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import org.yuzu.yuzu_emu.model.GameDatabase;
|
|
||||||
import org.yuzu.yuzu_emu.model.GameProvider;
|
|
||||||
|
|
||||||
public class AddDirectoryHelper {
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
public AddDirectoryHelper(Context context) {
|
|
||||||
this.mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDirectory(String dir, AddDirectoryListener addDirectoryListener) {
|
|
||||||
AsyncQueryHandler handler = new AsyncQueryHandler(mContext.getContentResolver()) {
|
|
||||||
@Override
|
|
||||||
protected void onInsertComplete(int token, Object cookie, Uri uri) {
|
|
||||||
addDirectoryListener.onDirectoryAdded();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ContentValues file = new ContentValues();
|
|
||||||
file.put(GameDatabase.KEY_FOLDER_PATH, dir);
|
|
||||||
|
|
||||||
handler.startInsert(0, // We don't need to identify this call to the handler
|
|
||||||
null, // We don't need to pass additional data to the handler
|
|
||||||
GameProvider.URI_FOLDER, // Tell the GameProvider we are adding a folder
|
|
||||||
file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface AddDirectoryListener {
|
|
||||||
void onDirectoryAdded();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.yuzu.yuzu_emu.utils
|
||||||
|
|
||||||
|
import android.content.AsyncQueryHandler
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import org.yuzu.yuzu_emu.model.GameDatabase
|
||||||
|
import org.yuzu.yuzu_emu.model.GameProvider
|
||||||
|
|
||||||
|
class AddDirectoryHelper(private val context: Context) {
|
||||||
|
fun addDirectory(dir: String?, onAddUnit: () -> Unit) {
|
||||||
|
val handler: AsyncQueryHandler = object : AsyncQueryHandler(context.contentResolver) {
|
||||||
|
override fun onInsertComplete(token: Int, cookie: Any?, uri: Uri) {
|
||||||
|
onAddUnit.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val file = ContentValues()
|
||||||
|
file.put(GameDatabase.KEY_FOLDER_PATH, dir)
|
||||||
|
handler.startInsert(
|
||||||
|
0, // We don't need to identify this call to the handler
|
||||||
|
null, // We don't need to pass additional data to the handler
|
||||||
|
GameProvider.URI_FOLDER, // Tell the GameProvider we are adding a folder
|
||||||
|
file
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue