Skip to content

Commit

Permalink
Implement insanely polished version of HUE 18
Browse files Browse the repository at this point in the history
  • Loading branch information
profiluefter committed Mar 4, 2021
0 parents commit c99ec28
Show file tree
Hide file tree
Showing 205 changed files with 1,512 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdkVersion 30

defaultConfig {
applicationId "me.profiluefter.profinote"
minSdkVersion 24
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'
}
}
buildFeatures {
// viewBinding true
dataBinding true
}
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.activity:activity-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.profiluefter.profinote">

<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.Notian">
<activity
android:name=".NoteEditorActivity"
android:windowSoftInputMode="adjustResize" />
<activity android:name=".NoteDetailsActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
103 changes: 103 additions & 0 deletions app/src/main/java/me/profiluefter/profinote/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package me.profiluefter.profinote

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import me.profiluefter.profinote.databinding.ActivityMainBinding
import me.profiluefter.profinote.models.MainActivityViewModel
import me.profiluefter.profinote.models.Note

class MainActivity : AppCompatActivity() {
private val viewModel: MainActivityViewModel by viewModels()

private val editorRequestCode = 187

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding: ActivityMainBinding =
DataBindingUtil.setContentView(this, R.layout.activity_main)

binding.viewModel = viewModel
binding.lifecycleOwner = this

val adapter = NotesAdapter(viewModel.notes.value!!, this)
viewModel.notes.observe(this) {
adapter.notes = it
}

val recyclerView = findViewById<RecyclerView>(R.id.notes)
recyclerView.adapter = adapter
recyclerView.addItemDecoration(
DividerItemDecoration(
recyclerView.context,
DividerItemDecoration.VERTICAL
)
)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main_menu, menu)
return super.onCreateOptionsMenu(menu)
}

fun onNewNote(item: MenuItem) {
val intent = Intent(this, NoteEditorActivity::class.java)
intent.putExtra("position", -1)
startActivityForResult(
intent,
editorRequestCode
) //TODO: Replace with registerForActivityResult(StartActivityForResult())
}

fun onSaveNotes(item: MenuItem) {
viewModel.saveNotes()
Snackbar.make(findViewById(R.id.notes), R.string.saved_notes, Snackbar.LENGTH_SHORT).show()
}

fun onEditNote(index: Int) {
val intent = Intent(this, NoteEditorActivity::class.java)
intent.putExtra("position", index)
intent.putExtra("note", viewModel.notes.value!![index])
startActivityForResult(
intent,
editorRequestCode
) //TODO: Replace with registerForActivityResult(StartActivityForResult())
}

fun onShowNoteDetails(index: Int) {
val intent = Intent(this, NoteDetailsActivity::class.java)
intent.putExtra("note", viewModel.notes.value!![index])
startActivity(intent)
}

fun onDeleteNote(index: Int, view: View) {
val note = viewModel.notes.value!![index]
viewModel.deleteNote(index)
val snackbar = Snackbar.make(view, R.string.note_deleted, Snackbar.LENGTH_SHORT)
snackbar.setAction(R.string.undo) {
viewModel.setNote(-1, note)
}
snackbar.show()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
editorRequestCode -> {
if (resultCode != RESULT_OK) return

val note = data!!.getSerializableExtra("note") as Note
val position = data.getIntExtra("position", -1)
viewModel.setNote(position, note)
}
else -> super.onActivityResult(requestCode, resultCode, data)
}
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/me/profiluefter/profinote/NoteDetailsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.profiluefter.profinote

import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import me.profiluefter.profinote.databinding.ActivityNoteDetailsBinding
import me.profiluefter.profinote.models.Note

class NoteDetailsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding: ActivityNoteDetailsBinding =
DataBindingUtil.setContentView(this, R.layout.activity_note_details)

binding.lifecycleOwner = this
binding.note = intent.extras!!["note"] as Note
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}
}
83 changes: 83 additions & 0 deletions app/src/main/java/me/profiluefter/profinote/NoteEditorActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package me.profiluefter.profinote

import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import me.profiluefter.profinote.databinding.ActivityNoteEditorBinding
import me.profiluefter.profinote.models.Note
import me.profiluefter.profinote.models.NoteEditorActivityViewModel
import java.util.*

class NoteEditorActivity : AppCompatActivity() {
private val viewModel: NoteEditorActivityViewModel by viewModels {
object : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return modelClass.getConstructor(Note::class.java, Int::class.java)
.newInstance(
intent.getSerializableExtra("note") as Note?,
intent.getIntExtra("position", -1)
)
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityNoteEditorBinding.inflate(layoutInflater)
binding.lifecycleOwner = this
binding.viewModel = viewModel
setContentView(binding.root)

supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
setResult(RESULT_CANCELED)
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}

fun saveNote(view: View) {
val intent = Intent()
intent.putExtra("note", viewModel.note)
intent.putExtra("position", viewModel.notePosition)
setResult(RESULT_OK, intent)
finish()
}

fun openTimePicker(view: View) {
val calendar = Calendar.getInstance()
val dialog = TimePickerDialog(
this,
{ _, hour, minute -> viewModel.setTime(hour, minute) },
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
false
)
dialog.show()
}

fun openDatePicker(view: View) {
val calendar = Calendar.getInstance()
val dialog = DatePickerDialog(
this,
{ _, year, month, day -> viewModel.setDate(day, month, year) },
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
)
dialog.show()
}
}
Loading

0 comments on commit c99ec28

Please sign in to comment.