├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_add.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_add.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_add.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_add.png │ │ │ ├── drawable-xxxhdpi │ │ │ │ └── ic_add.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── ids.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ ├── note.xml │ │ │ │ └── main.xml │ │ │ └── layout │ │ │ │ ├── note_info_dialog.xml │ │ │ │ ├── note_item_layout.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_note.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── imangazaliev │ │ │ │ └── notelin │ │ │ │ ├── bus │ │ │ │ ├── NoteEditAction.kt │ │ │ │ └── NoteDeleteAction.kt │ │ │ │ ├── mvp │ │ │ │ ├── model │ │ │ │ │ ├── AppDatabase.kt │ │ │ │ │ ├── NoteDao.kt │ │ │ │ │ └── Note.kt │ │ │ │ ├── views │ │ │ │ │ ├── NoteView.kt │ │ │ │ │ └── MainView.kt │ │ │ │ └── presenters │ │ │ │ │ ├── NotePresenter.kt │ │ │ │ │ └── MainPresenter.kt │ │ │ │ ├── utils │ │ │ │ ├── DateUtils.kt │ │ │ │ └── PrefsUtils.kt │ │ │ │ ├── di │ │ │ │ ├── NoteDaoModule.kt │ │ │ │ └── AppComponent.kt │ │ │ │ ├── NotelinApplication.kt │ │ │ │ └── ui │ │ │ │ ├── adapters │ │ │ │ └── NotesAdapter.kt │ │ │ │ ├── commons │ │ │ │ └── ItemClickSupport.kt │ │ │ │ └── activities │ │ │ │ ├── NoteActivity.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ └── test │ │ └── kotlin │ │ └── imangazaliev │ │ └── notelin │ │ └── ExampleUnitTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art └── splash.png ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── Notelin.iml ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /art/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/art/splash.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /Notelin.iml 3 | .gradle 4 | /local.properties 5 | .DS_Store 6 | /build 7 | /captures 8 | /.idea/ 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/drawable-hdpi/ic_add.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/drawable-mdpi/ic_add.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/drawable-xhdpi/ic_add.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/drawable-xxhdpi/ic_add.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/drawable-xxxhdpi/ic_add.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImangazalievM/Notelin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/bus/NoteEditAction.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.bus 2 | 3 | class NoteEditAction(val noteId: Long) 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/bus/NoteDeleteAction.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.bus 2 | 3 | class NoteDeleteAction(val noteId: Long) 4 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/model/AppDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.model 2 | 3 | import com.reactiveandroid.annotation.Database 4 | 5 | @Database(name = "AppDatabase", version = 1) 6 | class AppDatabase -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #5E9E76 4 | #3b8657 5 | #5E9E76 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Dec 01 08:07:32 MSK 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-4.4-20171031235950+0000-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/utils/DateUtils.kt: -------------------------------------------------------------------------------- 1 | @file:JvmName("DateUtils") 2 | 3 | package com.imangazaliev.notelin.utils 4 | 5 | import java.text.SimpleDateFormat 6 | import java.util.* 7 | 8 | fun formatDate(date: Date?): String { 9 | val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm") 10 | return dateFormat.format(date) 11 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/di/NoteDaoModule.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.di 2 | 3 | import dagger.Module 4 | import dagger.Provides 5 | import com.imangazaliev.notelin.mvp.model.NoteDao 6 | import javax.inject.Singleton 7 | 8 | @Module 9 | class NoteDaoModule { 10 | 11 | @Provides 12 | @Singleton 13 | fun provideNoteDao(): NoteDao = NoteDao() 14 | 15 | } -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/kotlin/imangazaliev/notelin/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/di/AppComponent.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.di 2 | 3 | import dagger.Component 4 | import com.imangazaliev.notelin.mvp.presenters.MainPresenter 5 | import com.imangazaliev.notelin.mvp.presenters.NotePresenter 6 | import javax.inject.Singleton 7 | 8 | @Singleton 9 | @Component(modules = [NoteDaoModule::class]) 10 | interface AppComponent { 11 | fun inject(mainPresenter: MainPresenter) 12 | 13 | fun inject(notePresenter: NotePresenter) 14 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/views/NoteView.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.views 2 | 3 | import com.arellomobile.mvp.MvpView 4 | import com.imangazaliev.notelin.mvp.model.Note 5 | 6 | interface NoteView : MvpView { 7 | 8 | fun showNote(note: Note) 9 | 10 | fun onNoteSaved() 11 | 12 | fun onNoteDeleted() 13 | 14 | fun showNoteInfoDialog(noteInfo: String) 15 | 16 | fun hideNoteInfoDialog() 17 | 18 | fun showNoteDeleteDialog() 19 | 20 | fun hideNoteDeleteDialog() 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/utils/PrefsUtils.kt: -------------------------------------------------------------------------------- 1 | @file:JvmName("PrefsUtils") 2 | 3 | package com.imangazaliev.notelin.utils 4 | 5 | import android.content.Context 6 | import com.imangazaliev.notelin.NotelinApplication 7 | 8 | private val prefs by lazy { 9 | NotelinApplication.context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE) 10 | } 11 | 12 | fun getNotesSortMethodName(defaultValue: String): String = prefs.getString("sort_method", defaultValue) 13 | 14 | fun setNotesSortMethod(sortMethod: String) { 15 | prefs.edit().putString("sort_method", sortMethod).apply() 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/menu/note.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 15 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/note_info_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Mahach\AndroidDeveloment\Programms\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/model/NoteDao.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.model 2 | 3 | import com.reactiveandroid.query.Delete 4 | import com.reactiveandroid.query.Select 5 | import org.jetbrains.annotations.Nullable 6 | import java.util.* 7 | 8 | class NoteDao { 9 | 10 | fun createNote(): Note { 11 | val note = Note("New note", Date()) 12 | note.save() 13 | return note 14 | } 15 | 16 | fun saveNote(note: Note): Long = note.save() 17 | 18 | fun loadAllNotes(): MutableList = Select.from(Note::class.java).fetch() 19 | 20 | fun getNoteById(noteId: Long): Note? = Select.from(Note::class.java).where("id = ?", noteId).fetchSingle() 21 | 22 | fun deleteAllNotes() = Delete.from(Note::class.java).execute() 23 | 24 | fun deleteNote(note: Note) = note.delete() 25 | 26 | } 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/views/MainView.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.views 2 | 3 | import com.arellomobile.mvp.MvpView 4 | import com.arellomobile.mvp.viewstate.strategy.AddToEndSingleStrategy 5 | import com.arellomobile.mvp.viewstate.strategy.StateStrategyType 6 | import com.imangazaliev.notelin.mvp.model.Note 7 | 8 | @StateStrategyType(value = AddToEndSingleStrategy::class) 9 | interface MainView : MvpView { 10 | 11 | fun onNotesLoaded(notes: List) 12 | 13 | fun updateView() 14 | 15 | fun onSearchResult(notes: List) 16 | 17 | fun onAllNotesDeleted() 18 | 19 | fun onNoteDeleted() 20 | 21 | fun showNoteInfoDialog(noteInfo: String) 22 | 23 | fun hideNoteInfoDialog() 24 | 25 | fun showNoteDeleteDialog(notePosition: Int) 26 | 27 | fun hideNoteDeleteDialog() 28 | 29 | fun showNoteContextDialog(notePosition: Int) 30 | 31 | fun hideNoteContextDialog() 32 | 33 | fun openNoteScreen(noteId: Long) 34 | 35 | } -------------------------------------------------------------------------------- /Notelin.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 16 | 17 | 18 | 19 | 22 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/model/Note.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.model 2 | 3 | import com.imangazaliev.notelin.utils.formatDate 4 | import com.reactiveandroid.Model 5 | import com.reactiveandroid.annotation.Column 6 | import com.reactiveandroid.annotation.PrimaryKey 7 | import com.reactiveandroid.annotation.Table 8 | import java.util.* 9 | 10 | @Table(name = "Notes", database = AppDatabase::class) 11 | class Note : Model { 12 | 13 | @PrimaryKey 14 | var id: Long = 0 15 | @Column(name = "title") 16 | var title: String? = null 17 | @Column(name = "text") 18 | var text: String? = null 19 | @Column(name = "created_at") 20 | var createAt: Date? = null 21 | @Column(name = "change_at") 22 | var changedAt: Date? = null 23 | 24 | constructor(title: String, createDate: Date) { 25 | this.title = title 26 | this.createAt = createDate 27 | this.changedAt = createDate 28 | } 29 | 30 | constructor() 31 | 32 | fun getInfo(): String = "Title:\n$title\n" + 33 | "Created at:\n${formatDate(createAt)}\n" + 34 | "Changed at:\n${formatDate(changedAt)}" 35 | 36 | } -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Notelin 3 | All notes deleted 4 | Delete 5 | Delete all 6 | Input your text... 7 | No 8 | Note deleted 9 | Note deletion 10 | Do you want to delete this note? 11 | Information 12 | No notes found 13 | OK 14 | Save 15 | Search 16 | Sort by 17 | Title 18 | Date 19 | Title 20 | Yes 21 | 22 | 23 | Open 24 | @string/note_info 25 | @string/delete 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 28 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/note_item_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/NotelinApplication.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin 2 | 3 | import android.annotation.SuppressLint 4 | import android.app.Application 5 | import android.content.Context 6 | import com.imangazaliev.notelin.di.AppComponent 7 | import com.imangazaliev.notelin.di.DaggerAppComponent 8 | import com.imangazaliev.notelin.di.NoteDaoModule 9 | import com.imangazaliev.notelin.mvp.model.AppDatabase 10 | import com.imangazaliev.notelin.mvp.model.Note 11 | import com.reactiveandroid.ReActiveAndroid 12 | import com.reactiveandroid.ReActiveConfig 13 | import com.reactiveandroid.internal.database.DatabaseConfig 14 | 15 | class NotelinApplication : Application() { 16 | 17 | companion object { 18 | lateinit var graph: AppComponent 19 | @SuppressLint("StaticFieldLeak") 20 | lateinit var context: Context 21 | } 22 | 23 | override fun onCreate() { 24 | super.onCreate() 25 | 26 | context = this 27 | graph = DaggerAppComponent.builder().noteDaoModule(NoteDaoModule()).build() 28 | 29 | val appDatabaseConfig = DatabaseConfig.Builder(AppDatabase::class.java) 30 | .addModelClasses(Note::class.java) 31 | .build() 32 | 33 | ReActiveAndroid.init(ReActiveConfig.Builder(this) 34 | .addDatabaseConfigs(appDatabaseConfig) 35 | .build()) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 22 | 23 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/ui/adapters/NotesAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.ui.adapters 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.TextView 8 | import com.imangazaliev.notelin.R 9 | import com.imangazaliev.notelin.mvp.model.Note 10 | import com.imangazaliev.notelin.utils.formatDate 11 | 12 | class NotesAdapter(private val notesList: List) : RecyclerView.Adapter() { 13 | 14 | override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): NotesAdapter.ViewHolder { 15 | val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.note_item_layout, viewGroup, false) 16 | return NotesAdapter.ViewHolder(v) 17 | } 18 | 19 | override 20 | fun onBindViewHolder(viewHolder: NotesAdapter.ViewHolder, i: Int) { 21 | val note = notesList[i] 22 | viewHolder.noteTitle.text = note.title 23 | viewHolder.noteDate.text = formatDate(note.changedAt) 24 | } 25 | 26 | override fun getItemCount(): Int { 27 | return notesList.size 28 | } 29 | 30 | class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { 31 | 32 | var noteTitle: TextView = itemView.findViewById(R.id.tvItemNoteTitle) as TextView 33 | var noteDate: TextView = itemView.findViewById(R.id.tvItemNoteDate) as TextView 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 20 | 21 | 31 | 32 | 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Image](https://raw.githubusercontent.com/ImangazalievM/Notelin/master/art/splash.png) 2 | 3 | Libraries and tools included: 4 | 5 | - Google AppCompat Support Libraries 6 | - Google Material Design Support Libraries 7 | - [ReActiveAndroid](https://github.com/ImangazalievM/ReActiveAndroid) - for persistence 8 | - [Eventbus](https://github.com/greenrobot/EventBus) - for change notifications 9 | - [Material Dialogs](https://github.com/afollestad/material-dialogs) - for dialogs 10 | - [Dagger 2](https://github.com/google/dagger) - for dependency injection 11 | - [Moxy](https://github.com/Arello-Mobile/Moxy) - for MVP pattern implementation 12 | 13 | ## License 14 | 15 | ``` 16 | The MIT License 17 | 18 | Copyright (c) 2017 Mahach Imangazaliev 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | ``` -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android-extensions' 3 | apply plugin: 'kotlin-android' 4 | apply plugin: 'kotlin-android-extensions' 5 | apply plugin: 'kotlin-kapt' 6 | 7 | android { 8 | compileSdkVersion 26 9 | buildToolsVersion "27.0.1" 10 | 11 | defaultConfig { 12 | applicationId "com.com.imangazaliev.notelin" 13 | minSdkVersion 16 14 | targetSdkVersion 26 15 | versionCode 2 16 | versionName "1.1.0" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | sourceSets { 27 | main.java.srcDirs += 'src/main/kotlin' 28 | androidTest.java.srcDirs += 'src/androidTest/kotlin' 29 | } 30 | } 31 | 32 | dependencies { 33 | implementation "com.android.support:appcompat-v7:26.1.0" 34 | implementation "com.android.support:recyclerview-v7:26.1.0" 35 | implementation "com.android.support:cardview-v7:26.1.0" 36 | implementation "com.android.support:design:26.1.0" 37 | 38 | implementation "com.pawegio.kandroid:kandroid:0.8.5@aar" 39 | 40 | implementation "com.arello-mobile:moxy:1.5.3" 41 | implementation 'com.arello-mobile:moxy-app-compat:1.5.3' 42 | kapt 'com.arello-mobile:moxy-compiler:1.5.3' 43 | 44 | implementation "com.reactiveandroid:reactiveandroid:1.2.1" 45 | implementation "org.greenrobot:eventbus:3.0.0" 46 | 47 | implementation "com.github.afollestad.material-dialogs:core:0.8.5.6@aar" 48 | 49 | kapt "com.google.dagger:dagger-compiler:2.11" 50 | implementation "com.google.dagger:dagger:2.11" 51 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 52 | } 53 | repositories { 54 | mavenCentral() 55 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/presenters/NotePresenter.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.presenters 2 | 3 | import com.arellomobile.mvp.InjectViewState 4 | import com.arellomobile.mvp.MvpPresenter 5 | import com.imangazaliev.notelin.NotelinApplication 6 | import com.imangazaliev.notelin.bus.NoteDeleteAction 7 | import com.imangazaliev.notelin.bus.NoteEditAction 8 | import com.imangazaliev.notelin.mvp.model.Note 9 | import com.imangazaliev.notelin.mvp.model.NoteDao 10 | import com.imangazaliev.notelin.mvp.views.NoteView 11 | import org.greenrobot.eventbus.EventBus 12 | import java.util.* 13 | import javax.inject.Inject 14 | 15 | @InjectViewState 16 | class NotePresenter(val noteId: Long) : MvpPresenter() { 17 | 18 | @Inject 19 | lateinit var noteDao: NoteDao 20 | private lateinit var note: Note 21 | 22 | init { 23 | NotelinApplication.graph.inject(this) 24 | } 25 | 26 | override fun onFirstViewAttach() { 27 | super.onFirstViewAttach() 28 | 29 | note = noteDao.getNoteById(noteId)!! 30 | viewState.showNote(note) 31 | } 32 | 33 | fun saveNote(title: String, text: String) { 34 | note.title = title 35 | note.text = text 36 | note.changedAt = Date() 37 | noteDao.saveNote(note) 38 | EventBus.getDefault().post(NoteEditAction(note.id)) 39 | viewState.onNoteSaved() 40 | } 41 | 42 | fun deleteNote() { 43 | //after deletion note id will be 0, 44 | // so we should save one before delete operation 45 | val noteId = note.id 46 | noteDao.deleteNote(note) 47 | EventBus.getDefault().post(NoteDeleteAction(noteId)) 48 | viewState.onNoteDeleted() 49 | } 50 | 51 | fun showNoteDeleteDialog() { 52 | viewState.showNoteDeleteDialog() 53 | } 54 | 55 | fun hideNoteDeleteDialog() { 56 | viewState.hideNoteDeleteDialog() 57 | } 58 | 59 | fun showNoteInfoDialog() { 60 | viewState.showNoteInfoDialog(note.getInfo()) 61 | } 62 | 63 | fun hideNoteInfoDialog() { 64 | viewState.hideNoteInfoDialog() 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/ui/commons/ItemClickSupport.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.ui.commons 2 | 3 | import android.support.v7.widget.RecyclerView 4 | 5 | import android.view.View 6 | import com.imangazaliev.notelin.R 7 | 8 | class ItemClickSupport private constructor(private val recyclerView: RecyclerView) { 9 | companion object { 10 | fun addTo(view: RecyclerView) = 11 | view.getTag(R.id.item_click_support) as? ItemClickSupport ?: ItemClickSupport(view) 12 | 13 | fun removeFrom(view: RecyclerView): ItemClickSupport? { 14 | val support = view.getTag(R.id.item_click_support) as? ItemClickSupport 15 | support?.detach(view) 16 | return support 17 | } 18 | } 19 | 20 | interface ItemClickListener { 21 | fun onClick(recyclerView: RecyclerView, position: Int, view: View) 22 | } 23 | 24 | interface ItemLongClickListener { 25 | fun onLongClick(recyclerView: RecyclerView, position: Int, view: View): Boolean 26 | } 27 | 28 | private var itemClickListener: ItemClickListener? = null 29 | private var itemLongClickListener: ItemLongClickListener? = null 30 | private val onClickListener = View.OnClickListener { 31 | val holder = recyclerView.getChildViewHolder(it) 32 | itemClickListener?.onClick(recyclerView, holder.adapterPosition, it) 33 | } 34 | private val onLongClickListener = View.OnLongClickListener listener@{ 35 | val position = recyclerView.getChildViewHolder(it).adapterPosition 36 | return@listener itemLongClickListener?.onLongClick(recyclerView, position, it) ?: false 37 | } 38 | private val attachListener = object : RecyclerView.OnChildAttachStateChangeListener { 39 | override fun onChildViewAttachedToWindow(view: View) { 40 | if (itemClickListener != null) { 41 | view.setOnClickListener(onClickListener) 42 | } 43 | 44 | if (itemLongClickListener != null) { 45 | view.setOnLongClickListener(onLongClickListener) 46 | } 47 | } 48 | 49 | override fun onChildViewDetachedFromWindow(view: View) = Unit 50 | } 51 | 52 | init { 53 | recyclerView.setTag(R.id.item_click_support, this) 54 | recyclerView.addOnChildAttachStateChangeListener(attachListener) 55 | } 56 | 57 | fun setOnItemClickListener(listener: ItemClickListener): ItemClickSupport { 58 | itemClickListener = listener 59 | return this 60 | } 61 | 62 | fun setOnItemClickListener(listener: (RecyclerView, Int, View) -> Unit) = 63 | setOnItemClickListener(object : ItemClickListener { 64 | override fun onClick(recyclerView: RecyclerView, position: Int, view: View) { 65 | listener(recyclerView, position, view) 66 | } 67 | }) 68 | 69 | fun setOnItemLongClickListener(listener: ItemLongClickListener): ItemClickSupport { 70 | itemLongClickListener = listener 71 | return this 72 | } 73 | 74 | fun setOnItemLongClickListener(block: (RecyclerView, Int, View) -> Boolean): ItemClickSupport = 75 | setOnItemLongClickListener(object : ItemLongClickListener { 76 | override fun onLongClick(recyclerView: RecyclerView, position: Int, view: View): Boolean { 77 | return block (recyclerView, position, view) 78 | } 79 | }) 80 | 81 | private fun detach(view: RecyclerView) { 82 | view.removeOnChildAttachStateChangeListener(attachListener) 83 | view.setTag(R.id.item_click_support, null) 84 | } 85 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/ui/activities/NoteActivity.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.ui.activities 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import android.view.Menu 7 | import android.view.MenuItem 8 | import android.view.View 9 | import android.widget.EditText 10 | import android.widget.Toast 11 | import com.afollestad.materialdialogs.MaterialDialog 12 | import com.arellomobile.mvp.MvpAppCompatActivity 13 | import com.arellomobile.mvp.presenter.InjectPresenter 14 | import com.arellomobile.mvp.presenter.ProvidePresenter 15 | import com.imangazaliev.notelin.R 16 | import com.imangazaliev.notelin.mvp.model.Note 17 | import com.imangazaliev.notelin.mvp.presenters.NotePresenter 18 | import com.imangazaliev.notelin.mvp.views.NoteView 19 | import com.imangazaliev.notelin.utils.formatDate 20 | import kotlinx.android.synthetic.main.activity_note.* 21 | 22 | class NoteActivity : MvpAppCompatActivity(), NoteView { 23 | 24 | companion object { 25 | const val NOTE_DELETE_ARG = "note_id" 26 | 27 | fun buildIntent(activity: Activity, noteId: Long) : Intent{ 28 | val intent = Intent(activity, NoteActivity::class.java) 29 | intent.putExtra(NOTE_DELETE_ARG, noteId) 30 | return intent 31 | } 32 | } 33 | 34 | @InjectPresenter 35 | lateinit var presenter: NotePresenter 36 | private var noteDeleteDialog: MaterialDialog? = null 37 | private var noteInfoDialog: MaterialDialog? = null 38 | 39 | @ProvidePresenter 40 | fun provideHelloPresenter(): NotePresenter { 41 | val noteId = intent.extras.getLong(NOTE_DELETE_ARG, -1) 42 | return NotePresenter(noteId) 43 | } 44 | 45 | override fun onCreate(savedInstanceState: Bundle?) { 46 | super.onCreate(savedInstanceState) 47 | setContentView(R.layout.activity_note) 48 | 49 | etTitle.onFocusChangeListener = View.OnFocusChangeListener { view, hasFocus -> 50 | if (hasFocus) { 51 | val editText = view as EditText 52 | editText.setSelection((editText.text.length)) 53 | } 54 | } 55 | } 56 | 57 | override fun showNote(note: Note) { 58 | tvNoteDate.text = formatDate(note.changedAt) 59 | etTitle.setText(note.title) 60 | etText.setText(note.text) 61 | } 62 | 63 | override fun showNoteInfoDialog(noteInfo: String) { 64 | noteInfoDialog = MaterialDialog.Builder(this) 65 | .title(R.string.note_info) 66 | .positiveText(R.string.ok) 67 | .content(noteInfo) 68 | .onPositive { materialDialog, dialogAction -> presenter.hideNoteInfoDialog() } 69 | .cancelListener { presenter.hideNoteInfoDialog() } 70 | .show() 71 | } 72 | 73 | override fun hideNoteInfoDialog() { 74 | noteInfoDialog?.dismiss() 75 | } 76 | 77 | override fun showNoteDeleteDialog() { 78 | noteDeleteDialog = MaterialDialog.Builder(this) 79 | .title(getString(R.string.note_deletion_title)) 80 | .content(getString(R.string.note_deletion_message)) 81 | .positiveText(getString(R.string.yes)) 82 | .negativeText(getString(R.string.no)) 83 | .onPositive { _, _ -> 84 | presenter.hideNoteDeleteDialog() 85 | presenter.deleteNote() 86 | } 87 | .onNegative { _, _ -> presenter.hideNoteDeleteDialog() } 88 | .cancelListener { presenter.hideNoteDeleteDialog() } 89 | .show() 90 | } 91 | 92 | 93 | override fun hideNoteDeleteDialog() { 94 | noteDeleteDialog?.dismiss() 95 | } 96 | 97 | override fun onNoteSaved() { 98 | Toast.makeText(this, "Note saved", Toast.LENGTH_SHORT).show() 99 | } 100 | 101 | override fun onNoteDeleted() { 102 | Toast.makeText(this, R.string.note_deleted, Toast.LENGTH_SHORT).show() 103 | finish() 104 | } 105 | 106 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 107 | menuInflater.inflate(R.menu.note, menu) 108 | return true 109 | } 110 | 111 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 112 | when (item.itemId) { 113 | R.id.menuSaveNote -> presenter.saveNote(etTitle.text.toString(), etText.text.toString()) 114 | 115 | R.id.menuDeleteNote -> presenter.showNoteDeleteDialog() 116 | 117 | R.id.menuNoteInfo -> presenter.showNoteInfoDialog() 118 | } 119 | return super.onOptionsItemSelected(item) 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/mvp/presenters/MainPresenter.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.mvp.presenters 2 | 3 | import android.util.Log 4 | import com.arellomobile.mvp.InjectViewState 5 | import com.arellomobile.mvp.MvpPresenter 6 | import com.imangazaliev.notelin.NotelinApplication 7 | import com.imangazaliev.notelin.bus.NoteDeleteAction 8 | import com.imangazaliev.notelin.bus.NoteEditAction 9 | import com.imangazaliev.notelin.mvp.model.Note 10 | import com.imangazaliev.notelin.mvp.model.NoteDao 11 | import com.imangazaliev.notelin.mvp.views.MainView 12 | import com.imangazaliev.notelin.utils.getNotesSortMethodName 13 | import com.imangazaliev.notelin.utils.setNotesSortMethod 14 | import org.greenrobot.eventbus.EventBus 15 | import org.greenrobot.eventbus.Subscribe 16 | import java.util.* 17 | import javax.inject.Inject 18 | 19 | @InjectViewState 20 | class MainPresenter : MvpPresenter() { 21 | 22 | enum class SortNotesBy : Comparator { 23 | DATE { 24 | override fun compare(note1: Note, note2: Note) = note1.changedAt!!.compareTo(note2.changedAt) 25 | }, 26 | NAME { 27 | override fun compare(note1: Note, note2: Note) = note1.title!!.compareTo(note2.title!!) 28 | }, 29 | } 30 | 31 | @Inject 32 | lateinit var noteDao: NoteDao 33 | private lateinit var notesList: MutableList 34 | 35 | init { 36 | NotelinApplication.graph.inject(this) 37 | EventBus.getDefault().register(this) 38 | } 39 | 40 | override fun onFirstViewAttach() { 41 | super.onFirstViewAttach() 42 | loadAllNotes() 43 | } 44 | 45 | fun deleteAllNotes() { 46 | noteDao.deleteAllNotes() 47 | notesList.removeAll(notesList) 48 | viewState.onAllNotesDeleted() 49 | } 50 | 51 | fun deleteNoteByPosition(position: Int) { 52 | val note = notesList[position] 53 | noteDao.deleteNote(note) 54 | notesList.remove(note) 55 | viewState.onNoteDeleted() 56 | } 57 | 58 | fun openNewNote() { 59 | val newNote = noteDao.createNote() 60 | notesList.add(newNote) 61 | sortNotesBy(getCurrentSortMethod()) 62 | viewState.openNoteScreen(newNote.id) 63 | } 64 | 65 | fun openNote(position: Int) { 66 | viewState.openNoteScreen(notesList[position].id) 67 | } 68 | 69 | fun search(query: String) { 70 | if (query == "") { 71 | viewState.onSearchResult(notesList) 72 | } else { 73 | val searchResults = notesList.filter { it.title!!.startsWith(query, ignoreCase = true) } 74 | viewState.onSearchResult(searchResults) 75 | } 76 | } 77 | 78 | fun sortNotesBy(sortMethod: SortNotesBy) { 79 | notesList.sortWith(sortMethod) 80 | setNotesSortMethod(sortMethod.toString()) 81 | viewState.updateView() 82 | } 83 | 84 | @Subscribe 85 | fun onNoteEdit(action: NoteEditAction) { 86 | val notePosition = getNotePositionById(action.noteId) 87 | notesList[notePosition] = noteDao.getNoteById(action.noteId)!! 88 | sortNotesBy(getCurrentSortMethod()) 89 | } 90 | 91 | @Subscribe 92 | fun onNoteDelete(action: NoteDeleteAction) { 93 | Log.d("Notelin", "onDeleted" + action.noteId); 94 | val notePosition = getNotePositionById(action.noteId) 95 | notesList.removeAt(notePosition) 96 | viewState.updateView() 97 | } 98 | 99 | fun showNoteContextDialog(position: Int) { 100 | viewState.showNoteContextDialog(position) 101 | } 102 | 103 | fun hideNoteContextDialog() { 104 | viewState.hideNoteContextDialog() 105 | } 106 | 107 | fun showNoteDeleteDialog(position: Int) { 108 | viewState.showNoteDeleteDialog(position) 109 | } 110 | 111 | fun hideNoteDeleteDialog() { 112 | viewState.hideNoteDeleteDialog() 113 | } 114 | 115 | fun showNoteInfo(position: Int) { 116 | viewState.showNoteInfoDialog(notesList[position].getInfo()) 117 | } 118 | 119 | fun hideNoteInfoDialog() { 120 | viewState.hideNoteInfoDialog() 121 | } 122 | 123 | private fun loadAllNotes() { 124 | notesList = noteDao.loadAllNotes() 125 | Collections.sort(notesList, getCurrentSortMethod()) 126 | viewState.onNotesLoaded(notesList) 127 | } 128 | 129 | private fun getCurrentSortMethod(): SortNotesBy { 130 | val defaultSortMethodName = SortNotesBy.DATE.toString() 131 | val currentSortMethodName = getNotesSortMethodName(defaultSortMethodName) 132 | return SortNotesBy.valueOf(currentSortMethodName) 133 | } 134 | 135 | private fun getNotePositionById(noteId: Long) = notesList.indexOfFirst { it.id == noteId } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/imangazaliev/notelin/ui/activities/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.imangazaliev.notelin.ui.activities 2 | 3 | import android.os.Bundle 4 | import android.support.v7.widget.SearchView 5 | import android.view.Menu 6 | import android.view.MenuItem 7 | import android.view.View 8 | import android.widget.Toast 9 | import com.afollestad.materialdialogs.MaterialDialog 10 | import com.arellomobile.mvp.MvpAppCompatActivity 11 | import com.arellomobile.mvp.presenter.InjectPresenter 12 | import com.pawegio.kandroid.onQueryChange 13 | import com.imangazaliev.notelin.R 14 | import com.imangazaliev.notelin.mvp.model.Note 15 | import com.imangazaliev.notelin.mvp.presenters.MainPresenter 16 | import com.imangazaliev.notelin.mvp.views.MainView 17 | import com.imangazaliev.notelin.ui.adapters.NotesAdapter 18 | import com.imangazaliev.notelin.ui.commons.ItemClickSupport 19 | import kotlinx.android.synthetic.main.activity_main.* 20 | 21 | class MainActivity : MvpAppCompatActivity(), MainView { 22 | 23 | @InjectPresenter 24 | lateinit var presenter: MainPresenter 25 | private var noteContextDialog: MaterialDialog? = null 26 | private var noteDeleteDialog: MaterialDialog? = null 27 | private var noteInfoDialog: MaterialDialog? = null 28 | 29 | override fun onCreate(savedInstanceState: Bundle?) { 30 | super.onCreate(savedInstanceState) 31 | setContentView(R.layout.activity_main) 32 | 33 | 34 | with(ItemClickSupport.addTo(notesList)) { 35 | setOnItemClickListener { _, position, _ -> presenter.openNote(position) } 36 | setOnItemLongClickListener { _, position, _ -> presenter.showNoteContextDialog(position); true } 37 | } 38 | 39 | newNoteFab.setOnClickListener { presenter.openNewNote() } 40 | } 41 | 42 | override fun onNotesLoaded(notes: List) { 43 | notesList.adapter = NotesAdapter(notes) 44 | updateView() 45 | } 46 | 47 | override fun updateView() { 48 | notesList.adapter.notifyDataSetChanged() 49 | if (notesList.adapter.itemCount == 0) { 50 | notesList.visibility = View.GONE 51 | tvNotesIsEmpty.visibility = View.VISIBLE 52 | } else { 53 | notesList.visibility = View.VISIBLE 54 | tvNotesIsEmpty.visibility = View.GONE 55 | } 56 | } 57 | 58 | override fun onNoteDeleted() { 59 | updateView() 60 | Toast.makeText(this, R.string.note_deleted, Toast.LENGTH_SHORT).show() 61 | } 62 | 63 | override fun onAllNotesDeleted() { 64 | updateView() 65 | Toast.makeText(this, R.string.all_notes_deleted, Toast.LENGTH_SHORT).show() 66 | } 67 | 68 | override fun onSearchResult(notes: List) { 69 | notesList.adapter = NotesAdapter(notes) 70 | } 71 | 72 | override fun showNoteContextDialog(notePosition: Int) { 73 | noteContextDialog = MaterialDialog.Builder(this) 74 | .items(R.array.main_note_context) 75 | .itemsCallback { _, _, position, _ -> 76 | onContextDialogItemClick(position, notePosition) 77 | presenter.hideNoteContextDialog() 78 | } 79 | .cancelListener { presenter.hideNoteContextDialog() } 80 | .show() 81 | } 82 | 83 | override fun hideNoteContextDialog() { 84 | noteContextDialog?.dismiss() 85 | } 86 | 87 | override fun showNoteDeleteDialog(notePosition: Int) { 88 | noteDeleteDialog = MaterialDialog.Builder(this) 89 | .title(getString(R.string.note_deletion_title)) 90 | .content(getString(R.string.note_deletion_message)) 91 | .positiveText(getString(R.string.yes)) 92 | .negativeText(getString(R.string.no)) 93 | .onPositive { _, _ -> 94 | presenter.deleteNoteByPosition(notePosition) 95 | noteInfoDialog?.dismiss() 96 | } 97 | .onNegative { _, _ -> presenter.hideNoteDeleteDialog() } 98 | .cancelListener { presenter.hideNoteDeleteDialog() } 99 | .show() 100 | } 101 | 102 | override fun hideNoteDeleteDialog() { 103 | noteDeleteDialog?.dismiss() 104 | } 105 | 106 | override fun showNoteInfoDialog(noteInfo: String) { 107 | noteInfoDialog = MaterialDialog.Builder(this) 108 | .title(R.string.note_info) 109 | .positiveText(getString(R.string.ok)) 110 | .content(noteInfo) 111 | .onPositive { materialDialog, dialogAction -> presenter.hideNoteInfoDialog() } 112 | .cancelListener { presenter.hideNoteInfoDialog() } 113 | .show() 114 | } 115 | 116 | override fun hideNoteInfoDialog() { 117 | noteInfoDialog?.dismiss() 118 | } 119 | 120 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 121 | menuInflater.inflate(R.menu.main, menu) 122 | 123 | initSearchView(menu) 124 | return true 125 | } 126 | 127 | override fun openNoteScreen(noteId: Long) { 128 | startActivity(NoteActivity.buildIntent(this, noteId)) 129 | } 130 | 131 | private fun initSearchView(menu: Menu) { 132 | val searchViewMenuItem = menu.findItem(R.id.action_search) 133 | val searchView = searchViewMenuItem.actionView as SearchView 134 | searchView.onQueryChange { query -> presenter.search(query) } 135 | searchView.setOnCloseListener { presenter.search(""); false } 136 | } 137 | 138 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 139 | when (item.itemId) { 140 | R.id.menuDeleteAllNotes -> presenter.deleteAllNotes() 141 | R.id.menuSortByName -> presenter.sortNotesBy(MainPresenter.SortNotesBy.NAME) 142 | R.id.menuSortByDate -> presenter.sortNotesBy(MainPresenter.SortNotesBy.DATE) 143 | } 144 | return super.onOptionsItemSelected(item) 145 | } 146 | 147 | private fun onContextDialogItemClick(contextItemPosition: Int, notePosition: Int) { 148 | when (contextItemPosition) { 149 | 0 -> presenter.openNote(notePosition) 150 | 1 -> presenter.showNoteInfo(notePosition) 151 | 2 -> presenter.showNoteDeleteDialog(notePosition) 152 | } 153 | } 154 | 155 | } 156 | --------------------------------------------------------------------------------