-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
144 additions
and
6 deletions.
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
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
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/luisansal/jetpack/features/login/LoginViewState.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.luisansal.jetpack.features.login | ||
|
||
sealed class LoginViewState { | ||
data class SuccessState(val ok: Boolean) : LoginViewState() | ||
data class LogoutSuccessState(val ok: Boolean) : LoginViewState() | ||
} |
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
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/luisansal/jetpack/features/workmanager/CalculatorWorker.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,28 @@ | ||
package com.luisansal.jetpack.features.workmanager | ||
|
||
import android.content.Context | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.widget.Toast | ||
import androidx.work.Worker | ||
import androidx.work.WorkerParameters | ||
|
||
class CalculatorWorker(private val context: Context, params: WorkerParameters) : Worker(context, params) { | ||
|
||
override fun doWork(): Result { | ||
var text = "" | ||
|
||
Handler(Looper.getMainLooper()).postDelayed({ | ||
for (x: Int in 1..2) { | ||
for (y: Int in 1..10) { | ||
text += "$x x $y = ${x * y}" | ||
Toast.makeText(context, text, Toast.LENGTH_SHORT).show() | ||
text = "" | ||
} | ||
} | ||
}, 500) | ||
|
||
|
||
return Result.success() | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/luisansal/jetpack/features/workmanager/WorkManagerActivity.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,45 @@ | ||
package com.luisansal.jetpack.features.workmanager | ||
|
||
import android.os.CountDownTimer | ||
import android.view.View | ||
import androidx.work.Constraints | ||
import androidx.work.OneTimeWorkRequest | ||
import androidx.work.WorkManager | ||
import com.luisansal.jetpack.R | ||
import com.luisansal.jetpack.base.BaseBindingActivity | ||
import com.luisansal.jetpack.databinding.ActivityWorkmanagerBinding | ||
import java.time.Duration | ||
|
||
class WorkManagerActivity : BaseBindingActivity() { | ||
private val binding by lazy { | ||
ActivityWorkmanagerBinding.inflate(layoutInflater).apply { | ||
lifecycleOwner = this@WorkManagerActivity | ||
} | ||
} | ||
private val mWork by lazy { | ||
OneTimeWorkRequest.Builder(CalculatorWorker::class.java) | ||
.setInitialDelay(Duration.ofSeconds(3)) | ||
.setConstraints(Constraints.Builder().setRequiresCharging(true).build()) | ||
.addTag("MY_CALCULATOR") | ||
.build() | ||
} | ||
|
||
override fun getViewResource() = binding.root | ||
|
||
fun onclickStartWorkManager(view: View) { | ||
binding.tvInfo2.visibility = View.VISIBLE | ||
val countDownTimer = object : CountDownTimer(3000, 1000) { | ||
override fun onFinish() = Unit | ||
override fun onTick(tickTime: Long) { | ||
binding.tvInfo2.text = String.format(getString(R.string.seconds_remaining), tickTime / 1000) | ||
} | ||
} | ||
countDownTimer.start() | ||
WorkManager.getInstance().enqueue(mWork) | ||
} | ||
|
||
fun onclickCancel(view: View) { | ||
WorkManager.getInstance().cancelWorkById(mWork.id) | ||
} | ||
|
||
} |
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,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="@dimen/ds_padding_xsmall" | ||
> | ||
<TextView | ||
android:id="@+id/tvInfo1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Tabla de multiplicar, configurado para que inicie en" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
android:gravity="center" | ||
android:layout_marginTop="@dimen/ds_margin_largex3" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/tvInfo2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/seconds_remaining" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/tvInfo1" | ||
android:gravity="center" | ||
android:visibility="gone" | ||
android:layout_marginTop="@dimen/ds_margin_small" | ||
/> | ||
<Button | ||
android:id="@+id/btnStart" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Start Work Manager" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/tvInfo2" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:onClick="onclickStartWorkManager" | ||
style="@style/Widget.ButtonGreen" | ||
/> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Cancel Manager" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/btnStart" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:onClick="onclickCancel" | ||
android:layout_marginTop="@dimen/ds_margin_largex3" | ||
/> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
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