Commit 74d80c75 authored by Jonas L.'s avatar Jonas L.

Add new about content dialog

parent 12e2d680
......@@ -14,7 +14,6 @@ import de.determapp.android.ui.viewer.ProjectSpec
import de.determapp.android.ui.viewer.ViewerActivity
import kotlinx.android.synthetic.main.fragment_content_list.*
// TODO: show image sources
class ContentListFragment: Fragment(), Handlers {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_content_list, container, false)
......
......@@ -46,7 +46,13 @@ data class ProjectSpec(val projectId: String, val type: PackageSource): Parcelab
// package source content must have a selected resolution
// local content must not have a selected resolution
// streamed content must have a base url
data class LoadedProjectSpec(val projectSpec: ProjectSpec, val isDownloaded: Boolean, val selectedResolution: Int?, val baseUrl: String?) {
data class LoadedProjectSpec(
val projectSpec: ProjectSpec,
val isDownloaded: Boolean,
val selectedResolution: Int?,
val baseUrl: String?,
val previewImageSource: String
) {
init {
if (projectSpec.type == PackageSource.DownloadedFromLocalNetwork) {
if (!isDownloaded) {
......@@ -74,4 +80,4 @@ data class LoadedProjectSpec(val projectSpec: ProjectSpec, val isDownloaded: Boo
enum class PackageSource {
DownloadedFromLocalNetwork, WebPackageSource
}
\ No newline at end of file
}
......@@ -16,6 +16,7 @@ import com.mikepenz.materialdrawer.DrawerBuilder
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem
import com.mikepenz.materialdrawer.model.ProfileDrawerItem
import de.determapp.android.R
import de.determapp.android.ui.viewer.info.ProjectInfoDialogFragment
import de.determapp.android.ui.viewer.info.ViewerContentInfoDialogFragment
import de.determapp.android.ui.viewer.loading.ViewerModel
import kotlinx.android.synthetic.main.app_bar_viewer.*
......@@ -76,6 +77,18 @@ class ViewerActivity : AppCompatActivity(), StackAdapterHandler, ViewPager.OnPag
.withToolbar(toolbar)
.withSavedInstance(savedInstanceState)
.withAccountHeader(accountHeader)
.addStickyDrawerItems(
PrimaryDrawerItem()
.withName(R.string.viewer_menu_about_project)
.withIcon(R.drawable.ic_info_outline_black_24dp)
.withIconTintingEnabled(true)
.withSelectable(false)
.withOnDrawerItemClickListener { _, _, _ ->
ProjectInfoDialogFragment().show(supportFragmentManager)
false
}
)
.build()
pager.adapter = pagerAdapter
......
......@@ -6,7 +6,11 @@ sealed class ViewerStatus
object ViewerStatusLoading: ViewerStatus()
object ViewerStatusError: ViewerStatus()
data class ViewerStatusRunning(val project: Project, val stack: Stack, val loadedProjectSpec: LoadedProjectSpec): ViewerStatus() {
data class ViewerStatusRunning(
val project: Project,
val stack: Stack,
val loadedProjectSpec: LoadedProjectSpec
): ViewerStatus() {
init {
if (!stack.doesMatchToProject(project)) {
throw IllegalStateException()
......
package de.determapp.android.ui.viewer.info
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import de.determapp.android.R
import de.determapp.android.databinding.ProjectInfoDialogBinding
import de.determapp.android.ui.viewer.ViewerActivity
import de.determapp.android.ui.viewer.ViewerStatusRunning
class ProjectInfoDialogFragment: BottomSheetDialogFragment() {
companion object {
const val TAG = "ProjectInfoDialogFragment"
}
fun show(fragmentManager: FragmentManager) {
show(fragmentManager, TAG)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding = ProjectInfoDialogBinding.inflate(inflater, container, false)
val activity = activity as ViewerActivity
val model = activity.model
val status = model.getStatus()
binding.handlers = object: ProjectInfoHandlers {
override fun openImprint() {
val currentStatus = status.value
if (currentStatus is ViewerStatusRunning) {
try {
startActivity(
Intent(Intent.ACTION_VIEW, Uri.parse(currentStatus.project.imprint))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
} catch (ex: Throwable) {
Toast.makeText(context, R.string.toast_open_external_failed, Toast.LENGTH_SHORT).show()
}
}
}
}
status.observe(this, Observer {
if (!(it is ViewerStatusRunning)) {
dismissAllowingStateLoss()
} else {
binding.status = ViewerProjectInfo(
it.project.title,
it.project.description,
!TextUtils.isEmpty(it.project.imprint),
previewImageSource = it.loadedProjectSpec.previewImageSource
)
}
})
return binding.root
}
}
data class ViewerProjectInfo (
val title: String,
val description: String,
val hasImprint: Boolean,
val previewImageSource: String
)
interface ProjectInfoHandlers {
fun openImprint()
}
......@@ -50,9 +50,10 @@ fun loadDownloadedLocalNetworkContentProject(projectId: String, context: Context
val loadedProjectSpec = LoadedProjectSpec(
ProjectSpec(projectId, PackageSource.DownloadedFromLocalNetwork),
true,
null,
null
isDownloaded = true,
selectedResolution = null,
baseUrl = null,
previewImageSource = ""
)
runOnUiThread(Runnable {
......
......@@ -4,7 +4,6 @@ import android.content.Context
import android.util.JsonReader
import android.util.Log
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations
import de.determapp.android.BuildConfig
import de.determapp.android.content.ContentJsonParser
......@@ -52,10 +51,11 @@ fun loadPackageSourceContent(projectId: String, context: Context): ProjectLoader
}
val loadedProjectSpec = LoadedProjectSpec(
ProjectSpec(projectId, PackageSource.WebPackageSource),
idDownloaded,
dbEntryValue.resolution,
dbEntryValue.url
projectSpec = ProjectSpec(projectId, PackageSource.WebPackageSource),
isDownloaded = idDownloaded,
selectedResolution = dbEntryValue.resolution,
baseUrl = dbEntryValue.url,
previewImageSource = dbEntryValue.imageSource
)
result.value = ProjectLoadingStatusReady(project, loadedProjectSpec)
......@@ -75,7 +75,7 @@ fun loadPackageSourceContent(projectId: String, context: Context): ProjectLoader
executor = Async.network
}
executor.execute({
executor.execute {
synchronized(loadingLock) {
if (dbEntryValue == null) {
result.value = ProjectLoadingStatusFailed
......@@ -114,32 +114,33 @@ fun loadPackageSourceContent(projectId: String, context: Context): ProjectLoader
}
}
}
})
}
}
result.addSource(urlAndLocalFilenameObservable, {
result.addSource(urlAndLocalFilenameObservable) {
if (BuildConfig.DEBUG) {
Log.d(LOG_TAG, "url or filename changed")
}
tryLoadingAsync()
})
}
result.addSource(resolutionObservable, Observer {
result.addSource(resolutionObservable) {
val value = result.value
if (value is ProjectLoadingStatusReady) {
result.value = ProjectLoadingStatusReady(
value.project,
LoadedProjectSpec(
value.loadedProjectSpec.projectSpec,
value.loadedProjectSpec.isDownloaded,
it,
value.loadedProjectSpec.baseUrl
projectSpec = value.loadedProjectSpec.projectSpec,
isDownloaded = value.loadedProjectSpec.isDownloaded,
selectedResolution = it,
baseUrl = value.loadedProjectSpec.baseUrl,
previewImageSource = value.loadedProjectSpec.previewImageSource
)
)
}
})
}
return ProjectLoaderResult(
result,
......
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="status"
type="de.determapp.android.ui.viewer.info.ViewerProjectInfo" />
<variable
name="handlers"
type="de.determapp.android.ui.viewer.info.ProjectInfoHandlers" />
<import type="android.view.View" />
<import type="android.text.TextUtils" />
</data>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:minWidth="400dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:padding="@dimen/view_margin"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="@{status.title}"
android:textAppearance="?android:textAppearanceLarge"
tools:text="Schmetterlinge"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:visibility="@{TextUtils.isEmpty(status.description) ? View.GONE : View.VISIBLE}"
android:text="@{status.description}"
android:textAppearance="?android:textAppearanceMedium"
tools:text="Dieser Bestimmungsschlüssel enthält die 50 häufigsten Tagfalter Deutschlands laut dem Tagfalter Monitoring Deutschland. Die Bildquellen sind jeweils auf den Ergebnissseiten angegeben."
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:visibility="@{TextUtils.isEmpty(status.description) ? View.VISIBLE : View.GONE}"
android:textAppearance="?android:textAppearanceMedium"
android:text="@string/viewer_info_dialog_no_description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:enabled="@{safeUnbox(status.hasImprint)}"
android:onClick="@{() -> handlers.openImprint()}"
style="?android:buttonStyleSmall"
android:background="?selectableItemBackground"
android:text="@string/viewer_info_dialog_btn_imprint"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:visibility="@{safeUnbox(status.hasImprint) ? View.GONE : View.VISIBLE}"
android:textAppearance="?android:textAppearanceSmall"
android:text="@string/viewer_info_dialog_no_description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:visibility="@{TextUtils.isEmpty(status.previewImageSource) ? View.GONE : View.VISIBLE}"
android:textAppearance="?android:textAppearanceLarge"
android:text="@string/viewer_info_dialog_preview_image_source"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:visibility="@{TextUtils.isEmpty(status.previewImageSource) ? View.GONE : View.VISIBLE}"
android:textAppearance="?android:textAppearanceMedium"
tools:text="https://www.google.com (dümmste mögliche Quellenangabe)"
android:text="@{status.previewImageSource}"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</layout>
......@@ -60,6 +60,8 @@
</plurals>
<string name="viewer_subtitle_last_question">Das ist die letzte Frage</string>
<string name="viewer_menu_about_project">Über den Bestimmungsschlüssel</string>
<string name="viewer_info_dialog_btn_imprint">Impressum des Bestimmungsschlüssels öffnen</string>
<string name="viewer_info_dialog_section_resolution">Auflösung der Bilder</string>
<string name="viewer_info_dialog_section_download">Download</string>
......@@ -75,6 +77,9 @@
<string name="viewer_info_dialog_notice_background_update">Heruntergeladene Bestimmungsschlüssel werden regelmäßig im Hintergrund aktualisiert</string>
<string name="viewer_info_dialog_resolution_spinner_item">%1$d Pixel breit (ingesamt %2$s groß)</string>
<string name="viewer_info_dialog_resolution_spinner_empty">Keine Bilder vorhanden</string>
<string name="viewer_info_dialog_no_description">Es wurde keine Beschreibung für diesen Bestimmunsschlüssel hinterlegt</string>
<string name="viewer_info_dialog_no_imprint">Es wurde kein Impressum für diesen Bestimmungsschlüssel hinterlegt</string>
<string name="viewer_info_dialog_preview_image_source">Quelle des Vorschaubilds</string>
<string name="toast_open_external_failed">Öffnen fehlgeschlagen</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment