diff --git a/app-sample/samples.json b/app-sample/samples.json index e1b01528..99073ffe 100644 --- a/app-sample/samples.json +++ b/app-sample/samples.json @@ -1,4 +1,35 @@ [ + { + "javaClassName": "io.noties.markwon.app.samples.nested.ThirdSample", + "id": "202006177155827", + "title": "Third sample", + "description": "\u003e yo! \n\n```\nfinal int i \u003d 0;\n```", + "artifacts": [ + "EDITOR", + "SIMPLE_EXT" + ], + "tags": [ + "a", + "c", + "test" + ] + }, + { + "javaClassName": "io.noties.markwon.app.samples.nested.SecondSample", + "id": "202006177155656", + "title": "Second sample", + "description": "# Hey hey hey", + "artifacts": [ + "CORE", + "RECYCLER" + ], + "tags": [ + "a", + "b", + "c", + "test" + ] + }, { "javaClassName": "io.noties.markwon.app.samples.FirstSample", "id": "202006164150023", diff --git a/app-sample/src/main/assets/samples b/app-sample/src/main/assets/samples new file mode 120000 index 00000000..8de4a4a9 --- /dev/null +++ b/app-sample/src/main/assets/samples @@ -0,0 +1 @@ +../../main/java/io/noties/markwon/app/samples/ \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/Sample.kt b/app-sample/src/main/java/io/noties/markwon/app/Sample.kt index 5a82c7cb..ffb7c5bd 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/Sample.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/Sample.kt @@ -12,4 +12,11 @@ data class Sample( val description: String, val artifacts: List, val tags: List -) : Parcelable \ No newline at end of file +) : Parcelable { + + enum class Language { + JAVA, KOTLIN + } + + data class Code(val language: Language, val sourceCode: String) +} \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/adapt/SampleItem.kt b/app-sample/src/main/java/io/noties/markwon/app/adapt/SampleItem.kt index 64d1c605..c294b874 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/adapt/SampleItem.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/adapt/SampleItem.kt @@ -81,6 +81,21 @@ class SampleItem( val artifacts: FlowLayout = requireView(R.id.artifacts) val tags: FlowLayout = requireView(R.id.tags) } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as SampleItem + + if (sample != other.sample) return false + + return true + } + + override fun hashCode(): Int { + return sample.hashCode() + } } private fun FlowLayout.ensure(viewsCount: Int, layoutResId: Int): List { diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/.editorconfig b/app-sample/src/main/java/io/noties/markwon/app/samples/.editorconfig new file mode 100644 index 00000000..90da45d5 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/.editorconfig @@ -0,0 +1,3 @@ +[{*.java, *.kt}] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/FirstSample.kt b/app-sample/src/main/java/io/noties/markwon/app/samples/FirstSample.kt index f7c484b4..cf20d3a5 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/samples/FirstSample.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/FirstSample.kt @@ -1,15 +1,30 @@ package io.noties.markwon.app.samples -import io.noties.markwon.app.ui.MarkwonSample +import io.noties.markwon.Markwon +import io.noties.markwon.app.ui.MarkwonTextViewSample import io.noties.markwon.sample.annotations.MarkwonArtifact import io.noties.markwon.sample.annotations.MarkwonSampleInfo @MarkwonSampleInfo( - id = "202006164150023", - title = "First Sample", - description = "This **is** _the first_ sample", - artifacts = [MarkwonArtifact.CORE], - tags = ["test"] + id = "202006164150023", + title = "First Sample", + description = "This **is** _the first_ sample", + artifacts = [MarkwonArtifact.CORE], + tags = ["test"] ) -class FirstSample : MarkwonSample() { +class FirstSample : MarkwonTextViewSample() { + + override fun render() { + + val md = """ + # Hello there! + > How are you? + + **bold** and _italic_ and **bold _italic bold_ just bold** + """.trimIndent() + + val markwon: Markwon = Markwon.create(context) + + markwon.setMarkdown(textView, md) + } } \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/nested/SecondSample.kt b/app-sample/src/main/java/io/noties/markwon/app/samples/nested/SecondSample.kt new file mode 100644 index 00000000..c63e645e --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/nested/SecondSample.kt @@ -0,0 +1,65 @@ +package io.noties.markwon.app.samples.nested + +import io.noties.markwon.Markwon +import io.noties.markwon.app.ui.MarkwonTextViewSample +import io.noties.markwon.sample.annotations.MarkwonArtifact +import io.noties.markwon.sample.annotations.MarkwonSampleInfo + +@MarkwonSampleInfo( + id = "202006177155656", + title = "Second sample", + description = "# Hey hey hey", + artifacts = [MarkwonArtifact.CORE, MarkwonArtifact.RECYCLER], + tags = ["b", "c", "a", "test"] +) +class SecondSample : MarkwonTextViewSample() { + override fun render() { + val md = """ + # Hello second + + ```java + final int i = 0; + ``` + """.trimIndent() + + val markwon = Markwon.create(context) + markwon.setMarkdown(textView, md) + } + + val _mock: String + get() = """ + a + b + d + s + as + sd + ds + sd + s + sd + sd + ds + sd + sd + sd + sd + sd + sd + ds + sd + sd + + s + sd + sd + sd + sd + sd + + ds + sd + sd + sd + """.trimIndent() +} \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/samples/nested/ThirdSample.java b/app-sample/src/main/java/io/noties/markwon/app/samples/nested/ThirdSample.java new file mode 100644 index 00000000..2e7ef678 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/samples/nested/ThirdSample.java @@ -0,0 +1,22 @@ +package io.noties.markwon.app.samples.nested; + +import io.noties.markwon.Markwon; +import io.noties.markwon.app.ui.MarkwonTextViewSample; +import io.noties.markwon.sample.annotations.MarkwonArtifact; +import io.noties.markwon.sample.annotations.MarkwonSampleInfo; + +@MarkwonSampleInfo( + id = "202006177155827", + title = "Third sample", + description = "> yo! \n\n```\nfinal int i = 0;\n```", + artifacts = {MarkwonArtifact.SIMPLE_EXT, MarkwonArtifact.EDITOR}, + tags = {"a", "c", "test"} +) +public class ThirdSample extends MarkwonTextViewSample { + @Override + public void render() { + final String md = "# Hello!"; + final Markwon markwon = Markwon.create(context); + markwon.setMarkdown(textView, md); + } +} diff --git a/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonSample.kt b/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonSample.kt index c339bcf0..67b78ccb 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonSample.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonSample.kt @@ -1,5 +1,16 @@ package io.noties.markwon.app.ui +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + abstract class MarkwonSample { + fun createView(inflater: LayoutInflater, container: ViewGroup?): View { + return inflater.inflate(layoutResId, container, false) + } + + abstract fun onViewCreated(view: View) + + protected abstract val layoutResId: Int } \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonTextViewSample.kt b/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonTextViewSample.kt new file mode 100644 index 00000000..58c4f5c8 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/ui/MarkwonTextViewSample.kt @@ -0,0 +1,23 @@ +package io.noties.markwon.app.ui + +import android.content.Context +import android.view.View +import android.widget.TextView + +import io.noties.markwon.app.R + +abstract class MarkwonTextViewSample : MarkwonSample() { + + protected lateinit var context: Context + protected lateinit var textView: TextView + + override val layoutResId: Int = R.layout.sample_text_view + + final override fun onViewCreated(view: View) { + context = view.context + textView = view.findViewById(R.id.text_view) + render() + } + + abstract fun render() +} \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/ui/SampleCodeFragment.kt b/app-sample/src/main/java/io/noties/markwon/app/ui/SampleCodeFragment.kt new file mode 100644 index 00000000..e2de2050 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/ui/SampleCodeFragment.kt @@ -0,0 +1,43 @@ +package io.noties.markwon.app.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.fragment.app.Fragment +import io.noties.markwon.app.R +import io.noties.markwon.app.Sample +import io.noties.markwon.app.utils.readCode + +class SampleCodeFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_sample_code, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val textView: TextView = view.findViewById(R.id.text_view) + val code = sample.readCode(requireContext()) + + textView.text = code.sourceCode + } + + private val sample: Sample by lazy(LazyThreadSafetyMode.NONE) { + arguments!!.getParcelable(ARG_SAMPLE) + } + + companion object { + private const val ARG_SAMPLE = "arg.Sample" + + fun init(sample: Sample): SampleCodeFragment { + return SampleCodeFragment().apply { + arguments = Bundle().apply { + putParcelable(ARG_SAMPLE, sample) + } + } + } + } +} \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/ui/SampleFragment.kt b/app-sample/src/main/java/io/noties/markwon/app/ui/SampleFragment.kt index ae5babe6..59ca1533 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/ui/SampleFragment.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/ui/SampleFragment.kt @@ -1,13 +1,127 @@ package io.noties.markwon.app.ui import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentTransaction +import io.noties.markwon.app.R import io.noties.markwon.app.Sample +import io.noties.markwon.app.utils.active class SampleFragment : Fragment() { + private lateinit var container: ViewGroup + + private var isCodeSelected = false + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_sample, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + container = view.findViewById(R.id.container) + isCodeSelected = savedInstanceState?.getBoolean(KEY_CODE_SELECTED) ?: false + + initAppBar(view) + initTabBar(view) + } + + private fun initAppBar(view: View) { + val appBar: View = view.findViewById(R.id.app_bar) + val icon: View = appBar.findViewById(R.id.app_bar_icon) + val title: TextView = appBar.findViewById(R.id.app_bar_title) + + icon.setOnClickListener { + activity?.onBackPressed() + } + + title.text = sample.title + } + + private fun initTabBar(view: View) { + val tabBar: View = view.findViewById(R.id.tab_bar) + val preview: View = tabBar.findViewById(R.id.tab_bar_preview) + val code: View = tabBar.findViewById(R.id.tab_bar_code) + + preview.setOnClickListener { + if (!it.active) { + it.active = true + code.active = false + showPreview() + } + } + + code.setOnClickListener { + if (!it.active) { + it.active = true + preview.active = false + showCode() + } + } + + // maybe check state (in case of restoration) + + // initial values + preview.active = !isCodeSelected + code.active = isCodeSelected + + if (isCodeSelected) { + showCode() + } else { + showPreview() + } + } + + private fun showPreview() { + isCodeSelected = false + showFragment(TAG_PREVIEW, TAG_CODE) { SamplePreviewFragment.init(sample) } + } + + private fun showCode() { + isCodeSelected = true + showFragment(TAG_CODE, TAG_PREVIEW) { SampleCodeFragment.init(sample) } + } + + private fun showFragment(showTag: String, hideTag: String, provider: () -> Fragment) { + val manager = childFragmentManager + manager.beginTransaction().apply { + setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) + + val existing = manager.findFragmentByTag(showTag) + if (existing != null) { + show(existing) + } else { + add(container.id, provider(), showTag) + } + + manager.findFragmentByTag(hideTag)?.also { + hide(it) + } + + commitAllowingStateLoss() + } + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + + outState.putBoolean(KEY_CODE_SELECTED, isCodeSelected) + } + + private val sample: Sample by lazy(LazyThreadSafetyMode.NONE) { + (arguments!!.getParcelable(ARG_SAMPLE)) + } + companion object { private const val ARG_SAMPLE = "arg.Sample" + private const val TAG_PREVIEW = "tag.Preview" + private const val TAG_CODE = "tag.Code" + private const val KEY_CODE_SELECTED = "key.Selected" fun init(sample: Sample): SampleFragment { val fragment = SampleFragment() diff --git a/app-sample/src/main/java/io/noties/markwon/app/ui/SamplePreviewFragment.kt b/app-sample/src/main/java/io/noties/markwon/app/ui/SamplePreviewFragment.kt new file mode 100644 index 00000000..3bd64ce0 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/ui/SamplePreviewFragment.kt @@ -0,0 +1,38 @@ +package io.noties.markwon.app.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import io.noties.markwon.app.Sample + +class SamplePreviewFragment : Fragment() { + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return markwonSample.createView(inflater, container) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + markwonSample.onViewCreated(view) + } + + private val markwonSample: MarkwonSample by lazy(LazyThreadSafetyMode.NONE) { + val sample: Sample = arguments!!.getParcelable(ARG_SAMPLE)!! + Class.forName(sample.javaClassName).newInstance() as MarkwonSample + } + + companion object { + private const val ARG_SAMPLE = "arg.Sample" + + fun init(sample: Sample): SamplePreviewFragment { + return SamplePreviewFragment().apply { + arguments = Bundle().apply { + putParcelable(ARG_SAMPLE, sample) + } + } + } + } +} \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/utils/SampleUtilsKt.kt b/app-sample/src/main/java/io/noties/markwon/app/utils/SampleUtilsKt.kt index c01f251a..6e88689c 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/utils/SampleUtilsKt.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/utils/SampleUtilsKt.kt @@ -1,9 +1,58 @@ package io.noties.markwon.app.utils +import android.content.Context +import io.noties.markwon.app.Sample import io.noties.markwon.sample.annotations.MarkwonArtifact +import java.io.InputStream +import java.util.Scanner val MarkwonArtifact.displayName: String get() = "@${artifactName()}" val String.tagDisplayName: String - get() = "#$this" \ No newline at end of file + get() = "#$this" + +private const val SAMPLE_PREFIX = "io.noties.markwon.app." + +fun Sample.readCode(context: Context): Sample.Code { + val assets = context.assets + + // keep sample and nested directories + val path = javaClassName + .removePrefix(SAMPLE_PREFIX) + .replace('.', '/') + + // now, we have 2 possibilities -> Kotlin or Java + fun read(stream: InputStream): String { + return Scanner(stream).useDelimiter("\\A").next() + } + + fun obtain(path: String): InputStream? { + return try { + assets.open(path) + } catch (t: Throwable) { + null + } + } + + var language: Sample.Language = Sample.Language.KOTLIN + var stream = obtain("$path.kt") + if (stream == null) { + language = Sample.Language.JAVA + stream = obtain("$path.java") + } + + if (stream == null) { + throw IllegalStateException("Cannot obtain sample file at path: $path") + } + + val code = read(stream) + + try { + stream.close() + } catch (t: Throwable) { + // ignore + } + + return Sample.Code(language, code) +} \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/utils/ViewGroupUtils.kt b/app-sample/src/main/java/io/noties/markwon/app/utils/ViewGroupUtils.kt new file mode 100644 index 00000000..f6cd05b8 --- /dev/null +++ b/app-sample/src/main/java/io/noties/markwon/app/utils/ViewGroupUtils.kt @@ -0,0 +1,7 @@ +package io.noties.markwon.app.utils + +import android.view.View +import android.view.ViewGroup + +val ViewGroup.children: List + get() = (0 until childCount).map { getChildAt(it) } \ No newline at end of file diff --git a/app-sample/src/main/java/io/noties/markwon/app/utils/ViewUtils.kt b/app-sample/src/main/java/io/noties/markwon/app/utils/ViewUtils.kt index b6a5e8f9..58c6e36e 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/utils/ViewUtils.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/utils/ViewUtils.kt @@ -3,6 +3,7 @@ package io.noties.markwon.app.utils import android.view.View import android.view.View.GONE import android.view.View.VISIBLE +import android.view.ViewGroup import android.view.ViewTreeObserver var View.hidden: Boolean @@ -23,4 +24,12 @@ fun View.onPreDraw(action: () -> Unit) { return true } }) -} \ No newline at end of file +} + +var View.active: Boolean + get() = isActivated + set(newValue) { + isActivated = newValue + + (this as? ViewGroup)?.children?.forEach { it.active = newValue } + } \ No newline at end of file diff --git a/app-sample/src/main/res/color/tab_bar_item.xml b/app-sample/src/main/res/color/tab_bar_item.xml new file mode 100644 index 00000000..315f6d25 --- /dev/null +++ b/app-sample/src/main/res/color/tab_bar_item.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app-sample/src/main/res/drawable/ic_arrow_back_white_24dp.xml b/app-sample/src/main/res/drawable/ic_arrow_back_white_24dp.xml index fa122e18..69ceb083 100644 --- a/app-sample/src/main/res/drawable/ic_arrow_back_white_24dp.xml +++ b/app-sample/src/main/res/drawable/ic_arrow_back_white_24dp.xml @@ -1,5 +1,10 @@ - - + + diff --git a/app-sample/src/main/res/drawable/ic_close_white_24dp.xml b/app-sample/src/main/res/drawable/ic_close_white_24dp.xml index 1544037f..85811738 100644 --- a/app-sample/src/main/res/drawable/ic_close_white_24dp.xml +++ b/app-sample/src/main/res/drawable/ic_close_white_24dp.xml @@ -2,8 +2,8 @@ android:width="24dp" android:height="24dp" android:tint="#FFFFFF" - android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportWidth="24" + android:viewportHeight="24"> diff --git a/app-sample/src/main/res/drawable/ic_code_white_24dp.xml b/app-sample/src/main/res/drawable/ic_code_white_24dp.xml new file mode 100644 index 00000000..3925a7c2 --- /dev/null +++ b/app-sample/src/main/res/drawable/ic_code_white_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app-sample/src/main/res/drawable/ic_remove_red_eye_white_24dp.xml b/app-sample/src/main/res/drawable/ic_remove_red_eye_white_24dp.xml new file mode 100644 index 00000000..14954cbf --- /dev/null +++ b/app-sample/src/main/res/drawable/ic_remove_red_eye_white_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app-sample/src/main/res/drawable/ic_search_white_24dp.xml b/app-sample/src/main/res/drawable/ic_search_white_24dp.xml index 4d0f1858..7f8f6ceb 100644 --- a/app-sample/src/main/res/drawable/ic_search_white_24dp.xml +++ b/app-sample/src/main/res/drawable/ic_search_white_24dp.xml @@ -2,8 +2,8 @@ android:width="24dp" android:height="24dp" android:tint="#FFFFFF" - android:viewportWidth="24.0" - android:viewportHeight="24.0"> + android:viewportWidth="24" + android:viewportHeight="24"> diff --git a/app-sample/src/main/res/layout/fragment_sample.xml b/app-sample/src/main/res/layout/fragment_sample.xml new file mode 100644 index 00000000..eea62d93 --- /dev/null +++ b/app-sample/src/main/res/layout/fragment_sample.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app-sample/src/main/res/layout/fragment_sample_code.xml b/app-sample/src/main/res/layout/fragment_sample_code.xml new file mode 100644 index 00000000..d8ac6205 --- /dev/null +++ b/app-sample/src/main/res/layout/fragment_sample_code.xml @@ -0,0 +1,28 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app-sample/src/main/res/layout/fragment_sample_list.xml b/app-sample/src/main/res/layout/fragment_sample_list.xml index a5c4ec48..353095ce 100644 --- a/app-sample/src/main/res/layout/fragment_sample_list.xml +++ b/app-sample/src/main/res/layout/fragment_sample_list.xml @@ -7,18 +7,13 @@ android:orientation="vertical"> + android:orientation="horizontal"> + android:src="@mipmap/ic_launcher" + tools:ignore="ContentDescription" /> + style="@style/AppBarTitle" + android:text="@string/app_name" /> diff --git a/app-sample/src/main/res/layout/fragment_sample_preview.xml b/app-sample/src/main/res/layout/fragment_sample_preview.xml new file mode 100644 index 00000000..47f479af --- /dev/null +++ b/app-sample/src/main/res/layout/fragment_sample_preview.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app-sample/src/main/res/layout/sample_text_view.xml b/app-sample/src/main/res/layout/sample_text_view.xml index bde44965..5ff75fc9 100644 --- a/app-sample/src/main/res/layout/sample_text_view.xml +++ b/app-sample/src/main/res/layout/sample_text_view.xml @@ -13,7 +13,7 @@ android:id="@+id/text_view" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/content_padding" + android:padding="@dimen/content_padding_double" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="?android:attr/textColorPrimary" tools:text="Hello there" /> diff --git a/app-sample/src/main/res/values/colors.xml b/app-sample/src/main/res/values/colors.xml index 0703abc1..46514d33 100644 --- a/app-sample/src/main/res/values/colors.xml +++ b/app-sample/src/main/res/values/colors.xml @@ -12,4 +12,7 @@ #eee #BFFFFFFF + #eee + #fafafa + \ No newline at end of file diff --git a/app-sample/src/main/res/values/dimens.xml b/app-sample/src/main/res/values/dimens.xml index 2b409b32..21ba14f5 100644 --- a/app-sample/src/main/res/values/dimens.xml +++ b/app-sample/src/main/res/values/dimens.xml @@ -8,4 +8,7 @@ 36dip 36dip + + 1dip + 56dip \ No newline at end of file diff --git a/app-sample/src/main/res/values/ids.xml b/app-sample/src/main/res/values/ids.xml index 15c85d84..f12156a6 100644 --- a/app-sample/src/main/res/values/ids.xml +++ b/app-sample/src/main/res/values/ids.xml @@ -1,4 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/app-sample/src/main/res/values/strings.xml b/app-sample/src/main/res/values/strings.xml index 74a01aa0..2ed0d912 100644 --- a/app-sample/src/main/res/values/strings.xml +++ b/app-sample/src/main/res/values/strings.xml @@ -1,4 +1,7 @@ Markwon + + Preview + Code \ No newline at end of file diff --git a/app-sample/src/main/res/values/styles.xml b/app-sample/src/main/res/values/styles.xml index e1416f34..6c16a228 100644 --- a/app-sample/src/main/res/values/styles.xml +++ b/app-sample/src/main/res/values/styles.xml @@ -6,22 +6,46 @@ @color/gray_light @color/gray @color/window_background - @drawable/bg_splash + @drawable/bg_splash + + + + + + + + + + + \ No newline at end of file diff --git a/art/sample-app.epgz b/art/sample-app.epgz index 10314e1f..43d2f596 100644 Binary files a/art/sample-app.epgz and b/art/sample-app.epgz differ diff --git a/sample-utils/processor/src/main/java/io/noties/markwon/sample/processor/MarkwonSampleProcessor.java b/sample-utils/processor/src/main/java/io/noties/markwon/sample/processor/MarkwonSampleProcessor.java index 1fc85213..735b3f21 100644 --- a/sample-utils/processor/src/main/java/io/noties/markwon/sample/processor/MarkwonSampleProcessor.java +++ b/sample-utils/processor/src/main/java/io/noties/markwon/sample/processor/MarkwonSampleProcessor.java @@ -20,11 +20,14 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; +import java.util.Comparator; import java.util.List; import java.util.ListIterator; import java.util.Locale; import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; @@ -33,6 +36,7 @@ import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; +import io.noties.markwon.sample.annotations.MarkwonArtifact; import io.noties.markwon.sample.annotations.MarkwonSampleInfo; public class MarkwonSampleProcessor extends AbstractProcessor { @@ -159,6 +163,8 @@ public class MarkwonSampleProcessor extends AbstractProcessor { // new items come first (DESC order) Collections.sort(samples, (lhs, rhs) -> rhs.id.compareTo(lhs.id)); + // sort each sample artifacts (alphabet) and tags (alphabet) + final String json = new GsonBuilder() .setPrettyPrinting() .create() @@ -176,13 +182,17 @@ public class MarkwonSampleProcessor extends AbstractProcessor { final String id = info.id(); + // NB! sorted artifacts (by name) and tags + final Set artifacts = Stream.of(info.artifacts()) + .collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MarkwonArtifact::name)))); + final MarkwonSample sample = new MarkwonSample( element.getQualifiedName().toString(), id, info.title(), info.description(), - new HashSet<>(Arrays.asList(info.artifacts())), - new HashSet<>(Arrays.asList(info.tags())) + artifacts, + new TreeSet<>(Arrays.asList(info.tags())) ); try {