Skip to content

Commit

Permalink
Add: LoadingDialog and lottie (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerarslnn committed Nov 30, 2021
1 parent 80bbb4d commit 3a114e4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
3 changes: 3 additions & 0 deletions FindSportEvents/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ dependencies {
//retrofit2
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

//lottie
implementation 'com.airbnb.android:lottie:3.6.1'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bounswe.findsportevents.main.fragments

import android.app.DatePickerDialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -12,16 +13,21 @@ import com.bounswe.findsportevents.databinding.FragmentProfileBinding
import com.bounswe.findsportevents.main.MainActivity
import com.bounswe.findsportevents.network.ReboundAPI
import com.bounswe.findsportevents.network.modalz.responses.UserResponse
import com.bounswe.findsportevents.util.DialogManager
import com.bounswe.findsportevents.util.LoadingDialog
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.lang.Exception
import java.text.SimpleDateFormat
import java.util.*

class FragmentProfile : Fragment() {
class FragmentProfile : Fragment(), DialogManager {
private var _binding: FragmentProfileBinding? = null
private val binding get() = _binding!!

private var dialog: LoadingDialog? = null

private lateinit var profileFragListener: FragmentProfileListener
private var token = ""
private var username = ""
Expand All @@ -32,10 +38,12 @@ class FragmentProfile : Fragment() {
token = requireArguments().getString(TOKEN_KEY) ?: ""
username = requireArguments().getString(USERNAME_KEY) ?: ""



context?.run {
showLoading(this)
}
ReboundAPI.create().getUser(token, username).enqueue(object: Callback<UserResponse> {
override fun onResponse(call: Call<UserResponse>, response: Response<UserResponse>) {
hideLoading()
if(response.isSuccessful){
binding.etFirstName.setText(response.body()?.first_name ?: "")
binding.etLastName.setText(response.body()?.last_name ?: "")
Expand All @@ -48,7 +56,7 @@ class FragmentProfile : Fragment() {
}

override fun onFailure(call: Call<UserResponse>, t: Throwable) {
// TODO("Not yet implemented")
hideLoading()
}

})
Expand Down Expand Up @@ -98,4 +106,24 @@ class FragmentProfile : Fragment() {
}
}
}

override fun showLoading(context: Context) {
try {
hideLoading()
dialog = LoadingDialog(context)
dialog?.setCancelable(false)
dialog?.show()
} catch (e: Exception) {
e.printStackTrace()
}
}

override fun hideLoading() {
try {
dialog?.dismiss()
dialog = null
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bounswe.findsportevents.util

import android.content.Context

interface DialogManager {
fun showLoading(context: Context)
fun hideLoading()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bounswe.findsportevents.util

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Window
import com.bounswe.findsportevents.R

class LoadingDialog(context: Context) : Dialog(context) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.loading_layout)
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
}
18 changes: 18 additions & 0 deletions FindSportEvents/app/src/main/res/layout/loading_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/loading" />
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions FindSportEvents/app/src/main/res/raw/loading.json

Large diffs are not rendered by default.

0 comments on commit 3a114e4

Please sign in to comment.