commit
aeaa8ed168
@ -6,7 +6,7 @@ apply plugin: 'jacoco'
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.3"
|
||||
compileOptions {
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
@ -44,7 +44,9 @@ dependencies {
|
||||
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
|
||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.16'
|
||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||
|
||||
implementation ("com.github.bumptech.glide:glide:4.11.0") {
|
||||
exclude group: "com.android.support"
|
||||
}
|
||||
testImplementation "com.github.tomakehurst:wiremock-jre8:2.26.2"
|
||||
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
testImplementation 'junit:junit:4.13'
|
||||
@ -73,4 +75,4 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea
|
||||
executionData = fileTree(dir: project.buildDir, includes: [
|
||||
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/debugAndroidTest/connected/*coverage.ec'
|
||||
])
|
||||
}
|
||||
}
|
||||
|
34
app/src/androidTest/java/com/h/pixeldroid/ProfileTest.kt
Normal file
34
app/src/androidTest/java/com/h/pixeldroid/ProfileTest.kt
Normal file
@ -0,0 +1,34 @@
|
||||
package com.h.pixeldroid
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.*
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.hamcrest.Matchers.not
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.lang.Thread.sleep
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ProfileTest {
|
||||
@get:Rule
|
||||
var activityRule: ActivityScenarioRule<MainActivity>
|
||||
= ActivityScenarioRule(MainActivity::class.java)
|
||||
|
||||
@Test
|
||||
fun testFollowersTextView() {
|
||||
onView(withId(R.id.button)).perform(click())
|
||||
onView(withId(R.id.followers)).check(matches(withText("Followers")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAccountNameTextView() {
|
||||
onView(withId(R.id.button)).perform(click())
|
||||
sleep((1000 * 5))
|
||||
onView(withId(R.id.accountName)).check(matches(not(withText("No Username"))))
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".ProfileActivity"></activity>
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -1,22 +1,20 @@
|
||||
package com.h.pixeldroid
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import com.h.pixeldroid.api.PixelfedAPI
|
||||
import com.h.pixeldroid.objects.Status
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
|
||||
val button = findViewById<Button>(R.id.button)
|
||||
button.setOnClickListener((View.OnClickListener {
|
||||
val intent = Intent(this, ProfileActivity::class.java)
|
||||
startActivity(intent) }))
|
||||
}
|
||||
}
|
||||
|
74
app/src/main/java/com/h/pixeldroid/ProfileActivity.kt
Normal file
74
app/src/main/java/com/h/pixeldroid/ProfileActivity.kt
Normal file
@ -0,0 +1,74 @@
|
||||
package com.h.pixeldroid
|
||||
|
||||
import android.graphics.Typeface
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.h.pixeldroid.api.PixelfedAPI
|
||||
import com.h.pixeldroid.objects.Status
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
||||
class ProfileActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_profile)
|
||||
|
||||
var statuses: ArrayList<Status>? = null
|
||||
val BASE_URL = "https://pixelfed.de/"
|
||||
|
||||
val pixelfedAPI = PixelfedAPI.create(BASE_URL)
|
||||
|
||||
|
||||
pixelfedAPI.timelinePublic(null, null, null, null, null)
|
||||
.enqueue(object : Callback<List<Status>> {
|
||||
override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) {
|
||||
if (response.code() == 200) {
|
||||
statuses = response.body() as ArrayList<Status>?
|
||||
|
||||
if(!statuses.isNullOrEmpty()) {
|
||||
|
||||
val account = statuses!![0].account
|
||||
|
||||
// ImageView : profile picture
|
||||
val profilePicture = findViewById<ImageView>(R.id.profilePicture)
|
||||
Glide.with(applicationContext).load(account.avatar).into(profilePicture)
|
||||
|
||||
// TextView : description / bio
|
||||
val description = findViewById<TextView>(R.id.description)
|
||||
description.setText(account.note)
|
||||
|
||||
// TextView : account name
|
||||
val accountName = findViewById<TextView>(R.id.accountName)
|
||||
accountName.setText(account.username)
|
||||
|
||||
// TextView : number of posts
|
||||
val nbPosts = findViewById<TextView>(R.id.nbPosts)
|
||||
nbPosts.text = account.statuses_count.toString()
|
||||
nbPosts.setTypeface(null, Typeface.BOLD)
|
||||
|
||||
// TextView : number of followers
|
||||
val nbFollowers = findViewById<TextView>(R.id.nbFollowers)
|
||||
nbFollowers.text = account.followers_count.toString()
|
||||
nbFollowers.setTypeface(null, Typeface.BOLD)
|
||||
|
||||
// TextView : number of following
|
||||
val nbFollowing = findViewById<TextView>(R.id.nbFollowing)
|
||||
nbFollowing.text = account.following_count.toString()
|
||||
nbFollowing.setTypeface(null, Typeface.BOLD)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<List<Status>>, t: Throwable) {
|
||||
Log.e("Ouch, not OK", t.toString())
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
package com.h.pixeldroid.api
|
||||
|
||||
import android.util.Log
|
||||
import com.h.pixeldroid.objects.*
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
@ -6,13 +6,17 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Show a profile" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
128
app/src/main/res/layout/activity_profile.xml
Normal file
128
app/src/main/res/layout/activity_profile.xml
Normal file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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=".ProfileActivity">
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/profilePicture"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="24dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nbFollowing"
|
||||
android:layout_width="38dp"
|
||||
android:layout_height="26dp"
|
||||
android:layout_marginTop="52dp"
|
||||
android:layout_marginEnd="36dp"
|
||||
android:text="N/A"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/posts"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Posts"
|
||||
app:layout_constraintEnd_toEndOf="@+id/nbPosts"
|
||||
app:layout_constraintStart_toStartOf="@+id/nbPosts"
|
||||
app:layout_constraintTop_toBottomOf="@+id/nbPosts" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nbPosts"
|
||||
android:layout_width="39dp"
|
||||
android:layout_height="27dp"
|
||||
android:layout_marginStart="152dp"
|
||||
android:layout_marginTop="52dp"
|
||||
android:text="N/A"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/followers"
|
||||
android:layout_width="65dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Followers"
|
||||
app:layout_constraintEnd_toEndOf="@+id/nbFollowers"
|
||||
app:layout_constraintStart_toStartOf="@+id/nbFollowers"
|
||||
app:layout_constraintTop_toBottomOf="@+id/nbFollowers" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/following"
|
||||
android:layout_width="65dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Following"
|
||||
app:layout_constraintEnd_toEndOf="@+id/nbFollowing"
|
||||
app:layout_constraintStart_toStartOf="@+id/nbFollowing"
|
||||
app:layout_constraintTop_toBottomOf="@+id/nbFollowing" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nbFollowers"
|
||||
android:layout_width="39dp"
|
||||
android:layout_height="27dp"
|
||||
android:layout_marginTop="52dp"
|
||||
android:text="N/A"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.669"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/accountName"
|
||||
android:layout_width="156dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:text="No Username"
|
||||
app:layout_constraintStart_toStartOf="@+id/profilePicture"
|
||||
app:layout_constraintTop_toBottomOf="@+id/profilePicture" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="348dp"
|
||||
android:layout_height="85dp"
|
||||
android:layout_marginTop="14dp"
|
||||
app:layout_constraintStart_toStartOf="@+id/accountName"
|
||||
app:layout_constraintTop_toBottomOf="@+id/accountName" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/followButton"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="38dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:text="Follow"
|
||||
app:layout_constraintStart_toStartOf="@+id/description"
|
||||
app:layout_constraintTop_toBottomOf="@+id/description" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/postsButton"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_marginStart="152dp"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/followButton"
|
||||
app:srcCompat="@android:drawable/ic_dialog_dialer" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/collectionButton"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_marginStart="4dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toEndOf="@+id/postsButton"
|
||||
app:layout_constraintTop_toTopOf="@+id/postsButton"
|
||||
app:srcCompat="@android:drawable/ic_menu_gallery" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -8,7 +8,7 @@ buildscript {
|
||||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.6.0'
|
||||
classpath 'com.android.tools.build:gradle:3.6.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
Loading…
x
Reference in New Issue
Block a user