Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Update dependencies, Update navigation, and fix bug when rotating #99

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
19 changes: 10 additions & 9 deletions Owl/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs.kotlin'

android {
compileSdkVersion 30
compileSdkVersion 33
defaultConfig {
applicationId 'com.materialstudies.owl'
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName '1.0'
vectorDrawables.useSupportLibrary = true
Expand All @@ -47,21 +47,22 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
namespace 'com.materialstudies.owl'
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.5.0-alpha04'
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'com.google.android.material:material:1.8.0-beta01'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation "androidx.navigation:navigation-runtime-ktx:$nav_version"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
}
6 changes: 3 additions & 3 deletions Owl/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.materialstudies.owl">
xmlns:tools="http://schemas.android.com/tools">

<!--Load images from Unsplash-->
<uses-permission android:name="android.permission.INTERNET"/>
Expand All @@ -31,7 +30,8 @@

<activity
android:name=".ui.MainActivity"
android:theme="@style/Owl.Blue">
android:theme="@style/Owl.Blue"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.core.view.doOnNextLayout
import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import androidx.navigation.fragment.FragmentNavigatorExtras
import com.materialstudies.owl.R
import com.materialstudies.owl.databinding.FragmentFeaturedBinding
import com.materialstudies.owl.model.CourseId
import com.materialstudies.owl.model.courses
Expand All @@ -46,14 +47,16 @@ class FeaturedFragment : Fragment() {
val extras = FragmentNavigatorExtras(
view to "shared_element"
)
val action = FeaturedFragmentDirections.actionFeaturedToLearn(courseId)
/* awaiting aosp/987385 in fragment 1.2.0-alpha02
exitTransition = Recede().apply {
addTarget(root)
excludeTarget(view, true)
duration = 300L
}*/
view.findNavController().navigate(action, extras)

val bundle = Bundle()
bundle.putLong("course_id", courseId)

view.findNavController().navigate(
R.id.action_featured_to_learn,
bundle, // Bundle of args
null, // NavOptions
extras
)
}
}
featuredGrid.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ class LessonsSheetFragment : Fragment() {
val course = this.course
if (course != null) {
binding.lessonsSheet.postDelayed(300L) {
val action =
LessonsSheetFragmentDirections.actionLessonsSheetToLesson(course.id, step)
// FIXME should be able to `navigate(action)` but not working

val navController = findNavController()
val onLesson = navController.currentDestination?.id != R.id.lesson
val bundle = Bundle()
bundle.putLong("course_id", course.id)
bundle.putInt("step_number", step)

navController.navigate(
R.id.lesson,
action.arguments,
R.id.action_featured_to_learn,
bundle, // Bundle of args
navOptions {
launchSingleTop = true
anim {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.materialstudies.owl.ui.mycourses

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -36,9 +37,20 @@ class MyCoursesAdapter : ListAdapter<Course, MyCourseViewHolder>(CourseDiff) {
val extras = FragmentNavigatorExtras(
view to "shared_element"
)
val action = MyCoursesFragmentDirections.actionMycoursesToLearn(courseId)
view.findNavController().navigate(action, extras)

val bundle = Bundle()
bundle.putLong("course_id", courseId)

view.findNavController().navigate(
R.id.action_mycourses_to_learn,
bundle, // Bundle of args
null, // NavOptions
extras
)
}



}

private val shapeTransform =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class TopicThumbnailDrawable(
callback?.invalidateDrawable(this)
}

override fun onStateChange(state: IntArray?): Boolean {
override fun onStateChange(state: IntArray): Boolean {
val initialProgress = progress
val newProgress = if (state?.contains(android.R.attr.state_activated) == true) {
val newProgress = if (state.contains(android.R.attr.state_activated)) {
1f
} else {
0f
Expand All @@ -115,8 +115,7 @@ class TopicThumbnailDrawable(

override fun isStateful() = true

override fun onBoundsChange(bounds: Rect?) {
if (bounds == null) return
override fun onBoundsChange(bounds: Rect) {
update()
val dLeft = (bounds.right - selectedDrawable.intrinsicWidth) / 2
val dTop = (bounds.bottom - selectedDrawable.intrinsicHeight) / 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import android.graphics.Bitmap.Config.ARGB_8888
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.View.GONE
import android.view.View.MeasureSpec
Expand Down Expand Up @@ -179,38 +181,40 @@ fun View.findAncestorById(@IdRes ancestorId: Int): View {
*/
fun BottomNavigationView.show() {
if (visibility == VISIBLE) return
Handler(Looper.myLooper()!!).postDelayed({

val parent = parent as ViewGroup
// View needs to be laid out to create a snapshot & know position to animate. If view isn't
// laid out yet, need to do this manually.
if (!isLaidOut) {
measure(
MeasureSpec.makeMeasureSpec(parent.width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(parent.height, MeasureSpec.AT_MOST)
)
layout(parent.left, parent.height - measuredHeight, parent.right, parent.height)
}

val drawable = BitmapDrawable(context.resources, drawToBitmap())
drawable.setBounds(left, parent.height, right, parent.height + height)
parent.overlay.add(drawable)
ValueAnimator.ofInt(parent.height, top).apply {
startDelay = 100L
duration = 300L
interpolator = AnimationUtils.loadInterpolator(
context,
android.R.interpolator.linear_out_slow_in
)
addUpdateListener {
val newTop = it.animatedValue as Int
drawable.setBounds(left, newTop, right, newTop + height)
val parent = parent as ViewGroup
// View needs to be laid out to create a snapshot & know position to animate. If view isn't
// laid out yet, need to do this manually.
if (!isLaidOut) {
measure(
MeasureSpec.makeMeasureSpec(parent.width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(parent.height, MeasureSpec.AT_MOST)
)
layout(parent.left, parent.height - measuredHeight, parent.right, parent.height)
}
doOnEnd {
parent.overlay.remove(drawable)
visibility = VISIBLE

val drawable = BitmapDrawable(context.resources, drawToBitmap())
drawable.setBounds(left, parent.height, right, parent.height + height)
parent.overlay.add(drawable)
ValueAnimator.ofInt(parent.height, top).apply {
startDelay = 100L
duration = 300L
interpolator = AnimationUtils.loadInterpolator(
context,
android.R.interpolator.linear_out_slow_in
)
addUpdateListener {
val newTop = it.animatedValue as Int
drawable.setBounds(left, newTop, right, newTop + height)
}
doOnEnd {
parent.overlay.remove(drawable)
visibility = VISIBLE
}
start()
}
start()
}
},100)
}

/**
Expand Down
10 changes: 5 additions & 5 deletions Owl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*/

buildscript {
ext.kotlin_version = '1.4.10'
ext.nav_version = '2.3.1'
ext.kotlin_version = '1.6.20'
ext.nav_version = '2.5.3'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
Expand All @@ -29,7 +29,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Owl/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip