1
0
mirror of https://gitlab.shinice.net/pixeldroid/PixelDroid synced 2024-12-23 13:33:36 +01:00

First draft of the profile page

This commit is contained in:
mjaillot 2020-03-04 19:32:41 +01:00
parent aa788f9720
commit 3f508b3a27
5 changed files with 251 additions and 1 deletions

View File

@ -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" />

View File

@ -1,8 +1,11 @@
package com.h.pixeldroid
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import com.h.pixeldroid.api.PixelfedAPI
import com.h.pixeldroid.objects.Status
import retrofit2.Call
@ -17,6 +20,11 @@ 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) }))
}
}

View File

@ -0,0 +1,104 @@
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.h.pixeldroid.api.PixelfedAPI
import com.h.pixeldroid.objects.Account
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()) {
// ImageView : profile picture
val profilePicture = findViewById<ImageView>(R.id.profilePicture)
//profilePicture.setImageBitmap()
// TODO : set profile picture from URL => profilePicture.setSomething(account.avatar)
// TextView : description / bio
val description = findViewById<TextView>(R.id.description)
description.setText("")
// TextView : account name
val accountName = findViewById<TextView>(R.id.accountName)
accountName.setText("No Name")
// TextView : number of posts
val nbPosts = findViewById<TextView>(R.id.nbPosts)
nbPosts.setText(0)
nbPosts.setTypeface(null, Typeface.BOLD)
// TextView : number of followers
val nbFollowers = findViewById<TextView>(R.id.nbFollowers)
nbFollowers.setText(0)
nbFollowers.setTypeface(null, Typeface.BOLD)
// TextView : number of following
val nbFollowing = findViewById<TextView>(R.id.nbFollowing)
nbFollowing.setText(0)
nbFollowing.setTypeface(null, Typeface.BOLD)
} else {
val account = statuses!![0].account
// ImageView : profile picture
val profilePicture = findViewById<ImageView>(R.id.profilePicture)
//profilePicture.setImageBitmap()
// TODO : set profile picture from URL => profilePicture.setSomething(account.avatar)
// 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())
}
})
}
}

View File

@ -15,4 +15,12 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="169dp"
tools:layout_editor_absoluteY="432dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,129 @@
<?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="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_launcher_foreground" />
<TextView
android:id="@+id/nbFollowing"
android:layout_width="38dp"
android:layout_height="26dp"
android:layout_marginTop="52dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.483"
app:layout_constraintStart_toEndOf="@+id/nbFollowers"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/posts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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="35dp"
android:layout_marginTop="52dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/profilePicture"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/followers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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="wrap_content"
android:layout_height="wrap_content"
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_marginStart="38dp"
android:layout_marginTop="52dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/nbPosts"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/accountName"
android:layout_width="156dp"
android:layout_height="22dp"
android:layout_marginTop="15dp"
android:text="Name"
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"
android:text="Description"
app:layout_constraintStart_toStartOf="@+id/accountName"
app:layout_constraintTop_toBottomOf="@+id/accountName" />
<Button
android:id="@+id/followButton"
android:layout_width="153dp"
android:layout_height="41dp"
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>