From f01909eb83e962fc76edeaf9001bc7d8ec8583a7 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sun, 19 Apr 2020 21:19:28 -0700 Subject: [PATCH] Update dependencies --- app/build.gradle | 13 ++++++++----- .../simplemarkdown/view/activity/MainActivity.kt | 7 +++---- .../view/activity/MarkdownInfoActivity.kt | 9 +++++---- .../simplemarkdown/view/fragment/EditFragment.kt | 9 +++------ .../simplemarkdown/view/fragment/PreviewFragment.kt | 11 ++++------- build.gradle | 8 ++------ 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 411181a..26996b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' -apply plugin: 'io.fabric' apply plugin: 'jacoco' def keystoreProperties = new Properties() @@ -34,6 +33,9 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = "1.8" + } defaultConfig { applicationId "com.wbrawner.simplemarkdown" minSdkVersion 21 @@ -75,7 +77,7 @@ android { dependencies { testImplementation 'junit:junit:4.12' - testImplementation 'org.robolectric:robolectric:4.2' + testImplementation 'org.robolectric:robolectric:4.2.1' implementation fileTree(include: ['*.jar'], dir: 'libs') def espresso_version = '3.2.0' androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version" @@ -88,13 +90,14 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.preference:preference:1.1.0' + implementation 'androidx.preference:preference:1.1.1' + implementation "androidx.fragment:fragment-ktx:1.2.4" implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' implementation 'com.commonsware.cwac:anddown:0.3.0' - implementation 'com.google.firebase:firebase-core:17.2.3' - implementation 'com.android.billingclient:billing:2.1.0' + implementation 'com.google.firebase:firebase-core:17.3.0' + implementation 'com.android.billingclient:billing:2.2.0' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation "androidx.core:core-ktx:1.2.0" implementation 'androidx.browser:browser:1.2.0' diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt index 646754b..78a6825 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MainActivity.kt @@ -13,12 +13,12 @@ import android.view.MenuItem import android.view.View import android.webkit.MimeTypeMap import android.widget.Toast +import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProviders import androidx.preference.PreferenceManager import com.wbrawner.simplemarkdown.R import com.wbrawner.simplemarkdown.utility.hideKeyboard @@ -34,7 +34,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes private var shouldAutoSave = true override val coroutineContext: CoroutineContext = Dispatchers.Main - private lateinit var viewModel: MarkdownViewModel + private val viewModel: MarkdownViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -49,7 +49,6 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ) } - viewModel = ViewModelProviders.of(this).get(MarkdownViewModel::class.java) val adapter = EditPagerAdapter(supportFragmentManager, this@MainActivity) pager.adapter = adapter pager.addOnPageChangeListener(adapter) @@ -60,7 +59,7 @@ class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsRes tabLayout!!.visibility = View.GONE } @Suppress("CAST_NEVER_SUCCEEDS") - viewModel.fileName.observe(this, Observer { + viewModel.fileName.observe(this, Observer { title = it }) intent?.data?.let { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.kt index 6f7addd..af53bb7 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/activity/MarkdownInfoActivity.kt @@ -11,7 +11,10 @@ import com.wbrawner.simplemarkdown.R import com.wbrawner.simplemarkdown.utility.readAssetToString import com.wbrawner.simplemarkdown.utility.toHtml import kotlinx.android.synthetic.main.activity_markdown_info.* -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch import kotlin.coroutines.CoroutineContext class MarkdownInfoActivity : AppCompatActivity(), CoroutineScope { @@ -57,9 +60,7 @@ class MarkdownInfoActivity : AppCompatActivity(), CoroutineScope { } override fun onDestroy() { - coroutineContext[Job]?.let { - cancel() - } + coroutineContext[Job]?.cancel() super.onDestroy() } diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.kt index 2c4fd9c..e411105 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.kt @@ -16,8 +16,8 @@ import android.widget.EditText import android.widget.ScrollView import android.widget.TextView import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProviders import androidx.preference.PreferenceManager import com.wbrawner.simplemarkdown.R import com.wbrawner.simplemarkdown.model.Readability @@ -32,7 +32,7 @@ import kotlin.math.abs class EditFragment : Fragment(), ViewPagerPage, CoroutineScope { private var markdownEditor: EditText? = null private var markdownEditorScroller: ScrollView? = null - lateinit var viewModel: MarkdownViewModel + private val viewModel: MarkdownViewModel by activityViewModels() override val coroutineContext: CoroutineContext = Dispatchers.Main private var readabilityWatcher: TextWatcher? = null @@ -44,9 +44,6 @@ class EditFragment : Fragment(), ViewPagerPage, CoroutineScope { @SuppressLint("ClickableViewAccessibility") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - activity?.let { - viewModel = ViewModelProviders.of(it).get(MarkdownViewModel::class.java) - } ?: return markdownEditor = view.findViewById(R.id.markdown_edit) markdownEditorScroller = view.findViewById(R.id.markdown_edit_container) markdownEditor?.addTextChangedListener(object : TextWatcher { @@ -97,7 +94,7 @@ class EditFragment : Fragment(), ViewPagerPage, CoroutineScope { } false } - viewModel.originalMarkdown.observe(this, Observer { + viewModel.originalMarkdown.observe(viewLifecycleOwner, Observer { markdownEditor?.setText(it) }) launch { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.kt index e5f963b..970c4aa 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/PreviewFragment.kt @@ -9,8 +9,8 @@ import android.view.ViewGroup import android.webkit.WebView import androidx.appcompat.app.AppCompatDelegate import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProviders import androidx.preference.PreferenceManager import com.wbrawner.simplemarkdown.BuildConfig import com.wbrawner.simplemarkdown.R @@ -21,7 +21,7 @@ import kotlin.coroutines.CoroutineContext class PreviewFragment : Fragment(), CoroutineScope { override val coroutineContext: CoroutineContext = Dispatchers.Main - lateinit var viewModel: MarkdownViewModel + private val viewModel: MarkdownViewModel by activityViewModels() private var markdownPreview: WebView? = null private var style: String = "" @@ -34,13 +34,10 @@ class PreviewFragment : Fragment(), CoroutineScope { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { markdownPreview = view.findViewById(R.id.markdown_view) WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG) - activity?.let { - viewModel = ViewModelProviders.of(it).get(MarkdownViewModel::class.java) - } ?: return launch { val isNightMode = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES - || context!!.resources.configuration.uiMode and UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES + || requireContext().resources.configuration.uiMode and UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES val defaultCssId = if (isNightMode) { R.string.pref_custom_css_default_dark } else { @@ -61,7 +58,7 @@ class PreviewFragment : Fragment(), CoroutineScope { } style = String.format(FORMAT_CSS, css ?: "") updateWebContent(viewModel.markdownUpdates.value ?: "") - viewModel.markdownUpdates.observe(this@PreviewFragment, Observer { + viewModel.markdownUpdates.observe(viewLifecycleOwner, Observer { updateWebContent(it) }) } diff --git a/build.gradle b/build.gradle index 7a828b3..239791a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.61' + ext.kotlin_version = '1.3.72' repositories { jcenter() google() - maven { - url 'https://maven.fabric.io/public' - } } dependencies { - classpath 'com.android.tools.build:gradle:3.6.1' + classpath 'com.android.tools.build:gradle:3.6.3' classpath 'com.google.gms:google-services:4.3.3' - classpath 'io.fabric.tools:gradle:1.31.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }