-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
1,577 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SimpleNote | ||
* build.gradle | ||
* Created by Rangga Dikarinata on 2020/11/3 | ||
* email : dikarinata@gmail.com | ||
* Copyright © 2020 Rangga Dikarinata. All rights reserved. | ||
*/ | ||
|
||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.2" | ||
|
||
defaultConfig { | ||
applicationId "id.radikz.simplenote" | ||
minSdkVersion 16 | ||
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' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.3.2' | ||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.0.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1' | ||
implementation 'androidx.navigation:navigation-ui-ktx:2.3.1' | ||
implementation 'androidx.recyclerview:recyclerview:1.0.0' | ||
implementation 'androidx.cardview:cardview:1.0.0' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
32 changes: 32 additions & 0 deletions
32
app/src/androidTest/java/id/radikz/simplenote/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SimpleNote | ||
* ExampleInstrumentedTest.kt | ||
* Created by Rangga Dikarinata on 2020/11/3 | ||
* email : dikarinata@gmail.com | ||
* Copyright © 2020 Rangga Dikarinata. All rights reserved. | ||
*/ | ||
|
||
package id.radikz.simplenote | ||
|
||
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("id.radikz.simplenote", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ SimpleNote | ||
~ AndroidManifest.xml | ||
~ Created by Rangga Dikarinata on 2020/11/3 | ||
~ email : dikarinata@gmail.com | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="id.radikz.simplenote"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.SimpleNote"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.SimpleNote.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SimpleNote | ||
* CreateFragment.kt | ||
* Created by Rangga Dikarinata on 2020/11/3 | ||
* email : dikarinata@gmail.com | ||
*/ | ||
|
||
package id.radikz.simplenote | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.navigation.Navigation | ||
import id.radikz.simplenote.db.DatabaseHelper | ||
|
||
/** | ||
* A simple [Fragment] subclass as the default destination in the navigation. | ||
*/ | ||
class CreateFragment : Fragment() { | ||
|
||
private lateinit var title: EditText | ||
private lateinit var description: EditText | ||
private lateinit var add: Button | ||
private lateinit var databaseHelper: DatabaseHelper | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_create, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
(requireContext() as AppCompatActivity).supportActionBar!!.setTitle("Create") | ||
|
||
title = view.findViewById(R.id.create_title) | ||
description = view.findViewById(R.id.create_description) | ||
add = view.findViewById(R.id.create_button) | ||
databaseHelper = DatabaseHelper(requireContext()) | ||
|
||
add.setOnClickListener{ | ||
insertData(it) | ||
} | ||
} | ||
|
||
private fun insertData(view: View){ | ||
val strTitle = title.text.toString() | ||
val strDesc = description.text.toString() | ||
|
||
val result = databaseHelper.insert(strTitle, strDesc) | ||
|
||
if (result) { | ||
Navigation.findNavController(view).navigate(R.id.action_createFragment_to_FirstFragment) | ||
} | ||
else{ | ||
Toast.makeText(requireContext(), "Failed to insert data", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
app/src/main/java/id/radikz/simplenote/FirstFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* SimpleNote | ||
* FirstFragment.kt | ||
* Created by Rangga Dikarinata on 2020/11/3 | ||
* email : dikarinata@gmail.com | ||
* Copyright © 2020 Rangga Dikarinata. All rights reserved. | ||
*/ | ||
|
||
package id.radikz.simplenote | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.* | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.Navigation | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
import id.radikz.simplenote.adapter.NotesAdapter | ||
import id.radikz.simplenote.db.DatabaseHelper | ||
import id.radikz.simplenote.model.Note | ||
|
||
/** | ||
* A simple [Fragment] subclass as the default destination in the navigation. | ||
*/ | ||
class FirstFragment : Fragment() { | ||
|
||
private lateinit var databaseHelper: DatabaseHelper | ||
private lateinit var notes: RecyclerView | ||
private lateinit var notesAdapter: NotesAdapter | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_first, container, false) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
setHasOptionsMenu(true) | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
(activity as? AppCompatActivity)?.supportActionBar?.title = "Simple Note" | ||
|
||
databaseHelper = DatabaseHelper(requireContext()) | ||
notes = view.findViewById(R.id.list_notes) | ||
notes.layoutManager = LinearLayoutManager(requireContext()) | ||
notesAdapter = NotesAdapter(requireContext(), mutableListOf()) | ||
notes.adapter = notesAdapter | ||
|
||
view.findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { | ||
Navigation.findNavController(view).navigate(R.id.action_FirstFragment_to_createFragment) | ||
} | ||
|
||
readDb() | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
inflater.inflate(R.menu.menu_main, menu) | ||
super.onCreateOptionsMenu(menu, inflater); | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
// Handle action bar item clicks here. The action bar will | ||
// automatically handle clicks on the Home/Up button, so long | ||
// as you specify a parent activity in AndroidManifest.xml. | ||
return when (item.itemId) { | ||
R.id.action_delete -> { | ||
alertDialog() | ||
return true | ||
} | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
|
||
private fun readDb(){ | ||
val data = databaseHelper.read() | ||
val listNotes = ArrayList<Note>() | ||
|
||
if (data.moveToFirst()) { | ||
|
||
do { | ||
val title = data.getString(data.getColumnIndex("title")) | ||
val description = data.getString(data.getColumnIndex("description")) | ||
val date = data.getString(data.getColumnIndex("date")) | ||
|
||
listNotes.add(Note(title, description, date)) | ||
|
||
} while (data.moveToNext()) | ||
|
||
} | ||
notesFetched(listNotes) | ||
} | ||
|
||
private fun notesFetched(notes: List<Note>) { | ||
notesAdapter.appendNotes(notes) | ||
} | ||
|
||
private fun alertDialog(){ | ||
val alertDialogBuilder = AlertDialog.Builder(requireContext()) | ||
alertDialogBuilder.setMessage("Are you sure do you want to delete all item?") | ||
alertDialogBuilder.setPositiveButton("Yes"){ _,_ -> | ||
|
||
val result: Boolean = databaseHelper.delete() | ||
if (result){ | ||
deleteAllNote() | ||
} | ||
else{ | ||
Toast.makeText(context, "Failed to delete", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
alertDialogBuilder.setNeutralButton("Cancel"){ _,_ -> } | ||
val alertDialog = alertDialogBuilder.create() | ||
alertDialog.show() | ||
} | ||
|
||
private fun deleteAllNote(){ | ||
notesAdapter.deleteNotes() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SimpleNote | ||
* MainActivity.kt | ||
* Created by Rangga Dikarinata on 2020/11/3 | ||
* email : dikarinata@gmail.com | ||
* Copyright © 2020 Rangga Dikarinata. All rights reserved. | ||
*/ | ||
|
||
package id.radikz.simplenote | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
setSupportActionBar(findViewById(R.id.toolbar)) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.