Skip to content

Commit

Permalink
Merge pull request #9 from physphil/feature/GH-8_replace_butterknife_ktx
Browse files Browse the repository at this point in the history
Feature/gh 8 replace butterknife ktx
  • Loading branch information
physphil authored Nov 25, 2018
2 parents 4dcf752 + 091abc8 commit 37e4bce
Show file tree
Hide file tree
Showing 39 changed files with 272 additions and 354 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/.idea/workspace.xml
/.idea/vcs.xml
/.idea/libraries
/.idea/markdown-navigator.xml
/.idea/markdown-navigator
/.idea/caches
.DS_Store
/build
/captures
Expand Down
40 changes: 19 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "com.physphil.android.remindme"
minSdkVersion 21
targetSdkVersion 27
versionCode 9030
versionName "0.9.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
targetSdkVersion 28
versionCode 9040
versionName "0.9.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -32,33 +32,31 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'android.arch.lifecycle:extensions:1.1.0'
kapt 'android.arch.lifecycle:compiler:1.1.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
kapt 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.persistence.room:rxjava2:1.0.0'
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0'
implementation 'androidx.room:room-runtime:2.0.0'
kapt 'androidx.room:room-compiler:2.0.0'
implementation 'androidx.room:room-rxjava2:2.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'

implementation 'com.evernote:android-job:1.2.1'
implementation 'com.jakewharton:butterknife:8.8.1'
kapt 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.google.dagger:dagger:2.14.1'
kapt 'com.google.dagger:dagger-compiler:2.14.1'

debugImplementation 'com.facebook.stetho:stetho:1.5.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.15.0'
testImplementation 'android.arch.core:core-testing:1.1.0'
testImplementation 'android.arch.persistence.room:testing:1.0.0'
testImplementation 'androidx.arch.core:core-testing:2.0.0'
testImplementation 'androidx.room:room-testing:2.1.0-alpha02'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'android.arch.core:core-testing:1.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.arch.core:core-testing:2.0.0'
}

apply plugin: 'kotlin-android-extensions'
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.physphil.android.remindme

import android.arch.core.executor.testing.InstantTaskExecutorRule
import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.room.Room
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import com.physphil.android.remindme.room.AppDatabase
import com.physphil.android.remindme.room.ReminderDao
import com.physphil.android.remindme.room.entities.Reminder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.physphil.android.remindme

import android.support.annotation.StringRes
import android.support.v7.app.AppCompatActivity
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import android.view.MenuItem

/**
Expand Down
52 changes: 16 additions & 36 deletions app/src/main/java/com/physphil/android/remindme/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@ package com.physphil.android.remindme

import android.app.NotificationChannel
import android.app.NotificationManager
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.content.Context
import android.graphics.drawable.InsetDrawable
import android.os.Build
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import butterknife.BindView
import butterknife.ButterKnife
import butterknife.OnClick
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import com.physphil.android.remindme.reminders.ReminderActivity
import com.physphil.android.remindme.reminders.list.DeleteAllDialogFragment
import com.physphil.android.remindme.reminders.list.DeleteReminderDialogFragment
import com.physphil.android.remindme.reminders.list.ReminderListAdapter
import com.physphil.android.remindme.room.entities.Reminder
import com.physphil.android.remindme.ui.ProgressSpinner
import com.physphil.android.remindme.ui.ReminderListDivider
import com.physphil.android.remindme.util.setVisibility
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.*
import javax.inject.Inject

class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClickListener,
Expand All @@ -38,18 +32,6 @@ class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClic
@Inject
lateinit var viewModelFactory: MainActivityViewModelFactory

@BindView(R.id.reminder_list_recyclerview)
lateinit var recyclerView: RecyclerView

@BindView(R.id.reminder_list_fab)
lateinit var fab: FloatingActionButton

@BindView(R.id.reminder_list_spinner)
lateinit var spinner: ProgressSpinner

@BindView(R.id.reminder_list_empty)
lateinit var empty: TextView

private val disposables = CompositeDisposable()
private val adapter = ReminderListAdapter()
private val viewModel: MainActivityViewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(MainActivityViewModel::class.java) }
Expand All @@ -59,7 +41,6 @@ class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClic
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
(application as RemindMeApplication).applicationComponent.inject(this)
ButterKnife.bind(this)
setupRecyclerview()

// Create required notification channel on Android 8.0+
Expand All @@ -69,6 +50,10 @@ class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClic
}

bindViewModel()

reminderListFabView.setOnClickListener {
startActivity(ReminderActivity.intent(this))
}
}

override fun onDestroy() {
Expand All @@ -78,14 +63,14 @@ class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClic

private fun setupRecyclerview() {
adapter.setOnClickListener(this)
recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.itemAnimator = DefaultItemAnimator()
reminderListRecyclerView.adapter = adapter
reminderListRecyclerView.layoutManager = LinearLayoutManager(this)
reminderListRecyclerView.itemAnimator = DefaultItemAnimator()

// Setup list divider
val inset = resources.getDimensionPixelSize(R.dimen.reminder_divider_margin)
val divider = ReminderListDivider(InsetDrawable(getDrawable(R.drawable.divider), inset, 0, inset, 0))
recyclerView.addItemDecoration(divider)
reminderListRecyclerView.addItemDecoration(divider)

// Setup random list header
val headers = resources.getStringArray(R.array.reminder_list_headers)
Expand All @@ -106,17 +91,12 @@ class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClic
// onNext
adapter.setReminderList(it)
viewModel.reminderListUpdated(it)
fab.show() // make sure the fab is always showing when the list is updated
reminderListFabView.show() // make sure the fab is always showing when the list is updated
}, {
// onError
}))
}

@OnClick(R.id.reminder_list_fab)
fun onAddReminderClick() {
startActivity(ReminderActivity.intent(this))
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.menu_main, menu)
Expand All @@ -135,11 +115,11 @@ class MainActivity : BaseActivity(), ReminderListAdapter.ReminderListAdapterClic

// region ViewModel observers
private val spinnerVisibilityObserver = Observer<Boolean> {
it?.let { spinner.setVisibility(it) }
it?.let { reminderListSpinnerView.setVisibility(it) }
}

private val emptyVisibilityObserver = Observer<Boolean> {
it?.let { empty.setVisibility(it) }
it?.let { reminderListEmptyView.setVisibility(it) }
}

private val deleteNotificationsObserver = Observer<Int?> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.physphil.android.remindme

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.physphil.android.remindme.data.ReminderRepo
import com.physphil.android.remindme.job.JobRequestScheduler
import com.physphil.android.remindme.room.entities.Reminder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.physphil.android.remindme

import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.physphil.android.remindme.data.ReminderRepo
import com.physphil.android.remindme.job.JobRequestScheduler

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.physphil.android.remindme.inject

import android.arch.persistence.room.Room
import androidx.room.Room
import android.content.Context
import com.physphil.android.remindme.DATABASE_NAME
import com.physphil.android.remindme.MainActivityViewModelFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.support.v4.app.NotificationCompat
import android.support.v4.app.TaskStackBuilder
import android.support.v4.content.ContextCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
import androidx.core.content.ContextCompat
import com.evernote.android.job.Job
import com.physphil.android.remindme.CHANNEL_NOTIFICATIONS
import com.physphil.android.remindme.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.physphil.android.remindme.reminders
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.appcompat.app.AlertDialog
import com.physphil.android.remindme.R
import com.physphil.android.remindme.models.Recurrence

Expand Down
Loading

0 comments on commit 37e4bce

Please sign in to comment.