-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Exploration Player base code for activity and fragment * Fake Data Provider * Nit changes mainly in documentation * Nit changes mainly in documentation for State too * Changed Controller to Presenter and optimised the fragment transaction code * Basic code for ExporationActivityTest * ExplorationActivity dummy test * Nit changes * Code checking and refactoring in ExplorationActivityTest
- Loading branch information
Showing
14 changed files
with
246 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/oppia/app/player/exploration/ExplorationActivity.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,16 @@ | ||
package org.oppia.app.player.exploration | ||
|
||
import android.os.Bundle | ||
import org.oppia.app.activity.InjectableAppCompatActivity | ||
import javax.inject.Inject | ||
|
||
/** The starting point for exploration. */ | ||
class ExplorationActivity : InjectableAppCompatActivity() { | ||
@Inject lateinit var explorationActivityPresenter: ExplorationActivityPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
activityComponent.inject(this) | ||
explorationActivityPresenter.handleOnCreate() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/org/oppia/app/player/exploration/ExplorationActivityPresenter.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,25 @@ | ||
package org.oppia.app.player.exploration | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import org.oppia.app.R | ||
import org.oppia.app.activity.ActivityScope | ||
import org.oppia.app.home.HomeFragment | ||
import javax.inject.Inject | ||
|
||
/** The controller for [ExplorationActivity]. */ | ||
@ActivityScope | ||
class ExplorationActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { | ||
fun handleOnCreate() { | ||
activity.setContentView(R.layout.exploration_activity) | ||
if (getExplorationFragment() == null) { | ||
activity.supportFragmentManager.beginTransaction().add( | ||
R.id.exploration_fragment_placeholder, | ||
ExplorationFragment() | ||
).commitNow() | ||
} | ||
} | ||
|
||
private fun getExplorationFragment(): ExplorationFragment? { | ||
return activity.supportFragmentManager.findFragmentById(R.id.exploration_fragment_placeholder) as ExplorationFragment? | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/oppia/app/player/exploration/ExplorationFragment.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,23 @@ | ||
package org.oppia.app.player.exploration | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import org.oppia.app.fragment.InjectableFragment | ||
import javax.inject.Inject | ||
|
||
/** Fragment that contains displays single exploration. */ | ||
class ExplorationFragment : InjectableFragment() { | ||
@Inject lateinit var explorationFragmentPresenter: ExplorationFragmentPresenter | ||
|
||
override fun onAttach(context: Context?) { | ||
super.onAttach(context) | ||
fragmentComponent.inject(this) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return explorationFragmentPresenter.handleCreateView(inflater, container) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/org/oppia/app/player/exploration/ExplorationFragmentPresenter.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,19 @@ | ||
package org.oppia.app.player.exploration | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import org.oppia.app.databinding.ExplorationFragmentBinding | ||
import org.oppia.app.fragment.FragmentScope | ||
import javax.inject.Inject | ||
|
||
/** The controller for [ExplorationFragment]. */ | ||
@FragmentScope | ||
class ExplorationFragmentPresenter @Inject constructor( | ||
private val fragment: Fragment | ||
) { | ||
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { | ||
return ExplorationFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false).root | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/oppia/app/player/state/StateFragment.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,23 @@ | ||
package org.oppia.app.player.state | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import org.oppia.app.fragment.InjectableFragment | ||
import javax.inject.Inject | ||
|
||
/** Fragment that represents the current state card of an exploration. */ | ||
class StateFragment : InjectableFragment() { | ||
@Inject lateinit var stateFragmentPresenter: StateFragmentPresenter | ||
|
||
override fun onAttach(context: Context?) { | ||
super.onAttach(context) | ||
fragmentComponent.inject(this) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return stateFragmentPresenter.handleCreateView(inflater, container) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.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,19 @@ | ||
package org.oppia.app.player.state | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import org.oppia.app.databinding.StateFragmentBinding | ||
import org.oppia.app.fragment.FragmentScope | ||
import javax.inject.Inject | ||
|
||
/** The controller for [StateFragment]. */ | ||
@FragmentScope | ||
class StateFragmentPresenter @Inject constructor( | ||
private val fragment: Fragment | ||
) { | ||
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { | ||
return StateFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false).root | ||
} | ||
} |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/exploration_fragment_placeholder" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".player.exploration.ExplorationActivity" /> |
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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/dummy_text_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="This is dummy TextView for testing" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
74 changes: 74 additions & 0 deletions
74
app/src/sharedTest/java/org/oppia/app/player/exploration/ExplorationActivityTest.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,74 @@ | ||
package org.oppia.app.player.exploration | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.os.Handler | ||
import android.os.Looper | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.IdlingRegistry | ||
import androidx.test.espresso.assertion.ViewAssertions | ||
import androidx.test.espresso.idling.CountingIdlingResource | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import dagger.BindsInstance | ||
import dagger.Component | ||
import dagger.Module | ||
import dagger.Provides | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.asCoroutineDispatcher | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.oppia.app.R | ||
import org.oppia.util.threading.BackgroundDispatcher | ||
import org.oppia.util.threading.BlockingDispatcher | ||
import java.util.concurrent.AbstractExecutorService | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Singleton | ||
|
||
/** Tests for [ExplorationActivity]. */ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExplorationActivityTest { | ||
|
||
@Test | ||
fun testExplorationActivity_loadExplorationFragment_hasDummyString() { | ||
ActivityScenario.launch(ExplorationActivity::class.java).use { | ||
Espresso.onView(ViewMatchers.withId(R.id.dummy_text_view)) | ||
.check(ViewAssertions.matches(ViewMatchers.withText("This is dummy TextView for testing"))) | ||
} | ||
} | ||
|
||
@Module | ||
class TestModule { | ||
@Provides | ||
@Singleton | ||
fun provideContext(application: Application): Context { | ||
return application | ||
} | ||
|
||
// TODO(#89): Introduce a proper IdlingResource for background dispatchers to ensure they all complete before | ||
// proceeding in an Espresso test. This solution should also be interoperative with Robolectric contexts by using a | ||
// test coroutine dispatcher. | ||
|
||
@Singleton | ||
@Provides | ||
@BackgroundDispatcher | ||
fun provideBackgroundDispatcher(@BlockingDispatcher blockingDispatcher: CoroutineDispatcher): CoroutineDispatcher { | ||
return blockingDispatcher | ||
} | ||
} | ||
|
||
@Singleton | ||
@Component(modules = [TestModule::class]) | ||
interface TestApplicationComponent { | ||
@Component.Builder | ||
interface Builder { | ||
@BindsInstance | ||
fun setApplication(application: Application): Builder | ||
|
||
fun build(): TestApplicationComponent | ||
} | ||
} | ||
} |