|
|
|
@ -2,7 +2,10 @@ package io.lowrespalmtree.harvestdawn
|
|
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.app.AlertDialog
|
|
|
|
|
import android.content.ContentValues
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.DialogInterface
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
|
import android.net.Uri
|
|
|
|
@ -81,15 +84,10 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
|
return when (item.itemId) {
|
|
|
|
|
R.id.action_share -> {
|
|
|
|
|
share(); true
|
|
|
|
|
}
|
|
|
|
|
R.id.action_save -> {
|
|
|
|
|
save(); true
|
|
|
|
|
}
|
|
|
|
|
R.id.action_clear_cache -> {
|
|
|
|
|
clearVideoCache(); true
|
|
|
|
|
}
|
|
|
|
|
R.id.action_share -> { share(); true }
|
|
|
|
|
R.id.action_save -> { save(); true }
|
|
|
|
|
R.id.action_clear_cache -> { clearVideoCache(); true }
|
|
|
|
|
R.id.action_pick_theme -> { showThemeDialog(); true }
|
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -185,9 +183,10 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
|
|
// Save the soundtrack as well cause we can't pass a resource to FFMPEG.
|
|
|
|
|
// Should be done only once, then it's kept in app internal storage.
|
|
|
|
|
val soundFile = File(filesDir, "harvestdawn.m4a")
|
|
|
|
|
val themeId = getThemeRawResource(getThemeId())
|
|
|
|
|
val soundFile = File(filesDir, "$themeId.m4a")
|
|
|
|
|
if (!soundFile.exists()) {
|
|
|
|
|
resources.openRawResource(R.raw.harvestdawn).use { resource ->
|
|
|
|
|
resources.openRawResource(themeId).use { resource ->
|
|
|
|
|
FileOutputStream(soundFile).use { fos ->
|
|
|
|
|
fos.buffered().write(resource.buffered().readBytes())
|
|
|
|
|
}
|
|
|
|
@ -346,6 +345,38 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
startActivity(Intent.createChooser(shareIntent, getString(R.string.send)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getThemeId() =
|
|
|
|
|
getSharedPreferences("app", Context.MODE_PRIVATE).getInt("theme", 0)
|
|
|
|
|
|
|
|
|
|
private fun setThemeId(id: Int) =
|
|
|
|
|
getSharedPreferences("app", Context.MODE_PRIVATE).edit().apply {
|
|
|
|
|
putInt("theme", id)
|
|
|
|
|
apply()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getThemeRawResource(id: Int) =
|
|
|
|
|
when (id) {
|
|
|
|
|
0 -> R.raw.harvestdawn
|
|
|
|
|
1 -> R.raw.sunriseofflutes
|
|
|
|
|
else -> R.raw.harvestdawn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showThemeDialog() {
|
|
|
|
|
val currentId = getThemeId()
|
|
|
|
|
val dialog = AlertDialog.Builder(this).run {
|
|
|
|
|
var selection = currentId
|
|
|
|
|
setTitle(R.string.action_theme)
|
|
|
|
|
setSingleChoiceItems(R.array.pick_theme, currentId) { _, which -> selection = which }
|
|
|
|
|
setPositiveButton(android.R.string.ok) { dialog, _ ->
|
|
|
|
|
setThemeId(selection)
|
|
|
|
|
dialog.dismiss()
|
|
|
|
|
}
|
|
|
|
|
setNegativeButton(android.R.string.cancel) { dialog, _ -> dialog.dismiss() }
|
|
|
|
|
create()
|
|
|
|
|
}
|
|
|
|
|
dialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun toast(text: String) {
|
|
|
|
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|