diff --git a/android/app/src/main/java/io/github/kichikuou/xsystem35/GameActivity.kt b/android/app/src/main/java/io/github/kichikuou/xsystem35/GameActivity.kt index 666e449..0057ef1 100644 --- a/android/app/src/main/java/io/github/kichikuou/xsystem35/GameActivity.kt +++ b/android/app/src/main/java/io/github/kichikuou/xsystem35/GameActivity.kt @@ -29,6 +29,7 @@ import java.io.IOException class GameActivity : SDLActivity() { companion object { const val EXTRA_GAME_ROOT = "GAME_ROOT" + const val EXTRA_ARCHIVE_NAME = "ARCHIVE_NAME" } private lateinit var gameRoot: File @@ -63,9 +64,12 @@ class GameActivity : SDLActivity() { override fun setTitle(title: CharSequence?) { super.setTitle(title) - val str = title?.toString()?.substringAfter(':', "") - if (str.isNullOrEmpty()) - return + var str = title?.toString()?.substringAfter(':', "") + if (str.isNullOrEmpty()) { + str = intent.getStringExtra(EXTRA_ARCHIVE_NAME) + if (str == null) + return + } File(gameRoot, Launcher.TITLE_FILE).writeText(str) Launcher.updateGameList() } diff --git a/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt b/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt index 5a21c20..3b5a943 100644 --- a/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt +++ b/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt @@ -35,7 +35,7 @@ private var gLauncher: Launcher? = null interface LauncherObserver { fun onGameListChange() fun onInstallProgress(path: String) - fun onInstallSuccess(path: File) + fun onInstallSuccess(path: File, archiveName: String?) fun onInstallFailure(msgId: Int) } @@ -73,7 +73,7 @@ class Launcher private constructor(private val rootDir: File) { updateGameList() } - fun install(input: InputStream) { + fun install(input: InputStream, archiveName: String?) { val dir = createDirForGame() @SuppressLint("HandlerLeak") val handler = object : Handler() { @@ -84,7 +84,7 @@ class Launcher private constructor(private val rootDir: File) { } SUCCESS -> { isInstalling = false - observer?.onInstallSuccess(msg.obj as File) + observer?.onInstallSuccess(msg.obj as File, archiveName) } FAILURE -> { isInstalling = false diff --git a/android/app/src/main/java/io/github/kichikuou/xsystem35/LauncherActivity.kt b/android/app/src/main/java/io/github/kichikuou/xsystem35/LauncherActivity.kt index ee824a6..bc787d8 100644 --- a/android/app/src/main/java/io/github/kichikuou/xsystem35/LauncherActivity.kt +++ b/android/app/src/main/java/io/github/kichikuou/xsystem35/LauncherActivity.kt @@ -19,7 +19,9 @@ package io.github.kichikuou.xsystem35 import android.app.* import android.content.Intent +import android.net.Uri import android.os.Bundle +import android.provider.OpenableColumns import android.util.Log import android.view.Menu import android.view.MenuItem @@ -60,7 +62,7 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) { super.onListItemClick(l, v, position, id) if (position < launcher.games.size) { - startGame(launcher.games[position].path) + startGame(launcher.games[position].path, null) } else { val i = Intent(Intent.ACTION_GET_CONTENT) i.type = CONTENT_TYPE_ZIP @@ -112,7 +114,7 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La INSTALL_REQUEST -> { val input = contentResolver.openInputStream(uri) ?: return showProgressDialog() - launcher.install(input) + launcher.install(input, getArchiveName(uri)) } SAVEDATA_EXPORT_REQUEST -> try { launcher.exportSaveData(contentResolver.openOutputStream(uri)!!) @@ -144,9 +146,9 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La progressDialog?.setProgress(getString(R.string.install_progress, path)) } - override fun onInstallSuccess(path: File) { + override fun onInstallSuccess(path: File, archiveName: String?) { dismissProgressDialog() - startGame(path) + startGame(path, archiveName) } override fun onInstallFailure(msgId: Int) { @@ -154,10 +156,11 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La errorDialog(msgId) } - private fun startGame(path: File) { + private fun startGame(path: File, archiveName: String?) { val i = Intent() i.setClass(applicationContext, GameActivity::class.java) i.putExtra(GameActivity.EXTRA_GAME_ROOT, path.path) + i.putExtra(GameActivity.EXTRA_ARCHIVE_NAME, archiveName) startActivity(i) } @@ -181,6 +184,17 @@ class LauncherActivity : ListActivity(), AdapterView.OnItemLongClickListener, La .setPositiveButton(R.string.ok) {_, _ -> } .show() } + + private fun getArchiveName(uri: Uri): String? { + val cursor = contentResolver.query(uri, null, null, null, null, null) + cursor?.use { + if (it.moveToFirst()) { + val fname = it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)) + return if (fname.endsWith(".zip", true)) fname.dropLast(4) else fname + } + } + return null + } } @Suppress("DEPRECATION") // for ProgressDialog