diff --git a/.gitignore b/.gitignore index 643d213..aa724b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,15 @@ -*.iml -.gradle -/local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -.DS_Store -/build -/captures -.externalNativeBuild -.cxx -local.properties +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore index eaf91e2..26d3352 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,3 +1,3 @@ -# Default ignored files -/shelf/ -/workspace.xml +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7d7ec2e..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 78708b3..5cd135a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,20 +1,20 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index 94ae73a..0380d8d 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4daf7e2..6199cc2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,9 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml index 93e4b17..797acea 100644 --- a/.idea/runConfigurations.xml +++ b/.idea/runConfigurations.xml @@ -1,10 +1,10 @@ - - - - - + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 9661ac7..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore index 87be99d..0355e9d 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,4 +1,4 @@ -/build -/release -/src/main/assets/*.js +/build +/release +/src/main/assets/*.js gradle.properties \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b836167..7eb8647 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,107 +1,107 @@ -plugins { - id 'com.android.application' - id 'com.google.android.gms.oss-licenses-plugin' - id 'kotlin-android' - id 'kotlin-kapt' -} - -android { - signingConfigs { - release { - storeFile file('./misc/keystore.jks') - storePassword 'i1KY2P37COLmzLtE' - keyAlias 'key0' - keyPassword 'i1KY2P37COLmzLtE' - } - } - compileSdkVersion 30 - buildToolsVersion "30.0.3" - - defaultConfig { - applicationId "com.nonnonstop.apimate" - minSdkVersion 26 - targetSdkVersion 30 - versionCode 300 - versionName "0.3.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - buildFeatures { - dataBinding true - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - signingConfig signingConfigs.release - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.3.2' - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation "androidx.activity:activity-ktx:1.2.3" - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation "androidx.fragment:fragment-ktx:1.3.3" - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' - implementation 'androidx.preference:preference-ktx:1.1.1' - implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'com.jakewharton.timber:timber:4.7.1' - implementation 'com.squareup.okhttp3:okhttp:4.9.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' - implementation 'org.mozilla:rhino:1.7.13' - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' -} - -// Build TypeScript -import org.apache.tools.ant.taskdefs.condition.Os - -class NodeExec extends Exec { - NodeExec() { - workingDir 'src/main/script' - if (project.hasProperty('NPM_DIR')) { - environment 'PATH', project['NPM_DIR'] - } - } - - void npmCommandLine(String... args) { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine('cmd', '/c', 'npm.cmd', *args) - } else { - commandLine('npm', *args) - } - } -} - -def prepareBuildAssetScripts = tasks.register('prepareBuildAssetScripts', NodeExec) { - npmCommandLine 'install' -} - -def buildAssetScripts = tasks.register('buildAssetScripts', NodeExec) { - npmCommandLine 'run', 'build' - dependsOn prepareBuildAssetScripts -} - -def cleanBuildAssetScripts = tasks.register('cleanBuildAssetScripts', NodeExec) { - npmCommandLine 'run', 'clean' -} - -android.applicationVariants.all { variant -> - variant.getMergeAssetsProvider().get().dependsOn(buildAssetScripts) -} - +plugins { + id 'com.android.application' + id 'com.google.android.gms.oss-licenses-plugin' + id 'kotlin-android' + id 'kotlin-kapt' +} + +android { + signingConfigs { + release { + storeFile file('./misc/keystore.jks') + storePassword 'i1KY2P37COLmzLtE' + keyAlias 'key0' + keyPassword 'i1KY2P37COLmzLtE' + } + } + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.nonnonstop.apimate" + minSdkVersion 26 + targetSdkVersion 30 + versionCode 300 + versionName "0.3.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildFeatures { + dataBinding true + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.release + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation "androidx.activity:activity-ktx:1.2.3" + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation "androidx.fragment:fragment-ktx:1.3.3" + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' + implementation 'androidx.preference:preference-ktx:1.1.1' + implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'com.jakewharton.timber:timber:4.7.1' + implementation 'com.squareup.okhttp3:okhttp:4.9.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' + implementation 'org.mozilla:rhino:1.7.13' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} + +// Build TypeScript +import org.apache.tools.ant.taskdefs.condition.Os + +class NodeExec extends Exec { + NodeExec() { + workingDir 'src/main/script' + if (project.hasProperty('NPM_DIR')) { + environment 'PATH', project['NPM_DIR'] + } + } + + void npmCommandLine(String... args) { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine('cmd', '/c', 'npm.cmd', *args) + } else { + commandLine('npm', *args) + } + } +} + +def prepareBuildAssetScripts = tasks.register('prepareBuildAssetScripts', NodeExec) { + npmCommandLine 'install' +} + +def buildAssetScripts = tasks.register('buildAssetScripts', NodeExec) { + npmCommandLine 'run', 'build' + dependsOn prepareBuildAssetScripts +} + +def cleanBuildAssetScripts = tasks.register('cleanBuildAssetScripts', NodeExec) { + npmCommandLine 'run', 'clean' +} + +android.applicationVariants.all { variant -> + variant.getMergeAssetsProvider().get().dependsOn(buildAssetScripts) +} + tasks.clean.dependsOn(cleanBuildAssetScripts) \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 64b4a05..481bb43 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,21 +1,21 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. #-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/nonnonstop/apimate/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/nonnonstop/apimate/ExampleInstrumentedTest.kt index 7adc454..d6e0283 100644 --- a/app/src/androidTest/java/com/nonnonstop/apimate/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/nonnonstop/apimate/ExampleInstrumentedTest.kt @@ -1,22 +1,22 @@ -package com.nonnonstop.apimate - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.nonnonstop.apimate", appContext.packageName) - } +package com.nonnonstop.apimate + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.nonnonstop.apimate", appContext.packageName) + } } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7b63fb9..b4631f6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,61 +1,61 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/EditActivity.kt b/app/src/main/java/com/nonnonstop/apimate/EditActivity.kt index a456fc9..382b9fd 100644 --- a/app/src/main/java/com/nonnonstop/apimate/EditActivity.kt +++ b/app/src/main/java/com/nonnonstop/apimate/EditActivity.kt @@ -1,37 +1,37 @@ -package com.nonnonstop.apimate - -import android.content.Intent -import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import androidx.activity.viewModels -import androidx.appcompat.app.AppCompatActivity - -class EditActivity : AppCompatActivity() { - private val viewModel: EditViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.edit_activity) - viewModel.fileName.value = intent.getStringExtra(Intent.EXTRA_TEXT) - } - - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.edit_menu, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - R.id.save_script -> { - viewModel.save() - true - } - R.id.revert_script -> { - viewModel.revert() - true - } - else -> super.onOptionsItemSelected(item) - } - } +package com.nonnonstop.apimate + +import android.content.Intent +import android.os.Bundle +import android.view.Menu +import android.view.MenuItem +import androidx.activity.viewModels +import androidx.appcompat.app.AppCompatActivity + +class EditActivity : AppCompatActivity() { + private val viewModel: EditViewModel by viewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.edit_activity) + viewModel.fileName.value = intent.getStringExtra(Intent.EXTRA_TEXT) + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.edit_menu, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.save_script -> { + viewModel.save() + true + } + R.id.revert_script -> { + viewModel.revert() + true + } + else -> super.onOptionsItemSelected(item) + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/EditFragment.kt b/app/src/main/java/com/nonnonstop/apimate/EditFragment.kt index b3efd40..5e7f50c 100644 --- a/app/src/main/java/com/nonnonstop/apimate/EditFragment.kt +++ b/app/src/main/java/com/nonnonstop/apimate/EditFragment.kt @@ -1,78 +1,78 @@ -package com.nonnonstop.apimate - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.databinding.DataBindingUtil -import androidx.fragment.app.Fragment -import androidx.fragment.app.activityViewModels -import com.google.android.material.snackbar.Snackbar -import com.nonnonstop.apimate.databinding.EditFragmentBinding -import timber.log.Timber - -class EditFragment : Fragment() { - private val viewModel: EditViewModel by activityViewModels() - private var binding: EditFragmentBinding? = null - private lateinit var scripts: Scripts - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - scripts = Scripts(requireContext()) - } - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - binding = DataBindingUtil.inflate( - inflater, - R.layout.edit_fragment, - container, - false - ) - binding!!.viewModel = viewModel - binding!!.lifecycleOwner = viewLifecycleOwner - return binding!!.root - } - - override fun onDestroyView() { - super.onDestroyView() - binding = null - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - val fileName = viewModel.fileName.value ?: return - viewModel.script.value = scripts.readScript(fileName) - viewModel.save.observe(viewLifecycleOwner) { - try { - val script = binding?.editText?.text?.toString() ?: return@observe - scripts.writeScript(fileName, script) - Snackbar.make(view, R.string.save_script_succeeded, Snackbar.LENGTH_SHORT).show() - } catch (ex: Exception) { - Timber.e(ex, "Failed to save script") - Snackbar.make(view, R.string.save_script_failed, Snackbar.LENGTH_LONG).show() - } - } - viewModel.revert.observe(viewLifecycleOwner) { - try { - scripts.revertScript(fileName) - val script = scripts.readScript(fileName) - viewModel.script.value = script - Snackbar.make( - requireView(), - R.string.revert_script_succeeded, - Snackbar.LENGTH_SHORT - ).show() - } catch (ex: Exception) { - Timber.e(ex, "Failed to revert script") - Snackbar.make( - requireView(), - R.string.revert_script_failed, - Snackbar.LENGTH_LONG - ).show() - } - } - } +package com.nonnonstop.apimate + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import com.google.android.material.snackbar.Snackbar +import com.nonnonstop.apimate.databinding.EditFragmentBinding +import timber.log.Timber + +class EditFragment : Fragment() { + private val viewModel: EditViewModel by activityViewModels() + private var binding: EditFragmentBinding? = null + private lateinit var scripts: Scripts + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + scripts = Scripts(requireContext()) + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = DataBindingUtil.inflate( + inflater, + R.layout.edit_fragment, + container, + false + ) + binding!!.viewModel = viewModel + binding!!.lifecycleOwner = viewLifecycleOwner + return binding!!.root + } + + override fun onDestroyView() { + super.onDestroyView() + binding = null + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val fileName = viewModel.fileName.value ?: return + viewModel.script.value = scripts.readScript(fileName) + viewModel.save.observe(viewLifecycleOwner) { + try { + val script = binding?.editText?.text?.toString() ?: return@observe + scripts.writeScript(fileName, script) + Snackbar.make(view, R.string.save_script_succeeded, Snackbar.LENGTH_SHORT).show() + } catch (ex: Exception) { + Timber.e(ex, "Failed to save script") + Snackbar.make(view, R.string.save_script_failed, Snackbar.LENGTH_LONG).show() + } + } + viewModel.revert.observe(viewLifecycleOwner) { + try { + scripts.revertScript(fileName) + val script = scripts.readScript(fileName) + viewModel.script.value = script + Snackbar.make( + requireView(), + R.string.revert_script_succeeded, + Snackbar.LENGTH_SHORT + ).show() + } catch (ex: Exception) { + Timber.e(ex, "Failed to revert script") + Snackbar.make( + requireView(), + R.string.revert_script_failed, + Snackbar.LENGTH_LONG + ).show() + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/EditViewModel.kt b/app/src/main/java/com/nonnonstop/apimate/EditViewModel.kt index 387fc9e..4c37a26 100644 --- a/app/src/main/java/com/nonnonstop/apimate/EditViewModel.kt +++ b/app/src/main/java/com/nonnonstop/apimate/EditViewModel.kt @@ -1,27 +1,27 @@ -package com.nonnonstop.apimate - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel - -class EditViewModel : ViewModel() { - val fileName by lazy { - MutableLiveData() - } - val script by lazy { - MutableLiveData() - } - val save by lazy { - MutableLiveData() - } - val revert by lazy { - MutableLiveData() - } - - fun save() { - save.value = true - } - - fun revert() { - revert.value = true - } +package com.nonnonstop.apimate + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +class EditViewModel : ViewModel() { + val fileName by lazy { + MutableLiveData() + } + val script by lazy { + MutableLiveData() + } + val save by lazy { + MutableLiveData() + } + val revert by lazy { + MutableLiveData() + } + + fun save() { + save.value = true + } + + fun revert() { + revert.value = true + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/FileTree.kt b/app/src/main/java/com/nonnonstop/apimate/FileTree.kt index 43ab19e..2cda585 100644 --- a/app/src/main/java/com/nonnonstop/apimate/FileTree.kt +++ b/app/src/main/java/com/nonnonstop/apimate/FileTree.kt @@ -1,70 +1,70 @@ -package com.nonnonstop.apimate - -import android.annotation.SuppressLint -import android.util.Log -import timber.log.Timber -import java.io.File -import java.text.SimpleDateFormat -import java.util.* -import java.util.logging.* -import java.util.logging.Formatter - -@SuppressLint("LogNotTimber") -class FileTree(baseDir: File) : Timber.Tree() { - companion object { - private const val LOG_LIMIT = 512 * 1024 - private const val LOG_COUNT = 2 - } - - private var logger: Logger - - init { - val path = File(baseDir, "exception%g.txt").absolutePath - val formatter = MyFormatter() - val handler = FileHandler(path, LOG_LIMIT, LOG_COUNT, true) - handler.formatter = formatter - logger = MyLogger("apimater").apply { - level = Level.ALL - addHandler(handler) - } - } - - override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { - val level = when (priority) { - Log.VERBOSE -> Level.FINER - Log.DEBUG -> Level.FINE - Log.INFO -> Level.INFO - Log.WARN -> Level.WARNING - Log.ERROR -> Level.SEVERE - Log.ASSERT -> Level.SEVERE - else -> Level.FINEST - } - logger.log(level, message, t) - } - - private class MyLogger(name: String) : Logger(name, null) - - private class MyFormatter() : Formatter() { - companion object { - private val dateFormatter = SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm'Z'", - Locale.ENGLISH - ) - - init { - dateFormatter.timeZone = TimeZone.getTimeZone("UTC") - } - } - - override fun format(record: LogRecord): String { - return StringBuilder() - .appendLine("----------------------") - .append(dateFormatter.format(Date(record.millis))) - .append(" ") - .append(record.level.name) - .append(": ") - .appendLine(record.message) - .toString() - } - } +package com.nonnonstop.apimate + +import android.annotation.SuppressLint +import android.util.Log +import timber.log.Timber +import java.io.File +import java.text.SimpleDateFormat +import java.util.* +import java.util.logging.* +import java.util.logging.Formatter + +@SuppressLint("LogNotTimber") +class FileTree(baseDir: File) : Timber.Tree() { + companion object { + private const val LOG_LIMIT = 512 * 1024 + private const val LOG_COUNT = 2 + } + + private var logger: Logger + + init { + val path = File(baseDir, "exception%g.txt").absolutePath + val formatter = MyFormatter() + val handler = FileHandler(path, LOG_LIMIT, LOG_COUNT, true) + handler.formatter = formatter + logger = MyLogger("apimater").apply { + level = Level.ALL + addHandler(handler) + } + } + + override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { + val level = when (priority) { + Log.VERBOSE -> Level.FINER + Log.DEBUG -> Level.FINE + Log.INFO -> Level.INFO + Log.WARN -> Level.WARNING + Log.ERROR -> Level.SEVERE + Log.ASSERT -> Level.SEVERE + else -> Level.FINEST + } + logger.log(level, message, t) + } + + private class MyLogger(name: String) : Logger(name, null) + + private class MyFormatter() : Formatter() { + companion object { + private val dateFormatter = SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm'Z'", + Locale.ENGLISH + ) + + init { + dateFormatter.timeZone = TimeZone.getTimeZone("UTC") + } + } + + override fun format(record: LogRecord): String { + return StringBuilder() + .appendLine("----------------------") + .append(dateFormatter.format(Date(record.millis))) + .append(" ") + .append(record.level.name) + .append(": ") + .appendLine(record.message) + .toString() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/LoadActivity.kt b/app/src/main/java/com/nonnonstop/apimate/LoadActivity.kt index 41867da..56b5347 100644 --- a/app/src/main/java/com/nonnonstop/apimate/LoadActivity.kt +++ b/app/src/main/java/com/nonnonstop/apimate/LoadActivity.kt @@ -1,35 +1,35 @@ -package com.nonnonstop.apimate - -import android.content.Intent -import android.os.Bundle -import androidx.activity.viewModels -import androidx.appcompat.app.AppCompatActivity - -class LoadActivity : AppCompatActivity() { - private val viewModel: LoadViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.load_activity) - } - - override fun onPostCreate(savedInstanceState: Bundle?) { - super.onPostCreate(savedInstanceState) - dispatchIntent(intent) - } - - override fun onNewIntent(intent: Intent?) { - super.onNewIntent(intent) - dispatchIntent(intent) - } - - private fun dispatchIntent(intent: Intent?) { - val htmlUrl = intent?.data?.normalizeScheme()?.run { - if (scheme == "apimater") - encodedSchemeSpecificPart - else - toString() - } ?: return - viewModel.htmlUrl.value = htmlUrl - } +package com.nonnonstop.apimate + +import android.content.Intent +import android.os.Bundle +import androidx.activity.viewModels +import androidx.appcompat.app.AppCompatActivity + +class LoadActivity : AppCompatActivity() { + private val viewModel: LoadViewModel by viewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.load_activity) + } + + override fun onPostCreate(savedInstanceState: Bundle?) { + super.onPostCreate(savedInstanceState) + dispatchIntent(intent) + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + dispatchIntent(intent) + } + + private fun dispatchIntent(intent: Intent?) { + val htmlUrl = intent?.data?.normalizeScheme()?.run { + if (scheme == "apimater") + encodedSchemeSpecificPart + else + toString() + } ?: return + viewModel.htmlUrl.value = htmlUrl + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/LoadFragment.kt b/app/src/main/java/com/nonnonstop/apimate/LoadFragment.kt index fb37001..de70080 100644 --- a/app/src/main/java/com/nonnonstop/apimate/LoadFragment.kt +++ b/app/src/main/java/com/nonnonstop/apimate/LoadFragment.kt @@ -1,82 +1,82 @@ -package com.nonnonstop.apimate - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.databinding.DataBindingUtil -import androidx.fragment.app.Fragment -import androidx.fragment.app.activityViewModels -import androidx.lifecycle.lifecycleScope -import com.google.android.material.snackbar.Snackbar -import com.nonnonstop.apimate.databinding.LoadFragmentBinding -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import timber.log.Timber - -class LoadFragment : Fragment() { - private val viewModel: LoadViewModel by activityViewModels() - private var binding: LoadFragmentBinding? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - viewModel.htmlUrl.observe(this) { htmlUrl -> - if (htmlUrl.isNullOrEmpty()) - return@observe - viewLifecycleOwner.lifecycleScope.launch { - val context = requireActivity().applicationContext - viewModel.isRunning.value = true - try { - val scripts = Scripts(context) - try { - withContext(Dispatchers.IO) { - scripts.translate(context, htmlUrl) - } - } catch (ex: Exception) { - Timber.e(ex, "Failed to execute script (translate)") - Snackbar.make( - requireView(), - R.string.translate_failed, - Snackbar.LENGTH_LONG - ).show() - return@launch - } - try { - scripts.view(requireActivity(), htmlUrl) - } catch (ex: Exception) { - Timber.e(ex, "Failed to execute script (view)") - Snackbar.make( - requireView(), - R.string.view_failed, - Snackbar.LENGTH_LONG - ).show() - return@launch - } - } finally { - viewModel.isRunning.value = false - } - } - } - } - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - binding = DataBindingUtil.inflate( - inflater, - R.layout.load_fragment, - container, - false - ) - binding!!.viewModel = viewModel - binding!!.lifecycleOwner = viewLifecycleOwner - return binding!!.root - } - - override fun onDestroyView() { - super.onDestroyView() - binding = null - } +package com.nonnonstop.apimate + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import androidx.lifecycle.lifecycleScope +import com.google.android.material.snackbar.Snackbar +import com.nonnonstop.apimate.databinding.LoadFragmentBinding +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import timber.log.Timber + +class LoadFragment : Fragment() { + private val viewModel: LoadViewModel by activityViewModels() + private var binding: LoadFragmentBinding? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + viewModel.htmlUrl.observe(this) { htmlUrl -> + if (htmlUrl.isNullOrEmpty()) + return@observe + viewLifecycleOwner.lifecycleScope.launch { + val context = requireActivity().applicationContext + viewModel.isRunning.value = true + try { + val scripts = Scripts(context) + try { + withContext(Dispatchers.IO) { + scripts.translate(context, htmlUrl) + } + } catch (ex: Exception) { + Timber.e(ex, "Failed to execute script (translate)") + Snackbar.make( + requireView(), + R.string.translate_failed, + Snackbar.LENGTH_LONG + ).show() + return@launch + } + try { + scripts.view(requireActivity(), htmlUrl) + } catch (ex: Exception) { + Timber.e(ex, "Failed to execute script (view)") + Snackbar.make( + requireView(), + R.string.view_failed, + Snackbar.LENGTH_LONG + ).show() + return@launch + } + } finally { + viewModel.isRunning.value = false + } + } + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = DataBindingUtil.inflate( + inflater, + R.layout.load_fragment, + container, + false + ) + binding!!.viewModel = viewModel + binding!!.lifecycleOwner = viewLifecycleOwner + return binding!!.root + } + + override fun onDestroyView() { + super.onDestroyView() + binding = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/LoadViewModel.kt b/app/src/main/java/com/nonnonstop/apimate/LoadViewModel.kt index e2c01e4..5b72b54 100644 --- a/app/src/main/java/com/nonnonstop/apimate/LoadViewModel.kt +++ b/app/src/main/java/com/nonnonstop/apimate/LoadViewModel.kt @@ -1,13 +1,13 @@ -package com.nonnonstop.apimate - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel - -class LoadViewModel : ViewModel() { - val htmlUrl by lazy { - MutableLiveData() - } - val isRunning by lazy { - MutableLiveData() - } +package com.nonnonstop.apimate + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +class LoadViewModel : ViewModel() { + val htmlUrl by lazy { + MutableLiveData() + } + val isRunning by lazy { + MutableLiveData() + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/MainActivity.kt b/app/src/main/java/com/nonnonstop/apimate/MainActivity.kt index 2d60c3b..d844d6b 100644 --- a/app/src/main/java/com/nonnonstop/apimate/MainActivity.kt +++ b/app/src/main/java/com/nonnonstop/apimate/MainActivity.kt @@ -1,11 +1,11 @@ -package com.nonnonstop.apimate - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity - -class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.main_activity) - } +package com.nonnonstop.apimate + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.main_activity) + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/MyApplication.kt b/app/src/main/java/com/nonnonstop/apimate/MyApplication.kt index 661d377..d34928a 100644 --- a/app/src/main/java/com/nonnonstop/apimate/MyApplication.kt +++ b/app/src/main/java/com/nonnonstop/apimate/MyApplication.kt @@ -1,41 +1,41 @@ -package com.nonnonstop.apimate - -import android.app.Application -import androidx.preference.PreferenceManager -import timber.log.Timber -import timber.log.Timber.DebugTree - -class MyApplication : Application(), Thread.UncaughtExceptionHandler { - private val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler() - - override fun onCreate() { - super.onCreate() - val logDir = externalCacheDir - if (logDir == null) - Timber.plant(DebugTree()) - else - Timber.plant(FileTree(logDir), DebugTree()) - Thread.setDefaultUncaughtExceptionHandler(this) - upgradeData() - } - - override fun uncaughtException(t: Thread, e: Throwable) { - Timber.e(e, "Unexpected error") - defaultExceptionHandler?.uncaughtException(t, e) - } - - private fun upgradeData() { - val pref = PreferenceManager.getDefaultSharedPreferences(applicationContext) - val savedVersion = pref.getInt("version", 100) - val currentVersion = BuildConfig.VERSION_CODE - if (savedVersion == currentVersion) - return - with(pref.edit()) { - putInt("version", currentVersion) - apply() - } - if (pref.getBoolean("revert_script_when_upgrade", true)) { - Scripts(applicationContext).revertAllScripts() - } - } +package com.nonnonstop.apimate + +import android.app.Application +import androidx.preference.PreferenceManager +import timber.log.Timber +import timber.log.Timber.DebugTree + +class MyApplication : Application(), Thread.UncaughtExceptionHandler { + private val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler() + + override fun onCreate() { + super.onCreate() + val logDir = externalCacheDir + if (logDir == null) + Timber.plant(DebugTree()) + else + Timber.plant(FileTree(logDir), DebugTree()) + Thread.setDefaultUncaughtExceptionHandler(this) + upgradeData() + } + + override fun uncaughtException(t: Thread, e: Throwable) { + Timber.e(e, "Unexpected error") + defaultExceptionHandler?.uncaughtException(t, e) + } + + private fun upgradeData() { + val pref = PreferenceManager.getDefaultSharedPreferences(applicationContext) + val savedVersion = pref.getInt("version", 100) + val currentVersion = BuildConfig.VERSION_CODE + if (savedVersion == currentVersion) + return + with(pref.edit()) { + putInt("version", currentVersion) + apply() + } + if (pref.getBoolean("revert_script_when_upgrade", true)) { + Scripts(applicationContext).revertAllScripts() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/Scripts.kt b/app/src/main/java/com/nonnonstop/apimate/Scripts.kt index 9bc7156..54a3271 100644 --- a/app/src/main/java/com/nonnonstop/apimate/Scripts.kt +++ b/app/src/main/java/com/nonnonstop/apimate/Scripts.kt @@ -1,95 +1,95 @@ -package com.nonnonstop.apimate - -import android.app.Activity -import android.content.Context -import androidx.fragment.app.Fragment -import androidx.preference.Preference -import org.mozilla.javascript.ContextFactory -import org.mozilla.javascript.Function -import java.io.File -import java.nio.file.Files -import java.nio.file.StandardCopyOption - -class Scripts(private val context: Context) { - private companion object { - const val TRANSLATOR_FILE = "translator.js" - const val VIEWER_FILE = "viewer.js" - const val PREFERENCE_FILE = "preference.js" - - val ALL_FILES = arrayOf( - TRANSLATOR_FILE, - VIEWER_FILE, - PREFERENCE_FILE, - ) - } - - init { - val filesDir = context.filesDir - ALL_FILES.forEach { fileName -> - val file = File(filesDir, fileName) - if (!file.exists()) { - revertScript(fileName) - } - } - } - - private fun execute(fileName: String, functionName: String, vararg args: Any?): Any? { - val file = File(context.filesDir, fileName) - val contextFactory = ContextFactory() - val context = contextFactory.enterContext() - try { - context.optimizationLevel = -1 - val scope = context.initStandardObjects() - Files.newBufferedReader(file.toPath()).use { reader -> - context.evaluateReader(scope, reader, file.name, 1, null) - } - val callable = scope.get(functionName, scope) as Function - return callable.call(context, scope, scope, args) - } finally { - org.mozilla.javascript.Context.exit() - } - } - - fun revertScript(fileName: String) { - val file = File(context.filesDir, fileName) - context.assets.open(fileName).use { stream -> - Files.copy(stream, file.toPath(), StandardCopyOption.REPLACE_EXISTING) - } - } - - fun revertAllScripts() { - ALL_FILES.forEach { fileName -> - revertScript(fileName) - } - } - - fun readScript(fileName: String): String { - val file = File(context.filesDir, fileName) - Files.newBufferedReader(file.toPath()).use { reader -> - return reader.readText() - } - } - - fun writeScript(fileName: String, script: String) { - val file = File(context.filesDir, fileName) - Files.newBufferedWriter(file.toPath()).use { writer -> - writer.write(script) - } - } - - fun translate(context: Context, htmlUrl: String) { - execute(TRANSLATOR_FILE, "translate", context, htmlUrl) - } - - fun onCreateDatPreference(fragment: Fragment, preference: Preference): Any? { - return execute(PREFERENCE_FILE, "onCreateDatPreference", fragment, preference) - } - - fun onClickDatPreference(fragment: Fragment, state: Any?) { - execute(PREFERENCE_FILE, "onClickDatPreference", fragment, state) - } - - fun view(activity: Activity, htmlUrl: String) { - execute(VIEWER_FILE, "view", activity, htmlUrl) - } +package com.nonnonstop.apimate + +import android.app.Activity +import android.content.Context +import androidx.fragment.app.Fragment +import androidx.preference.Preference +import org.mozilla.javascript.ContextFactory +import org.mozilla.javascript.Function +import java.io.File +import java.nio.file.Files +import java.nio.file.StandardCopyOption + +class Scripts(private val context: Context) { + private companion object { + const val TRANSLATOR_FILE = "translator.js" + const val VIEWER_FILE = "viewer.js" + const val PREFERENCE_FILE = "preference.js" + + val ALL_FILES = arrayOf( + TRANSLATOR_FILE, + VIEWER_FILE, + PREFERENCE_FILE, + ) + } + + init { + val filesDir = context.filesDir + ALL_FILES.forEach { fileName -> + val file = File(filesDir, fileName) + if (!file.exists()) { + revertScript(fileName) + } + } + } + + private fun execute(fileName: String, functionName: String, vararg args: Any?): Any? { + val file = File(context.filesDir, fileName) + val contextFactory = ContextFactory() + val context = contextFactory.enterContext() + try { + context.optimizationLevel = -1 + val scope = context.initStandardObjects() + Files.newBufferedReader(file.toPath()).use { reader -> + context.evaluateReader(scope, reader, file.name, 1, null) + } + val callable = scope.get(functionName, scope) as Function + return callable.call(context, scope, scope, args) + } finally { + org.mozilla.javascript.Context.exit() + } + } + + fun revertScript(fileName: String) { + val file = File(context.filesDir, fileName) + context.assets.open(fileName).use { stream -> + Files.copy(stream, file.toPath(), StandardCopyOption.REPLACE_EXISTING) + } + } + + fun revertAllScripts() { + ALL_FILES.forEach { fileName -> + revertScript(fileName) + } + } + + fun readScript(fileName: String): String { + val file = File(context.filesDir, fileName) + Files.newBufferedReader(file.toPath()).use { reader -> + return reader.readText() + } + } + + fun writeScript(fileName: String, script: String) { + val file = File(context.filesDir, fileName) + Files.newBufferedWriter(file.toPath()).use { writer -> + writer.write(script) + } + } + + fun translate(context: Context, htmlUrl: String) { + execute(TRANSLATOR_FILE, "translate", context, htmlUrl) + } + + fun onCreateDatPreference(fragment: Fragment, preference: Preference): Any? { + return execute(PREFERENCE_FILE, "onCreateDatPreference", fragment, preference) + } + + fun onClickDatPreference(fragment: Fragment, state: Any?) { + execute(PREFERENCE_FILE, "onClickDatPreference", fragment, state) + } + + fun view(activity: Activity, htmlUrl: String) { + execute(VIEWER_FILE, "view", activity, htmlUrl) + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/SettingsFragment.kt b/app/src/main/java/com/nonnonstop/apimate/SettingsFragment.kt index a371c02..6f72ca5 100644 --- a/app/src/main/java/com/nonnonstop/apimate/SettingsFragment.kt +++ b/app/src/main/java/com/nonnonstop/apimate/SettingsFragment.kt @@ -1,45 +1,45 @@ -package com.nonnonstop.apimate - -import android.os.Bundle -import android.view.View -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat -import com.google.android.material.snackbar.Snackbar -import timber.log.Timber - -class SettingsFragment : PreferenceFragmentCompat() { - private lateinit var scripts: Scripts - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - setPreferencesFromResource(R.xml.root_preferences, rootKey) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - scripts = Scripts(requireContext()) - val preparePreference = findPreference("prepare")!! - try { - val configState = scripts.onCreateDatPreference(this, preparePreference) - preparePreference.setOnPreferenceClickListener { - try { - scripts.onClickDatPreference(this, configState) - } catch (ex: Exception) { - Timber.e(ex, "Failed to execute script (onClickDatPreference)") - Snackbar.make( - requireView(), - R.string.prepare_click_failed, - Snackbar.LENGTH_LONG - ).show() - } - true - } - } catch (ex: Exception) { - Timber.e(ex, "Failed to execute script (onCreateDatPreference)") - Snackbar.make( - requireView(), - R.string.prepare_create_failed, - Snackbar.LENGTH_LONG - ).show() - } - } +package com.nonnonstop.apimate + +import android.os.Bundle +import android.view.View +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import com.google.android.material.snackbar.Snackbar +import timber.log.Timber + +class SettingsFragment : PreferenceFragmentCompat() { + private lateinit var scripts: Scripts + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.root_preferences, rootKey) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + scripts = Scripts(requireContext()) + val preparePreference = findPreference("prepare")!! + try { + val configState = scripts.onCreateDatPreference(this, preparePreference) + preparePreference.setOnPreferenceClickListener { + try { + scripts.onClickDatPreference(this, configState) + } catch (ex: Exception) { + Timber.e(ex, "Failed to execute script (onClickDatPreference)") + Snackbar.make( + requireView(), + R.string.prepare_click_failed, + Snackbar.LENGTH_LONG + ).show() + } + true + } + } catch (ex: Exception) { + Timber.e(ex, "Failed to execute script (onCreateDatPreference)") + Snackbar.make( + requireView(), + R.string.prepare_create_failed, + Snackbar.LENGTH_LONG + ).show() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/nonnonstop/apimate/ViewBindingAdapters.kt b/app/src/main/java/com/nonnonstop/apimate/ViewBindingAdapters.kt index c27966e..91be35f 100644 --- a/app/src/main/java/com/nonnonstop/apimate/ViewBindingAdapters.kt +++ b/app/src/main/java/com/nonnonstop/apimate/ViewBindingAdapters.kt @@ -1,12 +1,12 @@ -package com.nonnonstop.apimate - -import android.view.View -import androidx.databinding.BindingAdapter - -object ViewBindingAdapters { - @BindingAdapter("android:visibility") - @JvmStatic - fun View.setBoolToVisibility(b: Boolean) { - this.visibility = if (b) View.VISIBLE else View.GONE - } +package com.nonnonstop.apimate + +import android.view.View +import androidx.databinding.BindingAdapter + +object ViewBindingAdapters { + @BindingAdapter("android:visibility") + @JvmStatic + fun View.setBoolToVisibility(b: Boolean) { + this.visibility = if (b) View.VISIBLE else View.GONE + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index a4f78de..07d5da9 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,170 +1,170 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml index cc14f03..2b068d1 100644 --- a/app/src/main/res/drawable/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -1,30 +1,30 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/edit_activity.xml b/app/src/main/res/layout/edit_activity.xml index 24d58b8..99fa14f 100644 --- a/app/src/main/res/layout/edit_activity.xml +++ b/app/src/main/res/layout/edit_activity.xml @@ -1,18 +1,18 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/edit_fragment.xml b/app/src/main/res/layout/edit_fragment.xml index 8724f9b..c0f067e 100644 --- a/app/src/main/res/layout/edit_fragment.xml +++ b/app/src/main/res/layout/edit_fragment.xml @@ -1,32 +1,32 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/load_activity.xml b/app/src/main/res/layout/load_activity.xml index 2a39aab..6714d7c 100644 --- a/app/src/main/res/layout/load_activity.xml +++ b/app/src/main/res/layout/load_activity.xml @@ -1,18 +1,18 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/load_fragment.xml b/app/src/main/res/layout/load_fragment.xml index f0a5910..0418e75 100644 --- a/app/src/main/res/layout/load_fragment.xml +++ b/app/src/main/res/layout/load_fragment.xml @@ -1,27 +1,27 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index f11ef6b..bcf9233 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -1,16 +1,16 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/edit_menu.xml b/app/src/main/res/menu/edit_menu.xml index 65979f1..4c6401e 100644 --- a/app/src/main/res/menu/edit_menu.xml +++ b/app/src/main/res/menu/edit_menu.xml @@ -1,14 +1,14 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index a26f6fb..eca70cf 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index a26f6fb..eca70cf 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 2dad905..c68b8fb 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,16 +1,16 @@ - - - + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 823492c..f8c6127 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,10 +1,10 @@ - - - #FFBB86FC - #FF6200EE - #FF3700B3 - #FF03DAC5 - #FF018786 - #FF000000 - #FFFFFFFF + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ede6135..0798dab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,22 +1,22 @@ - - - APIMateR - Basic Preferences - Advanced Preferences - Select dat directory - Update scripts when upgrading - Edit translator script - Edit viewer script - Edit preference script - Open source licenses - Save - Revert to default - Saved - Failed to save script - Reverted - Failed to revert script - Failed to execute script (translate) - Failed to execute script (view) - Failed to execute script (onCreateDatPreference) - Failed to execute script (onClickDatPreference) + + + APIMateR + Basic Preferences + Advanced Preferences + Select dat directory + Update scripts when upgrading + Edit translator script + Edit viewer script + Edit preference script + Open source licenses + Save + Revert to default + Saved + Failed to save script + Reverted + Failed to revert script + Failed to execute script (translate) + Failed to execute script (view) + Failed to execute script (onCreateDatPreference) + Failed to execute script (onClickDatPreference) \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 9590eb9..ae42dc9 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,16 +1,16 @@ - - - + + + \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 1ca783b..e7efe24 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -1,59 +1,59 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/test/java/com/nonnonstop/apimate/ExampleUnitTest.kt b/app/src/test/java/com/nonnonstop/apimate/ExampleUnitTest.kt index aa361bc..c8afefd 100644 --- a/app/src/test/java/com/nonnonstop/apimate/ExampleUnitTest.kt +++ b/app/src/test/java/com/nonnonstop/apimate/ExampleUnitTest.kt @@ -1,16 +1,16 @@ -package com.nonnonstop.apimate - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } +package com.nonnonstop.apimate + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 370da25..ca65994 100644 --- a/build.gradle +++ b/build.gradle @@ -1,27 +1,27 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - ext.kotlin_version = "1.5.0" - repositories { - google() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' - classpath "com.google.android.gms:oss-licenses-plugin:0.10.4" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - mavenCentral() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + ext.kotlin_version = "1.5.0" + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.2.1' + classpath "com.google.android.gms:oss-licenses-plugin:0.10.4" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index a9e374b..2521752 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,19 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app"s APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn -android.useAndroidX=true -# Kotlin code style for this project: "official" or "obsolete": +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5282aef..bffd281 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 10 12:13:23 JST 2021 -distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip -distributionPath=wrapper/dists -zipStorePath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME +#Mon May 10 12:13:23 JST 2021 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index e95643d..f955316 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,84 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index d734fbc..0c3c4aa 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = "APIMateR" -include ':app' +rootProject.name = "APIMateR" +include ':app'