-
Notifications
You must be signed in to change notification settings - Fork 1
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
mercuriete
committed
Dec 4, 2018
1 parent
3be35ff
commit 4e65ec6
Showing
16 changed files
with
192 additions
and
71 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
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
28 changes: 28 additions & 0 deletions
28
app/src/main/java/org/mercuriete/musiciantools/MainActivity.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,28 @@ | ||
package org.mercuriete.musiciantools | ||
|
||
import android.os.Bundle | ||
import dagger.android.support.DaggerAppCompatActivity | ||
import org.mercuriete.musiciantools.bpmcalculator.BPMCalculatorFragment | ||
import org.mercuriete.musiciantools.di.ActivityScoped | ||
import org.mercuriete.musiciantools.util.replaceFragmentInActivity | ||
import javax.inject.Inject | ||
|
||
class MainActivity : DaggerAppCompatActivity() { | ||
|
||
@Inject | ||
lateinit var injectedFragment: BPMCalculatorFragment | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(R.layout.main_activity) | ||
|
||
|
||
val bpmCalculatorFragment = supportFragmentManager.findFragmentById(R.id.content) | ||
as BPMCalculatorFragment? ?: injectedFragment.also { | ||
replaceFragmentInActivity(it, R.id.content) | ||
} | ||
|
||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
app/src/main/java/org/mercuriete/musiciantools/bpmcalculator/BPMCalculatorActivity.kt
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
app/src/main/java/org/mercuriete/musiciantools/bpmcalculator/BPMCalculatorFragment.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,45 @@ | ||
package org.mercuriete.musiciantools.bpmcalculator | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import dagger.android.support.DaggerFragment | ||
import kotlinx.android.synthetic.main.bpm_calculator_fragment.* | ||
import org.mercuriete.musiciantools.R | ||
import javax.inject.Inject | ||
|
||
|
||
class BPMCalculatorFragment @Inject constructor() : DaggerFragment(), BPMCalculatorContract.View { | ||
|
||
@Inject | ||
lateinit var presenter: BPMCalculatorContract.Presenter | ||
|
||
override fun showBPM(bpm: String) { | ||
bpmText.text = bpm | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.bpm_calculator_fragment, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
button.setOnClickListener { | ||
presenter.addBeat() | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
presenter.takeView(this) | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
presenter.dropView() //prevent leaking activity in | ||
// case presenter is orchestrating a long running task | ||
} | ||
|
||
} |
30 changes: 20 additions & 10 deletions
30
app/src/main/java/org/mercuriete/musiciantools/bpmcalculator/BPMCalculatorModule.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 |
---|---|---|
@@ -1,21 +1,31 @@ | ||
package org.mercuriete.musiciantools.bpmcalculator | ||
|
||
import dagger.Provides | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.android.ContributesAndroidInjector | ||
import org.mercuriete.musiciantools.di.ActivityScoped | ||
import org.mercuriete.musiciantools.di.FragmentScoped | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
class BPMCalculatorModule { | ||
abstract class BPMCalculatorModule { | ||
|
||
@Provides | ||
fun bpmCalculatorServiceProvider(): BPMCalculatorService { | ||
return BPMCalculatorServiceImpl() | ||
} | ||
@Module | ||
companion object { | ||
@JvmStatic | ||
@Provides | ||
fun bpmCalculatorServiceProvider(): BPMCalculatorService { | ||
return BPMCalculatorServiceImpl() | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun bpmCalculatorPresenterProvider(bpmCalculatorService: BPMCalculatorService): BPMCalculatorContract.Presenter { | ||
return BPMCalculatorPresenter(bpmCalculatorService) | ||
@JvmStatic | ||
@Provides | ||
fun bpmCalculatorPresenterProvider(bpmCalculatorService: BPMCalculatorService): BPMCalculatorContract.Presenter { | ||
return BPMCalculatorPresenter(bpmCalculatorService) | ||
} | ||
} | ||
|
||
@ContributesAndroidInjector | ||
abstract fun bpmCalculatorFragment(): BPMCalculatorFragment | ||
} |
10 changes: 2 additions & 8 deletions
10
app/src/main/java/org/mercuriete/musiciantools/bpmcalculator/BPMCalculatorPresenter.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
2 changes: 2 additions & 0 deletions
2
app/src/main/java/org/mercuriete/musiciantools/bpmcalculator/BPMCalculatorServiceImpl.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
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
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
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/mercuriete/musiciantools/di/FragmentScoped.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,7 @@ | ||
package org.mercuriete.musiciantools.di | ||
|
||
import javax.inject.Scope | ||
|
||
@Scope | ||
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME) | ||
annotation class FragmentScoped |
60 changes: 60 additions & 0 deletions
60
app/src/main/java/org/mercuriete/musiciantools/util/AppCompatActivityExt.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,60 @@ | ||
/* | ||
* Copyright (C) 2017 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.mercuriete.musiciantools.util | ||
|
||
|
||
import android.support.annotation.IdRes | ||
import android.support.v4.app.Fragment | ||
import android.support.v4.app.FragmentManager | ||
import android.support.v4.app.FragmentTransaction | ||
import android.support.v7.app.ActionBar | ||
import android.support.v7.app.AppCompatActivity | ||
|
||
/** | ||
* The `fragment` is added to the container view with id `frameId`. The operation is | ||
* performed by the `fragmentManager`. | ||
*/ | ||
fun AppCompatActivity.replaceFragmentInActivity(fragment: Fragment, @IdRes frameId: Int) { | ||
supportFragmentManager.transact { | ||
replace(frameId, fragment) | ||
} | ||
} | ||
|
||
/** | ||
* The `fragment` is added to the container view with tag. The operation is | ||
* performed by the `fragmentManager`. | ||
*/ | ||
fun AppCompatActivity.addFragmentToActivity(fragment: Fragment, tag: String) { | ||
supportFragmentManager.transact { | ||
add(fragment, tag) | ||
} | ||
} | ||
|
||
fun AppCompatActivity.setupActionBar(@IdRes toolbarId: Int, action: ActionBar.() -> Unit) { | ||
setSupportActionBar(findViewById(toolbarId)) | ||
supportActionBar?.run { | ||
action() | ||
} | ||
} | ||
|
||
/** | ||
* Runs a FragmentTransaction, then calls commit(). | ||
*/ | ||
private inline fun FragmentManager.transact(action: FragmentTransaction.() -> Unit) { | ||
beginTransaction().apply { | ||
action() | ||
}.commit() | ||
} |
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
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
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