From 9e538771fb340bf31765f4c3382f89b4cd1311a3 Mon Sep 17 00:00:00 2001 From: s452641 Date: Thu, 18 Nov 2021 14:11:04 +0100 Subject: [PATCH] first --- .gitignore | 15 ++ .idea/.gitignore | 3 + .idea/.name | 1 + .idea/codeStyles/Project.xml | 123 +++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/compiler.xml | 6 + .idea/gradle.xml | 21 +++ .idea/jarRepositories.xml | 25 +++ .idea/misc.xml | 25 +++ .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 77 ++++++++ app/proguard-rules.pro | 21 +++ .../tasklist/ExampleInstrumentedTest.kt | 24 +++ app/src/main/AndroidManifest.xml | 22 +++ .../java/com/example/tasklist/Adding_tasks.kt | 61 +++++++ .../java/com/example/tasklist/ChangePass.kt | 48 +++++ .../java/com/example/tasklist/LoginPage.kt | 55 ++++++ .../java/com/example/tasklist/MainActivity.kt | 25 +++ .../com/example/tasklist/MainApplication.kt | 23 +++ .../com/example/tasklist/data/DataSource.kt | 42 +++++ .../com/example/tasklist/data/Database.kt | 14 ++ .../com/example/tasklist/data/Repository.kt | 18 ++ .../java/com/example/tasklist/data/Result.kt | 18 ++ .../java/com/example/tasklist/data/Task.kt | 6 + .../com/example/tasklist/data/dao/TaskDao.kt | 74 ++++++++ .../tasklist/ui/adapters/TaskAdapter.kt | 63 +++++++ .../ui/choose/list/TaskListFragment.kt | 76 ++++++++ .../ui/choose/list/TaskListViewModel.kt | 11 ++ .../example/tasklist/ui/main/MainFragment.kt | 30 +++ .../example/tasklist/ui/main/MainViewModel.kt | 7 + .../drawable-v24/ic_launcher_foreground.xml | 30 +++ app/src/main/res/drawable/bordershape.xml | 11 ++ app/src/main/res/drawable/buttonshape.xml | 9 + .../res/drawable/ic_email_light_blue_24dp.xml | 9 + .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 +++ .../res/drawable/ic_lock_light_blue_24dp.xml | 9 + .../res/drawable/ic_touch_app_white_24dp.xml | 9 + .../main/res/layout/fragment_adding_tasks.xml | 51 ++++++ .../main/res/layout/fragment_change_pass.xml | 116 ++++++++++++ .../main/res/layout/fragment_login_page.xml | 95 ++++++++++ .../main/res/layout/fragment_task_list.xml | 80 ++++++++ app/src/main/res/layout/item_task.xml | 30 +++ app/src/main/res/layout/main_activity.xml | 44 +++++ app/src/main/res/layout/main_fragment.xml | 20 ++ .../main/res/menu/bottom_navigation_menu.xml | 8 + .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes .../main/res/navigation/mobile_navigation.xml | 53 ++++++ app/src/main/res/values-night/themes.xml | 17 ++ app/src/main/res/values/colors.xml | 11 ++ app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 25 +++ app/src/main/res/values/themes.xml | 16 ++ ...agment_task_list_xml_framelayout_scene.xml | 19 ++ .../com/example/tasklist/ExampleUnitTest.kt | 17 ++ build.gradle | 26 +++ gradle.properties | 21 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 2 + 74 files changed, 2151 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/tasklist/ExampleInstrumentedTest.kt create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/tasklist/Adding_tasks.kt create mode 100644 app/src/main/java/com/example/tasklist/ChangePass.kt create mode 100644 app/src/main/java/com/example/tasklist/LoginPage.kt create mode 100644 app/src/main/java/com/example/tasklist/MainActivity.kt create mode 100644 app/src/main/java/com/example/tasklist/MainApplication.kt create mode 100644 app/src/main/java/com/example/tasklist/data/DataSource.kt create mode 100644 app/src/main/java/com/example/tasklist/data/Database.kt create mode 100644 app/src/main/java/com/example/tasklist/data/Repository.kt create mode 100644 app/src/main/java/com/example/tasklist/data/Result.kt create mode 100644 app/src/main/java/com/example/tasklist/data/Task.kt create mode 100644 app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt create mode 100644 app/src/main/java/com/example/tasklist/ui/adapters/TaskAdapter.kt create mode 100644 app/src/main/java/com/example/tasklist/ui/choose/list/TaskListFragment.kt create mode 100644 app/src/main/java/com/example/tasklist/ui/choose/list/TaskListViewModel.kt create mode 100644 app/src/main/java/com/example/tasklist/ui/main/MainFragment.kt create mode 100644 app/src/main/java/com/example/tasklist/ui/main/MainViewModel.kt create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/bordershape.xml create mode 100644 app/src/main/res/drawable/buttonshape.xml create mode 100644 app/src/main/res/drawable/ic_email_light_blue_24dp.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_lock_light_blue_24dp.xml create mode 100644 app/src/main/res/drawable/ic_touch_app_white_24dp.xml create mode 100644 app/src/main/res/layout/fragment_adding_tasks.xml create mode 100644 app/src/main/res/layout/fragment_change_pass.xml create mode 100644 app/src/main/res/layout/fragment_login_page.xml create mode 100644 app/src/main/res/layout/fragment_task_list.xml create mode 100644 app/src/main/res/layout/item_task.xml create mode 100644 app/src/main/res/layout/main_activity.xml create mode 100644 app/src/main/res/layout/main_fragment.xml create mode 100644 app/src/main/res/menu/bottom_navigation_menu.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/navigation/mobile_navigation.xml create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/xml/fragment_task_list_xml_framelayout_scene.xml create mode 100644 app/src/test/java/com/example/tasklist/ExampleUnitTest.kt create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +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 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a0b56fb --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +TaskList \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..7643783 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,123 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2c7e034 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1d827e5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..e304954 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,77 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'kotlin-kapt' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.lsm.learnwords" + minSdkVersion 21 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + + buildFeatures { + dataBinding true + viewBinding true + } + kapt { + generateStubs = true + } +} + +dependencies { + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.annotation:annotation:1.2.0' + def nav_version = "2.3.3" + def lifecycle_version = "2.2.0" + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.core:core-ktx:1.3.2' + implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" + implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" + implementation "androidx.navigation:navigation-ui-ktx:$nav_version" + + implementation 'com.google.android.material:material:1.3.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + + testImplementation 'junit:junit:4.13.1' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" + + // na potrzeby serializacji do SharedPreferences + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.google.code.gson:gson:2.8.5' + + implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/tasklist/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/tasklist/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..15e559a --- /dev/null +++ b/app/src/androidTest/java/com/example/tasklist/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.tasklist + +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("com.example.tasklist", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8ad39f9 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/Adding_tasks.kt b/app/src/main/java/com/example/tasklist/Adding_tasks.kt new file mode 100644 index 0000000..749e113 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/Adding_tasks.kt @@ -0,0 +1,61 @@ +package com.example.tasklist + +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.navigation.fragment.findNavController +import com.example.tasklist.data.Database +import com.example.tasklist.data.Task +import com.example.tasklist.databinding.FragmentAddingTasksBinding +import java.text.SimpleDateFormat +import java.util.* + +// TODO: Rename parameter arguments, choose names that match +// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER +private const val ARG_PARAM1 = "param1" +private const val ARG_PARAM2 = "param2" + +/** + * A simple [Fragment] subclass. + * Use the [Adding_tasks.newInstance] factory method to + * create an instance of this fragment. + */ +class Adding_tasks : Fragment() { + + private lateinit var binding: FragmentAddingTasksBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + + binding = DataBindingUtil.inflate( + inflater, R.layout.fragment_adding_tasks, container, false + ) + + binding.fragment = this@Adding_tasks + return binding.root + } + + fun goToTasks() { + var pattern = "dd-MM-yyyy hh:mm" + var simpleDateFormat = SimpleDateFormat(pattern, Locale("pl", "PL")) + + val textTask = binding.editTextName.text.toString() + val dateTask = simpleDateFormat.format(Date()) + if (textTask != "" && dateTask != "") { + val ttask = Task(textTask, dateTask) + Database.taskDao.addTask(ttask) + } + findNavController().navigate(R.id.action_adding_tasks_to_taskListFragment) + } + + +} diff --git a/app/src/main/java/com/example/tasklist/ChangePass.kt b/app/src/main/java/com/example/tasklist/ChangePass.kt new file mode 100644 index 0000000..18ce55c --- /dev/null +++ b/app/src/main/java/com/example/tasklist/ChangePass.kt @@ -0,0 +1,48 @@ +package com.example.tasklist + +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.navigation.fragment.findNavController +import com.example.tasklist.databinding.FragmentChangePassBinding + +// TODO: Rename parameter arguments, choose names that match +// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER +private const val ARG_PARAM1 = "param1" +private const val ARG_PARAM2 = "param2" + +/** + * A simple [Fragment] subclass. + * Use the [ChangePass.newInstance] factory method to + * create an instance of this fragment. + */ +class ChangePass : Fragment(){ + private lateinit var binding: FragmentChangePassBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + + binding = DataBindingUtil.inflate( + inflater, R.layout.fragment_change_pass, container, false + ) + + + binding.change = this@ChangePass + return binding.root + } + + fun goToList() { + findNavController().navigate(R.id.action_changePass_to_taskListFragment) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/LoginPage.kt b/app/src/main/java/com/example/tasklist/LoginPage.kt new file mode 100644 index 0000000..8ba2b30 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/LoginPage.kt @@ -0,0 +1,55 @@ +package com.example.tasklist + +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.navigation.fragment.findNavController +import com.example.tasklist.databinding.FragmentLoginPageBinding +import android.content.SharedPreferences +import java.util.* + +// TODO: Rename parameter arguments, choose names that match +// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER +private const val ARG_PARAM1 = "param1" +private const val ARG_PARAM2 = "param2" + +/** + * A simple [Fragment] subclass. + * Use the [activity_login_page.newInstance] factory method to + * create an instance of this fragment. + */ +class LoginPage : Fragment(){ + private lateinit var binding: FragmentLoginPageBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + + binding = DataBindingUtil.inflate( + inflater, R.layout.fragment_login_page, container, false + ) + + + binding.login = this@LoginPage + return binding.root + } + + fun goToList() { + if(binding.password.text.toString().equals("pass",true)){ + findNavController().navigate(R.id.action_loginPage_to_taskListFragment) + } + else{ + findNavController().navigate(R.id.action_loginPage_self) + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/MainActivity.kt b/app/src/main/java/com/example/tasklist/MainActivity.kt new file mode 100644 index 0000000..48fd20f --- /dev/null +++ b/app/src/main/java/com/example/tasklist/MainActivity.kt @@ -0,0 +1,25 @@ +package com.example.tasklist + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.navigation.NavController +import androidx.navigation.findNavController +import androidx.navigation.ui.setupWithNavController +import com.google.android.material.bottomnavigation.BottomNavigationView + +class MainActivity : AppCompatActivity() { + + private lateinit var navController : NavController + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.main_activity) + + val navView: BottomNavigationView = findViewById(R.id.bottom_navigation) + navController = findNavController(R.id.nav_host_fragment) + navView.setupWithNavController(navController) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/MainApplication.kt b/app/src/main/java/com/example/tasklist/MainApplication.kt new file mode 100644 index 0000000..9951032 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/MainApplication.kt @@ -0,0 +1,23 @@ +package com.example.tasklist + +import android.app.Application +import android.content.Context + +class MainApplication : Application() { + init { + instance = this + } + + companion object { + private var instance: MainApplication? = null + + fun applicationContext(): Context { + return instance!!.applicationContext + } + } + + override fun onCreate() { + super.onCreate() + val context: Context = MainApplication.applicationContext() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/data/DataSource.kt b/app/src/main/java/com/example/tasklist/data/DataSource.kt new file mode 100644 index 0000000..bf54d73 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/data/DataSource.kt @@ -0,0 +1,42 @@ +package com.example.tasklist.data + +import android.os.Build +import androidx.annotation.RequiresApi +import java.text.SimpleDateFormat +import java.util.* +import kotlin.collections.ArrayList + +object DataSource { + + private var listOfTasks: Array = arrayOf("Zrobic zakupy", + "Zrobic zadanie domowe", "Pojsc na spacer", + "Posprzataс w domu", "Pomoc bratu", "Pospacerowac z psem", "Odebrac brata ze szkoly", + "Kupic laptop", "Zadzwonic do przyjaciol", "Zaspiewac piosenke") + private var _tasks: ArrayList? = null + val tasks: ArrayList + @RequiresApi(Build.VERSION_CODES.O) + get() { + if(_tasks == null) { + MockTasks() + } + return _tasks!! + } + + var zadanie = ArrayList() + + @RequiresApi(Build.VERSION_CODES.O) + private fun MockTasks() { + var pattern = "dd-MM-yyyy hh:mm" + var simpleDateFormat = SimpleDateFormat(pattern, Locale("pl", "PL")) + _tasks = ArrayList() + repeat((6..10).random()) { + indexTask -> + val newTask = Task( + listOfTasks[indexTask], + simpleDateFormat.format(Date()) + ) + _tasks?.add(newTask) + zadanie.add(newTask) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/data/Database.kt b/app/src/main/java/com/example/tasklist/data/Database.kt new file mode 100644 index 0000000..b75b2da --- /dev/null +++ b/app/src/main/java/com/example/tasklist/data/Database.kt @@ -0,0 +1,14 @@ +package com.example.tasklist.data + +import com.example.tasklist.data.dao.TaskDao + +object Database { + + var _taskDao : TaskDao? = null + val taskDao : TaskDao + get() { + if(_taskDao == null) + _taskDao = TaskDao() + return _taskDao!! + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/data/Repository.kt b/app/src/main/java/com/example/tasklist/data/Repository.kt new file mode 100644 index 0000000..fbe9df6 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/data/Repository.kt @@ -0,0 +1,18 @@ +package com.example.tasklist.data + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData + +object Repository { + + var tasks : MutableLiveData> = MutableLiveData() + + init { + tasks.value = Database.taskDao.getAllTasks() + + } + + fun getAllTasks() : LiveData> { + return tasks + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/data/Result.kt b/app/src/main/java/com/example/tasklist/data/Result.kt new file mode 100644 index 0000000..3aef9f4 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/data/Result.kt @@ -0,0 +1,18 @@ +package com.example.tasklist.data + +/** + * A generic class that holds a value with its loading status. + * @param + */ +sealed class Result { + + data class Success(val data: T) : Result() + data class Error(val exception: Exception) : Result() + + override fun toString(): String { + return when (this) { + is Success<*> -> "Success[data=$data]" + is Error -> "Error[exception=$exception]" + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/data/Task.kt b/app/src/main/java/com/example/tasklist/data/Task.kt new file mode 100644 index 0000000..82f4b30 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/data/Task.kt @@ -0,0 +1,6 @@ +package com.example.tasklist.data + +data class Task ( + var name: String, + var date: String +) \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt b/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt new file mode 100644 index 0000000..f8ca197 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/data/dao/TaskDao.kt @@ -0,0 +1,74 @@ +package com.example.tasklist.data.dao + +import android.content.Context +import android.content.SharedPreferences +import com.example.tasklist.MainApplication +import com.example.tasklist.data.DataSource +import com.example.tasklist.data.Task +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken + +class TaskDao { + fun getAllTasks() : ArrayList { + return DataSource.zadanie + } + + companion object { + public const val SHARED_PREFERENCES_TAG = "TaskDao" + } + init { + readFromSharedPreferences() + } + + fun saveInSharedPreferences() { + val context = MainApplication.applicationContext() + var dataToSave = getAllTasks() + + saveListInSharedPreferences(context, SHARED_PREFERENCES_TAG, dataToSave) + } + + /** save givent list of learningProcessData into given tag of the shared preferences*/ + private fun saveListInSharedPreferences( + context: Context, + sharedPreferencesTag: String, + dataToSave: ArrayList + ) { + var sharedPreferences = context.getSharedPreferences(sharedPreferencesTag, Context.MODE_PRIVATE) + val gson = Gson() + val json = gson.toJson(dataToSave) + val editor: SharedPreferences.Editor = sharedPreferences.edit() + editor.putString(sharedPreferencesTag, json) + editor.commit() + } + + fun readFromSharedPreferences() { + val context = MainApplication.applicationContext() + val readedData: List = loadListFromSharedPreferneces( + context, SHARED_PREFERENCES_TAG + ) + DataSource.zadanie.clear() + DataSource.zadanie.addAll(readedData) + } + + private fun loadListFromSharedPreferneces( + context: Context, + sharedPreferencesTag: String + ): List { + val gson = Gson() + var sharedPreferences = context.getSharedPreferences(sharedPreferencesTag, Context.MODE_PRIVATE) + + val json = sharedPreferences.getString(SHARED_PREFERENCES_TAG, "") + if (json == null || json.length < 10) + return arrayListOf() + val itemType = object : TypeToken>() {}.type + val dataListFromSharedPreferneces: List = + gson.fromJson>(json, itemType) + return dataListFromSharedPreferneces + } + + + fun addTask(task: Task) { + DataSource.zadanie.add(task) + saveInSharedPreferences() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/ui/adapters/TaskAdapter.kt b/app/src/main/java/com/example/tasklist/ui/adapters/TaskAdapter.kt new file mode 100644 index 0000000..e2b3a60 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/ui/adapters/TaskAdapter.kt @@ -0,0 +1,63 @@ +package com.example.tasklist.ui.adapters + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import com.example.tasklist.R +import com.example.tasklist.data.Task +import com.example.tasklist.databinding.ItemTaskBinding + +class TaskAdapter internal constructor( + private val nListener : TaskItemClickListener +): ListAdapter(TaskDiffCallback()) { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskViewHolder { + return TaskViewHolder.from(parent) + } + + override fun onBindViewHolder(holder: TaskViewHolder, position: Int) { + val task = getItem(position) + holder.bind(task, nListener) + } + + + class TaskViewHolder(val binding: ItemTaskBinding) : RecyclerView.ViewHolder(binding.root) { + + + fun bind(currentTask: Task, listener: TaskItemClickListener) { + binding.task = currentTask + binding.clickListener = listener + binding.executePendingBindings() + } + + companion object { + fun from(parent: ViewGroup) : TaskViewHolder { + val layoutInflater = LayoutInflater.from(parent.context) + val binding: ItemTaskBinding = DataBindingUtil.inflate( + layoutInflater, R.layout.item_task, + parent, false + ) + return TaskViewHolder(binding) + } + } + + } +} + +interface TaskItemClickListener { + fun chooseTask(task: Task) +} + +private class TaskDiffCallback : DiffUtil.ItemCallback () { + override fun areItemsTheSame(oldItem: Task, newItem: Task): Boolean { + return oldItem.name == newItem.name + } + + override fun areContentsTheSame(oldItem: Task, newItem: Task): Boolean { + return oldItem == newItem + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/ui/choose/list/TaskListFragment.kt b/app/src/main/java/com/example/tasklist/ui/choose/list/TaskListFragment.kt new file mode 100644 index 0000000..9dd4735 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/ui/choose/list/TaskListFragment.kt @@ -0,0 +1,76 @@ +package com.example.tasklist.ui.choose.list + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import androidx.navigation.fragment.findNavController +import com.example.tasklist.R +import com.example.tasklist.data.DataSource +import com.example.tasklist.data.Database +import com.example.tasklist.data.Repository +import com.example.tasklist.data.Task +import com.example.tasklist.databinding.FragmentTaskListBinding +import com.example.tasklist.ui.adapters.TaskAdapter +import com.example.tasklist.ui.adapters.TaskItemClickListener + +/** + * A simple [Fragment] subclass. + * Use the [TaskListFragment.newInstance] factory method to + * create an instance of this fragment. + */ +class TaskListFragment : Fragment(), TaskItemClickListener { + + lateinit var mAdapter : TaskAdapter + val sharedViewModel : TaskListViewModel by activityViewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val binding = DataBindingUtil.inflate( + inflater, R.layout.fragment_task_list, container, false + ) + + mAdapter = TaskAdapter(this) + mAdapter.submitList(Repository.getAllTasks().value) + binding.recyclerView.adapter = mAdapter + binding.fragment = this@TaskListFragment + + subscribeUi(mAdapter, binding) + + return binding.root + } + private fun subscribeUi(newAdapter: TaskAdapter, binding: FragmentTaskListBinding) { + binding.recyclerView.adapter = newAdapter + newAdapter.notifyDataSetChanged() + } + + override fun chooseTask(task: Task) { + val taskToast = Toast.makeText(activity, "Zostało wybrane zadanie ${task.name}", Toast.LENGTH_LONG) + taskToast.show() + } + + fun addTask(){ + findNavController().navigate(R.id.action_taskListFragment_to_adding_tasks) + } + + fun clearSharedPref(){ + DataSource.zadanie.clear() + Database.taskDao.saveInSharedPreferences() + findNavController().navigate(R.id.action_taskListFragment_self) + } + + fun goToPassChange(){ + findNavController().navigate(R.id.action_taskListFragment_to_changePass) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/ui/choose/list/TaskListViewModel.kt b/app/src/main/java/com/example/tasklist/ui/choose/list/TaskListViewModel.kt new file mode 100644 index 0000000..4c4c1ff --- /dev/null +++ b/app/src/main/java/com/example/tasklist/ui/choose/list/TaskListViewModel.kt @@ -0,0 +1,11 @@ +package com.example.tasklist.ui.choose.list + +import androidx.lifecycle.LiveData +import androidx.lifecycle.ViewModel +import com.example.tasklist.data.Repository +import com.example.tasklist.data.Task + +class TaskListViewModel : ViewModel() { + var tasks: LiveData> = Repository.getAllTasks() + +} diff --git a/app/src/main/java/com/example/tasklist/ui/main/MainFragment.kt b/app/src/main/java/com/example/tasklist/ui/main/MainFragment.kt new file mode 100644 index 0000000..d475c2e --- /dev/null +++ b/app/src/main/java/com/example/tasklist/ui/main/MainFragment.kt @@ -0,0 +1,30 @@ +package com.example.tasklist.ui.main + +import androidx.lifecycle.ViewModelProvider +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.example.tasklist.R + +class MainFragment : Fragment() { + + companion object { + fun newInstance() = MainFragment() + } + + private lateinit var viewModel: MainViewModel + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View { + return inflater.inflate(R.layout.main_fragment, container, false) + } + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + viewModel = ViewModelProvider(this).get(MainViewModel::class.java) + // TODO: Use the ViewModel + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/tasklist/ui/main/MainViewModel.kt b/app/src/main/java/com/example/tasklist/ui/main/MainViewModel.kt new file mode 100644 index 0000000..ca17da4 --- /dev/null +++ b/app/src/main/java/com/example/tasklist/ui/main/MainViewModel.kt @@ -0,0 +1,7 @@ +package com.example.tasklist.ui.main + +import androidx.lifecycle.ViewModel + +class MainViewModel : ViewModel() { + // TODO: Implement the ViewModel +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bordershape.xml b/app/src/main/res/drawable/bordershape.xml new file mode 100644 index 0000000..6af347a --- /dev/null +++ b/app/src/main/res/drawable/bordershape.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/buttonshape.xml b/app/src/main/res/drawable/buttonshape.xml new file mode 100644 index 0000000..999d40f --- /dev/null +++ b/app/src/main/res/drawable/buttonshape.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_email_light_blue_24dp.xml b/app/src/main/res/drawable/ic_email_light_blue_24dp.xml new file mode 100644 index 0000000..0070459 --- /dev/null +++ b/app/src/main/res/drawable/ic_email_light_blue_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_lock_light_blue_24dp.xml b/app/src/main/res/drawable/ic_lock_light_blue_24dp.xml new file mode 100644 index 0000000..636189d --- /dev/null +++ b/app/src/main/res/drawable/ic_lock_light_blue_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_touch_app_white_24dp.xml b/app/src/main/res/drawable/ic_touch_app_white_24dp.xml new file mode 100644 index 0000000..378c06a --- /dev/null +++ b/app/src/main/res/drawable/ic_touch_app_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_adding_tasks.xml b/app/src/main/res/layout/fragment_adding_tasks.xml new file mode 100644 index 0000000..4160bb6 --- /dev/null +++ b/app/src/main/res/layout/fragment_adding_tasks.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + +