From f625b677873012ace36ff73f052cd8eed84faeaa Mon Sep 17 00:00:00 2001
From: Cyrus Bakhtiari-Haftlang <cyrus.bh@gmail.com>
Date: Mon, 1 Oct 2018 15:10:43 +0200
Subject: [PATCH] Separation of MarkwonView from MarkwonViewCompat

Rationale:
Consumers may now include MarkwonView without transitively including the support library
---
 markwon-view-common/README.md                 | 22 +++++++++++++
 markwon-view-common/build.gradle              | 20 ++++++++++++
 markwon-view-common/gradle.properties         |  3 ++
 .../debug/DebugConfigurationProvider.java     |  0
 .../src/debug/res/values/debug_strings.xml    |  0
 .../src/main/AndroidManifest.xml              |  1 +
 .../ru/noties/markwon/view/IMarkwonView.java  |  0
 .../markwon/view/MarkwonViewHelper.java       |  0
 .../src/main/res/values/attrs.xml             |  0
 markwon-view-compat/README.md                 | 21 ++++++++++++
 markwon-view-compat/build.gradle              | 23 +++++++++++++
 markwon-view-compat/gradle.properties         |  3 ++
 .../layout/debug_markwon_preview_compat.xml   |  0
 .../src/main/AndroidManifest.xml              |  1 +
 .../markwon/view/MarkwonViewCompat.java       |  0
 markwon-view/README.md                        | 32 ++++---------------
 markwon-view/build.gradle                     |  7 +---
 settings.gradle                               |  4 ++-
 18 files changed, 104 insertions(+), 33 deletions(-)
 create mode 100644 markwon-view-common/README.md
 create mode 100644 markwon-view-common/build.gradle
 create mode 100644 markwon-view-common/gradle.properties
 rename {markwon-view => markwon-view-common}/src/debug/java/ru/noties/markwon/view/debug/DebugConfigurationProvider.java (100%)
 rename {markwon-view => markwon-view-common}/src/debug/res/values/debug_strings.xml (100%)
 create mode 100644 markwon-view-common/src/main/AndroidManifest.xml
 rename {markwon-view => markwon-view-common}/src/main/java/ru/noties/markwon/view/IMarkwonView.java (100%)
 rename {markwon-view => markwon-view-common}/src/main/java/ru/noties/markwon/view/MarkwonViewHelper.java (100%)
 rename {markwon-view => markwon-view-common}/src/main/res/values/attrs.xml (100%)
 create mode 100644 markwon-view-compat/README.md
 create mode 100644 markwon-view-compat/build.gradle
 create mode 100644 markwon-view-compat/gradle.properties
 rename {markwon-view => markwon-view-compat}/src/debug/res/layout/debug_markwon_preview_compat.xml (100%)
 create mode 100644 markwon-view-compat/src/main/AndroidManifest.xml
 rename {markwon-view => markwon-view-compat}/src/main/java/ru/noties/markwon/view/MarkwonViewCompat.java (100%)

diff --git a/markwon-view-common/README.md b/markwon-view-common/README.md
new file mode 100644
index 00000000..16e6d5a4
--- /dev/null
+++ b/markwon-view-common/README.md
@@ -0,0 +1,22 @@
+# Markwon View Common
+
+[![maven|markwon-view](https://img.shields.io/maven-central/v/ru.noties/markwon-view.svg?label=maven%7Cmarkwon-view)](http://search.maven.org/#search|ga|1|g%3A%22ru.noties%22%20AND%20a%3A%markwon-view%22)
+
+This library is the backbone of `MarkwonView` and `MarkwonViewCompat` and acts as glue code to `Markwon` by exposing `IMarkwonView`:
+```java
+public interface IMarkwonView {
+
+    interface ConfigurationProvider {
+        @NonNull
+        SpannableConfiguration provide(@NonNull Context context);
+    }
+
+    void setConfigurationProvider(@NonNull ConfigurationProvider provider);
+
+    void setMarkdown(@Nullable String markdown);
+    void setMarkdown(@Nullable SpannableConfiguration configuration, @Nullable String markdown);
+
+    @Nullable
+    String getMarkdown();
+}
+```
\ No newline at end of file
diff --git a/markwon-view-common/build.gradle b/markwon-view-common/build.gradle
new file mode 100644
index 00000000..cd01be3c
--- /dev/null
+++ b/markwon-view-common/build.gradle
@@ -0,0 +1,20 @@
+apply plugin: 'com.android.library'
+
+android {
+
+    compileSdkVersion config['compile-sdk']
+    buildToolsVersion config['build-tools']
+
+    defaultConfig {
+        minSdkVersion config['min-sdk']
+        targetSdkVersion config['target-sdk']
+        versionCode 1
+        versionName version
+    }
+}
+
+dependencies {
+    api project(':markwon')
+}
+
+registerArtifact(this)
diff --git a/markwon-view-common/gradle.properties b/markwon-view-common/gradle.properties
new file mode 100644
index 00000000..ed244110
--- /dev/null
+++ b/markwon-view-common/gradle.properties
@@ -0,0 +1,3 @@
+POM_NAME=Markwon-View
+POM_ARTIFACT_ID=markwon-view-common
+POM_PACKAGING=aar
\ No newline at end of file
diff --git a/markwon-view/src/debug/java/ru/noties/markwon/view/debug/DebugConfigurationProvider.java b/markwon-view-common/src/debug/java/ru/noties/markwon/view/debug/DebugConfigurationProvider.java
similarity index 100%
rename from markwon-view/src/debug/java/ru/noties/markwon/view/debug/DebugConfigurationProvider.java
rename to markwon-view-common/src/debug/java/ru/noties/markwon/view/debug/DebugConfigurationProvider.java
diff --git a/markwon-view/src/debug/res/values/debug_strings.xml b/markwon-view-common/src/debug/res/values/debug_strings.xml
similarity index 100%
rename from markwon-view/src/debug/res/values/debug_strings.xml
rename to markwon-view-common/src/debug/res/values/debug_strings.xml
diff --git a/markwon-view-common/src/main/AndroidManifest.xml b/markwon-view-common/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..6340e29d
--- /dev/null
+++ b/markwon-view-common/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest package="ru.noties.markwon.view" />
diff --git a/markwon-view/src/main/java/ru/noties/markwon/view/IMarkwonView.java b/markwon-view-common/src/main/java/ru/noties/markwon/view/IMarkwonView.java
similarity index 100%
rename from markwon-view/src/main/java/ru/noties/markwon/view/IMarkwonView.java
rename to markwon-view-common/src/main/java/ru/noties/markwon/view/IMarkwonView.java
diff --git a/markwon-view/src/main/java/ru/noties/markwon/view/MarkwonViewHelper.java b/markwon-view-common/src/main/java/ru/noties/markwon/view/MarkwonViewHelper.java
similarity index 100%
rename from markwon-view/src/main/java/ru/noties/markwon/view/MarkwonViewHelper.java
rename to markwon-view-common/src/main/java/ru/noties/markwon/view/MarkwonViewHelper.java
diff --git a/markwon-view/src/main/res/values/attrs.xml b/markwon-view-common/src/main/res/values/attrs.xml
similarity index 100%
rename from markwon-view/src/main/res/values/attrs.xml
rename to markwon-view-common/src/main/res/values/attrs.xml
diff --git a/markwon-view-compat/README.md b/markwon-view-compat/README.md
new file mode 100644
index 00000000..285f179f
--- /dev/null
+++ b/markwon-view-compat/README.md
@@ -0,0 +1,21 @@
+# Markwon View Compat
+
+[![maven|markwon-view](https://img.shields.io/maven-central/v/ru.noties/markwon-view.svg?label=maven%7Cmarkwon-view)](http://search.maven.org/#search|ga|1|g%3A%22ru.noties%22%20AND%20a%3A%markwon-view%22)
+
+This library allows for rendering markdown through a widget `MarkwonViewCompat` and supports the following XML attributes:
+```
+app:mv_markdown="string"
+app:mv_configurationProvider="string"
+```
+
+`MarkdownViewCompat` extends Android's support library's `AppCompatTextView`. Prefer this library when you benefit from features in `AppCompatTextView`.
+
+Android Studio's layout-preview supports rendering (with some exceptions, for example, bold span is not rendered due to some limitations of layout preview) markdown text.
+
+`mv_markdown` accepts a string and represents raw markdown
+
+`mv_configurationProvider` accepts a string and represents a full class name of a class of type `ConfigurationProvider`,
+for example: `com.example.my.package.MyConfigurationProvider` (this class must have an empty constructor
+in order to be instantiated via reflection).
+
+Please note that those views parse markdown in main thread, so their usage must be for relatively small markdown portions only
\ No newline at end of file
diff --git a/markwon-view-compat/build.gradle b/markwon-view-compat/build.gradle
new file mode 100644
index 00000000..4253abfa
--- /dev/null
+++ b/markwon-view-compat/build.gradle
@@ -0,0 +1,23 @@
+apply plugin: 'com.android.library'
+
+android {
+
+    compileSdkVersion config['compile-sdk']
+    buildToolsVersion config['build-tools']
+
+    defaultConfig {
+        minSdkVersion config['min-sdk']
+        targetSdkVersion config['target-sdk']
+        versionCode 1
+        versionName version
+    }
+}
+
+dependencies {
+    api project(':markwon-view-common')
+    deps.with {
+        compileOnly it['support-app-compat']
+    }
+}
+
+registerArtifact(this)
diff --git a/markwon-view-compat/gradle.properties b/markwon-view-compat/gradle.properties
new file mode 100644
index 00000000..7c2cb779
--- /dev/null
+++ b/markwon-view-compat/gradle.properties
@@ -0,0 +1,3 @@
+POM_NAME=Markwon-View
+POM_ARTIFACT_ID=markwon-view-compat
+POM_PACKAGING=aar
\ No newline at end of file
diff --git a/markwon-view/src/debug/res/layout/debug_markwon_preview_compat.xml b/markwon-view-compat/src/debug/res/layout/debug_markwon_preview_compat.xml
similarity index 100%
rename from markwon-view/src/debug/res/layout/debug_markwon_preview_compat.xml
rename to markwon-view-compat/src/debug/res/layout/debug_markwon_preview_compat.xml
diff --git a/markwon-view-compat/src/main/AndroidManifest.xml b/markwon-view-compat/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..6340e29d
--- /dev/null
+++ b/markwon-view-compat/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest package="ru.noties.markwon.view" />
diff --git a/markwon-view/src/main/java/ru/noties/markwon/view/MarkwonViewCompat.java b/markwon-view-compat/src/main/java/ru/noties/markwon/view/MarkwonViewCompat.java
similarity index 100%
rename from markwon-view/src/main/java/ru/noties/markwon/view/MarkwonViewCompat.java
rename to markwon-view-compat/src/main/java/ru/noties/markwon/view/MarkwonViewCompat.java
diff --git a/markwon-view/README.md b/markwon-view/README.md
index 71f032db..a6e9e54f 100644
--- a/markwon-view/README.md
+++ b/markwon-view/README.md
@@ -2,40 +2,20 @@
 
 [![maven|markwon-view](https://img.shields.io/maven-central/v/ru.noties/markwon-view.svg?label=maven%7Cmarkwon-view)](http://search.maven.org/#search|ga|1|g%3A%22ru.noties%22%20AND%20a%3A%markwon-view%22)
 
-This is simple library containing 2 views that are able to display markdown:
-* MarkwonView - extends `android.view.TextView`
-* MarkwonViewCompat - extends `android.support.v7.widget.AppCompatTextView`
-
-Both of them implement common `IMarkwonView` interface:
-```java
-public interface IMarkwonView {
-
-    interface ConfigurationProvider {
-        @NonNull
-        SpannableConfiguration provide(@NonNull Context context);
-    }
-
-    void setConfigurationProvider(@NonNull ConfigurationProvider provider);
-
-    void setMarkdown(@Nullable String markdown);
-    void setMarkdown(@Nullable SpannableConfiguration configuration, @Nullable String markdown);
-
-    @Nullable
-    String getMarkdown();
-}
-```
-
-Both views support layout-preview in Android Studio (with some exceptions, for example, bold span is not rendered due to some limitations of layout preview).
-These are XML attributes:
+This library allows for rendering markdown through a widget `MarkwonView` and supports the following XML attributes:
 ```
 app:mv_markdown="string"
 app:mv_configurationProvider="string"
 ```
 
+Prefer this library over `MarkdownViewCompat` if you do not want dependency to Android's support library.
+
+Android Studio's layout-preview supports rendering (with some exceptions, for example, bold span is not rendered due to some limitations of layout preview) markdown text.
+
 `mv_markdown` accepts a string and represents raw markdown
 
 `mv_configurationProvider` accepts a string and represents a full class name of a class of type `ConfigurationProvider`,
 for example: `com.example.my.package.MyConfigurationProvider` (this class must have an empty constructor
 in order to be instantiated via reflection).
 
-Please note that those views parse markdown in main thread, so their usage must be for relatively small markdown portions only
+Please note that those views parse markdown in main thread, so their usage must be for relatively small markdown portions only
\ No newline at end of file
diff --git a/markwon-view/build.gradle b/markwon-view/build.gradle
index 5e4e72ab..3c80cd45 100644
--- a/markwon-view/build.gradle
+++ b/markwon-view/build.gradle
@@ -14,12 +14,7 @@ android {
 }
 
 dependencies {
-
-    api project(':markwon')
-
-    deps.with {
-        compileOnly it['support-app-compat']
-    }
+    api project(':markwon-view-common')
 }
 
 registerArtifact(this)
diff --git a/settings.gradle b/settings.gradle
index 11192dbe..4edbb27d 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,3 +1,5 @@
 rootProject.name = 'MarkwonProject'
-include ':app', ':markwon', ':markwon-image-loader', ':markwon-view', ':sample-custom-extension', ':sample-latex-math',
+include ':app', ':markwon', ':markwon-image-loader',
+        ':markwon-view', ':markwon-view-compat', ':markwon-view-common',
+        ':sample-custom-extension', ':sample-latex-math',
         ':markwon-syntax-highlight', ':markwon-html-parser-api', ':markwon-html-parser-impl'