diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png
deleted file mode 100644
index f767bd1..0000000
Binary files a/app/src/main/ic_launcher-playstore.png and /dev/null differ
diff --git a/app/src/main/java/com/example/allyoucantweet/ui/MainActivity.kt b/app/src/main/java/com/example/allyoucantweet/ui/MainActivity.kt
index b10e852..c4e2b44 100644
--- a/app/src/main/java/com/example/allyoucantweet/ui/MainActivity.kt
+++ b/app/src/main/java/com/example/allyoucantweet/ui/MainActivity.kt
@@ -3,12 +3,14 @@ package com.example.allyoucantweet.ui
import android.os.Bundle
import android.util.Log
import android.view.animation.AlphaAnimation
-import android.view.animation.Animation
import android.view.animation.DecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
import com.example.allyoucantweet.R
import com.example.allyoucantweet.databinding.ActivityMainBinding
import com.example.allyoucantweet.network.service.AYCTService
+import com.example.allyoucantweet.utils.empty
+import com.example.allyoucantweet.utils.gone
+import com.example.allyoucantweet.utils.show
import com.google.gson.GsonBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
@@ -35,27 +37,45 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
+
+ binding.retry.setOnClickListener {
+ it.gone()
+ binding.hello.gone()
+ getHelloMessage()
+ }
}
override fun onResume() {
super.onResume()
- CoroutineScope(IO).launch {
- try {
- val hello = service.getHello()
- Log.d("AYCT", "hello: $hello")
- runOnUiThread {
- binding.hello.apply {
- text = hello
- val fadeIn: Animation = AlphaAnimation(0f, 1f).apply {
- interpolator = DecelerateInterpolator()
- duration = 1500
- }
- animation = fadeIn
- }
+ getHelloMessage()
+ }
+
+ private fun getHelloMessage() = CoroutineScope(IO).launch {
+ runOnUiThread {
+ binding.progressCircular.show()
+ binding.retry.gone()
+ }
+ var message = String.empty()
+ try {
+ message = service.getHello()
+ } catch (e: Exception) {
+ message = getString(R.string.sth_went_wrong)
+ runOnUiThread { binding.retry.show() }
+ Log.d("AYCT", "error message: ${e.message}")
+ } finally {
+ runOnUiThread {
+ binding.hello.show()
+ binding.progressCircular.gone()
+ binding.hello.apply {
+ text = message
+ animation = this@MainActivity.getAnimation()
}
- } catch (e: Exception) {
- Log.d("AYCT", "error message: ${e.message}")
}
}
}
+
+ private fun getAnimation() = AlphaAnimation(0f, 1f).apply {
+ interpolator = DecelerateInterpolator()
+ duration = 1500
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/allyoucantweet/utils/Extensions.kt b/app/src/main/java/com/example/allyoucantweet/utils/Extensions.kt
new file mode 100644
index 0000000..cb13715
--- /dev/null
+++ b/app/src/main/java/com/example/allyoucantweet/utils/Extensions.kt
@@ -0,0 +1,13 @@
+package com.example.allyoucantweet.utils
+
+import android.view.View
+
+fun View.show() = this.apply {
+ visibility = View.VISIBLE
+}
+
+fun View.gone() = this.apply {
+ visibility = View.GONE
+}
+
+fun String.Companion.empty() = ""
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_sync.xml b/app/src/main/res/drawable/ic_sync.xml
new file mode 100644
index 0000000..f16a1b0
--- /dev/null
+++ b/app/src/main/res/drawable/ic_sync.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 2ec0d62..5271fc1 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -5,27 +5,53 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/brand"
+ android:padding="@dimen/app_margin"
tools:context=".ui.MainActivity">
-
+
+
+
+
+ app:layout_constraintTop_toTopOf="parent"
+ tools:text="Hello There" />
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index 81b7a9c..94ca903 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -6,7 +6,7 @@
- @color/brand
- @color/black
- - @color/teal_200
+ - @color/brand_text
- @color/teal_200
- @color/black
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..318ffad
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,4 @@
+
+
+ 16dp
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 44e135e..dda2a46 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,6 @@
AllYouCanTweet
https://young-spire-63034.herokuapp.com/
+ retry
+ Ups… Something went wrong!
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index dbd3359..9980fa5 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -6,7 +6,7 @@
- @color/brand
- @color/white
- - @color/teal_200
+ - @color/brand_text
- @color/teal_700
- @color/black