Skip to content

Commit

Permalink
back button done, not tested yet
Browse files Browse the repository at this point in the history
  • Loading branch information
RedSnail committed Jun 17, 2019
1 parent f323ef9 commit 476d523
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/src/main/java/msu/ug/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package msu.ug

class Const {
companion object {
const val CUR_CHOICE_KEY = "current_choise"
const val STEPS_NUM_KEY = "steps_num"
const val PATH_LEN_KEY = "path_len"

const val DEFAULT_TAXON = "Nihil"
Expand All @@ -17,5 +17,9 @@ class Const {
fun folderKey(folderIndex : Int) : String {
return "folder_$folderIndex"
}

fun stepKey(stepIndex : Int) : String {
return "step_$stepIndex"
}
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/msu/ug/IntroActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class IntroActivity : AppCompatActivity() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

setContentView(R.layout.activity_intro)
val context:Context = this

val classButton = findViewById<Button>(R.id.button_classifier)
classButton.setOnClickListener {
val intent = Intent(context, MainActivity::class.java)
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
val aboutButton = findViewById<Button>(R.id.button_about)
aboutButton.setOnClickListener {
val intent = Intent(context, AboutActivity::class.java)
val intent = Intent(this, AboutActivity::class.java)
startActivity(intent)
}

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/msu/ug/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package msu.ug
import android.content.pm.ActivityInfo
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

import android.view.View
import android.widget.Toast


class MainActivity : AppCompatActivity() {
val storage = Storage(this)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -17,4 +19,10 @@ class MainActivity : AppCompatActivity() {
transaction.replace(R.id.fragment_frame, ChoiceFragment(this))
transaction.commit()
}

fun onBackClick(view : View) {
if (!storage.goBack()) {
Toast.makeText(this, "Вы в начале", Toast.LENGTH_SHORT).show()
}
}
}
35 changes: 33 additions & 2 deletions app/src/main/java/msu/ug/Storage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,34 @@ class Storage (context : Context) {
switchListeners.add(listener)
}

private var stepsNum : Int
set(value) {
sp.edit().putInt(Const.STEPS_NUM_KEY, value).apply()
}
get() {
return sp.getInt(Const.STEPS_NUM_KEY, 0)
}

private var pathLen : Int
set(value) {
sp.edit().putInt(Const.PATH_LEN_KEY, value).apply()
}
get() {
return sp.getInt(Const.PATH_LEN_KEY, 0)
}

var currentChoise : Int
set(value) {
if (value > 0) {
sp.edit().putInt(Const.CUR_CHOICE_KEY, value).apply()
stepsNum += 1
sp.edit().putInt(Const.stepKey(stepsNum), value).apply()
switchListeners.forEach {
it.invoke()
}
}
}
get() {
return sp.getInt(Const.CUR_CHOICE_KEY, 1)
return sp.getInt(Const.stepKey(stepsNum), 1)
}

fun getPath() : List<String> {
Expand All @@ -43,4 +60,18 @@ class Storage (context : Context) {
sp.edit().putString(Const.folderKey(len), folder).apply()
sp.edit().putInt(Const.PATH_LEN_KEY, len + 1).apply()
}

fun goBack() : Boolean {
return if (stepsNum > 1) {
if (currentChoise == 1) {
pathLen -= 1
}

stepsNum -= 1

true
} else {
false
}
}
}
25 changes: 16 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_frame" android:background="#4CAF50">
android:layout_height="0dp"
android:id="@+id/fragment_frame"
android:background="#4CAF50"
android:layout_weight="0.9">

</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/back"
android:layout_gravity="center"
android:onClick="onBackClick"/>
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="name">The Big\nMayevsky</string>
<string name="classifier_button">Определитель</string>
<string name="about_button">О программе</string>
<string name="back">Назад</string>
<string name="copyrights">There will be copyright</string>

</resources>

0 comments on commit 476d523

Please sign in to comment.