Skip to content

Commit

Permalink
add logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Alhams committed Apr 21, 2023
1 parent f3b7054 commit a09e299
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ package com.red_velvet_cake.dailytodo.data.local
interface LocalData {
fun getUserToken(): String?
fun setUserToken(userToken: String)
fun clearUserToken()
fun saveUserName(userName: String)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.red_velvet_cake.dailytodo.data.local

class LocalDataImpl() : LocalData {
class LocalDataImpl : LocalData {
override fun getUserToken(): String? {
return SharedPrefs.token
}

override fun setUserToken(userToken: String) {
SharedPrefs.token = userToken
}

override fun clearUserToken() {
SharedPrefs.token = null
}

override fun saveUserName(userName: String) {
SharedPrefs.userName = userName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.red_velvet_cake.dailytodo.data.local
import android.content.Context
import android.content.SharedPreferences

private const val USERNAME = "username"

object SharedPrefs {
private lateinit var sharedPreferences: SharedPreferences
private const val SHARED_PREF = "TodoPrefs"
Expand All @@ -17,4 +19,10 @@ object SharedPrefs {
set(value) {
sharedPreferences.edit().putString(AUTH_TOKEN, value).apply()
}

var userName: String?
get() = sharedPreferences.getString(USERNAME, null)
set(value) {
sharedPreferences.edit().putString(USERNAME, value).apply()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.red_velvet_cake.dailytodo.data.model.GetAllTeamTodosResponse
import com.red_velvet_cake.dailytodo.data.model.PersonalTodo
import com.red_velvet_cake.dailytodo.data.model.Statistics
import com.red_velvet_cake.dailytodo.data.model.TeamTodo
import com.red_velvet_cake.dailytodo.databinding.DialogBinding
import com.red_velvet_cake.dailytodo.databinding.FragmentHomeBinding
import com.red_velvet_cake.dailytodo.ui.activity.AuthActivity
import com.red_velvet_cake.dailytodo.ui.base.BaseFragment
Expand All @@ -21,6 +22,7 @@ import com.red_velvet_cake.dailytodo.ui.personal_todo.PersonalTodoFragment
import com.red_velvet_cake.dailytodo.ui.personal_todo_details.PersonalTodoDetailsFragment
import com.red_velvet_cake.dailytodo.ui.team_todo.TeamTodoFragment
import com.red_velvet_cake.dailytodo.ui.team_todo_details.TeamTodoDetailsFragment
import com.red_velvet_cake.dailytodo.ui.utils.showDialog
import com.red_velvet_cake.dailytodo.utils.navigateTo


Expand Down Expand Up @@ -71,6 +73,19 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), HomeView {
homePresenter.getAllTodos()
}
}

binding.textViewName.text = homePresenter.getUsername()
binding.textViewAvatar.text = homePresenter.getUsername()[0].toString()

binding.textViewAvatar.setOnClickListener {
showDialog<DialogBinding>(requireActivity()) {
it.buttonLogout.setOnClickListener {
homePresenter.logout()
}
it.textViewName.text = homePresenter.getUsername()
it.textViewAvatar.text = homePresenter.getUsername()[0].toString()
}
}
}

private fun onClickTeamTodo(teamTodo: TeamTodo) {
Expand Down Expand Up @@ -110,7 +125,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(), HomeView {

override fun showPendingPersonalTodos(pendingTodo: Int) {
requireActivity().runOnUiThread { adapter.setPersonalPendingCount(pendingTodo) }

}

override fun showCompletedTeamTodos(completedTodo: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.red_velvet_cake.dailytodo.ui.home

import com.red_velvet_cake.dailytodo.data.local.LocalDataImpl
import com.red_velvet_cake.dailytodo.data.local.SharedPrefs
import com.red_velvet_cake.dailytodo.data.model.GetAllPersonalTodosResponse
import com.red_velvet_cake.dailytodo.data.model.GetAllTeamTodosResponse
import com.red_velvet_cake.dailytodo.data.model.PersonalTodo
Expand All @@ -9,6 +11,7 @@ import com.red_velvet_cake.dailytodo.data.remote.util.CustomException

class HomePresenter(val view: HomeView) {
private val todoServiceImpl = TodoServiceImpl()
private val localDataImpl = LocalDataImpl()

fun getAllTodos() {
view.showLoadStatus()
Expand Down Expand Up @@ -77,4 +80,13 @@ class HomePresenter(val view: HomeView) {
}
}
}

fun getUsername(): String {
return SharedPrefs.userName!!
}

fun logout() {
localDataImpl.clearUserToken()
view.navigateToLogin()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LoginPresenter(private val view: LoginView) {

fun loginUser(username: String, password: String) {
view.showLoadingState()
localDataImpl.saveUserName(username)
authService.loginAccount(
username,
password,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.red_velvet_cake.dailytodo.ui.utils

import android.app.Activity
import android.app.Dialog
import android.view.Window
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.red_velvet_cake.dailytodo.databinding.DialogBinding


fun <T : ViewBinding> Fragment.showDialog(
activity: Activity,
onCreateDialog: (T) -> Unit
) {
val dialog = Dialog(activity)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
val binding = DialogBinding.inflate(layoutInflater)
dialog.setContentView(binding.root)
onCreateDialog(binding as T)
dialog.show()
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/background_circular.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/primary" />
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/baseline_close_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z" />
</vector>
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/close_square.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#00000000"
android:pathData="M2,12C2,7.286 2,4.929 3.464,3.464C4.929,2 7.286,2 12,2C16.714,2 19.071,2 20.535,3.464C22,4.929 22,7.286 22,12C22,16.714 22,19.071 20.535,20.535C19.071,22 16.714,22 12,22C7.286,22 4.929,22 3.464,20.535C2,19.071 2,16.714 2,12Z"
android:strokeWidth="1.5"
android:strokeAlpha="0.38"
android:strokeColor="#000000" />
<path
android:fillColor="#00000000"
android:pathData="M14.5,9.5L9.5,14.5M9.5,9.5L14.5,14.5"
android:strokeWidth="1.5"
android:strokeAlpha="0.38"
android:strokeColor="#000000"
android:strokeLineCap="round" />
</vector>
61 changes: 61 additions & 0 deletions app/src/main/res/drawable/frame_48095910.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="25dp"
android:viewportWidth="65"
android:viewportHeight="16">
<path
android:fillColor="#E6E6E6"
android:pathData="M1.879,15.427C1.898,15.297 1.762,15.17 1.575,15.143C1.388,15.116 1.221,15.199 1.202,15.329C1.183,15.459 1.319,15.586 1.506,15.613C1.693,15.641 1.86,15.557 1.879,15.427Z" />
<path
android:fillColor="#3F3D56"
android:pathData="M4.104,15.21C4.122,15.08 3.986,14.953 3.799,14.926C3.613,14.898 3.446,14.982 3.427,15.112C3.408,15.242 3.544,15.369 3.731,15.396C3.918,15.424 4.085,15.34 4.104,15.21Z" />
<path
android:fillColor="#FF6584"
android:pathData="M1.268,13.626C1.287,13.496 1.15,13.369 0.964,13.341C0.777,13.314 0.61,13.398 0.591,13.528C0.572,13.658 0.708,13.785 0.895,13.812C1.082,13.839 1.249,13.756 1.268,13.626Z" />
<path
android:fillColor="#E6E6E6"
android:pathData="M0.302,12.888C0.303,12.769 0.237,12.672 0.154,12.671C0.071,12.67 0.003,12.767 0.002,12.886C0.001,13.005 0.067,13.103 0.15,13.103C0.233,13.104 0.301,13.008 0.302,12.888Z" />
<path
android:fillColor="#E6E6E6"
android:pathData="M2.523,13.933C2.524,13.813 2.457,13.716 2.374,13.715C2.291,13.715 2.223,13.811 2.222,13.93C2.221,14.05 2.288,14.147 2.371,14.148C2.454,14.148 2.522,14.052 2.523,13.933Z" />
<path
android:fillColor="#FF6584"
android:pathData="M1.449,14.469C1.45,14.35 1.383,14.253 1.3,14.252C1.217,14.251 1.149,14.348 1.148,14.467C1.147,14.586 1.214,14.684 1.297,14.684C1.38,14.685 1.448,14.589 1.449,14.469Z" />
<path
android:fillColor="#3F3D56"
android:pathData="M2.945,15.462C2.946,15.342 2.879,15.245 2.796,15.245C2.713,15.244 2.645,15.34 2.644,15.459C2.643,15.579 2.71,15.676 2.793,15.677C2.876,15.677 2.944,15.581 2.945,15.462Z" />
<path
android:fillColor="#ffffff"
android:pathData="M10.306,15.932C14.061,15.932 17.105,12.888 17.105,9.132C17.105,5.377 14.061,2.333 10.306,2.333C6.55,2.333 3.506,5.377 3.506,9.132C3.506,12.888 6.55,15.932 10.306,15.932Z" />
<path
android:fillColor="#6C63FF"
android:pathData="M10.307,16C6.52,16 3.439,12.919 3.439,9.132C3.439,5.345 6.52,2.265 10.307,2.265C14.094,2.265 17.175,5.345 17.175,9.132C17.175,12.919 14.094,16 10.307,16ZM10.307,2.4C6.595,2.4 3.575,5.42 3.575,9.132C3.575,12.844 6.595,15.864 10.307,15.864C14.019,15.864 17.039,12.844 17.039,9.132C17.039,5.42 14.019,2.4 10.307,2.4Z" />
<path
android:fillColor="#6C63FF"
android:pathData="M9.381,12.671C9.264,12.671 9.148,12.644 9.043,12.592C8.938,12.539 8.846,12.463 8.776,12.369L6.921,9.895C6.861,9.816 6.818,9.725 6.793,9.629C6.769,9.533 6.763,9.433 6.777,9.335C6.791,9.236 6.824,9.142 6.875,9.056C6.926,8.971 6.993,8.896 7.072,8.836C7.152,8.777 7.242,8.733 7.338,8.709C7.434,8.684 7.535,8.679 7.633,8.693C7.731,8.707 7.826,8.74 7.911,8.791C7.997,8.841 8.071,8.908 8.131,8.988L9.345,10.606L12.462,5.93C12.573,5.763 12.746,5.648 12.943,5.608C13.139,5.569 13.344,5.61 13.51,5.721C13.677,5.832 13.793,6.005 13.833,6.202C13.872,6.398 13.832,6.602 13.721,6.769L10.01,12.335C9.943,12.435 9.853,12.518 9.747,12.577C9.641,12.635 9.523,12.668 9.402,12.671C9.395,12.671 9.388,12.671 9.381,12.671Z" />
<path
android:fillColor="#E6E6E6"
android:pathData="M17.313,2.758C17.331,2.628 17.195,2.5 17.008,2.473C16.822,2.446 16.655,2.529 16.636,2.659C16.617,2.789 16.753,2.917 16.94,2.944C17.127,2.971 17.294,2.888 17.313,2.758Z" />
<path
android:fillColor="#3F3D56"
android:pathData="M19.537,2.54C19.556,2.41 19.42,2.283 19.233,2.256C19.046,2.229 18.879,2.312 18.86,2.442C18.841,2.572 18.978,2.699 19.164,2.726C19.351,2.754 19.518,2.67 19.537,2.54Z" />
<path
android:fillColor="#FF6584"
android:pathData="M16.703,0.956C16.722,0.826 16.586,0.699 16.399,0.671C16.212,0.644 16.045,0.728 16.026,0.858C16.007,0.988 16.144,1.115 16.331,1.142C16.517,1.169 16.684,1.086 16.703,0.956Z" />
<path
android:fillColor="#E6E6E6"
android:pathData="M15.738,0.218C15.739,0.099 15.672,0.002 15.589,0.001C15.506,0 15.438,0.097 15.437,0.216C15.436,0.335 15.503,0.433 15.586,0.433C15.669,0.434 15.737,0.338 15.738,0.218Z" />
<path
android:fillColor="#E6E6E6"
android:pathData="M17.958,1.263C17.959,1.143 17.893,1.046 17.81,1.046C17.727,1.045 17.659,1.141 17.658,1.26C17.657,1.38 17.724,1.477 17.807,1.478C17.89,1.478 17.958,1.382 17.958,1.263Z" />
<path
android:fillColor="#FF6584"
android:pathData="M16.882,1.8C16.883,1.68 16.817,1.583 16.734,1.582C16.651,1.582 16.583,1.678 16.582,1.797C16.581,1.917 16.647,2.014 16.73,2.015C16.813,2.015 16.882,1.919 16.882,1.8Z" />
<path
android:fillColor="#3F3D56"
android:pathData="M18.38,2.792C18.381,2.672 18.315,2.575 18.232,2.575C18.149,2.574 18.081,2.67 18.08,2.79C18.079,2.909 18.145,3.006 18.229,3.007C18.312,3.007 18.379,2.911 18.38,2.792Z" />
<path
android:fillAlpha="0.6"
android:fillColor="#000000"
android:pathData="M26.434,5.44C27.026,5.44 27.543,5.555 27.986,5.784C28.434,6.008 28.778,6.333 29.018,6.76C29.263,7.181 29.386,7.675 29.386,8.24C29.386,8.805 29.263,9.296 29.018,9.712C28.778,10.128 28.434,10.448 27.986,10.672C27.543,10.891 27.026,11 26.434,11H24.618V5.44H26.434ZM26.434,10.256C27.084,10.256 27.583,10.08 27.93,9.728C28.276,9.376 28.45,8.88 28.45,8.24C28.45,7.595 28.276,7.091 27.93,6.728C27.583,6.365 27.084,6.184 26.434,6.184H25.53V10.256H26.434ZM29.986,8.776C29.986,8.333 30.076,7.941 30.257,7.6C30.444,7.259 30.695,6.995 31.01,6.808C31.33,6.616 31.681,6.52 32.065,6.52C32.412,6.52 32.714,6.589 32.97,6.728C33.231,6.861 33.439,7.029 33.593,7.232V6.592H34.514V11H33.593V10.344C33.439,10.552 33.228,10.725 32.961,10.864C32.695,11.003 32.391,11.072 32.049,11.072C31.671,11.072 31.324,10.976 31.01,10.784C30.695,10.587 30.444,10.315 30.257,9.968C30.076,9.616 29.986,9.219 29.986,8.776ZM33.593,8.792C33.593,8.488 33.529,8.224 33.402,8C33.279,7.776 33.116,7.605 32.914,7.488C32.711,7.371 32.492,7.312 32.257,7.312C32.023,7.312 31.804,7.371 31.601,7.488C31.399,7.6 31.233,7.768 31.105,7.992C30.983,8.211 30.921,8.472 30.921,8.776C30.921,9.08 30.983,9.347 31.105,9.576C31.233,9.805 31.399,9.981 31.601,10.104C31.809,10.221 32.028,10.28 32.257,10.28C32.492,10.28 32.711,10.221 32.914,10.104C33.116,9.987 33.279,9.816 33.402,9.592C33.529,9.363 33.593,9.096 33.593,8.792ZM36.175,6.008C36.01,6.008 35.871,5.952 35.759,5.84C35.647,5.728 35.591,5.589 35.591,5.424C35.591,5.259 35.647,5.12 35.759,5.008C35.871,4.896 36.01,4.84 36.175,4.84C36.335,4.84 36.471,4.896 36.583,5.008C36.695,5.12 36.751,5.259 36.751,5.424C36.751,5.589 36.695,5.728 36.583,5.84C36.471,5.952 36.335,6.008 36.175,6.008ZM36.623,6.592V11H35.711V6.592H36.623ZM38.733,5.08V11H37.821V5.08H38.733ZM43.898,6.592L41.194,13.072H40.25L41.146,10.928L39.41,6.592H40.426L41.666,9.952L42.954,6.592H43.898ZM48.178,5.44V6.184H46.698V11H45.786V6.184H44.298V5.44H48.178ZM51.014,11.072C50.598,11.072 50.222,10.979 49.886,10.792C49.55,10.6 49.286,10.333 49.094,9.992C48.902,9.645 48.806,9.245 48.806,8.792C48.806,8.344 48.905,7.947 49.102,7.6C49.299,7.253 49.569,6.987 49.91,6.8C50.251,6.613 50.633,6.52 51.054,6.52C51.475,6.52 51.857,6.613 52.198,6.8C52.539,6.987 52.809,7.253 53.006,7.6C53.203,7.947 53.302,8.344 53.302,8.792C53.302,9.24 53.201,9.637 52.998,9.984C52.795,10.331 52.518,10.6 52.166,10.792C51.819,10.979 51.435,11.072 51.014,11.072ZM51.014,10.28C51.249,10.28 51.467,10.224 51.67,10.112C51.878,10 52.046,9.832 52.174,9.608C52.302,9.384 52.366,9.112 52.366,8.792C52.366,8.472 52.305,8.203 52.182,7.984C52.059,7.76 51.897,7.592 51.694,7.48C51.491,7.368 51.273,7.312 51.038,7.312C50.803,7.312 50.585,7.368 50.382,7.48C50.185,7.592 50.027,7.76 49.91,7.984C49.793,8.203 49.734,8.472 49.734,8.792C49.734,9.267 49.854,9.635 50.094,9.896C50.339,10.152 50.646,10.28 51.014,10.28ZM53.9,8.776C53.9,8.333 53.99,7.941 54.172,7.6C54.358,7.259 54.609,6.995 54.924,6.808C55.243,6.616 55.598,6.52 55.987,6.52C56.276,6.52 56.558,6.584 56.835,6.712C57.118,6.835 57.342,7 57.507,7.208V5.08H58.428V11H57.507V10.336C57.358,10.549 57.15,10.725 56.883,10.864C56.622,11.003 56.321,11.072 55.979,11.072C55.596,11.072 55.243,10.976 54.924,10.784C54.609,10.587 54.358,10.315 54.172,9.968C53.99,9.616 53.9,9.219 53.9,8.776ZM57.507,8.792C57.507,8.488 57.444,8.224 57.315,8C57.193,7.776 57.03,7.605 56.827,7.488C56.625,7.371 56.406,7.312 56.172,7.312C55.937,7.312 55.718,7.371 55.515,7.488C55.313,7.6 55.147,7.768 55.02,7.992C54.897,8.211 54.835,8.472 54.835,8.776C54.835,9.08 54.897,9.347 55.02,9.576C55.147,9.805 55.313,9.981 55.515,10.104C55.723,10.221 55.942,10.28 56.172,10.28C56.406,10.28 56.625,10.221 56.827,10.104C57.03,9.987 57.193,9.816 57.315,9.592C57.444,9.363 57.507,9.096 57.507,8.792ZM61.537,11.072C61.121,11.072 60.745,10.979 60.409,10.792C60.073,10.6 59.809,10.333 59.617,9.992C59.425,9.645 59.329,9.245 59.329,8.792C59.329,8.344 59.428,7.947 59.625,7.6C59.823,7.253 60.092,6.987 60.433,6.8C60.775,6.613 61.156,6.52 61.577,6.52C61.999,6.52 62.38,6.613 62.721,6.8C63.063,6.987 63.332,7.253 63.529,7.6C63.727,7.947 63.825,8.344 63.825,8.792C63.825,9.24 63.724,9.637 63.521,9.984C63.319,10.331 63.041,10.6 62.689,10.792C62.343,10.979 61.959,11.072 61.537,11.072ZM61.537,10.28C61.772,10.28 61.991,10.224 62.193,10.112C62.401,10 62.569,9.832 62.697,9.608C62.825,9.384 62.889,9.112 62.889,8.792C62.889,8.472 62.828,8.203 62.705,7.984C62.583,7.76 62.42,7.592 62.217,7.48C62.015,7.368 61.796,7.312 61.561,7.312C61.327,7.312 61.108,7.368 60.905,7.48C60.708,7.592 60.551,7.76 60.433,7.984C60.316,8.203 60.257,8.472 60.257,8.792C60.257,9.267 60.377,9.635 60.617,9.896C60.863,10.152 61.169,10.28 61.537,10.28Z" />
</vector>
21 changes: 21 additions & 0 deletions app/src/main/res/drawable/logout_3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillAlpha="0.228"
android:fillColor="#000000"
android:pathData="M15,2H14C11.172,2 9.757,2 8.879,2.879C8,3.757 8,5.172 8,8V16C8,18.828 8,20.243 8.879,21.121C9.757,22 11.172,22 14,22H15C17.828,22 19.243,22 20.121,21.121C21,20.243 21,18.828 21,16V8C21,5.172 21,3.757 20.121,2.879C19.243,2 17.828,2 15,2Z"
android:strokeAlpha="0.6" />
<path
android:fillAlpha="0.152"
android:fillColor="#000000"
android:pathData="M8,8C8,6.462 8,5.343 8.141,4.5H8C5.643,4.5 4.464,4.5 3.732,5.232C3,5.964 3,7.143 3,9.5V14.5C3,16.857 3,18.035 3.732,18.768C4.464,19.5 5.643,19.5 8,19.5H8.141C8,18.657 8,17.538 8,16V12.75V11.25V8Z"
android:strokeAlpha="0.4" />
<path
android:fillAlpha="0.38"
android:fillColor="#000000"
android:fillType="evenOdd"
android:pathData="M4.47,11.47C4.177,11.763 4.177,12.237 4.47,12.53L6.47,14.53C6.763,14.823 7.237,14.823 7.53,14.53C7.823,14.237 7.823,13.763 7.53,13.47L6.811,12.75L14,12.75C14.414,12.75 14.75,12.414 14.75,12C14.75,11.586 14.414,11.25 14,11.25L6.811,11.25L7.53,10.53C7.823,10.237 7.823,9.763 7.53,9.47C7.237,9.177 6.763,9.177 6.47,9.47L4.47,11.47Z" />
</vector>
Loading

0 comments on commit a09e299

Please sign in to comment.