Skip to content

Commit

Permalink
Update demo app UI
Browse files Browse the repository at this point in the history
  • Loading branch information
David Blanc committed Jul 16, 2019
1 parent 0f6a5c6 commit e2eea39
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 103 deletions.
10 changes: 5 additions & 5 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ apply plugin: 'kotlin-android-extensions'


android {
compileSdkVersion 28
compileSdkVersion 29
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "fr.speekha.httpmocker.demo"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -62,9 +62,9 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

implementation "androidx.appcompat:appcompat:$support_version"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation "com.google.android.material:material:1.1.0-alpha08"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha08'

implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-jackson:$retrofit_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import androidx.annotation.IntegerRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -85,7 +86,7 @@ class MainActivity : AppCompatActivity(), MainContract.View {
}
}

override fun updateStorageLabel(enabled: Boolean) {
tvDirectory.isEnabled = enabled
override fun updateDescriptionLabel(@IntegerRes resId: Int) {
tvMessage.setText(resId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package fr.speekha.httpmocker.demo.ui

import androidx.annotation.IntegerRes
import fr.speekha.httpmocker.MockResponseInterceptor
import fr.speekha.httpmocker.demo.model.Repo

Expand All @@ -25,7 +26,7 @@ interface MainContract {
fun setResult(result: List<Repo>)
fun setError(message: String?)
fun checkPermission()
fun updateStorageLabel(enabled: Boolean)
fun updateDescriptionLabel(@IntegerRes resId: Int)
}

interface Presenter {
Expand Down
31 changes: 22 additions & 9 deletions demo/src/main/java/fr/speekha/httpmocker/demo/ui/MainPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ package fr.speekha.httpmocker.demo.ui

import android.util.Log
import fr.speekha.httpmocker.MockResponseInterceptor
import fr.speekha.httpmocker.demo.R
import fr.speekha.httpmocker.demo.service.GithubApiEndpoints
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext


class MainPresenter(
Expand Down Expand Up @@ -48,21 +53,29 @@ class MainPresenter(
apiService.listRepositoriesForOrganisation(org)
}

private suspend fun loadTopContributor(org: String, repo: String) = withContext(Dispatchers.IO) {
try {
apiService.listContributorsForRepository(org, repo)
} catch (e: Throwable) {
Log.e("Presenter", e.message, e)
null
private suspend fun loadTopContributor(org: String, repo: String) =
withContext(Dispatchers.IO) {
try {
apiService.listContributorsForRepository(org, repo)
} catch (e: Throwable) {
Log.e("Presenter", e.message, e)
null
}
}
}

override fun setMode(mode: MockResponseInterceptor.Mode) {
mocker.mode = mode
if (mocker.mode == MockResponseInterceptor.Mode.RECORD) {
view.checkPermission()
}
view.updateStorageLabel(mocker.mode == MockResponseInterceptor.Mode.RECORD)
view.updateDescriptionLabel(
when (mocker.mode) {
MockResponseInterceptor.Mode.DISABLED -> R.string.disabled_description
MockResponseInterceptor.Mode.ENABLED -> R.string.enabled_description
MockResponseInterceptor.Mode.MIXED -> R.string.mixed_description
MockResponseInterceptor.Mode.RECORD -> R.string.record_description
}
)
}

override fun stop() {
Expand Down
158 changes: 73 additions & 85 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,108 +14,96 @@
~ limitations under the License.
-->

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">

<TextView
android:id="@+id/tvState"
style="?textAppearanceSubtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="@string/mocking_state"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
android:id="@+id/tvState"
style="?textAppearanceSubtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="@string/mocking_state"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/radioState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:checkedButton="@id/stateDisabled"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvState"
app:singleSelection="true"
>

<com.google.android.material.button.MaterialButton
android:id="@+id/stateDisabled"
style="?materialButtonOutlinedStyle"
android:id="@+id/radioState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_disabled"
/>
android:layout_marginTop="8dp"
app:checkedButton="@id/stateDisabled"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvState"
app:singleSelection="true">

<com.google.android.material.button.MaterialButton
android:id="@+id/stateEnabled"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_enabled"
/>
android:id="@+id/stateDisabled"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_disabled" />

<com.google.android.material.button.MaterialButton
android:id="@+id/stateMixed"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_mixed"
/>
android:id="@+id/stateEnabled"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_enabled" />

<com.google.android.material.button.MaterialButton
android:id="@+id/stateRecord"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_record"
/>
android:id="@+id/stateMixed"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_mixed" />

<com.google.android.material.button.MaterialButton
android:id="@+id/stateRecord"
style="?materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/state_record" />
</com.google.android.material.button.MaterialButtonToggleGroup>

<TextView
android:id="@+id/tvDirectory"
style="?textAppearanceSubtitle1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:enabled="false"
android:text="@string/download_directory_info"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioState"
/>
android:id="@+id/tvMessage"
style="?textAppearanceSubtitle1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/disabled_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioState" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btnCall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/call_service_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvDirectory"
/>
android:id="@+id/btnCall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/call_service_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvMessage" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/results"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnCall"
/>
android:id="@+id/results"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnCall" />
</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 4 additions & 1 deletion demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<string name="state_enabled">Enabled</string>
<string name="state_mixed">Mixed</string>
<string name="state_record">Record</string>
<string name="download_directory_info">Saving in device\'s Download directory</string>
<string name="disabled_description">Interceptor is disabled. Network calls can go through (complete repo list and details).</string>
<string name="enabled_description">Network calls are intercepted. List call with titles is mocked (shortened list), details are not (details are in error).</string>
<string name="mixed_description">Interceptor is in mixed mode. List call with titles is mocked (shortened list), details are retrieved from a real call.</string>
<string name="record_description">Calls are recorded in the device\'s Download directory</string>
<string name="call_service_button">Call service</string>
</resources>

0 comments on commit e2eea39

Please sign in to comment.