mirror of
https://github.com/NiciDieNase/chaosflix
synced 2025-02-17 05:28:24 +00:00
cleanup unused activities
This commit is contained in:
parent
6d5b9dc791
commit
28b37986d7
7 changed files with 3 additions and 682 deletions
|
@ -30,7 +30,8 @@
|
|||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".NavigationActivity">
|
||||
<activity android:name=".NavigationActivity"
|
||||
android:launchMode="singleInstance">
|
||||
<nav-graph android:value="@navigation/main_navigation"/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
|
@ -47,10 +48,6 @@
|
|||
android:launchMode="singleTop"
|
||||
android:parentActivityName=".eventdetails.EventDetailsActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".settings.SettingsActivity"
|
||||
android:parentActivityName=".browse.BrowseActivity"/>
|
||||
|
||||
<activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
|
||||
<activity android:name=".favoritesimport.FavoritesImportActivity" >
|
||||
<intent-filter>
|
||||
|
|
|
@ -1,77 +1,13 @@
|
|||
package de.nicidienase.chaosflix.touch
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Conference
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.common.viewmodel.SplashViewModel
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.touch.browse.eventslist.EventsListActivity
|
||||
import de.nicidienase.chaosflix.touch.eventdetails.EventDetailsActivity
|
||||
|
||||
class SplashActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
when (intent.action) {
|
||||
Intent.ACTION_VIEW -> {
|
||||
setContentView(R.layout.activity_splash)
|
||||
handleViewAction(intent.data)
|
||||
}
|
||||
else -> {
|
||||
goToOverview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleViewAction(data: Uri?) {
|
||||
val viewModel = ViewModelProviders.of(
|
||||
this,
|
||||
ViewModelFactory.getInstance(this)
|
||||
)[SplashViewModel::class.java]
|
||||
|
||||
viewModel.state.observe(this, Observer {
|
||||
when (it.state) {
|
||||
SplashViewModel.State.FOUND -> {
|
||||
when (val item = it.data) {
|
||||
is Event -> goToEvent(item)
|
||||
is Conference -> goToConference(item)
|
||||
else -> goToOverview()
|
||||
}
|
||||
}
|
||||
SplashViewModel.State.NOT_FOUND -> {
|
||||
goToOverview()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (data != null) {
|
||||
when (data.pathSegments[0]) {
|
||||
"v" -> viewModel.findEventForUri(data)
|
||||
"c" -> viewModel.findConferenceForUri(data)
|
||||
}
|
||||
} else {
|
||||
goToOverview()
|
||||
}
|
||||
}
|
||||
|
||||
private fun goToOverview() {
|
||||
NavigationActivity.launch(this)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun goToEvent(event: Event) {
|
||||
EventDetailsActivity.launch(this, event)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun goToConference(conference: Conference) {
|
||||
EventsListActivity.start(this, conference)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,310 +0,0 @@
|
|||
package de.nicidienase.chaosflix.touch.browse
|
||||
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.transition.TransitionInflater
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Conference
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.StreamUrl
|
||||
import de.nicidienase.chaosflix.common.viewmodel.BrowseViewModel
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.touch.NavigationActivity
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import de.nicidienase.chaosflix.touch.browse.cast.CastService
|
||||
import de.nicidienase.chaosflix.touch.browse.download.DownloadsListFragment
|
||||
import de.nicidienase.chaosflix.touch.browse.eventslist.EventsListActivity
|
||||
import de.nicidienase.chaosflix.touch.browse.eventslist.EventsListFragment
|
||||
import de.nicidienase.chaosflix.touch.browse.streaming.LivestreamListFragment
|
||||
import de.nicidienase.chaosflix.touch.browse.streaming.StreamingItem
|
||||
import de.nicidienase.chaosflix.touch.databinding.ActivityBrowseBinding
|
||||
import de.nicidienase.chaosflix.touch.eventdetails.EventDetailsActivity
|
||||
import de.nicidienase.chaosflix.touch.playback.PlayerActivity
|
||||
import de.nicidienase.chaosflix.touch.settings.SettingsActivity
|
||||
|
||||
class BrowseActivity : AppCompatActivity(), OnEventSelectedListener {
|
||||
|
||||
private var drawerOpen: Boolean = false
|
||||
|
||||
private lateinit var drawerToggle: ActionBarDrawerToggle
|
||||
private lateinit var binding: ActivityBrowseBinding
|
||||
|
||||
private lateinit var viewModel: BrowseViewModel
|
||||
|
||||
protected val numColumns: Int
|
||||
get() = resources.getInteger(R.integer.num_columns)
|
||||
|
||||
private lateinit var castService: CastService
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_browse)
|
||||
|
||||
castService = CastService(this)
|
||||
|
||||
val navigationView = findViewById<NavigationView>(R.id.navigation_view)
|
||||
navigationView.setNavigationItemSelectedListener { item ->
|
||||
when (item.itemId) {
|
||||
R.id.nav_recordings -> showConferencesFragment()
|
||||
R.id.nav_bookmarks -> showBookmarksFragment()
|
||||
R.id.nav_inprogress -> showInProgressFragment()
|
||||
R.id.nav_about -> showAboutPage()
|
||||
R.id.nav_streams -> showStreamsFragment()
|
||||
R.id.nav_downloads -> showDownloadsFragment()
|
||||
R.id.nav_preferences -> showSettingsPage()
|
||||
R.id.nav_new_navigation -> {
|
||||
startActivity(Intent(this, NavigationActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
else -> Snackbar.make(binding.drawerLayout, "Not implemented yet", Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
binding.drawerLayout.closeDrawers()
|
||||
true
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
showConferencesFragment()
|
||||
}
|
||||
viewModel = ViewModelProviders.of(this, ViewModelFactory.getInstance(this)).get(BrowseViewModel::class.java)
|
||||
|
||||
viewModel.state.observe(this, Observer { event ->
|
||||
if (event == null) {
|
||||
return@Observer
|
||||
}
|
||||
val errorMessage = event.error
|
||||
if (errorMessage != null) {
|
||||
Snackbar.make(binding.root, errorMessage, Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
when (event.state) {
|
||||
BrowseViewModel.State.ShowEventDetails -> {
|
||||
event.data?.let {
|
||||
EventDetailsActivity.launch(this, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun setupDrawerToggle(toolbar: Toolbar?) {
|
||||
if (toolbar != null) {
|
||||
drawerToggle = object : ActionBarDrawerToggle(this, binding.drawerLayout,
|
||||
toolbar, R.string.drawer_open, R.string.drawer_close) {
|
||||
override fun onDrawerOpened(drawerView: View) {
|
||||
super.onDrawerOpened(drawerView)
|
||||
drawerOpen = true
|
||||
}
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
super.onDrawerClosed(drawerView)
|
||||
drawerOpen = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
drawerToggle = object : ActionBarDrawerToggle(this, binding.drawerLayout,
|
||||
R.string.drawer_open, R.string.drawer_close) {
|
||||
override fun onDrawerOpened(drawerView: View) {
|
||||
super.onDrawerOpened(drawerView)
|
||||
drawerOpen = true
|
||||
}
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
super.onDrawerClosed(drawerView)
|
||||
drawerOpen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.drawerLayout.addDrawerListener(drawerToggle)
|
||||
drawerToggle.syncState()
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
||||
super.onPostCreate(savedInstanceState, persistentState)
|
||||
drawerToggle.syncState()
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
drawerToggle.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menu?.let {
|
||||
castService.addMediaRouteMenuItem(it)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (drawerToggle.onOptionsItemSelected(item)) {
|
||||
return true
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
fun onConferenceSelected(conference: Conference) {
|
||||
EventsListActivity.start(this, conference)
|
||||
}
|
||||
|
||||
fun onStreamSelected(streamingItem: StreamingItem) {
|
||||
val entries = HashMap<String, StreamUrl>()
|
||||
|
||||
if (castService.connected) {
|
||||
val hdStreams = streamingItem.room.streams // .filter { it.slug.startsWith("hd-") }
|
||||
Log.i(TAG, "found ${hdStreams.size} suitable streams, starting selection")
|
||||
if (hdStreams.size > 1) {
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.select_stream))
|
||||
.setItems(hdStreams.map { it.display }.toTypedArray()) { _, i ->
|
||||
val stream = hdStreams[i]
|
||||
val keys = stream.urls.keys.toTypedArray()
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(this.getString(R.string.select_stream))
|
||||
.setItems(keys) { _: DialogInterface?, which: Int ->
|
||||
val streamUrl = stream.urls[keys[which]]
|
||||
if (streamUrl != null) {
|
||||
castService.castStream(streamingItem, streamUrl, keys[which])
|
||||
} else {
|
||||
Snackbar.make(binding.root, "could not play stream", Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
.create()
|
||||
dialog.show()
|
||||
}
|
||||
.create()
|
||||
dialog.show()
|
||||
} else {
|
||||
Log.i(TAG, "Found no HD-Stream")
|
||||
}
|
||||
} else {
|
||||
val dashStreams = streamingItem.room.streams.filter { it.slug == "dash-native" }
|
||||
if (dashStreams.size > 0 &&
|
||||
viewModel.getAutoselectStream()) {
|
||||
playStream(streamingItem.conference.conference,
|
||||
streamingItem.room.display,
|
||||
dashStreams.first().urls["dash"]
|
||||
)
|
||||
} else {
|
||||
streamingItem.room.streams.flatMap { stream ->
|
||||
stream.urls.map { entry ->
|
||||
entries.put(stream.slug + " " + entry.key, entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
val builder = AlertDialog.Builder(this)
|
||||
val strings = entries.keys.sorted().toTypedArray()
|
||||
builder.setTitle(getString(R.string.select_stream))
|
||||
.setItems(strings) { _, i ->
|
||||
Toast.makeText(this, strings[i], Toast.LENGTH_LONG).show()
|
||||
playStream(
|
||||
streamingItem.conference.conference,
|
||||
streamingItem.room.display,
|
||||
entries[strings[i]])
|
||||
}
|
||||
builder.create().show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun playStream(conference: String, room: String, streamUrl: StreamUrl?) {
|
||||
if (streamUrl != null) {
|
||||
PlayerActivity.launch(this, conference, room, streamUrl)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showConferencesFragment() {
|
||||
showFragment(ConferencesTabBrowseFragment.newInstance(numColumns), "conferences")
|
||||
}
|
||||
|
||||
private fun showBookmarksFragment() {
|
||||
val bookmarksFragment = EventsListFragment.newInstance(EventsListFragment.TYPE_BOOKMARKS, null)
|
||||
showFragment(bookmarksFragment, "bookmarks")
|
||||
}
|
||||
|
||||
private fun showInProgressFragment() {
|
||||
val progressEventsFragment = EventsListFragment.newInstance(EventsListFragment.TYPE_IN_PROGRESS, null)
|
||||
showFragment(progressEventsFragment, "in_progress")
|
||||
}
|
||||
|
||||
private fun showStreamsFragment() {
|
||||
val fragment = LivestreamListFragment.newInstance(numColumns)
|
||||
showFragment(fragment, "streams")
|
||||
}
|
||||
|
||||
private fun showDownloadsFragment() {
|
||||
val fragment = DownloadsListFragment.getInstance(numColumns)
|
||||
showFragment(fragment, "downloads")
|
||||
}
|
||||
|
||||
private fun showSettingsPage() {
|
||||
val intent = Intent(this, SettingsActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun showAboutPage() {
|
||||
// val intent = Intent(this, AboutActivity::class.java)
|
||||
// startActivity(intent)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (drawerOpen) {
|
||||
binding.drawerLayout.closeDrawers()
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
protected fun showFragment(fragment: androidx.fragment.app.Fragment, tag: String) {
|
||||
val fm = supportFragmentManager
|
||||
val oldFragment = fm.findFragmentById(R.id.fragment_container)
|
||||
|
||||
val transitionInflater = TransitionInflater.from(this)
|
||||
if (oldFragment != null) {
|
||||
if (oldFragment.tag.equals(tag)) {
|
||||
return
|
||||
}
|
||||
oldFragment.exitTransition = transitionInflater.inflateTransition(android.R.transition.fade)
|
||||
}
|
||||
fragment.enterTransition = transitionInflater.inflateTransition(android.R.transition.fade)
|
||||
|
||||
// val slideTransition = Slide(Gravity.RIGHT)
|
||||
// fragment.enterTransition = slideTransition
|
||||
|
||||
val ft = fm.beginTransaction()
|
||||
ft.replace(R.id.fragment_container, fragment, tag)
|
||||
ft.setReorderingAllowed(true)
|
||||
ft.setTransition(androidx.fragment.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
ft.commit()
|
||||
}
|
||||
|
||||
override fun onEventSelected(event: Event) {
|
||||
EventDetailsActivity.launch(this, event)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = BrowseActivity::class.simpleName
|
||||
|
||||
fun launch(context: Context) {
|
||||
context.startActivity(Intent(context, BrowseActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package de.nicidienase.chaosflix.touch.browse.eventslist
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Conference
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import de.nicidienase.chaosflix.touch.browse.cast.CastService
|
||||
import de.nicidienase.chaosflix.touch.eventdetails.EventDetailsActivity
|
||||
|
||||
class EventsListActivity : AppCompatActivity(), OnEventSelectedListener {
|
||||
|
||||
protected val numColumns: Int
|
||||
get() = resources.getInteger(R.integer.num_columns)
|
||||
|
||||
private lateinit var casty: CastService
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_events_list)
|
||||
|
||||
casty = CastService(this)
|
||||
|
||||
val conference = intent.getParcelableExtra<Conference>(CONFERENCE_KEY)
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
val eventsListFragment = EventsListFragment.newInstance(EventsListFragment.TYPE_EVENTS, conference)
|
||||
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.fragment_container, eventsListFragment)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menu?.let {
|
||||
casty.addMediaRouteMenuItem(it)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onEventSelected(event: Event) {
|
||||
EventDetailsActivity.launch(this, event)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val CONFERENCE_KEY = "conference_id"
|
||||
|
||||
fun start(context: Context, conference: Conference) {
|
||||
val i = Intent(context, EventsListActivity::class.java)
|
||||
i.putExtra(CONFERENCE_KEY, conference)
|
||||
context.startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
package de.nicidienase.chaosflix.touch.eventdetails
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import de.nicidienase.chaosflix.common.ChaosflixUtil
|
||||
import de.nicidienase.chaosflix.common.OfflineItemManager
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording
|
||||
import de.nicidienase.chaosflix.common.viewmodel.DetailsViewModel
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.touch.OnEventSelectedListener
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import de.nicidienase.chaosflix.touch.browse.cast.CastService
|
||||
import de.nicidienase.chaosflix.touch.playback.PlayerActivity
|
||||
import kotlinx.android.synthetic.main.activity_eventdetails.fragment_container
|
||||
|
||||
class EventDetailsActivity : AppCompatActivity(),
|
||||
EventDetailsFragment.OnEventDetailsFragmentInteractionListener,
|
||||
OnEventSelectedListener {
|
||||
private lateinit var viewModel: DetailsViewModel
|
||||
|
||||
private lateinit var castService: CastService
|
||||
|
||||
private var selectDialog: AlertDialog? = null
|
||||
private var pendingDownload: Bundle? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_eventdetails)
|
||||
|
||||
castService = CastService(this)
|
||||
|
||||
viewModel = ViewModelProviders.of(this, ViewModelFactory.getInstance(this)).get(DetailsViewModel::class.java)
|
||||
|
||||
viewModel.state.observe(this, Observer { liveEvent ->
|
||||
if (liveEvent == null) {
|
||||
return@Observer
|
||||
}
|
||||
val event = liveEvent.data?.getParcelable<Event>(DetailsViewModel.EVENT)
|
||||
val recording = liveEvent.data?.getParcelable<Recording>(DetailsViewModel.RECORDING)
|
||||
val localFile = liveEvent.data?.getString(DetailsViewModel.KEY_LOCAL_PATH)
|
||||
val selectItems: List<Recording>? = liveEvent.data?.getParcelableArrayList(DetailsViewModel.KEY_SELECT_RECORDINGS)
|
||||
when (liveEvent.state) {
|
||||
DetailsViewModel.State.DisplayEvent -> {
|
||||
if (event != null) {
|
||||
showFragmentForEvent(event, true)
|
||||
}
|
||||
}
|
||||
DetailsViewModel.State.PlayOfflineItem -> {
|
||||
if (event != null && recording != null) {
|
||||
playItem(event, recording, localFile)
|
||||
}
|
||||
}
|
||||
DetailsViewModel.State.PlayOnlineItem -> {
|
||||
if (event != null && recording != null) {
|
||||
playItem(event, recording)
|
||||
}
|
||||
}
|
||||
DetailsViewModel.State.SelectRecording -> {
|
||||
if (event != null && selectItems != null) {
|
||||
selectRecording(event, selectItems) { e, r ->
|
||||
viewModel.recordingSelected(e, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
DetailsViewModel.State.DownloadRecording -> {
|
||||
if (event != null && selectItems != null) {
|
||||
selectRecording(event, selectItems) { e, r ->
|
||||
viewModel.download(e, r).observe(this, Observer {
|
||||
when (it?.state) {
|
||||
OfflineItemManager.State.Downloading -> {
|
||||
Snackbar.make(fragment_container, "Download started", Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
OfflineItemManager.State.PermissionRequired -> {
|
||||
pendingDownload = liveEvent.data
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
this.requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
WRITE_PERMISSION_REQUEST)
|
||||
}
|
||||
}
|
||||
OfflineItemManager.State.Done -> {}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
DetailsViewModel.State.PlayExternal -> {
|
||||
if (event != null) {
|
||||
if (selectItems != null) {
|
||||
selectRecording(event, selectItems) { _, r ->
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(r.recordingUrl)))
|
||||
}
|
||||
} else if (recording != null) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(recording.recordingUrl)))
|
||||
}
|
||||
}
|
||||
}
|
||||
DetailsViewModel.State.Error -> {
|
||||
showSnackbar(liveEvent.error ?: "An Error occured")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
val event = intent.getParcelableExtra<Event>(EXTRA_EVENT)
|
||||
|
||||
showFragmentForEvent(event)
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
if (requestCode == WRITE_PERMISSION_REQUEST) {
|
||||
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
|
||||
pendingDownload?.let {
|
||||
val recording = it.getParcelable<Recording>(DetailsViewModel.RECORDING)
|
||||
val event = it.getParcelable<Event>(DetailsViewModel.EVENT)
|
||||
if (event != null && recording != null) {
|
||||
viewModel.download(event, recording)
|
||||
}
|
||||
}
|
||||
pendingDownload = null
|
||||
}
|
||||
} else {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSnackbar(message: String, duration: Int = Snackbar.LENGTH_LONG) {
|
||||
Snackbar.make(fragment_container, message, duration)
|
||||
}
|
||||
|
||||
private fun selectRecording(event: Event, recordings: List<Recording>, action: (Event, Recording) -> Unit) {
|
||||
val items: List<String> = recordings.map { ChaosflixUtil.getStringForRecording(it) }
|
||||
selectRecordingFromList(items) { i ->
|
||||
action.invoke(event, recordings[i])
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectRecordingFromList(items: List<String>, resultHandler: (Int) -> Unit) {
|
||||
val onClickListener = DialogInterface.OnClickListener { _, which -> resultHandler.invoke(which) }
|
||||
if (selectDialog != null) {
|
||||
selectDialog?.dismiss()
|
||||
}
|
||||
val builder = AlertDialog.Builder(this)
|
||||
builder.setItems(items.toTypedArray(), onClickListener)
|
||||
selectDialog = builder.create()
|
||||
selectDialog?.show()
|
||||
}
|
||||
|
||||
private fun showFragmentForEvent(event: Event, addToBackStack: Boolean = false) {
|
||||
val detailsFragment = EventDetailsFragment.newInstance(event)
|
||||
|
||||
detailsFragment.allowEnterTransitionOverlap = true
|
||||
detailsFragment.allowReturnTransitionOverlap = true
|
||||
|
||||
val ft = supportFragmentManager.beginTransaction()
|
||||
ft.replace(R.id.fragment_container, detailsFragment)
|
||||
if (addToBackStack) {
|
||||
ft.addToBackStack(null)
|
||||
}
|
||||
ft.setReorderingAllowed(true)
|
||||
|
||||
ft.commit()
|
||||
}
|
||||
|
||||
override fun onEventSelected(event: Event) {
|
||||
showFragmentForEvent(event, true)
|
||||
}
|
||||
|
||||
override fun onToolbarStateChange() {
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
private fun playItem(event: Event, recording: Recording, localFile: String? = null) {
|
||||
if (castService.connected) {
|
||||
castService.loadMediaAndPlay(recording, event)
|
||||
} else {
|
||||
if (localFile != null) {
|
||||
PlayerActivity.launch(this, event, localFile)
|
||||
} else {
|
||||
PlayerActivity.launch(this, event, recording)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menu?.let {
|
||||
castService.addMediaRouteMenuItem(it)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val EXTRA_EVENT = "extra_event"
|
||||
private const val EXTRA_URI = "extra_uri"
|
||||
private const val EXTRA_GUID = "extra_guid"
|
||||
private const val WRITE_PERMISSION_REQUEST = 23
|
||||
private val TAG = EventDetailsActivity::class.java.simpleName
|
||||
|
||||
fun launch(context: Context, event: Event) {
|
||||
val intent = Intent(context, EventDetailsActivity::class.java)
|
||||
intent.putExtra(EXTRA_EVENT, event)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
fun launch(context: Context, eventId: Uri) {
|
||||
val intent = Intent(context, EventDetailsActivity::class.java)
|
||||
intent.putExtra(EXTRA_URI, eventId)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package de.nicidienase.chaosflix.touch.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import de.nicidienase.chaosflix.touch.R
|
||||
import de.nicidienase.chaosflix.touch.databinding.ActivitySettingsBinding
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val binding = DataBindingUtil
|
||||
.setContentView<ActivitySettingsBinding>(this, R.layout.activity_settings)
|
||||
setSupportActionBar(binding.toolbarInc.toolbar)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setTitle(R.string.preferences)
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="de.nicidienase.chaosflix.touch.settings.SettingsActivity">
|
||||
tools:context="de.nicidienase.chaosflix.touch.NavigationActivity">
|
||||
|
||||
<include
|
||||
android:id="@+id/toolbar_inc"
|
||||
|
|
Loading…
Add table
Reference in a new issue