-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
489 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/github/muellerma/tabletoptools/ui/fragments/CounterFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.github.muellerma.tabletoptools.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.widget.doOnTextChanged | ||
import com.github.muellerma.tabletoptools.databinding.CounterBinding | ||
import com.github.muellerma.tabletoptools.databinding.FragmentCounterBinding | ||
|
||
|
||
class CounterFragment : AbstractBaseFragment() { | ||
private lateinit var binding: FragmentCounterBinding | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentCounterBinding.inflate(inflater, container, false) | ||
|
||
setupScreenOn(binding.root) | ||
|
||
return binding.root | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
|
||
setupCounter(1, binding.counter1) | ||
setupCounter(2, binding.counter2) | ||
setupCounter(3, binding.counter3) | ||
setupCounter(4, binding.counter4) | ||
setupCounter(5, binding.counter5) | ||
} | ||
|
||
private fun setupCounter(id: Int, counter: CounterBinding) { | ||
fun getInput() = counter.count.text.toString().toIntOrNull() ?: 1 | ||
|
||
counter.less.setOnClickListener { | ||
counter.count.setText(getInput().dec().toString()) | ||
} | ||
counter.more.setOnClickListener { | ||
counter.count.setText(getInput().inc().toString()) | ||
} | ||
|
||
val prefs = prefs.Counter(id) | ||
counter.label.setText(prefs.label) | ||
counter.label.doOnTextChanged { text, _, _, _ -> prefs.label = text?.toString() } | ||
|
||
counter.count.setText(prefs.count.toString()) | ||
counter.count.doOnTextChanged { _, _, _, _ -> prefs.count = getInput() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#FFFFFF" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M10,7L8,7v4L4,11v2h4v4h2v-4h4v-2h-4L10,7zM20,18h-2L18,7.38L15,8.4L15,6.7L19.7,5h0.3v13z"/> | ||
</vector> |
5 changes: 5 additions & 0 deletions
5
app/src/main/res/drawable/baseline_keyboard_arrow_left_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:autoMirrored="true" android:height="24dp" | ||
android:tint="#FFFFFF" android:viewportHeight="24" | ||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M15.41,16.59L10.83,12l4.58,-4.59L14,6l-6,6 6,6 1.41,-1.41z"/> | ||
</vector> |
5 changes: 5 additions & 0 deletions
5
app/src/main/res/drawable/baseline_keyboard_arrow_right_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:autoMirrored="true" android:height="24dp" | ||
android:tint="#FFFFFF" android:viewportHeight="24" | ||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M8.59,16.59L13.17,12 8.59,7.41 10,6l6,6 -6,6 -1.41,-1.41z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<EditText | ||
android:id="@+id/label" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/counter_label" | ||
android:gravity="center" | ||
android:maxLines="1" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" /> | ||
|
||
<ImageButton | ||
android:id="@+id/less" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/baseline_keyboard_arrow_left_24" | ||
app:layout_constraintTop_toBottomOf="@+id/label" | ||
app:layout_constraintStart_toStartOf="parent" | ||
android:layout_marginTop="16dp" /> | ||
|
||
<EditText | ||
android:id="@+id/count" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:hint="1" | ||
android:gravity="center" | ||
android:maxLines="1" | ||
android:inputType="number" | ||
app:layout_constraintTop_toBottomOf="@+id/label" | ||
android:layout_marginTop="16dp" | ||
app:layout_constraintStart_toEndOf="@+id/less" | ||
app:layout_constraintEnd_toStartOf="@+id/more" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginEnd="8dp" /> | ||
|
||
<ImageButton | ||
android:id="@+id/more" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/baseline_keyboard_arrow_right_24" | ||
app:layout_constraintTop_toBottomOf="@+id/label" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:layout_marginTop="16dp" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ScrollView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="16dp" | ||
android:gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<include android:id="@+id/counter1" layout="@layout/counter" android:layout_margin="8dp" /> | ||
<include android:id="@+id/counter2" layout="@layout/counter" android:layout_margin="8dp" /> | ||
<include android:id="@+id/counter3" layout="@layout/counter" android:layout_margin="8dp" /> | ||
<include android:id="@+id/counter4" layout="@layout/counter" android:layout_margin="8dp" /> | ||
<include android:id="@+id/counter5" layout="@layout/counter" android:layout_margin="8dp" /> | ||
|
||
</LinearLayout> | ||
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.