Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating dependencies + fixes #26

Merged
merged 9 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.gu.toolargetool.sample"
minSdkVersion 15
targetSdkVersion 28
versionCode 2
versionName "1.1"
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -23,5 +25,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation project(path: ':toolargetool')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".TooLargeToolApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/gu/toolargetool/sample/MainActivity.java

This file was deleted.

25 changes: 25 additions & 0 deletions app/src/main/java/com/gu/toolargetool/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gu.toolargetool.sample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

import com.gu.toolargetool.TooLargeTool

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.add(R.id.container, TestFragment())
.commit()
}
}

override fun onSaveInstanceState(outState: Bundle?) {
super.onSaveInstanceState(outState)
outState?.putString("MainActivity.test", "MainActivity put this string here.")
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/com/gu/toolargetool/sample/TestFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gu.toolargetool.sample

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

class TestFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_test, container, false)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString("TestFragment.test", "TestFragment put this string here.")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gu.toolargetool.sample

import android.app.Application

import com.gu.toolargetool.TooLargeTool

@Suppress("unused")
class TooLargeToolApplication : Application() {
override fun onCreate() {
super.onCreate()
TooLargeTool.startLogging(this)
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="@android:color/black" />
</shape>
17 changes: 13 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gu.toolargetool.sample.MainActivity">
android:orientation="vertical"
tools:context="com.gu.toolargetool.sample.MainActivity"
android:padding="8dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
android:text="@string/welcome_message"
android:layout_marginBottom="8dp"/>

</FrameLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>

</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border"
android:padding="8dp"
android:text="@string/test_fragment_message" />
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">TooLarge Tool Sample</string>
<string name="app_name">TooLargeTool Sample</string>
<string name="welcome_message">Welcome to the TooLargeTool sample app 👋 Rotating the device or emulator this app is running on should cause some TooLargeTool logging output.</string>
<string name="test_fragment_message">This is a TestFragment.</string>
</resources>
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.31'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.5.0-beta01'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand All @@ -18,6 +18,7 @@ allprojects {
repositories {
jcenter()
google()
mavenCentral()
}
}

Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.enableJetifier=true
android.useAndroidX=true
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Tue Sep 18 11:17:47 BST 2018
#Fri May 10 12:01:18 BST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-rc-1-all.zip

15 changes: 5 additions & 10 deletions toolargetool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,22 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 2
versionName "1.1"
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFile "proguard-rules.pro"
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'org.mockito:mockito-core:2.23.0'
androidTestImplementation 'org.mockito:mockito-core:2.24.0'
androidTestImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.5.0'
}

apply from: 'bintray.gradle'
repositories {
mavenCentral()
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import android.app.Activity
import android.app.Application
import android.os.Bundle
import androidx.fragment.app.FragmentActivity

import java.util.HashMap
import java.util.*

/**
* [android.app.Application.ActivityLifecycleCallbacks] implementation that logs information
Expand All @@ -30,10 +29,7 @@ class ActivitySavedStateLogger(
}

override fun onActivityDestroyed(activity: Activity) {
if (activity is FragmentActivity && fragmentLogger != null) {
activity.supportFragmentManager
.unregisterFragmentLifecycleCallbacks(fragmentLogger)
}
logAndRemoveSavedState(activity)
}

override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) {
Expand All @@ -43,6 +39,10 @@ class ActivitySavedStateLogger(
}

override fun onActivityStopped(activity: Activity) {
logAndRemoveSavedState(activity)
}

private fun logAndRemoveSavedState(activity: Activity) {
val savedState = savedStates.remove(activity)
if (savedState != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package com.gu.toolargetool
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager

import java.util.HashMap
import java.util.*

/**
* [android.support.v4.app.FragmentManager.FragmentLifecycleCallbacks] implementation that
* logs information about the saved state of Fragments.
* [FragmentManager.FragmentLifecycleCallbacks] implementation that logs information about the
* saved state of Fragments.
*/
class FragmentSavedStateLogger(private val formatter: Formatter, private val logger: Logger) : FragmentManager.FragmentLifecycleCallbacks() {
private val savedStates = HashMap<Fragment, Bundle?>()
Expand All @@ -21,6 +20,14 @@ class FragmentSavedStateLogger(private val formatter: Formatter, private val log
}

override fun onFragmentStopped(fm: FragmentManager, f: Fragment) {
logAndRemoveSavedState(f, fm)
}

override fun onFragmentDestroyed(fm: FragmentManager, f: Fragment) {
logAndRemoveSavedState(f, fm)
}

private fun logAndRemoveSavedState(f: Fragment, fm: FragmentManager) {
val savedState = savedStates.remove(f)
if (savedState != null) {
try {
Expand Down