Skip to content

Commit

Permalink
Drop core & commons name convention
Browse files Browse the repository at this point in the history
  • Loading branch information
hanggrian committed Aug 15, 2023
1 parent dbcca48 commit bdea594
Show file tree
Hide file tree
Showing 76 changed files with 687 additions and 1,015 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100

[*.md]
max_line_length = 80

[*.{kt,kts}]
indent_size = 4

Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ repositories {
google()
}
dependencies {
implementation "com.hendraanggrian.appcompat:socialview-core:$version" // base widgets
implementation "com.hendraanggrian.appcompat:socialview-commons:$version" // auto-complete EditText
// base widgets
implementation "com.hendraanggrian.appcompat:socialview:$version"
// auto-complete widgets
implementation "com.hendraanggrian.appcompat:socialview-autocomplete:$version"
}
```

## Usage

### Core

Core library contains `SocialTextView`, `SocialEditText` and helper class applies these behavior
into any `TextView`.
Core library contains `SocialTextView`, `SocialEditText` and helper class
applies these behavior into any `TextView`.

```xml
<com.hendraanggrian.appcompat.widget.SocialTextView
Expand Down Expand Up @@ -61,9 +64,9 @@ textView.setOnHashtagClickListener(new SocialView.OnClickListener() {
});
```

### Commons
### Auto-complete

Commons library comes with `SocialAutoCompleteTextView`.
Extended library comes with `SocialAutoCompleteTextView`.

```xml
<com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView
Expand All @@ -75,7 +78,8 @@ Commons library comes with `SocialAutoCompleteTextView`.
app:hyperlinkColor="@color/green"/>
```

To display suggestions, it is required to `setHashtagAdapter()` and `setMentionAdapter()`.
To display suggestions, it is required to `setHashtagAdapter()`
and `setMentionAdapter()`.

```java
ArrayAdapter<Hashtag> hashtagAdapter = new HashtagAdapter(getContext());
Expand All @@ -91,8 +95,8 @@ mentionAdapter.add(new Mention("hendraanggrian", "Hendra Anggrian", "https://ava
textView.setMentionAdapter(mentionAdapter);
```

To customize hashtag or mention adapter, create a custom adapter using customized `SocialAdapter` or
write your own `ArrayAdapter`.
To customize hashtag or mention adapter, create a custom adapter using
customized `SocialAdapter` or write your own `ArrayAdapter`.

> Custom adapters are experimental, see sample for example.
Expand Down
16 changes: 5 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
kotlin("android") version libs.versions.kotlin apply false
kotlin("android.extensions") version libs.versions.kotlin apply false
kotlin("kapt") version libs.versions.kotlin apply false
}

Expand All @@ -27,23 +26,18 @@ subprojects {
plugins.withType<AppPlugin>().configureEach {
configure<BaseAppModuleExtension>(::configureAndroid)
}
plugins.withType<KotlinAndroidPluginWrapper> {
kotlinExtension.jvmToolchain(libs.versions.jdk.get().toInt())
(the<BaseExtension>() as ExtensionAware).extensions.getByType<KotlinJvmOptions>()
.jvmTarget = JavaVersion.toVersion(libs.versions.android.jdk.get()).toString()
}
}

fun configureAndroid(extension: BaseExtension) {
extension.setCompileSdkVersion(libs.versions.android.target.get().toInt())
extension.setCompileSdkVersion(libs.versions.sdk.target.get().toInt())
extension.defaultConfig {
minSdk = libs.versions.android.min.get().toInt()
targetSdk = libs.versions.android.target.get().toInt()
minSdk = libs.versions.sdk.min.get().toInt()
targetSdk = libs.versions.sdk.target.get().toInt()
version = RELEASE_VERSION
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
extension.compileOptions {
targetCompatibility = JavaVersion.toVersion(libs.versions.android.jdk.get())
sourceCompatibility = JavaVersion.toVersion(libs.versions.android.jdk.get())
targetCompatibility = JavaVersion.toVersion(libs.versions.jdk.get())
sourceCompatibility = JavaVersion.toVersion(libs.versions.jdk.get())
}
}
25 changes: 12 additions & 13 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[versions]
jdk = "11" # minimum for Android
kotlin = "1.7.20"
android-plugin = "7.3.1"
android-jdk = "8"
android-min = "14"
android-target = "33"
jdk = "17" # min for android
kotlin = "1.8.20"
sdk-min = "14"
sdk-target = "33"
android-plugin = "8.1.0"
androidx = "1.6.0"
androidx-test = "1.5.0"

Expand All @@ -13,15 +12,15 @@ android-application = { id = "com.android.application", version.ref = "android-p
android-library = { id = "com.android.library", version.ref = "android-plugin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "kotlin" }
kotlinx-kover = "org.jetbrains.kotlinx.kover:0.6.1"
maven-publish = "com.vanniktech.maven.publish.base:0.23.1"
git-publish = "org.ajoberstar.git-publish:3.0.1"
maven-publish = "com.vanniktech.maven.publish.base:0.25.3"
git-publish = "org.ajoberstar.git-publish:4.2.0"
pages = "com.hendraanggrian.pages:0.1"

[libraries]
# lint
rulebook-checkstyle = "com.hendraanggrian.rulebook:rulebook-checkstyle:0.2-SNAPSHOT"
rulebook-checkstyle = "com.hendraanggrian.rulebook:rulebook-checkstyle:0.3-SNAPSHOT"
# main
kotlinx-coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
kotlinx-coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
material = { module = "com.google.android.material:material", version.ref = "androidx" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx" }
Expand All @@ -31,9 +30,9 @@ picasso = "com.squareup.picasso:picasso:2.8"
# test
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test" }
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test" }
androidx-test-junit = "androidx.test.ext:junit:1.1.3"
robolectric = "org.robolectric:robolectric:4.9.2"
truth = "com.google.truth:truth:1.1.3"
androidx-test-junit = "androidx.test.ext:junit:1.1.5"
robolectric = "org.robolectric:robolectric:4.10.3"
truth = "com.google.truth:truth:1.1.5"

[bundles]
androidx-test = ["androidx-test-core", "androidx-test-runner", "androidx-test-junit", "robolectric", "truth"]
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 10 additions & 6 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,26 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Remove check `MissingJavadocMethod`.
- Remove check `MissingJavadocType`.
- Change property `AbbreviationAsWordInName#allowedAbbreviationLength` from `0` to `1`.
Find out more at https://github.com/hendraanggrian/rulebook/.
-->

Expand Down
5 changes: 3 additions & 2 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
plugins {
alias(libs.plugins.android.application)
kotlin("android") version libs.versions.kotlin
kotlin("android.extensions") version libs.versions.kotlin
kotlin("kapt") version libs.versions.kotlin
}

android {
namespace = "com.example.$RELEASE_ARTIFACT"
testNamespace = "$namespace.test"
defaultConfig {
minSdk = 23
applicationId = "com.example.socialview"
Expand All @@ -15,7 +16,7 @@ android {
}

dependencies {
implementation(project(":$RELEASE_ARTIFACT-commons"))
implementation(project(":$RELEASE_ARTIFACT-autocomplete"))
implementation(libs.material)
implementation(libs.androidx.multidex)
implementation(libs.process.phoenix)
Expand Down
15 changes: 12 additions & 3 deletions sample/src/main/kotlin/com/example/socialview/ExampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.hendraanggrian.appcompat.widget.Hashtag
import androidx.appcompat.widget.Toolbar
import com.hendraanggrian.appcompat.socialview.Hashtag
import com.hendraanggrian.appcompat.socialview.Mention
import com.hendraanggrian.appcompat.widget.HashtagArrayAdapter
import com.hendraanggrian.appcompat.widget.Mention
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter
import com.hendraanggrian.appcompat.widget.SocialArrayAdapter
import kotlinx.android.synthetic.main.activity_example.*
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView

class ExampleActivity : AppCompatActivity() {
private companion object {
Expand All @@ -32,6 +33,9 @@ class ExampleActivity : AppCompatActivity() {
const val MENTION3_DISPLAYNAME = "Hendra Anggrian"
}

private lateinit var toolbar: Toolbar
private lateinit var textView: SocialAutoCompleteTextView

private lateinit var defaultHashtagAdapter: ArrayAdapter<Hashtag>
private lateinit var defaultMentionAdapter: ArrayAdapter<Mention>
private lateinit var customHashtagAdapter: ArrayAdapter<Person>
Expand All @@ -40,6 +44,8 @@ class ExampleActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_example)
toolbar = findViewById(R.id.toolbar)
textView = findViewById(R.id.textView)
setSupportActionBar(toolbar)

defaultHashtagAdapter = HashtagArrayAdapter(this)
Expand Down Expand Up @@ -94,11 +100,13 @@ class ExampleActivity : AppCompatActivity() {
textView.hashtagAdapter = customHashtagAdapter
textView.mentionAdapter = customMentionAdapter
}

else -> {
textView.hashtagAdapter = defaultHashtagAdapter
textView.mentionAdapter = defaultMentionAdapter
}
}

R.id.enableHashtagItem -> textView.isHashtagEnabled = item.isChecked
R.id.enableMentionItem -> textView.isMentionEnabled = item.isChecked
R.id.enableHyperlinkItem -> textView.isHyperlinkEnabled = item.isChecked
Expand All @@ -120,6 +128,7 @@ class ExampleActivity : AppCompatActivity() {
holder = ViewHolder(view!!)
view.tag = holder
}

else -> holder = view.tag as ViewHolder
}
getItem(position)?.let { model -> holder.textView.text = model.name }
Expand Down
42 changes: 21 additions & 21 deletions sample/src/main/res/layout/activity_example.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ExampleActivity">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ExampleActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
</com.google.android.material.appbar.AppBarLayout>

<com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:completionThreshold="0"
android:hint="What's on your mind?"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:completionThreshold="0"
android:hint="What's on your mind?"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
14 changes: 7 additions & 7 deletions sample/src/main/res/layout/item_person.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<com.google.android.material.textview.MaterialTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textViewName"
style="?android:attr/dropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
android:id="@+id/textViewName"
style="?android:attr/dropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
Loading

0 comments on commit bdea594

Please sign in to comment.