diff --git a/app/build.gradle b/app/build.gradle index b64d504..f9b76f4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,15 +40,15 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${kotlin_version}" implementation "androidx.appcompat:appcompat:${androidXAppcompatVersion}" implementation 'androidx.core:core-ktx:1.3.0' implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'androidx.navigation:navigation-fragment:2.3.0' - implementation 'androidx.navigation:navigation-ui:2.3.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' + implementation "androidx.navigation:navigation-fragment:${androidXNavigationVersion}" + implementation "androidx.navigation:navigation-ui:${androidXNavigationVersion}" + implementation "androidx.navigation:navigation-fragment-ktx:${androidXNavigationVersion}" + implementation "androidx.navigation:navigation-ui-ktx:${androidXNavigationVersion}" implementation project(':library-timeline') } diff --git a/app/src/main/java/com/alexvas/timeline/demo/ui/TimelineFragment.kt b/app/src/main/java/com/alexvas/timeline/demo/ui/TimelineFragment.kt index eb1698b..6b0467e 100644 --- a/app/src/main/java/com/alexvas/timeline/demo/ui/TimelineFragment.kt +++ b/app/src/main/java/com/alexvas/timeline/demo/ui/TimelineFragment.kt @@ -1,6 +1,8 @@ package com.alexvas.timeline.demo.ui import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.util.Log import android.view.LayoutInflater import android.view.View @@ -10,6 +12,7 @@ import androidx.lifecycle.ViewModelProvider import com.alexvas.timeline.demo.R import com.alexvas.widget.TimelineView import com.alexvas.widget.TimelineView.TimeRecord +import kotlin.math.max class TimelineFragment : Fragment() { @@ -47,6 +50,33 @@ class TimelineFragment : Fragment() { override fun onRequestMoreBackgroundData() { } }) + val zoomIn = root.findViewById(R.id.zoomIn) + val zoomOut = root.findViewById(R.id.zoomOut) + zoomIn.setOnClickListener { + timelineView.decreaseIntervalWithAnimation() + // isMinInterval will be valid only after animation completed (150 msec) + Handler(Looper.getMainLooper()).postDelayed({ + zoomIn.isEnabled = !timelineView.isMinInterval + zoomOut.isEnabled = true + }, TimelineView.ANIMATION_DURATION_MSEC + 1) + } + zoomOut.setOnClickListener { + timelineView.increaseIntervalWithAnimation() + // isMaxInterval will be valid only after animation completed (150 msec) + Handler(Looper.getMainLooper()).postDelayed({ + zoomOut.isEnabled = !timelineView.isMaxInterval + zoomIn.isEnabled = true + }, TimelineView.ANIMATION_DURATION_MSEC + 1) + } + root.findViewById(R.id.lastEvent).setOnClickListener { + gotoLastMajor1Record() + } + root.findViewById(R.id.prevEvent).setOnClickListener { + gotoPrevRecord(true) + } + root.findViewById(R.id.nextEvent).setOnClickListener { + gotoNextRecord(true) + } return root } @@ -98,7 +128,7 @@ class TimelineFragment : Fragment() { private fun gotoLastMajor1Record() { if (DEBUG) Log.v(TAG, "gotoLastMajor1Record()") - var records: java.util.ArrayList = timelineView.getMajor1Records() + var records: java.util.ArrayList = timelineView.major1Records // At least one event exists if (records.size > 0) { val record = records[0] @@ -108,11 +138,11 @@ class TimelineFragment : Fragment() { timelineView.invalidate() } else { // No events found. Show last video recording. - records = timelineView.getBackgroundRecords() + records = timelineView.backgroundRecords if (records.size > 0) { val record = records[0] // 30 sec before video finished. - val timestamp = record.timestampMsec + Math.max(record.durationMsec - 30000, 0) + val timestamp = record.timestampMsec + max(record.durationMsec - 30000, 0) onTimeSelected(timestamp, record) timelineView.setCurrentWithAnimation(record.timestampMsec) timelineView.invalidate() @@ -120,6 +150,36 @@ class TimelineFragment : Fragment() { } } + private fun gotoPrevRecord(animation: Boolean) { + if (DEBUG) Log.v(TAG, "gotoPrevRecord(animation=$animation)") + val record: TimeRecord? = timelineView.getPrevMajorRecord() + if (record != null) { + Log.i(TAG, record.toString()) + val timestamp = getTimestampFromRecord(record) + onTimeSelected(timestamp, record) + if (animation) + timelineView.setCurrentWithAnimation(record.timestampMsec) + else + timelineView.setCurrent(record.timestampMsec) + timelineView.invalidate() + } + } + + private fun gotoNextRecord(animation: Boolean) { + if (DEBUG) Log.v(TAG, "gotoNextRecord(animation=$animation)") + val record: TimeRecord? = timelineView.getNextMajorRecord() + if (record != null) { + Log.i(TAG, record.toString()) + val timestamp = getTimestampFromRecord(record) + onTimeSelected(timestamp, record) + if (animation) + timelineView.setCurrentWithAnimation(record.timestampMsec) + else + timelineView.setCurrent(record.timestampMsec) + timelineView.invalidate() + } + } + private fun getTimestampFromRecord(record: TimeRecord): Long { return record.timestampMsec } diff --git a/app/src/main/res/drawable/ic_minus_black_36dp.xml b/app/src/main/res/drawable/ic_minus_black_36dp.xml new file mode 100644 index 0000000..2306a5d --- /dev/null +++ b/app/src/main/res/drawable/ic_minus_black_36dp.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/drawable/ic_plus_black_36dp.xml b/app/src/main/res/drawable/ic_plus_black_36dp.xml new file mode 100644 index 0000000..b9f7569 --- /dev/null +++ b/app/src/main/res/drawable/ic_plus_black_36dp.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/drawable/ic_rewind_black_36dp.xml b/app/src/main/res/drawable/ic_rewind_black_36dp.xml new file mode 100644 index 0000000..70b2a3c --- /dev/null +++ b/app/src/main/res/drawable/ic_rewind_black_36dp.xml @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_skip_forward_black_36dp.xml b/app/src/main/res/drawable/ic_skip_forward_black_36dp.xml new file mode 100644 index 0000000..303aedb --- /dev/null +++ b/app/src/main/res/drawable/ic_skip_forward_black_36dp.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/layout/fragment_timeline.xml b/app/src/main/res/layout/fragment_timeline.xml index 845fcf2..8c32fe2 100644 --- a/app/src/main/res/layout/fragment_timeline.xml +++ b/app/src/main/res/layout/fragment_timeline.xml @@ -1,10 +1,11 @@ - - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/constants.gradle b/constants.gradle index 47a1fc7..f88172e 100644 --- a/constants.gradle +++ b/constants.gradle @@ -2,10 +2,11 @@ project.ext { compileSdkVersion = 30 buildToolsVersion = '30.0.0' minSdkVersion = 21 // 5.0 - targetSdkVersion = 30 // 10.0 - releaseVersion = "1.2.0" - releaseVersionCode = 120 + targetSdkVersion = 30 // 11.0 + releaseVersion = "1.3.0" + releaseVersionCode = 130 androidXAnnotationVersion = '1.1.0' androidXAppcompatVersion = '1.1.0' + androidXNavigationVersion = '2.3.0' }