Skip to content

Commit

Permalink
Merge pull request #27 from msarac99/develop
Browse files Browse the repository at this point in the history
TL-013 change language for each activity [MI, SM]
  • Loading branch information
Irma1997 authored May 6, 2021
2 parents 8b7b382 + 2e6a8bb commit 48f162f
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 19 deletions.
28 changes: 28 additions & 0 deletions Tutorly/app/src/main/java/com/example/tutorly/FilterActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.tutorly

import android.app.AlertDialog
import android.content.Intent
import android.media.Image
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -20,6 +23,7 @@ class FilterActivity : AppCompatActivity() {
setContentView(R.layout.activity_filter)

val availableSubjects: ArrayList<Subject> = ArrayList()
val changeLang: Button = findViewById(R.id.btn_change_lang_filter)
/*
TODO:
* retrieve subjects from database!!!
Expand All @@ -41,6 +45,30 @@ class FilterActivity : AppCompatActivity() {
filterRecyclerView.itemAnimator = DefaultItemAnimator()
subjectAdapter = RecyclerViewAdapter(this, availableSubjects)
filterRecyclerView.adapter = subjectAdapter

changeLang.setOnClickListener{
val list = arrayOf("English", "Russian")
val builder = AlertDialog.Builder(this@FilterActivity)
builder.setTitle(R.string.choose_lang)

builder.setSingleChoiceItems(list, -1) { dialog, which ->
if (which == 0) {
Translation().changeLang("default", this)
recreate()
}
else if (which == 1) {
Translation().changeLang("kv", this)
recreate()
}
dialog.dismiss()
}
builder.show()
}
}

override fun onBackPressed() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}


Expand Down
15 changes: 7 additions & 8 deletions Tutorly/app/src/main/java/com/example/tutorly/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.tutorly

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
Expand Down Expand Up @@ -42,17 +43,18 @@ class LoginActivity : AppCompatActivity() {
val inputPassword: EditText = findViewById(R.id.input_password_login)

changeLang.setOnClickListener {

val list = arrayOf("English", "Russian")
val builder = AlertDialog.Builder(this@LoginActivity)
builder.setTitle(R.string.choose_lang)

builder.setSingleChoiceItems(list, -1) { dialog, which ->
if (which == 0) {
changeLang("default")
Translation().changeLang("default", this)
recreate()
}
else if (which == 1) {
changeLang("kv")
Translation().changeLang("kv", this)
recreate()
}
dialog.dismiss()
}
Expand Down Expand Up @@ -112,16 +114,13 @@ class LoginActivity : AppCompatActivity() {
}
}

private fun changeLang(localeName: String) {
fun changeLang(localeName: String, context: Context) {
locale = Locale(localeName)
val res = resources
val res = context.resources
val dm = res.displayMetrics
val conf = res.configuration
conf.locale = locale
res.updateConfiguration(conf, dm)
val intent = Intent(
this, LoginActivity::class.java)
startActivity(intent)
}

}
33 changes: 32 additions & 1 deletion Tutorly/app/src/main/java/com/example/tutorly/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
package com.example.tutorly

import android.app.AlertDialog
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import kotlin.system.exitProcess

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val button: Button = findViewById(R.id.btnTownSelection)
val changeLang: Button = findViewById(R.id.btn_change_lang_main_activity)

button.setOnClickListener {
val intent = Intent(this, TownSelection::class.java)
startActivity(intent);

}

changeLang.setOnClickListener {
val list = arrayOf("English", "Russian")
val builder = AlertDialog.Builder(this@MainActivity)
builder.setTitle(R.string.choose_lang)

builder.setSingleChoiceItems(list, -1) { dialog, which ->
if (which == 0) {
Translation().changeLang("default", this)
recreate()
}
else if (which == 1) {
Translation().changeLang("kv", this)
recreate()
}
dialog.dismiss()
}
builder.show()
}
}



fun switchToFilter(view: View) {
val switchIntent = Intent(this, FilterActivity::class.java).apply() {
}
startActivity(switchIntent)
}

override fun onBackPressed() {

}



}
32 changes: 31 additions & 1 deletion Tutorly/app/src/main/java/com/example/tutorly/TownSelection.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.tutorly

import android.Manifest
import android.app.AlertDialog
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.Button
Expand All @@ -19,6 +21,7 @@ import com.google.android.libraries.places.widget.listener.PlaceSelectionListene
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode
import java.util.*
import javax.net.ssl.SSLEngineResult
import kotlin.system.exitProcess


class TownSelection : AppCompatActivity() {
Expand All @@ -35,8 +38,30 @@ class TownSelection : AppCompatActivity() {
setContentView(R.layout.activity_town_selection)
setSupportActionBar(findViewById(R.id.titleToolbar))

var changeLang: Button = findViewById(R.id.btn_change_lang_town_selection)

placesAutocomplete()


changeLang.setOnClickListener{
val list = arrayOf("English", "Russian")
val builder = AlertDialog.Builder(this@TownSelection)
builder.setTitle(R.string.choose_lang)

builder.setSingleChoiceItems(list, -1) { dialog, which ->
if (which == 0) {
Translation().changeLang("default", this)
recreate()
}
else if (which == 1) {
Translation().changeLang("kv", this)
recreate()
}
dialog.dismiss()
}
builder.show()
}

}


Expand All @@ -48,7 +73,7 @@ class TownSelection : AppCompatActivity() {

autocompleteFragment.setPlaceFields(placeFields)

autocompleteFragment.setHint("City..")
autocompleteFragment.setHint(resources.getString(R.string.city_hint))

autocompleteFragment.setOnPlaceSelectedListener(object : PlaceSelectionListener {
override fun onPlaceSelected(p0: Place) {
Expand All @@ -65,5 +90,10 @@ class TownSelection : AppCompatActivity() {
})
}

override fun onBackPressed() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}

}

23 changes: 23 additions & 0 deletions Tutorly/app/src/main/java/com/example/tutorly/Translation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.tutorly

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.startActivity
import java.util.*

class Translation : AppCompatActivity(){

lateinit var locale: Locale

fun changeLang(localeName: String, context: Context) {
locale = Locale(localeName)
val res = context.resources
val dm = res.displayMetrics
val conf = res.configuration
conf.locale = locale
res.updateConfiguration(conf, dm)
}
}
24 changes: 17 additions & 7 deletions Tutorly/app/src/main/res/layout/activity_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,35 @@
android:orientation="horizontal">

<RadioButton
android:layout_width="130dp"
android:layout_width="102dp"
android:layout_height="wrap_content"
android:text="@string/filterRadioBtnLvl1"
android:buttonTint="@color/radioButtonTint"
/>
android:text="@string/filterRadioBtnLvl1" />

<RadioButton
android:layout_width="130dp"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:text="@string/filterRadioBtnLvl2"
android:buttonTint="@color/radioButtonTint"
/>
android:text="@string/filterRadioBtnLvl2" />
<RadioButton
android:layout_width="130dp"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="@string/filterRadioBtnLvl3"
android:checked="true"
android:buttonTint="@color/radioButtonTint"
/>

<Button
android:id="@+id/btn_change_lang_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="2dp"
android:text="@string/lang_short"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</RadioGroup>
<View
android:id="@+id/filterLineSplit"
Expand Down
15 changes: 13 additions & 2 deletions Tutorly/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
android:text="@string/subject" />

<Button
android:id="@+id/btnTownSelection"
android:id="@+id/btn_change_lang_main_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/town_selection" />
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="8dp"
android:text="@string/lang_short"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</LinearLayout>
Expand All @@ -49,6 +54,12 @@
android:layout_weight="1"
android:onClick="switchToFilter"
android:text="@string/filter" />

<Button
android:id="@+id/btnTownSelection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/town_selection" />
</LinearLayout>

</LinearLayout>
Expand Down
11 changes: 11 additions & 0 deletions Tutorly/app/src/main/res/layout/activity_town_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
app:layout_constraintVertical_bias="0.445" />

<Button
android:id="@+id/btn_change_lang_town_selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/lang_short"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions Tutorly/app/src/main/res/values-kv-rRU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
<string name="learn_maths">Учить 2 + 2</string>
<string name="example_subject">Пример темы</string>
<string name="learn_example_subject">выучить тему примера</string>
<string name="city_hint">Город</string>
<string name="lang_short">RU</string>
</resources>
2 changes: 2 additions & 0 deletions Tutorly/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@
<string name="learn_maths">Learn 2+2</string>
<string name="example_subject">ExampleSubject</string>
<string name="learn_example_subject">learn ExampleSubject</string>
<string name="city_hint">City</string>
<string name="lang_short">EN</string>

</resources>

0 comments on commit 48f162f

Please sign in to comment.