Improve markdown activity.

This commit is contained in:
Fox2Code 2022-02-11 23:30:55 +01:00
parent f11b7e8cd7
commit 4cd9d9d5c9
4 changed files with 41 additions and 13 deletions

View File

@ -4,7 +4,9 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
@ -40,7 +42,12 @@ public class MarkdownActivity extends CompatActivity {
.getString(Constants.EXTRA_MARKDOWN_TITLE);
String config = intent.getExtras()
.getString(Constants.EXTRA_MARKDOWN_CONFIG);
if (title != null && !title.isEmpty()) setTitle(title);
if (title != null && !title.isEmpty()) {
setTitle(title);
}
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (config != null && !config.isEmpty()) {
String configPkg = IntentHelper.getPackageOfConfig(config);
try {
@ -75,6 +82,8 @@ public class MarkdownActivity extends CompatActivity {
String markdown = new String(rawMarkdown, StandardCharsets.UTF_8);
Log.d(TAG, "Done!");
runOnUiThread(() -> {
findViewById(R.id.markdownFooter)
.setMinimumHeight(this.getNavigationBarHeight());
MainApplication.getINSTANCE().getMarkwon().setMarkdown(
textView, MarkdownUrlLinker.urlLinkify(markdown));
if (markdownBackground != null) {
@ -92,4 +101,11 @@ public class MarkdownActivity extends CompatActivity {
}
}, "Markdown load thread").start();
}
@Override
protected void onResume() {
super.onResume();
View footer = findViewById(R.id.markdownFooter);
if (footer != null) footer.setMinimumHeight(this.getNavigationBarHeight());
}
}

View File

@ -15,8 +15,9 @@ public class MarkdownUrlLinker {
ArrayList<LinkifyTask> linkifyTasks = new ArrayList<>();
int extra = 0;
while (index != -1) {
int end = Math.min(url.indexOf('\n', index),
url.indexOf(' ', index));
int end = url.indexOf(' ', index);
end = end == -1 ? url.indexOf('\n', index) :
Math.min(url.indexOf('\n', index), end);
if (end == -1) end = url.length();
if (index == 0 ||
'\n' == url.charAt(index - 1) ||

View File

@ -1,25 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:id="@+id/markdownBackground">
android:id="@+id/markdownBackground"
app:fitsSystemWindowsInsets="top">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/markdown_border_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
app:cardCornerRadius="@dimen/card_corner_radius" >
app:cardCornerRadius="@dimen/card_corner_radius">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/markdownView"
android:text="@string/loading"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/markdownView"
android:text="@string/loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/markdown_border_content" />
<TextView
android:id="@+id/markdownFooter"
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</androidx.cardview.widget.CardView>
</LinearLayout>

View File

@ -4,5 +4,5 @@
<dimen name="card_corner_radius">8dp</dimen>
<dimen name="markdown_side_clearance">0dp</dimen>
<dimen name="markdown_topdown_clearance">32dp</dimen>
<dimen name="markdown_border_content">0dp</dimen>
<dimen name="markdown_border_content">8dp</dimen>
</resources>