commit d9d598b02159788278d01c5807a4568b3d177ac1 Author: Sebastian Seedorf Date: Sun Dec 6 20:17:19 2020 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ea113c --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.gradle +/local.properties +/.idea/* +/.idea - PC/* +.DS_Store +/build +/captures +.externalNativeBuild +app/release/* diff --git a/Mental Arithmetic.iml b/Mental Arithmetic.iml new file mode 100644 index 0000000..3ed3487 --- /dev/null +++ b/Mental Arithmetic.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..49eb95d --- /dev/null +++ b/app/app.iml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..a615760 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,43 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + defaultConfig { + applicationId "de.sebse.mentalarithmetic" + minSdkVersion 15 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation "androidx.cardview:cardview:1.0.0" + implementation "androidx.gridlayout:gridlayout:1.0.0" + implementation "androidx.preference:preference:1.1.0" + implementation "androidx.viewpager2:viewpager2:1.0.0" + implementation 'com.google.android.material:material:1.2.0-alpha03' + implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1' + implementation 'me.relex:circleindicator:2.1.4' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +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. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/de/sebse/mentalarithmetic/ExampleInstrumentedTest.kt b/app/src/androidTest/java/de/sebse/mentalarithmetic/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..7f4c5c8 --- /dev/null +++ b/app/src/androidTest/java/de/sebse/mentalarithmetic/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package de.sebse.mentalarithmetic + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * 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("de.sebse.mentalarithmetic", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a172027 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..b77d326 Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/de/sebse/mentalarithmetic/MainActivity.kt b/app/src/main/java/de/sebse/mentalarithmetic/MainActivity.kt new file mode 100644 index 0000000..34d6e2f --- /dev/null +++ b/app/src/main/java/de/sebse/mentalarithmetic/MainActivity.kt @@ -0,0 +1,100 @@ +package de.sebse.mentalarithmetic + +import android.os.Bundle +import android.util.Log +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentTransaction +import de.sebse.mentalarithmetic.fragments.* +import de.sebse.mentalarithmetic.types.ItemObject +import de.sebse.mentalarithmetic.types.TaskObject +import de.sebse.mentalarithmetic.types.TipObject + + +class MainActivity : AppCompatActivity(), TaskItemFragment.OnListFragmentInteractionListener, + TaskFragment.IGameListener, SummaryFragment.IGameSummaryListener { + + var currentFragment: Fragment? = null + val CURRENT_FRAGMENT_STATE: String = "CURRENT_FRAGMENT_STATE" + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + savedInstanceState?.let { + //Restore the fragment's instance + Log.d("APP", "here1") + val fragment = supportFragmentManager.getFragment(savedInstanceState, CURRENT_FRAGMENT_STATE) + fragment?.let { + Log.d("APP", "here") + val ft: FragmentTransaction = supportFragmentManager.beginTransaction() + ft.replace(R.id.fragment_holder, fragment) + ft.commit() + currentFragment = fragment + return + } + } + + val fragment = TaskPagerFragment.newInstance() + val ft: FragmentTransaction = supportFragmentManager.beginTransaction() + ft.replace(R.id.fragment_holder, fragment) + ft.commit() + currentFragment = fragment + } + + override fun onListFragmentInteraction(item: ItemObject) { + val fragment: Fragment? = if (item is TaskObject) { + item.start(applicationContext) + TaskFragment.newInstance(item) + } else if (item is TipObject) { + TipFragment.newInstance(item) + } else { + null + } + if (fragment != null) { + val ft: FragmentTransaction = supportFragmentManager.beginTransaction() + ft.replace(R.id.fragment_holder, fragment) + ft.commit() + currentFragment = fragment + } + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + currentFragment?.let { supportFragmentManager.putFragment(outState, CURRENT_FRAGMENT_STATE, it) } + } + + override fun onGameFinished(item: TaskObject) { + val fragment = SummaryFragment.newInstance(item) + val ft: FragmentTransaction = supportFragmentManager.beginTransaction() + ft.replace(R.id.fragment_holder, fragment) + ft.commit() + currentFragment = fragment + } + + override fun onGameSummaryRetry(item: TaskObject) { + onListFragmentInteraction(item) + } + + override fun onGameSummaryFinished() { + goToList() + } + + fun goToList() { + val fragment = TaskPagerFragment.newInstance() + val ft: FragmentTransaction = supportFragmentManager.beginTransaction() + ft.replace(R.id.fragment_holder, fragment) + ft.commit() + currentFragment = fragment + } + + override fun onBackPressed() { + if (currentFragment is TaskPagerFragment) { + if (!(currentFragment as TaskPagerFragment).previous()) { + super.onBackPressed() + } + } else { + goToList() + } + } +} diff --git a/app/src/main/java/de/sebse/mentalarithmetic/fragments/SummaryFragment.kt b/app/src/main/java/de/sebse/mentalarithmetic/fragments/SummaryFragment.kt new file mode 100644 index 0000000..c83693f --- /dev/null +++ b/app/src/main/java/de/sebse/mentalarithmetic/fragments/SummaryFragment.kt @@ -0,0 +1,96 @@ +package de.sebse.mentalarithmetic.fragments + + +/*import android.inputmethodservice.Keyboard +import android.inputmethodservice.KeyboardView +import android.inputmethodservice.KeyboardView.OnKeyboardActionListener*/ +import android.content.Context +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.TextView +import androidx.fragment.app.Fragment +import de.sebse.mentalarithmetic.R +import de.sebse.mentalarithmetic.types.ItemFactory +import de.sebse.mentalarithmetic.types.TaskObject + + +/** + * A simple [Fragment] subclass. + * Use the [SummaryFragment.newInstance] factory method to + * create an instance of this fragment. + */ +class SummaryFragment : Fragment() { + private lateinit var listener: IGameSummaryListener + private var item: TaskObject? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + Log.d("SummaryFragment", (savedInstanceState != null).toString()) + arguments?.let { + val param1 = it.getString(ARG_PARAM1) + item = ItemFactory.ITEM_MAP[param1] as TaskObject + } + savedInstanceState?.let { + val param1 = it.getString(ARG_PARAM1) + item = ItemFactory.ITEM_MAP[param1] as TaskObject + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_summary, container, false)?.also { view -> + view.findViewById