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

Commit

Permalink
Merge pull request #4 from Irineu333/release/v1.0.3
Browse files Browse the repository at this point in the history
Release/v1.0.3

refactor : improving scroll && ignore unnecessary files
feat : created undo and redo function
feat : improving register history validation
feat : translate strings
feat : translate all app
fix : correcting not catching error
fix : improving green color un dark theme
  • Loading branch information
Irineu333 authored Jan 8, 2022
2 parents 9c6e61f + 58640ae commit e50d5fc
Show file tree
Hide file tree
Showing 28 changed files with 329 additions and 201 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea
.DS_Store
/build
/captures
Expand Down
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/dictionaries/aiqfome.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

43 changes: 0 additions & 43 deletions .idea/misc.xml

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/vcs.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "com.neo.fbrules"
minSdk 21
targetSdk 31
versionCode 3
versionName "1.0.2"
versionCode 4
versionName "1.0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/debug/res/values/constants.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="environment">development</string>
<string name="environment" translatable="false">development</string>
</resources>
92 changes: 92 additions & 0 deletions app/src/main/java/com/neo/fbrules/core/HistoricTextWatcher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.neo.fbrules.core

import android.text.Editable
import android.text.Selection
import android.text.TextWatcher
import com.neo.fbrules.main.domain.model.HistoricModel
import kotlinx.coroutines.*

class HistoricTextWatcher(private val model: HistoricModel) : TextWatcher {

var historyListener: HistoryListener? = null

private var job: Job? = null

override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit

override fun afterTextChanged(rules: Editable) {
job?.cancel()
job = CoroutineScope(Dispatchers.IO).launch {
delay(150)
val position = Selection.getSelectionStart(rules)
addRule(position, rules.toString())
}
}

@Synchronized
private fun addRule(position: Int, rules: String) = with(model) {

if (list[point -1 ].second == rules) return@with

if (point < list.size) {
list.clear(point, list.size)
}

list.add(position to rules)

if (list.size > MAX_HISTORIC) {
list.removeAt(0)
}

point = list.size

update()
}

private fun MutableList<*>.clear(start: Int, end: Int) {
for (index in end downTo start) {

if (index == 1) continue

this.removeAt(index - 1)
}
}

@Synchronized
fun undo() = with(model) {
if (list.isEmpty() || point == 1) return@with

historyListener?.update(list[(--point) - 1])

update()
}

fun redo() = with(model) {
if (point == list.size) return@with

historyListener?.update(list[(++point) - 1])

update()
}

private fun update() = with(model) {
historyListener?.hasUndo(point != 1)
historyListener?.hasRedo(point < list.size)
}

fun getActual(): String {
return model.list[model.point - 1].second
}

interface HistoryListener {
fun hasRedo(has: Boolean)
fun hasUndo(has: Boolean)
fun update(history: Pair<Int, String>)
}

private companion object {
const val MAX_HISTORIC = 50
}
}
9 changes: 7 additions & 2 deletions app/src/main/java/com/neo/fbrules/core/Result.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.neo.fbrules.core

import androidx.annotation.StringRes
import com.neo.fbrules.R

sealed class Result<out R> {

data class Success<T>(val data: T) : Result<T>()
Expand All @@ -12,6 +15,8 @@ sealed class Result<out R> {
}

class Message(
val title: String = "Message",
val message: String
@StringRes
val title: Int = R.string.text_success,
@StringRes
val message: Int
)
29 changes: 15 additions & 14 deletions app/src/main/java/com/neo/fbrules/main/data/FirebaseRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ class FirebaseRepositoryImpl @Inject constructor(

override suspend fun getRules(credential: DataCredential): Result<String> {

return try {
return runCatching {
val result = service.getRules(
credential.databaseKey,
credential.privateKey
)

Result.Success(result)
} catch (e: HttpException) {
Result.Error(
title = "${e.message}\n",
message = "${e.response()?.errorBody()?.errorMessage()}"
)
}
}.getOrElse(::onFailure)
}

override suspend fun setRules(
rules: String,
credential: DataCredential
): Result<Unit> {

return try {
return runCatching {
val requestBody = rules.toRequestBody()

service.setRules(
Expand All @@ -53,12 +48,18 @@ class FirebaseRepositoryImpl @Inject constructor(
)

Result.Success(Unit)
} catch (e: HttpException) {
}.getOrElse(::onFailure)
}

Result.Error(
title = "${e.message}\n",
message = "${e.response()?.errorBody()?.errorMessage()}"
)
}
private fun onFailure(it: Throwable) = if (it is HttpException) {
Result.Error(
title = "${it.message}\n",
message = "${it.response()?.errorBody()?.errorMessage()}"
)
} else {
Result.Error(
title = "${it::class.simpleName}\n",
message = "${it.message}"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.neo.fbrules.main.domain.model

data class HistoricModel(
val list: MutableList<Pair<Int, String>>,
var point: Int = list.size
)
Loading

0 comments on commit e50d5fc

Please sign in to comment.