Use IDEEditor to show logs

The syntax highlighting for logs has been removed and will be implemented later with better efficiency
This commit is contained in:
Akash Yadav
2022-06-23 14:09:37 +05:30
parent c8bdc40e6f
commit edb30a7cf3
6 changed files with 65 additions and 66 deletions
+1 -1
View File
@@ -642,7 +642,7 @@
<option name="ASSIGNMENT_WRAP" value="0" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
<option name="KEEP_INDENTS_ON_EMPTY_LINES" value="true" />
</indentOptions>
Binary file not shown.
@@ -1378,12 +1378,12 @@ public class EditorActivity extends StudioActivity
}
} else if (fragment instanceof LogViewFragment) {
final LogViewFragment logFrag = (LogViewFragment) fragment;
final var adapter = logFrag.getAdapter();
if (adapter != null) {
adapter.clear();
final var binding = logFrag.getBinding();
if (binding != null) {
binding.editor.setText("");
} else {
LOG.error(
"Cannot clear contents. Adapter in LogViewFragment("
"Cannot clear contents. Binding in LogViewFragment("
+ logFrag.getLogType()
+ ") is null.");
}
@@ -1399,15 +1399,15 @@ public class EditorActivity extends StudioActivity
if (fragment instanceof LogViewFragment) {
final var logFrag = (LogViewFragment) fragment;
final var type = logFrag.getLogType();
final var adapter = logFrag.getAdapter();
if (adapter != null) {
final var binding = logFrag.getBinding();
if (binding != null) {
//noinspection deprecation
final var progress =
ProgressDialog.show(EditorActivity.this, null, getString(R.string.please_wait));
CompletableFuture.runAsync(
() -> {
final var text = adapter.allAsString();
final var text = binding.editor.getText();
ThreadUtils.runOnUiThread(
() -> {
progress.dismiss();
@@ -1415,7 +1415,7 @@ public class EditorActivity extends StudioActivity
});
});
} else {
LOG.error("Adapter in LogViewFragment(" + type + ") is null");
LOG.error("Binding in LogViewFragment(" + type + ") is null");
}
return;
}
@@ -22,12 +22,13 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.itsaky.androidide.adapters.LogLinesAdapter
import com.blankj.utilcode.util.ThreadUtils
import com.itsaky.androidide.databinding.FragmentLogBinding
import com.itsaky.androidide.models.LogLine
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE
import com.itsaky.androidide.utils.ILogger
import com.itsaky.androidide.utils.ILogger.Priority
import com.itsaky.androidide.utils.TypefaceUtils
/**
* Fragment to show logs in a [androidx.recyclerview.widget.RecyclerView].
@@ -35,51 +36,63 @@ import com.itsaky.androidide.utils.ILogger.Priority
*/
abstract class LogViewFragment : Fragment() {
private val log = ILogger.newInstance(javaClass.simpleName)
var binding: FragmentLogBinding? = null
var adapter: LogLinesAdapter? = null
private val log = ILogger.newInstance(javaClass.simpleName)
var binding: FragmentLogBinding? = null
fun appendLog(line: LogLine) {
if (this.binding == null || this.adapter == null) {
return
}
this.binding!!.lines.post {
this.adapter!!.simpleFormatting = isSimpleFormattingEnabled()
this.adapter!!.add(line)
}
fun appendLog(line: LogLine) {
if (this.binding == null) {
System.err.println("Cannot append log line. Binding is null.")
return
}
abstract fun getLogType(): String
var lineString =
if (isSimpleFormattingEnabled()) {
line.toSimpleString()
} else {
line.toString()
}
abstract fun isSimpleFormattingEnabled(): Boolean
protected open fun logLine(priority: Priority, tag: String, message: String) {
val line = LogLine(priority, tag, message)
appendLog(line)
if (!lineString.endsWith("\n")) {
lineString += "\n"
}
ThreadUtils.runOnUiThread { this.binding!!.editor.append(lineString) }
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
binding = FragmentLogBinding.inflate(inflater, container, false)
return binding!!.root
}
abstract fun getLogType(): String
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val manager = LinearLayoutManager(requireContext())
this.binding!!.lines.layoutManager = manager
abstract fun isSimpleFormattingEnabled(): Boolean
this.adapter = LogLinesAdapter()
this.binding!!.lines.adapter = this.adapter
}
protected open fun logLine(priority: Priority, tag: String, message: String) {
val line = LogLine(priority, tag, message)
appendLog(line)
}
override fun onDestroy() {
super.onDestroy()
this.binding = null
this.adapter = null
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
binding = FragmentLogBinding.inflate(inflater, container, false)
return binding!!.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val editor = this.binding!!.editor
editor.props.autoIndent = false
editor.isEditable = false
editor.dividerWidth = 0f
editor.isWordwrap = false
editor.isUndoEnabled = false
editor.typefaceLineNumber = TypefaceUtils.jetbrainsMono()
editor.setTextSize(12f)
editor.typefaceText = TypefaceUtils.jetbrainsMono()
editor.colorScheme = SchemeAndroidIDE()
}
override fun onDestroy() {
super.onDestroy()
this.binding = null
}
}
+3 -17
View File
@@ -14,21 +14,7 @@
~ You should have received a copy of the GNU General Public License
~ along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
-->
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/horizontalScrollView"
<com.itsaky.androidide.views.editor.IDEEditor xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/editor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lines"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingStart="8dp"
android:paddingEnd="8dp" />
</HorizontalScrollView>
android:layout_height="match_parent" />