Momkin (ممكن) Android app https://momkin.dorfbrunnen.eu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.7 KiB

package eu.dorfbrunnen.momkin
import android.app.Activity
import android.content.ClipData
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import eu.dorfbrunnen.momkin.fragments.MediaItemSelectionFragment.Companion.INTENT_OPEN_LANGUAGE_MEDIA_CODE
import eu.dorfbrunnen.momkin.fragments.MediaItemSelectionFragmentDirections
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == INTENT_OPEN_LANGUAGE_MEDIA_CODE && resultCode == Activity.RESULT_OK && data != null) {
handleLanguageMediaIntent(data)
}
}
private fun handleLanguageMediaIntent(data: Intent) {
val filePaths = mutableListOf<String>()
val clipData: ClipData? = data.clipData
if (clipData != null) {
for (i in 0 until clipData.itemCount) {
filePaths.add(clipData.getItemAt(i).uri.toString())
}
} else {
filePaths.add(data.data.toString())
}
openLanguageMediaFile(filePaths)
}
private fun openLanguageMediaFile(filePaths: MutableList<String>) {
val action =
MediaItemSelectionFragmentDirections.actionMediaItemSelectionFragmentToMediaItemDetailsFragment(
filePaths.joinToString(" ")
)
findNavController(R.id.nav_host_fragment).navigate(action)
}
}