Skip to content
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
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

android {
compileSdk 34
compileSdk 35

defaultConfig {
applicationId "com.telefonica.androidlogger.app"
minSdkVersion 21
targetSdkVersion 34
targetSdkVersion 35
versionCode 1
versionName "1.0.0"

Expand All @@ -32,6 +32,7 @@ android {
}

dependencies {
implementation libs.androidx.activity
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required for enableEdgeToEdge method

implementation libs.androidx.appcompat
implementation project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.telefonica.androidlogger.app
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.telefonica.androidlogger.domain.LogPriority
import com.telefonica.androidlogger.domain.log
Expand All @@ -13,6 +14,7 @@ import kotlin.random.nextInt
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupViews()
Expand Down
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[versions]
android-gradle-plugin = "8.7.2"
activity = "1.10.1"
android-gradle-plugin = "8.7.3"
junit = "4.13.2"
kotlin = "1.9.21"
kotlin = "2.1.10"
androidx-lifecycle = "2.2.0"
material = "1.9.0"
material = "1.12.0"
elviswhew-xlog = "1.11.1"
okio = "3.9.1"

[libraries]
androidx-activity = { module = "androidx.activity:activity", version.ref = "activity" }
androidx-annotation = { module = "androidx.annotation:annotation", version = "1.9.1" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.7.0" }
androidx-lifecycle-extensions = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "androidx-lifecycle" }
Expand Down
5 changes: 3 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins{
}

android {
compileSdk 34
compileSdk 35

defaultConfig {
minSdkVersion 21
targetSdkVersion 34
targetSdkVersion 35
}

flavorDimensions "loggerMode"
Expand Down Expand Up @@ -37,6 +37,7 @@ android {
dependencies {
//noinspection GradleDependency
implementation libs.org.jetbrains.kotlin
implementation libs.androidx.activity
implementation libs.androidx.annotation
enabledImplementation libs.com.google.android.material
enabledImplementation libs.androidx.lifecycle.extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import android.view.ViewGroup
import android.widget.CompoundButton
import android.widget.TextView
import android.widget.Toast
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DefaultItemAnimator
Expand Down Expand Up @@ -56,6 +62,10 @@ class AppLoggerActivity : AppCompatActivity() {
private var shareAllLogsCallback: TaskCallback<Uri>? = null

override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.dark(android.graphics.Color.TRANSPARENT),
navigationBarStyle = SystemBarStyle.dark(android.graphics.Color.TRANSPARENT),
)
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_app_logger)
Expand All @@ -69,13 +79,16 @@ class AppLoggerActivity : AppCompatActivity() {
initToolbar()
initLogsList()
initFiltersView()
setOnBackPressed()
setWindowsInsets()

viewModel.getFilteredLogs().observe(this@AppLoggerActivity, Observer {
adapter.onDataModified(it)
if (automaticScrollEnabled) {
recyclerView.post { scrollToBottom() }
}
})

}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down Expand Up @@ -129,14 +142,18 @@ class AppLoggerActivity : AppCompatActivity() {
else -> super.onOptionsItemSelected(item)
}

override fun onBackPressed() {
Copy link
Contributor Author

@juangardi21 juangardi21 Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is deprecated. I've replaced it by the new way of going back

searchView?.let {
if (!it.isIconified) {
it.isIconified = true
return
private fun setOnBackPressed() {
onBackPressedDispatcher.addCallback(this, object : androidx.activity.OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
searchView?.let {
if (!it.isIconified) {
it.isIconified = true
return
}
}
finish()
}
}
super.onBackPressed()
})
}

override fun onDestroy() {
Expand Down Expand Up @@ -275,7 +292,7 @@ class AppLoggerActivity : AppCompatActivity() {
}

private fun toggleCategoryFilter() {
if (filtersView.visibility == View.VISIBLE) {
if (filtersView.isVisible) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a warning

filtersView.visibility = View.GONE
} else {
filtersView.visibility = View.VISIBLE
Expand Down Expand Up @@ -325,8 +342,25 @@ class AppLoggerActivity : AppCompatActivity() {
}, null)
startActivity(shareIntent)
}

private fun setWindowsInsets() {
setOnApplyWindowInsetsListener(recyclerView) { v, windowInsets ->
val bars = windowInsets.getInsets(
WindowInsetsCompat.Type.systemBars()
or WindowInsetsCompat.Type.displayCutout()
)
v.updatePadding(
top = v.paddingTop,
left = bars.left,
right = bars.right,
bottom = bars.bottom,
)
WindowInsetsCompat.CONSUMED
}
}
}


private const val EXTRA_CATEGORIES_NAMES = "extra_categories_names"

@JvmOverloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Handler
import android.os.Looper
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.map

internal class FilterableLiveData<T>(
source: LiveData<T>,
Expand Down Expand Up @@ -62,5 +62,4 @@ internal fun <T> LiveData<T>.throttle(duration: Long = 1000L): LiveData<T> = Med
}
}

internal fun <From, To> LiveData<From>.map(mapFunc: (From) -> To): LiveData<To> =
Transformations.map(this, mapFunc)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer used in new versions

internal fun <From, To> LiveData<From>.map(mapFunc: (From) -> To): LiveData<To> = map(mapFunc)
25 changes: 13 additions & 12 deletions library/src/enabled/res/layout/activity_app_logger.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:scrollbars="vertical"/>

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_gravity="top"
android:animateLayoutChanges="true"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
Expand Down Expand Up @@ -72,4 +66,11 @@

</com.google.android.material.appbar.AppBarLayout>

</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />

</LinearLayout>