This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
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.
Merge pull request #4 from Irineu333/release/v1.0.3
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
Showing
28 changed files
with
329 additions
and
201 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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
92
app/src/main/java/com/neo/fbrules/core/HistoricTextWatcher.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,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 | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/neo/fbrules/main/domain/model/HistoricModel.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,6 @@ | ||
package com.neo.fbrules.main.domain.model | ||
|
||
data class HistoricModel( | ||
val list: MutableList<Pair<Int, String>>, | ||
var point: Int = list.size | ||
) |
Oops, something went wrong.