A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
0

Configure Feed

Select the types of activity you want to include in your feed.

change record layout to custom view

razeeman (May 16, 2020, 11:17 AM +0300) 840f8649 ba1e136f

+184 -91
+83
core/src/main/res/layout/record_view_layout.xml
··· 1 + <?xml version="1.0" encoding="utf-8"?> 2 + <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 3 + xmlns:app="http://schemas.android.com/apk/res-auto" 4 + xmlns:tools="http://schemas.android.com/tools" 5 + android:id="@+id/layoutRecordItem" 6 + android:layout_width="match_parent" 7 + android:layout_height="wrap_content" 8 + android:layout_marginStart="8dp" 9 + android:layout_marginTop="4dp" 10 + android:layout_marginEnd="8dp" 11 + android:layout_marginBottom="4dp" 12 + app:cardBackgroundColor="@color/black" 13 + app:cardCornerRadius="8dp" 14 + app:cardElevation="4dp"> 15 + 16 + <androidx.constraintlayout.widget.ConstraintLayout 17 + android:layout_width="match_parent" 18 + android:layout_height="wrap_content" 19 + android:background="?selectableItemBackground" 20 + android:paddingTop="8dp" 21 + android:paddingBottom="8dp"> 22 + 23 + <androidx.appcompat.widget.AppCompatImageView 24 + android:id="@+id/ivRecordItemIcon" 25 + android:layout_width="wrap_content" 26 + android:layout_height="0dp" 27 + android:layout_marginStart="8dp" 28 + app:backgroundTint="@color/white" 29 + app:layout_constraintBottom_toBottomOf="parent" 30 + app:layout_constraintDimensionRatio="h,1:1" 31 + app:layout_constraintStart_toStartOf="parent" 32 + app:layout_constraintTop_toTopOf="parent" 33 + tools:background="@drawable/ic_unknown" /> 34 + 35 + <androidx.appcompat.widget.AppCompatTextView 36 + android:id="@+id/tvRecordItemName" 37 + android:layout_width="0dp" 38 + android:layout_height="wrap_content" 39 + android:layout_marginStart="8dp" 40 + android:textColor="@color/white" 41 + android:textStyle="bold" 42 + app:layout_constraintEnd_toStartOf="@id/tvRecordItemDuration" 43 + app:layout_constraintStart_toEndOf="@id/ivRecordItemIcon" 44 + app:layout_constraintTop_toTopOf="parent" 45 + tools:text="Item name" /> 46 + 47 + <androidx.appcompat.widget.AppCompatTextView 48 + android:id="@+id/tvRecordItemTimeStarted" 49 + android:layout_width="0dp" 50 + android:layout_height="wrap_content" 51 + android:layout_marginStart="8dp" 52 + android:textColor="@color/white" 53 + app:layout_constraintEnd_toStartOf="@id/tvRecordItemDuration" 54 + app:layout_constraintStart_toEndOf="@id/ivRecordItemIcon" 55 + app:layout_constraintTop_toBottomOf="@id/tvRecordItemName" 56 + tools:text="15.02.2020 07:35" /> 57 + 58 + <androidx.appcompat.widget.AppCompatTextView 59 + android:id="@+id/tvRecordItemTimeFinished" 60 + android:layout_width="0dp" 61 + android:layout_height="wrap_content" 62 + android:layout_marginStart="8dp" 63 + android:textColor="@color/white" 64 + app:layout_constraintEnd_toStartOf="@id/tvRecordItemDuration" 65 + app:layout_constraintStart_toEndOf="@id/ivRecordItemIcon" 66 + app:layout_constraintTop_toBottomOf="@id/tvRecordItemTimeStarted" 67 + tools:text="15.02.2020 11:58" /> 68 + 69 + <androidx.appcompat.widget.AppCompatTextView 70 + android:id="@+id/tvRecordItemDuration" 71 + android:layout_width="wrap_content" 72 + android:layout_height="wrap_content" 73 + android:layout_marginEnd="8dp" 74 + android:textColor="@color/white" 75 + android:textStyle="bold" 76 + app:layout_constraintBottom_toBottomOf="parent" 77 + app:layout_constraintEnd_toEndOf="parent" 78 + app:layout_constraintTop_toTopOf="parent" 79 + tools:text="5h 23m 3s" /> 80 + 81 + </androidx.constraintlayout.widget.ConstraintLayout> 82 + 83 + </androidx.cardview.widget.CardView>
+12 -3
core/src/main/res/values/attrs.xml
··· 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <resources> 3 3 <declare-styleable name="RecordTypeView"> 4 - <attr name="name" format="string"/> 5 - <attr name="icon" format="reference"/> 6 - <attr name="color" format="color"/> 4 + <attr name="name" format="string" /> 5 + <attr name="icon" format="reference" /> 6 + <attr name="color" format="color" /> 7 + </declare-styleable> 8 + 9 + <declare-styleable name="RecordView"> 10 + <attr name="name" /> 11 + <attr name="icon" /> 12 + <attr name="color" /> 13 + <attr name="timeStarted" format="string" /> 14 + <attr name="timeEnded" format="string" /> 15 + <attr name="duration" format="string" /> 7 16 </declare-styleable> 8 17 </resources>
+6 -79
feature_records/src/main/res/layout/record_item_layout.xml
··· 1 1 <?xml version="1.0" encoding="utf-8"?> 2 - <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 3 - xmlns:app="http://schemas.android.com/apk/res-auto" 2 + <com.example.util.simpletimetracker.core.view.RecordView xmlns:android="http://schemas.android.com/apk/res/android" 4 3 xmlns:tools="http://schemas.android.com/tools" 5 - android:id="@+id/layoutRecordItem" 4 + android:id="@+id/viewRecordItem" 6 5 android:layout_width="match_parent" 7 6 android:layout_height="wrap_content" 8 - android:layout_marginStart="8dp" 9 - android:layout_marginTop="4dp" 10 - android:layout_marginEnd="8dp" 11 - android:layout_marginBottom="4dp" 12 - app:cardBackgroundColor="@color/black" 13 - app:cardCornerRadius="8dp" 14 - app:cardElevation="4dp"> 15 - 16 - <androidx.constraintlayout.widget.ConstraintLayout 17 - android:layout_width="match_parent" 18 - android:layout_height="wrap_content" 19 - android:background="?selectableItemBackground" 20 - android:paddingTop="8dp" 21 - android:paddingBottom="8dp"> 22 - 23 - <androidx.appcompat.widget.AppCompatImageView 24 - android:id="@+id/ivRecordItemIcon" 25 - android:layout_width="wrap_content" 26 - android:layout_height="0dp" 27 - android:layout_marginStart="8dp" 28 - app:backgroundTint="@color/white" 29 - app:layout_constraintBottom_toBottomOf="parent" 30 - app:layout_constraintDimensionRatio="h,1:1" 31 - app:layout_constraintStart_toStartOf="parent" 32 - app:layout_constraintTop_toTopOf="parent" 33 - tools:background="@drawable/ic_unknown" /> 34 - 35 - <androidx.appcompat.widget.AppCompatTextView 36 - android:id="@+id/tvRecordItemName" 37 - android:layout_width="0dp" 38 - android:layout_height="wrap_content" 39 - android:layout_marginStart="8dp" 40 - android:textColor="@color/white" 41 - android:textStyle="bold" 42 - app:layout_constraintEnd_toStartOf="@id/tvRecordItemDuration" 43 - app:layout_constraintStart_toEndOf="@id/ivRecordItemIcon" 44 - app:layout_constraintTop_toTopOf="parent" 45 - tools:text="Item name" /> 46 - 47 - <androidx.appcompat.widget.AppCompatTextView 48 - android:id="@+id/tvRecordItemTimeStarted" 49 - android:layout_width="0dp" 50 - android:layout_height="wrap_content" 51 - android:layout_marginStart="8dp" 52 - android:textColor="@color/white" 53 - app:layout_constraintEnd_toStartOf="@id/tvRecordItemDuration" 54 - app:layout_constraintStart_toEndOf="@id/ivRecordItemIcon" 55 - app:layout_constraintTop_toBottomOf="@id/tvRecordItemName" 56 - tools:text="15.02.2020 07:35" /> 57 - 58 - <androidx.appcompat.widget.AppCompatTextView 59 - android:id="@+id/tvRecordItemTimeFinished" 60 - android:layout_width="0dp" 61 - android:layout_height="wrap_content" 62 - android:layout_marginStart="8dp" 63 - android:textColor="@color/white" 64 - app:layout_constraintEnd_toStartOf="@id/tvRecordItemDuration" 65 - app:layout_constraintStart_toEndOf="@id/ivRecordItemIcon" 66 - app:layout_constraintTop_toBottomOf="@id/tvRecordItemTimeStarted" 67 - tools:text="15.02.2020 11:58" /> 68 - 69 - <androidx.appcompat.widget.AppCompatTextView 70 - android:id="@+id/tvRecordItemDuration" 71 - android:layout_width="wrap_content" 72 - android:layout_height="wrap_content" 73 - android:layout_marginEnd="8dp" 74 - android:textColor="@color/white" 75 - android:textStyle="bold" 76 - app:layout_constraintBottom_toBottomOf="parent" 77 - app:layout_constraintEnd_toEndOf="parent" 78 - app:layout_constraintTop_toTopOf="parent" 79 - tools:text="5h 23m 3s" /> 80 - 81 - </androidx.constraintlayout.widget.ConstraintLayout> 82 - 83 - </androidx.cardview.widget.CardView> 7 + tools:duration="5h 23m 3s" 8 + tools:name="Item name" 9 + tools:timeEnded="15.02.2020 11:58" 10 + tools:timeStarted="15.02.2020 07:35" />
+3 -1
feature_running_records/src/main/res/layout/item_record_type_layout.xml
··· 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <com.example.util.simpletimetracker.core.view.RecordTypeView xmlns:android="http://schemas.android.com/apk/res/android" 3 + xmlns:tools="http://schemas.android.com/tools" 3 4 android:id="@+id/viewRecordTypeItem" 4 5 android:layout_width="wrap_content" 5 - android:layout_height="wrap_content" /> 6 + android:layout_height="wrap_content" 7 + tools:name="Item name" />
+72
core/src/main/java/com/example/util/simpletimetracker/core/view/RecordView.kt
··· 1 + package com.example.util.simpletimetracker.core.view 2 + 3 + import android.content.Context 4 + import android.graphics.Color 5 + import android.util.AttributeSet 6 + import android.view.View 7 + import android.widget.FrameLayout 8 + import com.example.util.simpletimetracker.core.R 9 + import kotlinx.android.synthetic.main.record_view_layout.view.* 10 + 11 + class RecordView @JvmOverloads constructor( 12 + context: Context, 13 + attrs: AttributeSet? = null, 14 + defStyleAttr: Int = 0 15 + ) : FrameLayout( 16 + context, 17 + attrs, 18 + defStyleAttr 19 + ) { 20 + 21 + init { 22 + // TODO Merge layout? 23 + View.inflate(context, R.layout.record_view_layout, this) 24 + 25 + context.obtainStyledAttributes(attrs, R.styleable.RecordView, defStyleAttr, 0) 26 + .run { 27 + name = getString(R.styleable.RecordView_name).orEmpty() 28 + color = getColor(R.styleable.RecordView_color, Color.BLACK) 29 + icon = getResourceId(R.styleable.RecordView_icon, R.drawable.ic_unknown) 30 + timeStarted = getString(R.styleable.RecordView_timeStarted).orEmpty() 31 + timeEnded = getString(R.styleable.RecordView_timeEnded).orEmpty() 32 + duration = getString(R.styleable.RecordView_duration).orEmpty() 33 + recycle() 34 + } 35 + } 36 + 37 + var name: String = "" 38 + set(value) { 39 + tvRecordItemName.text = value 40 + field = value 41 + } 42 + 43 + var color: Int = 0 44 + set(value) { 45 + layoutRecordItem.setCardBackgroundColor(value) 46 + field = value 47 + } 48 + 49 + var icon: Int = 0 50 + set(value) { 51 + ivRecordItemIcon.setBackgroundResource(value) 52 + field = value 53 + } 54 + 55 + var timeStarted: String = "" 56 + set(value) { 57 + tvRecordItemTimeStarted.text = value 58 + field = value 59 + } 60 + 61 + var timeEnded: String = "" 62 + set(value) { 63 + tvRecordItemTimeFinished.text = value 64 + field = value 65 + } 66 + 67 + var duration: String = "" 68 + set(value) { 69 + tvRecordItemDuration.text = value 70 + field = value 71 + } 72 + }
+8 -8
feature_records/src/main/java/com/example/util/simpletimetracker/feature_records/adapter/RecordAdapterDelegate.kt
··· 17 17 inner class RunningRecordsViewHolder(parent: ViewGroup) : 18 18 BaseRecyclerViewHolder(parent, R.layout.record_item_layout) { 19 19 20 - override fun bind(item: ViewHolderType) = with(itemView) { 20 + override fun bind(item: ViewHolderType) = with(itemView.viewRecordItem) { 21 21 item as RecordViewData 22 22 23 - layoutRecordItem.setCardBackgroundColor(item.color) 24 - ivRecordItemIcon.setBackgroundResource(item.iconId) 25 - tvRecordItemName.text = item.name 26 - tvRecordItemTimeStarted.text = item.timeStarted 27 - tvRecordItemTimeFinished.text = item.timeFinished 28 - tvRecordItemDuration.text = item.duration 23 + color = item.color 24 + icon = item.iconId 25 + name = item.name 26 + timeStarted = item.timeStarted 27 + timeEnded = item.timeFinished 28 + duration = item.duration 29 29 30 - layoutRecordItem.setOnClickListener { 30 + setOnClickListener { 31 31 onItemClick.invoke(item) 32 32 } 33 33 }