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
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {

defaultConfig {
applicationId "ca.snoe.deedum"
minSdkVersion 16
minSdkVersion flutter.minSdkVersion
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="deedum"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
4 changes: 3 additions & 1 deletion lib/browser_tab/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ class SearchAlertState extends State<SearchAlert> {
SelectableText(widget.prompt),
DecoratedBox(
decoration:
BoxDecoration(color: _inputError ? Colors.deepOrange : null),
BoxDecoration(color: _inputError ? Colors.deepOrange : null),
child: TextField(
focusNode: focusNode,
maxLines: null,
keyboardType: TextInputType.multiline,
controller: widget.searchController,
onChanged: _inputChanged),
),
Expand Down
135 changes: 28 additions & 107 deletions lib/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import 'package:deedum/contents/blockquote.dart';
import 'package:deedum/contents/heading.dart';
import 'package:deedum/contents/link.dart';
import 'package:deedum/contents/list_item.dart';
import 'package:deedum/contents/pre_text.dart';
import 'package:deedum/contents/plain_text.dart';
import 'package:deedum/models/content_data.dart';
import 'package:deedum/parser.dart';
import 'package:deedum/shared.dart';
import 'package:extended_text/extended_text.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'contents/ansi_pre_text.dart';

const baseFontSize = 16.0;

class Content extends StatefulWidget {
const Content({
Expand All @@ -35,6 +38,21 @@ class Content extends StatefulWidget {

class _ContentState extends State<Content> {
var plainTextControls = false;
int ansiLevel = 1;

@override
void initState() {
super.initState();
changeAnsi();
}

changeAnsi() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
ansiLevel = int.parse(prefs.getString('ansiColors') ?? '0');
});
}


showControls(show) {
setState(() {
Expand Down Expand Up @@ -84,11 +102,11 @@ class _ContentState extends State<Content> {
Widget groupsToWidget(List<dynamic> groups) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (final r in groups)
if (r["type"] == "pre")
PreText(actualText: r["data"], maxLine: r["maxLine"])
getPreTextWidget(r)
else if (r["type"] == "header")
Heading(
content: r["data"],
Expand All @@ -108,112 +126,15 @@ class _ContentState extends State<Content> {
PlainText(content: r["data"])
]);
}
}

class PreText extends StatefulWidget {
final String actualText;
final int maxLine;

const PreText({Key? key, required this.actualText, required this.maxLine})
: super(key: key);

@override
_PreTextState createState() => _PreTextState();
}

class _PreTextState extends State<PreText> {
int? _scale;

@override
initState() {
super.initState();
if (widget.maxLine > 120) {
_scale = -1;
}
if (widget.maxLine <= 32) {
_scale = 32;
}
}

setScale(s) {
setState(() {
_scale = s;
});
}

@override
Widget build(BuildContext context) {
var availableWidth = MediaQuery.of(context).size.width - (padding * 2);
Widget fit;

if (_scale == -1) {
fit = SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ExtendedText(
widget.actualText,
selectionEnabled: true,
style: const TextStyle(
fontFamily: "DejaVu Sans Mono",
fontSize: baseFontSize,
),
));
} else if (_scale != null) {
double size = (TextPainter(
text: TextSpan(
text: "0".padLeft(_scale!),
style: const TextStyle(
fontFamily: "DejaVu Sans Mono",
fontSize: baseFontSize,
),
),
maxLines: 1,
textScaleFactor: MediaQuery.of(context).textScaleFactor,
textDirection: TextDirection.ltr)
..layout())
.size
.width;

fit = FittedBox(
fit: BoxFit.fill,
child: SizedBox(
child: ExtendedText(widget.actualText,
softWrap: true,
style: const TextStyle(
fontFamily: "DejaVu Sans Mono", fontSize: baseFontSize),
selectionEnabled: true),
width: size));
} else {
fit = FittedBox(
child: ExtendedText(widget.actualText,
selectionEnabled: true,
style: const TextStyle(
fontFamily: "DejaVu Sans Mono", fontSize: baseFontSize)),
fit: BoxFit.fill);
getPreTextWidget(r) {
changeAnsi();
if (ansiLevel == 0){
return PreText(actualText: r["data"], maxLine: r["maxLine"]);
}
var res = GestureDetector(
onDoubleTap: () async {
var picked = await showMenu(
items: <PopupMenuEntry>[
CheckedPopupMenuItem(
checked: _scale == null,
value: null,
child: const Text("Fit"))
] +
[-1, 32, 40, 64, 80, 120]
.map((i) => CheckedPopupMenuItem(
checked: _scale == i,
value: i,
child: Text("${i == -1 ? "Scroll" : i}")))
.toList(),
context: context,
position: const RelativeRect.fromLTRB(20, 100, 400, 200),
);
setScale(picked);
},
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(width: availableWidth, child: fit)));
return AnsiPreText(actualText: r["data"],
maxLine: r["maxLine"],
ansiLevel: ansiLevel);

return res;
}
}
Loading