Skip to content

Commit

Permalink
feat, refactor: Add Text magnifier to Code Editor, small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
omeraydindev committed Oct 30, 2021
1 parent e61b0d5 commit 99c0b21
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 39 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ dependencies {
testImplementation 'org.eclipse.jdt.core.compiler:ecj:4.6.1'
testImplementation 'com.android.tools:r8:3.0.73'

implementation 'io.github.Rosemoe.sora-editor:editor:0.7.2'
implementation 'io.github.Rosemoe.sora-editor:language-base:0.7.2'
implementation 'io.github.Rosemoe.sora-editor:language-universal:0.7.2'
implementation 'io.github.Rosemoe.sora-editor:language-java:0.7.2'
implementation 'io.github.Rosemoe.sora-editor:editor:0.8.2'
implementation 'io.github.Rosemoe.sora-editor:language-base:0.8.2'
implementation 'io.github.Rosemoe.sora-editor:language-universal:0.8.2'
implementation 'io.github.Rosemoe.sora-editor:language-java:0.8.2'
implementation 'com.github.angads25:filepicker:1.1.1'
implementation 'me.zhanghai.android.fastscroll:library:1.1.7'
implementation 'com.github.zawadz88.materialpopupmenu:material-popup-menu:4.1.0'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/ma/dexter/editor/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import android.view.inputmethod.EditorInfo
import io.github.rosemoe.sora.widget.CodeEditor

fun CodeEditor.setDefaults() {
isLigatureEnabled = true
isOverScrollEnabled = false
inputType =
EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS or EditorInfo.TYPE_CLASS_TEXT or EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE or EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO

setTextSize(16f)
setTextSize(12f)
}

fun CodeEditor.setOnTextChangedListener(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ma.dexter.ui.activity
package ma.dexter.ui.base

import androidx.appcompat.app.AppCompatActivity

Expand Down
18 changes: 18 additions & 0 deletions app/src/main/kotlin/ma/dexter/ui/base/BaseFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ma.dexter.ui.base

import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment

open class BaseFragment : Fragment() {

fun drawable(@DrawableRes drawableRes: Int) =
ContextCompat.getDrawable(requireContext(), drawableRes)

override fun onResume() {
super.onResume()

setHasOptionsMenu(isVisible)
}

}
28 changes: 16 additions & 12 deletions app/src/main/kotlin/ma/dexter/ui/fragment/BaseCodeEditorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package ma.dexter.ui.fragment
import android.os.Bundle
import android.view.*
import androidx.annotation.CallSuper
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import com.github.zawadz88.materialpopupmenu.MaterialPopupMenuBuilder
import io.github.rosemoe.sora.widget.CodeEditor
import ma.dexter.R
import ma.dexter.databinding.FragmentBaseCodeEditorBinding
import ma.dexter.editor.util.setDefaults
import ma.dexter.editor.util.setOnTextChangedListener
import ma.dexter.ui.base.BaseFragment
import ma.dexter.ui.util.checkableItem
import ma.dexter.ui.viewmodel.MainViewModel

Expand All @@ -19,7 +19,7 @@ open class BaseCodeEditorFragment : BaseFragment() {
private val viewModel: MainViewModel by activityViewModels()

protected lateinit var codeEditor: CodeEditor
protected var isEdited = false
private var isEdited = false

@CallSuper
override fun onCreateView(
Expand Down Expand Up @@ -75,18 +75,14 @@ open class BaseCodeEditorFragment : BaseFragment() {

item {
label = "Search"
iconDrawable =
ContextCompat.getDrawable(requireContext(), R.drawable.ic_baseline_search_24)
iconDrawable = drawable(R.drawable.ic_baseline_search_24)
callback = codeEditor::beginSearchMode
}

customItem {
checkableItem {
label = "Word wrap"
iconDrawable = ContextCompat.getDrawable(
requireContext(),
R.drawable.ic_baseline_wrap_text_24
)
iconDrawable = drawable(R.drawable.ic_baseline_wrap_text_24)
checked = codeEditor.isWordwrap
callback = {
codeEditor.isWordwrap = it
Expand All @@ -97,16 +93,24 @@ open class BaseCodeEditorFragment : BaseFragment() {
customItem {
checkableItem {
label = "Auto complete"
iconDrawable = ContextCompat.getDrawable(
requireContext(),
R.drawable.ic_baseline_copyright_24
)
iconDrawable = drawable(R.drawable.ic_baseline_copyright_24)
checked = codeEditor.isAutoCompletionEnabled
callback = {
codeEditor.isAutoCompletionEnabled = it
}
}
}

customItem {
checkableItem {
label = "Magnifier"
iconDrawable = drawable(R.drawable.ic_baseline_zoom_in_24)
checked = codeEditor.isMagnifierEnabled
callback = {
codeEditor.isMagnifierEnabled = it
}
}
}
}
afterBuildMoreMenu(builder)

Expand Down
13 changes: 0 additions & 13 deletions app/src/main/kotlin/ma/dexter/ui/fragment/BaseFragment.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import ma.dexter.dex.MutableDexFile
import ma.dexter.model.SmaliGotoDef
import ma.dexter.project.DexGotoManager
import ma.dexter.project.DexProject
import ma.dexter.ui.activity.BaseActivity
import ma.dexter.ui.base.BaseActivity
import ma.dexter.ui.base.BaseFragment
import ma.dexter.ui.tree.TreeNode
import ma.dexter.ui.tree.TreeView
import ma.dexter.ui.tree.dex.SmaliTree
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/ma/dexter/ui/model/DexPageItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ma.dexter.R
import ma.dexter.model.GotoDef
import ma.dexter.model.JavaGotoDef
import ma.dexter.model.SmaliGotoDef
import ma.dexter.util.getClassDefPath
import ma.dexter.util.getNameFromSmaliPath

sealed class DexPageItem(val typeDef: String?) {
abstract fun getTitle(): String
Expand All @@ -24,7 +24,7 @@ class SmaliItem(
) : DexPageItem(smaliGotoDef.classDef.type) {

override fun getTitle() =
getClassDefPath(smaliGotoDef.classDef.type).substringAfterLast("/") + ".smali"
getNameFromSmaliPath(smaliGotoDef.classDef.type) + ".smali"

override fun getIconResId() = R.drawable.ic_letter_s_24

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/ma/dexter/ui/tree/dex/SmaliTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ma.dexter.dex.MutableDexFile
import ma.dexter.ui.tree.*
import ma.dexter.ui.tree.model.DexClassItem
import ma.dexter.ui.tree.model.DexItem
import ma.dexter.util.getClassDefPath
import ma.dexter.util.normalizeSmaliPath

class SmaliTree {
private val dexList = mutableListOf<MutableDexFile>()
Expand Down Expand Up @@ -41,7 +41,7 @@ class SmaliTree {
dex.classes.forEach { classDef ->
var currentNode = rootTreeNode

val classDefSegments = getClassDefPath(classDef.type).split("/")
val classDefSegments = normalizeSmaliPath(classDef.type).split("/")

classDefSegments.forEachIndexed { level, segment ->
val subNode: TreeNode<DexItem>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/ma/dexter/util/SmaliUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const val END_METHOD_DIRECTIVE = ".end method"
/**
* Ltest/aaa; -> test/aaa
*/
fun getClassDefPath(classDefType: String) =
if (classDefType.length >= 2) {
fun normalizeSmaliPath(classDefType: String) =
if (classDefType.startsWith("L") && classDefType.endsWith(";")) {
classDefType.substring(1, classDefType.length - 1)
} else {
classDefType
Expand All @@ -43,7 +43,7 @@ fun getClassDefPath(classDefType: String) =
* Ltest/aaa; -> aaa
*/
fun getNameFromSmaliPath(classDefType: String) =
getClassDefPath(classDefType).substringAfterLast("/")
normalizeSmaliPath(classDefType).substringAfterLast("/")

/**
* Utility method to tokenize smali.
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/ic_baseline_zoom_in_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="@color/textColor"
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.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
<path android:fillColor="@android:color/white" android:pathData="M12,10h-2v2H9v-2H7V9h2V7h1v2h2v1z"/>
</vector>

0 comments on commit 99c0b21

Please sign in to comment.