Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2021 Andy Scherzinger <info@andy-scherzinger.de>
* SPDX-FileCopyrightText: 2021 Marcel Hibbe <dev@mhibbe.de>
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package com.nextcloud.talk.fullscreenfile

import android.content.res.Configuration
import android.widget.TextView
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.nextcloud.talk.R
import com.nextcloud.talk.components.StandardAppBar
import io.noties.markwon.Markwon

@Composable
fun FullScreenTextScreen(title: String, text: String, isMarkdown: Boolean, onShare: () -> Unit, onSave: () -> Unit) {
val menuItems = listOf(
stringResource(R.string.share) to onShare,
stringResource(R.string.nc_save_message) to onSave
)

Scaffold(
topBar = { StandardAppBar(title = title, menuItems = menuItems) },
contentWindowInsets = WindowInsets.safeDrawing
) { paddingValues ->
if (isMarkdown) {
AndroidView(
factory = { ctx ->
TextView(ctx).apply {
setTextIsSelectable(true)
val markwon = Markwon.create(ctx)
markwon.setMarkdown(this, text)
}
},
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
.padding(start = 16.dp, top = 0.dp, end = 16.dp, bottom = 0.dp)
)
} else {
SelectionContainer(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
.verticalScroll(rememberScrollState())
) {
Text(
text = text,
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, top = 0.dp, end = 16.dp, bottom = 0.dp)
)
}
}
}
}

private const val PREVIEW_TEXT = """
# Heading

This is a sample paragraph with **bold** and *italic* text.

- Item one
- Item two
- Item three
"""

@Preview(name = "Light", showBackground = true)
@Composable
private fun PreviewFullScreenTextScreenLight() {
MaterialTheme(colorScheme = lightColorScheme()) {
FullScreenTextScreen(
title = "notes.md",
text = PREVIEW_TEXT,
isMarkdown = false,
onShare = {},
onSave = {}
)
}
}

@Preview(name = "Dark", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun PreviewFullScreenTextScreenDark() {
MaterialTheme(colorScheme = darkColorScheme()) {
FullScreenTextScreen(
title = "notes.md",
text = PREVIEW_TEXT,
isMarkdown = false,
onShare = {},
onSave = {}
)
}
}

@Preview(name = "RTL - Arabic", showBackground = true, locale = "ar")
@Composable
private fun PreviewFullScreenTextScreenRtl() {
MaterialTheme(colorScheme = lightColorScheme()) {
FullScreenTextScreen(
title = "ملاحظات.md",
text = "هذا نص تجريبي باللغة العربية لاختبار تخطيط الواجهة من اليمين إلى اليسار.",
isMarkdown = false,
onShare = {},
onSave = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,114 +10,69 @@ package com.nextcloud.talk.fullscreenfile

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.MaterialTheme
import androidx.core.content.FileProvider
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.DialogFragment
import autodagger.AutoInjector
import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.databinding.ActivityFullScreenTextBinding
import com.nextcloud.talk.components.ColoredStatusBar
import com.nextcloud.talk.ui.dialog.SaveToStorageDialogFragment
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.Mimetype.TEXT_PREFIX_GENERIC
import io.noties.markwon.Markwon
import com.nextcloud.talk.utils.adjustUIForAPILevel35
import java.io.File
import javax.inject.Inject

@AutoInjector(NextcloudTalkApplication::class)
class FullScreenTextViewerActivity : AppCompatActivity() {
lateinit var binding: ActivityFullScreenTextBinding

@Inject
lateinit var viewThemeUtils: ViewThemeUtils

private lateinit var path: String

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_preview, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> {
onBackPressedDispatcher.onBackPressed()
true
}

R.id.share -> {
val shareUri = FileProvider.getUriForFile(
this,
BuildConfig.APPLICATION_ID,
File(path)
)

val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, shareUri)
type = TEXT_PREFIX_GENERIC
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.send_to)))

true
}

R.id.save -> {
val saveFragment: DialogFragment = SaveToStorageDialogFragment.newInstance(
intent.getStringExtra("FILE_NAME").toString()
)
saveFragment.show(
supportFragmentManager,
SaveToStorageDialogFragment.TAG
)
true
}

else -> {
super.onOptionsItemSelected(item)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)

binding = ActivityFullScreenTextBinding.inflate(layoutInflater)
setContentView(binding.root)

setSupportActionBar(binding.textviewToolbar)

val fileName = intent.getStringExtra("FILE_NAME")
val fileName = intent.getStringExtra("FILE_NAME").orEmpty()
val isMarkdown = intent.getBooleanExtra("IS_MARKDOWN", false)
path = applicationContext.cacheDir.absolutePath + "/" + fileName
val path = applicationContext.cacheDir.absolutePath + "/" + fileName
val text = readFile(path)

if (isMarkdown) {
val markwon = Markwon.create(applicationContext)
markwon.setMarkdown(binding.textView, text)
} else {
binding.textView.text = text
adjustUIForAPILevel35()

setContent {
val colorScheme = viewThemeUtils.getColorScheme(this)
MaterialTheme(colorScheme = colorScheme) {
ColoredStatusBar()
FullScreenTextScreen(
title = fileName,
text = text,
isMarkdown = isMarkdown,
onShare = { shareFile(path) },
onSave = { showSaveDialog(fileName) }
)
}
}
}

supportActionBar?.title = fileName
supportActionBar?.setDisplayHomeAsUpEnabled(true)

viewThemeUtils.platform.themeStatusBar(this)
viewThemeUtils.material.themeToolbar(binding.textviewToolbar)
viewThemeUtils.material.colorToolbarOverflowIcon(binding.textviewToolbar)

if (resources != null) {
DisplayUtils.applyColorToNavigationBar(
this.window,
ResourcesCompat.getColor(resources, R.color.bg_default, null)
)
private fun shareFile(path: String) {
val shareUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID, File(path))
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, shareUri)
type = TEXT_PREFIX_GENERIC
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.send_to)))
}

private fun showSaveDialog(fileName: String) {
val saveFragment: DialogFragment = SaveToStorageDialogFragment.newInstance(fileName)
saveFragment.show(supportFragmentManager, SaveToStorageDialogFragment.TAG)
}

private fun readFile(fileName: String) = File(fileName).inputStream().readBytes().toString(Charsets.UTF_8)
Expand Down
53 changes: 0 additions & 53 deletions app/src/main/res/layout/activity_full_screen_text.xml

This file was deleted.

Loading