Add generate function
This commit is contained in:
parent
7a09d0b925
commit
00aea1b7cf
|
@ -19,15 +19,36 @@
|
|||
package ht.sr.huyngo.genword
|
||||
|
||||
import android.os.Bundle
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import android.util.Log
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
val categories : Map<String, List<String>>
|
||||
get() {
|
||||
val input = findViewById<TextInputEditText>(R.id.categories_input).text
|
||||
val cates = input!!.split("\n").associate {
|
||||
val (left, right) = it.split("=")
|
||||
left to right.split("/")
|
||||
}
|
||||
// TODO: Handle if the input is incorrect format
|
||||
return cates
|
||||
}
|
||||
val pattern : String
|
||||
get() = findViewById<TextInputEditText>(R.id.pattern_input).text.toString()
|
||||
val times : Int
|
||||
get() = findViewById<TextInputEditText>(R.id.n_words_input).text.toString().toInt()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -57,8 +78,15 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
fun generate(view: View) {
|
||||
//
|
||||
/* Generate a new word based on the parameters.*/
|
||||
public fun generate(view: View) {
|
||||
var s : String = ""
|
||||
for (c in pattern) {
|
||||
Log.e("DEBUG", categories.toString())
|
||||
Log.e("DEBUG", c.toString())
|
||||
Log.e("DEBUG", categories[c.toString()].toString())
|
||||
s += categories[c.toString()].random()
|
||||
}
|
||||
findViewById<TextView>(R.id.output).text = s
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
android:layout_width="match_parent"
|
||||
>
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/categories_input"
|
||||
android:text="@string/categories_value"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -35,12 +36,28 @@
|
|||
android:layout_width="match_parent"
|
||||
>
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/pattern_input"
|
||||
android:text="@string/pattern_value"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/n_words"
|
||||
android:hint="@string/n_words"
|
||||
android:inputType="number"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:layout_width="match_parent"
|
||||
>
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/n_words_input"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/generate"
|
||||
android:text="@string/generate"
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
<string name="app_name">GenWord</string>
|
||||
<string name="categories">Categories</string>
|
||||
<string name="categories_value">
|
||||
"C=m/p/b/t/d/k/g/n/ñ/ñ/ng/r/s/sh/z/zh/ts/dz/x/'/h/l\n"
|
||||
"F=m/p/t/k/n/ñ/ng/s/sh/ts/x\n"
|
||||
"V=a/e/é/i/y/o/ô/ø/u\n"
|
||||
"T=0/1/2"
|
||||
"C=m/p/b/t/d/k/g/n/ñ/ñ/ng/r/s/sh/z/zh/ts/dz/x/'/h/l\nF=m/p/t/k/n/ñ/ng/s/sh/ts/x\nV=a/e/é/i/y/o/ô/ø/u\nT=0/1/2"
|
||||
</string>
|
||||
<string name="n_words">Number of words</string>
|
||||
<string name="pattern">Pattern</string>
|
||||
<string name="pattern_value">CVV?TF?</string>
|
||||
<string name="pattern_value">CVVTF</string>
|
||||
<string name="generate">Generate</string>
|
||||
<string name="large_text">
|
||||
"Material is the metaphor.\n\n"
|
||||
|
|
Loading…
Reference in New Issue