Skip to content

Commit

Permalink
Merge pull request #3 from bmarty/bma/fix_crash
Browse files Browse the repository at this point in the history
Fix crash with Emoji
  • Loading branch information
BillCarsonFr authored Jan 3, 2022
2 parents a8fa35d + 0002666 commit 218cf30
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 177 deletions.
31 changes: 16 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "org.billcarsonfr.jsonviewerexample"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 31
multiDexEnabled true
versionCode 1
versionName "1.0"
Expand All @@ -25,34 +25,35 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
}

buildFeatures {
viewBinding true
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.multidex:multidex:2.0.1'



//=== ADD IN YOUR PROJECT
// Epoxy dependency
implementation("com.airbnb.android:epoxy:$epoxy_version")
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "com.airbnb.android:epoxy:$epoxy_version"
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation 'com.airbnb.android:mavericks:2.4.0'
implementation 'com.airbnb.android:mavericks:2.5.0'
// ============

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation project(path: ':jsonviewer')
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.Fragment
import org.billcarsonfr.jsonviewerexample.databinding.FragmentChooseSampleBinding

/**
* Activities that contain this fragment must implement the
Expand All @@ -16,42 +16,30 @@ import androidx.fragment.app.Fragment
* create an instance of this fragment.
*/
class ChooseSampleFragment : Fragment() {


private var mListener: OnFragmentMainNavigationListener? = null

lateinit var showWrappedButton: Button

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
private lateinit var viewBinding: FragmentChooseSampleBinding

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_choose_sample, container, false).also { view ->
view.findViewById<Button>(R.id.showWrappedViewer)?.let {
it.setOnClickListener {
mListener?.navigateToWrapSample(true)
}

view.findViewById<Button>(R.id.showWrappedViewerScroll)?.let {
it.setOnClickListener {
mListener?.navigateToWrapSample(false)
}
}

): View {
viewBinding = FragmentChooseSampleBinding.inflate(inflater, container, false)
return viewBinding.root
}

view.findViewById<Button>(R.id.showAsBottomSheet)?.let {
it.setOnClickListener {
mListener?.navigateToDialog()
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewBinding.showWrappedViewer.setOnClickListener {
mListener?.navigateToSample(wrap = true)
}

viewBinding.showWrappedViewerScroll.setOnClickListener {
mListener?.navigateToSample(wrap = false)
}

}
viewBinding.showAsBottomSheet.setOnClickListener {
mListener?.navigateToDialog()
}
}

Expand Down Expand Up @@ -79,7 +67,7 @@ class ChooseSampleFragment : Fragment() {
* See the Android Training lesson [Communicating with Other Fragments](http://developer.android.com/training/basics/fragments/communicating.html) for more information.
*/
interface OnFragmentMainNavigationListener {
fun navigateToWrapSample(wrap: Boolean)
fun navigateToSample(wrap: Boolean)
fun navigateToDialog()
}

Expand All @@ -88,5 +76,4 @@ class ChooseSampleFragment : Fragment() {
return ChooseSampleFragment()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.billcarsonfr.jsonviewerexample
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.annotation.RawRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.forEach
import org.billcarsonfr.jsonviewer.JSonViewerDialog
Expand All @@ -25,43 +26,29 @@ class MainActivity : AppCompatActivity(), ChooseSampleFragment.OnFragmentMainNav
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.sample1 -> loadSample(R.raw.sample1)
R.id.sample2 -> loadSample(R.raw.sample2)
R.id.sample3 -> loadSample(R.raw.sample3)
R.id.sample4 -> loadSample(R.raw.sample4)
R.id.sample5 -> loadSample(R.raw.sample5)
R.id.sample6 -> loadSample(R.raw.sample6)
else -> super.onOptionsItemSelected(item)
}
}

private fun loadSample(@RawRes sampleId: Int): Boolean {
val jsonViewerFragment =
supportFragmentManager.findFragmentByTag("JSONVIEWER") as? JSonViewerFragment
when (item.itemId) {
R.id.sample1 -> {
val sample = resources.openRawResource(R.raw.sample1)
.bufferedReader().use { it.readText() }
jsonViewerFragment?.showJson(sample, -1)
}
R.id.sample2 -> {
val sample = resources.openRawResource(R.raw.sample2)
.bufferedReader().use { it.readText() }
jsonViewerFragment?.showJson(sample, -1)

}
R.id.sample3 -> {
val sample = resources.openRawResource(R.raw.sample3)
.bufferedReader().use { it.readText() }
jsonViewerFragment?.showJson(sample, -1)

}
R.id.sample4 -> {
val sample = resources.openRawResource(R.raw.sample4)
.bufferedReader().use { it.readText() }
jsonViewerFragment?.showJson(sample, -1)

}
R.id.sample5 -> {
val sample = resources.openRawResource(R.raw.sample5)
.bufferedReader().use { it.readText() }
jsonViewerFragment?.showJson(sample, -1)

}
}
return super.onOptionsItemSelected(item)
val sample = resources.openRawResource(sampleId)
.bufferedReader()
.use { it.readText() }
jsonViewerFragment?.showJson(sample, -1)
return true
}

override fun navigateToWrapSample(wrap: Boolean) {
override fun navigateToSample(wrap: Boolean) {
val sample = resources.openRawResource(R.raw.sample1)
.bufferedReader().use { it.readText() }
supportFragmentManager.beginTransaction()
Expand Down Expand Up @@ -100,5 +87,4 @@ class MainActivity : AppCompatActivity(), ChooseSampleFragment.OnFragmentMainNav
.commit()
}
}

}
19 changes: 11 additions & 8 deletions app/src/main/res/menu/samples.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="HardcodedText">
<item
android:id="@+id/sample1"
android:title="sample 1"/>

android:title="sample 1" />
<item
android:id="@+id/sample2"
android:title="sample 2"/>
android:title="sample 2" />
<item
android:id="@+id/sample3"
android:title="sample 3"/>
android:title="sample 3" />
<item
android:id="@+id/sample4"
android:title="sample 4"/>
android:title="sample 4" />
<item
android:id="@+id/sample5"
android:title="sample 5"/>
android:title="sample 5" />
<item
android:id="@+id/sample6"
android:title="Emoji" />
</menu>
4 changes: 4 additions & 0 deletions app/src/main/res/raw/sample6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"emoji1": "\uD83D\uDE2E\u200D\uD83D\uDCA8",
"emoji2": "😮‍💨"
}
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.31'
ext.epoxy_version = '4.4.2'
ext.kotlin_version = '1.5.31'
ext.epoxy_version = '4.6.2'
repositories {
google()
jcenter()

mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -21,8 +20,8 @@ buildscript {
allprojects {
repositories {
google()
mavenCentral()
jcenter()

}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionSha256Sum=c9490e938b221daf0094982288e4038deed954a3f12fb54cbf270ddf4e37d879
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
29 changes: 13 additions & 16 deletions jsonviewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'com.jakewharton.butterknife'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
targetSdkVersion 31

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -25,33 +23,32 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = "11"
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'

// Epoxy dependency
implementation "com.airbnb.android:epoxy:$epoxy_version"
kapt "com.airbnb.android:epoxy-processor:$epoxy_version"
implementation 'com.airbnb.android:mavericks:2.4.0'
implementation 'com.airbnb.android:mavericks:2.5.0'
// Span utils
implementation 'me.gujun.android:span:1.7'
implementation 'com.google.android.material:material:1.4.0-alpha01'
implementation 'com.google.android.material:material:1.6.0-alpha01'

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"

testImplementation 'org.json:json:20190722'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Loading

0 comments on commit 218cf30

Please sign in to comment.