Skip to content

Commit 9e19e04

Browse files
committed
first commit
0 parents  commit 9e19e04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1265
-0
lines changed

Diff for: .gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

Diff for: .idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/compiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/gradle.xml

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

Diff for: app/build.gradle

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
compileSdk 32
8+
9+
defaultConfig {
10+
applicationId "com.example.devnotes"
11+
minSdk 23
12+
targetSdk 32
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
kotlinOptions {
30+
jvmTarget = '1.8'
31+
}
32+
buildFeatures {
33+
viewBinding true
34+
}
35+
}
36+
37+
dependencies {
38+
39+
implementation 'androidx.core:core-ktx:1.8.0'
40+
implementation 'androidx.appcompat:appcompat:1.4.2'
41+
implementation 'com.google.android.material:material:1.6.1'
42+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
43+
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0'
44+
45+
testImplementation 'junit:junit:4.13.2'
46+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
47+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
48+
}

Diff for: app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.devnotes
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.devnotes", appContext.packageName)
23+
}
24+
}

Diff for: app/src/main/AndroidManifest.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.devnotes">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.DevNotes">
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true"
15+
android:windowSoftInputMode="adjustResize">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.example.devnotes
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import androidx.core.content.ContextCompat
8+
import androidx.core.widget.doOnTextChanged
9+
import androidx.fragment.app.Fragment
10+
import androidx.fragment.app.activityViewModels
11+
import androidx.fragment.app.commit
12+
import androidx.recyclerview.widget.GridLayoutManager
13+
import androidx.recyclerview.widget.RecyclerView
14+
import com.example.devnotes.databinding.FragmentHomeBinding
15+
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
16+
17+
class HomeFragment : Fragment() {
18+
19+
private val viewModel by activityViewModels<NotesViewModel>()
20+
private lateinit var adapter: NotesAdapter
21+
private lateinit var binding: FragmentHomeBinding
22+
val fbutton: ExtendedFloatingActionButton
23+
get() = (activity as? MainActivity)?.fbutton!!
24+
25+
override fun onCreateView(
26+
inflater: LayoutInflater,
27+
container: ViewGroup?,
28+
savedInstanceState: Bundle?
29+
): View {
30+
binding = FragmentHomeBinding.inflate(inflater, container, false)
31+
return binding.root
32+
}
33+
34+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35+
super.onViewCreated(view, savedInstanceState)
36+
fbutton.shrink()
37+
fbutton.isEnabled = true
38+
fbutton.icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_add)
39+
fbutton.setOnClickListener {
40+
parentFragmentManager.commit {
41+
addToBackStack(null)
42+
replace(R.id.nav_container, NewNotesFragment())
43+
}
44+
}
45+
46+
binding.rvNotes.layoutManager = GridLayoutManager(
47+
requireContext(), 2, RecyclerView.VERTICAL, false
48+
)
49+
adapter = NotesAdapter { note: Note ->
50+
viewModel.remove(note)
51+
}
52+
binding.rvNotes.adapter = adapter
53+
54+
binding.etSearch.doOnTextChanged { text, _, _, _ ->
55+
viewModel.searchNote(text.toString())
56+
}
57+
58+
viewModel.notes.observe(viewLifecycleOwner) { notes: List<Note> ->
59+
adapter.items = notes
60+
}
61+
}
62+
63+
companion object {
64+
const val TITLE_KEY = "TITLE_KEY"
65+
66+
fun newInstance(text: String) : HomeFragment {
67+
val fragment = HomeFragment()
68+
fragment.arguments = Bundle().apply {
69+
putString(TITLE_KEY, text)
70+
}
71+
return fragment
72+
}
73+
}
74+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.example.devnotes
2+
3+
import android.app.Activity
4+
import androidx.appcompat.app.AppCompatActivity
5+
import android.os.Bundle
6+
import androidx.activity.viewModels
7+
import androidx.fragment.app.Fragment
8+
import androidx.fragment.app.commit
9+
import com.example.devnotes.databinding.ActivityMainBinding
10+
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
private val viewModel by viewModels<NotesViewModel>()
15+
private lateinit var binding: ActivityMainBinding
16+
val fbutton: ExtendedFloatingActionButton
17+
get() = binding.fbutton
18+
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
22+
binding = ActivityMainBinding.inflate(layoutInflater)
23+
24+
setContentView(binding.root)
25+
val navhost = binding.navContainer.id
26+
supportFragmentManager.commit {
27+
add(navhost, HomeFragment())
28+
}
29+
}
30+
}
31+
32+
fun AppCompatActivity.addFragment(host: Int, fragment: Fragment) {
33+
supportFragmentManager.commit {
34+
add(host, fragment)
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.example.devnotes
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import androidx.core.content.ContextCompat
8+
import androidx.core.widget.doOnTextChanged
9+
import androidx.fragment.app.Fragment
10+
import androidx.fragment.app.activityViewModels
11+
import com.example.devnotes.databinding.FragmentNewNotesBinding
12+
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
13+
14+
class NewNotesFragment : Fragment() {
15+
16+
private val viewModel by activityViewModels<NotesViewModel>()
17+
private lateinit var binding: FragmentNewNotesBinding
18+
val fbutton: ExtendedFloatingActionButton
19+
get() = (activity as? MainActivity)?.fbutton!!
20+
21+
override fun onCreateView(
22+
inflater: LayoutInflater,
23+
container: ViewGroup?,
24+
savedInstanceState: Bundle?
25+
): View? {
26+
binding = FragmentNewNotesBinding.inflate(inflater, container, false)
27+
return binding.root
28+
}
29+
30+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
31+
super.onViewCreated(view, savedInstanceState)
32+
fbutton.apply {
33+
icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_save)
34+
text = context.getString(R.string.action_save)
35+
isEnabled = false
36+
setOnClickListener {
37+
val title = binding.etTitle.text.toString()
38+
val body = binding.etBody.text.toString()
39+
viewModel.add(
40+
Note(title, body)
41+
)
42+
activity?.onBackPressed()
43+
}
44+
}
45+
binding.toolbar2.setOnClickListener {
46+
activity?.onBackPressed()
47+
}
48+
49+
binding.etTitle.doOnTextChanged { _, _, _, count ->
50+
val bodyText = binding.etBody.text
51+
val hasBody = bodyText.isNotEmpty() && bodyText.isNotBlank()
52+
if (count > 0 && hasBody) {
53+
fbutton.extend()
54+
fbutton.isEnabled = true
55+
} else {
56+
fbutton.shrink()
57+
fbutton.isEnabled = false
58+
}
59+
}
60+
61+
binding.etBody.doOnTextChanged { _, _, _, count ->
62+
val bodyTile = binding.etTitle.text
63+
val hasTitle = bodyTile.isNotEmpty() && bodyTile.isNotBlank()
64+
if (count > 0 && hasTitle) {
65+
fbutton.extend()
66+
fbutton.isEnabled = true
67+
} else {
68+
fbutton.shrink()
69+
fbutton.isEnabled = false
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)