aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2018-09-13 22:09:17 +0200
committerMarvin Borner2018-09-13 22:09:17 +0200
commit85509c84cfb00830d56185c2d7bc1fb0357be944 (patch)
tree5ec7c7527efcd4c060a961e20e3ea6ea4892925f
parentdb6887daf259f7d919493223002784ddd739249e (diff)
Added better post layout :lipstick: :sparkles:
-rw-r--r--app/src/main/java/me/texx/Texx/MainActivity.kt32
-rw-r--r--app/src/main/res/drawable/btn_comment.xml10
-rw-r--r--app/src/main/res/drawable/btn_like.xml10
-rw-r--r--app/src/main/res/drawable/btn_share.xml10
-rw-r--r--app/src/main/res/layout/content_main.xml30
-rw-r--r--app/src/main/res/layout/template_text_post.xml97
-rw-r--r--app/src/main/res/values/launcher_background.xml (renamed from app/src/main/res/values/ic_launcher_background.xml)0
-rw-r--r--app/src/main/res/values/strings.xml1
8 files changed, 173 insertions, 17 deletions
diff --git a/app/src/main/java/me/texx/Texx/MainActivity.kt b/app/src/main/java/me/texx/Texx/MainActivity.kt
index 337ec75..59f0fe0 100644
--- a/app/src/main/java/me/texx/Texx/MainActivity.kt
+++ b/app/src/main/java/me/texx/Texx/MainActivity.kt
@@ -3,9 +3,9 @@ package me.texx.Texx
import android.os.Bundle
import android.os.StrictMode
import android.support.v7.app.AppCompatActivity
+import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
-import android.view.ViewGroup
import android.widget.TextView
import com.github.kittinunf.fuel.android.extension.responseJson
import com.github.kittinunf.fuel.httpGet
@@ -86,7 +86,7 @@ class MainActivity : AppCompatActivity() {
private fun getPosts(): JSONObject? {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy)
- val (_, _, result) = "/posts".httpGet().responseJson()
+ val (_, _, result) = "/posts?includes[]=user".httpGet().responseJson()
val (data, error) = result
return if (error == null) {
data?.obj()
@@ -107,13 +107,21 @@ class MainActivity : AppCompatActivity() {
when (postType) {
"Text" -> {
- val text: String = (postObject.get("post") as JSONObject).get("text").toString()
- val padding = calculatePadding()
- val textView = TextView(this)
- textView.text = text
- textView.setPadding(padding, padding, padding, padding)
- textView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
- post_list.addView(textView)
+ val postTemplate = LayoutInflater.from(this).inflate(R.layout.template_text_post, null)
+
+ val postComposer: String = (postObject.get("user") as JSONObject).get("name").toString()
+ val postComposerTextView: TextView = postTemplate.findViewById(R.id.text_post_composer)
+ postComposerTextView.text = postComposer
+
+ val postDate: String = postObject.get("created_at").toString()
+ val postDateTextView: TextView = postTemplate.findViewById(R.id.text_post_date)
+ postDateTextView.text = postDate
+
+ val postContent: String = (postObject.get("post") as JSONObject).get("text").toString()
+ val postContentTextView: TextView = postTemplate.findViewById(R.id.text_post_content)
+ postContentTextView.text = postContent
+
+ post_list.addView(postTemplate)
}
"Media" -> {
@@ -122,10 +130,4 @@ class MainActivity : AppCompatActivity() {
}
}
}
-
- private fun calculatePadding(): Int {
- val paddingDp = 16
- val screenDensity = this.resources.displayMetrics.density
- return (paddingDp * screenDensity).toInt()
- }
} \ No newline at end of file
diff --git a/app/src/main/res/drawable/btn_comment.xml b/app/src/main/res/drawable/btn_comment.xml
new file mode 100644
index 0000000..c799ead
--- /dev/null
+++ b/app/src/main/res/drawable/btn_comment.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="#1A1A1A"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M20,2L4,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h14l4,4L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z" />
+</vector>
diff --git a/app/src/main/res/drawable/btn_like.xml b/app/src/main/res/drawable/btn_like.xml
new file mode 100644
index 0000000..38b3e44
--- /dev/null
+++ b/app/src/main/res/drawable/btn_like.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="#1A1A1A"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z" />
+</vector>
diff --git a/app/src/main/res/drawable/btn_share.xml b/app/src/main/res/drawable/btn_share.xml
new file mode 100644
index 0000000..ba36bd4
--- /dev/null
+++ b/app/src/main/res/drawable/btn_share.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="#1A1A1A"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
+</vector>
diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml
index c892763..7c7ef1e 100644
--- a/app/src/main/res/layout/content_main.xml
+++ b/app/src/main/res/layout/content_main.xml
@@ -16,10 +16,36 @@
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
- android:id="@+id/post_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical" />
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:id="@+id/compose_post"
+ android:layout_width="match_parent"
+ android:layout_height="124dp"
+ android:layout_marginBottom="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginStart="16dp"
+ android:layout_marginTop="16dp"
+ android:orientation="vertical">
+
+ <EditText
+ android:id="@+id/text_post_compose"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10"
+ android:hint="@string/text_post_compose_hint"
+ android:inputType="textMultiLine" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/post_list"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"></LinearLayout>
+ </LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/template_text_post.xml b/app/src/main/res/layout/template_text_post.xml
new file mode 100644
index 0000000..a56683c
--- /dev/null
+++ b/app/src/main/res/layout/template_text_post.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/post_template"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginStart="16dp"
+ android:layout_marginTop="16dp"
+ android:background="@android:color/background_light">
+
+ <TextView
+ android:id="@+id/text_post_composer"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:layout_marginTop="8dp"
+ android:text="Text missing."
+ android:textColor="@android:color/darker_gray"
+ android:textSize="16sp"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <TextView
+ android:id="@+id/text_post_date"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="8dp"
+ android:layout_marginTop="8dp"
+ android:text="Text missing."
+ android:textColor="@android:color/darker_gray"
+ android:textSize="12sp"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/text_post_composer" />
+
+ <Button
+ android:id="@+id/button_share"
+ android:layout_width="30dp"
+ android:layout_height="30dp"
+ android:layout_margin="16dp"
+ android:layout_marginBottom="8dp"
+ android:layout_marginEnd="16dp"
+ android:layout_marginTop="16dp"
+ android:background="@drawable/btn_share"
+ app:layout_constraintBottom_toTopOf="@+id/text_post_content"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <Button
+ android:id="@+id/button_comment"
+ android:layout_width="30dp"
+ android:layout_height="30dp"
+ android:layout_margin="16dp"
+ android:layout_marginBottom="8dp"
+ android:layout_marginEnd="32dp"
+ android:background="@drawable/btn_comment"
+ app:layout_constraintBottom_toTopOf="@+id/text_post_content"
+ app:layout_constraintEnd_toStartOf="@+id/button_share" />
+
+ <Button
+ android:id="@+id/button_like"
+ android:layout_width="30dp"
+ android:layout_height="30dp"
+ android:layout_marginBottom="16dp"
+ android:layout_marginEnd="16dp"
+ android:background="@drawable/btn_like"
+ app:layout_constraintBottom_toTopOf="@+id/text_post_content"
+ app:layout_constraintEnd_toStartOf="@+id/button_comment" />
+
+ <TextView
+ android:id="@+id/text_post_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="8dp"
+ android:layout_marginStart="8dp"
+ android:layout_marginTop="8dp"
+ android:text="Text missing."
+ android:textColor="@android:color/darker_gray"
+ android:textSize="16sp"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/text_post_date" />
+
+ </android.support.constraint.ConstraintLayout>
+
+ </LinearLayout>
+</LinearLayout>
diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/launcher_background.xml
index 23d3c2c..23d3c2c 100644
--- a/app/src/main/res/values/ic_launcher_background.xml
+++ b/app/src/main/res/values/launcher_background.xml
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index df13742..496c715 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -37,6 +37,7 @@
<string name="bug_report_edit_title_hint">Title</string>
<string name="bug_report_edit_description">Describe your issue</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
+ <string name="text_post_compose_hint">What\'s happening?</string>
<!--<string name="pref_title_add_friends_to_messages">Add friends to messages</string>
<string-array name="pref_example_list_titles">