Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sunny/points-shop-2024' into sun…
Browse files Browse the repository at this point in the history
…ny/points-shop-2024
  • Loading branch information
leesunny790 committed Jan 25, 2024
2 parents b4ef4a4 + ef75d15 commit 78c68bf
Show file tree
Hide file tree
Showing 57 changed files with 384 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
android:name="org.hackillinois.android.App"
android:allowBackup="false"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher_23"
android:roundIcon="@mipmap/ic_launcher_23_round"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">


Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/swirling_cauldron.json

Large diffs are not rendered by default.

Binary file modified app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/src/main/java/org/hackillinois/android/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package org.hackillinois.android

import org.hackillinois.android.database.entity.*
import org.hackillinois.android.model.checkin.CheckIn
import org.hackillinois.android.model.event.EventId
import org.hackillinois.android.model.event.EventsList
import org.hackillinois.android.model.leaderboard.LeaderboardList
import org.hackillinois.android.model.user.FavoritesResponse
import org.hackillinois.android.model.version.Version
import org.hackillinois.android.notifications.DeviceToken
import retrofit2.Call
Expand Down Expand Up @@ -71,6 +73,15 @@ interface API {
@GET("user/")
suspend fun user(): User

@PUT("user/follow/")
suspend fun favoriteEvents(): FavoritesResponse

@PUT("user/follow/")
fun followEvent(@Body eventId: EventId): Call<FavoritesResponse>

@PUT("user/unfollow/")
fun unfollowEvent(@Body eventId: EventId): Call<FavoritesResponse>

@GET("user/qr/")
suspend fun qrCode(): QR

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.hackillinois.android.model.event

data class EventId(val eventId: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.hackillinois.android.model.user

data class FavoritesResponse(val userId: String, val following: List<String>)
22 changes: 22 additions & 0 deletions app/src/main/java/org/hackillinois/android/view/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import kotlinx.coroutines.withContext
import org.hackillinois.android.API
import org.hackillinois.android.App
import org.hackillinois.android.R
import org.hackillinois.android.common.FavoritesManager
import org.hackillinois.android.common.JWTUtilities
import org.hackillinois.android.database.entity.Event
import org.hackillinois.android.database.entity.Roles
import org.hackillinois.android.model.auth.JWT
import org.hackillinois.android.model.user.FavoritesResponse
import java.net.SocketTimeoutException

class LoginActivity : AppCompatActivity() {
Expand Down Expand Up @@ -96,8 +99,10 @@ class LoginActivity : AppCompatActivity() {
try {
val loginRoles: Roles = api.roles()
Log.d("ROLES", "${loginRoles.roles}")

// Check if user's roles are correct. If not, display corresponding error message
if (loginRoles.roles.contains(role)) {
getFavoritedEvents(api)
JWTUtilities.writeJWT(applicationContext, jwt) // save JWT to sharedPreferences for auto-login in the future
launchMainActivity()
} else {
Expand All @@ -113,6 +118,23 @@ class LoginActivity : AppCompatActivity() {
}
}

private fun getFavoritedEvents(api: API) {
// make api call to get list of event ids that user has favorited
GlobalScope.launch {
try {
val response: FavoritesResponse = api.favoriteEvents()
// loop through favorited event ids, wrap as Event object, and store in SharedPreferences
for (eventId in response.following) {
val dummyEvent = Event(eventId, "", "", 0, 0, emptyList(), "", "", "0", false, false, false)
FavoritesManager.favoriteEvent(applicationContext, dummyEvent)
}
Log.d("Fetched favorites", response.toString())
} catch (e: Exception) {
Log.d("Fetched favorites ERROR", e.message.toString())
}
}
}

private fun showFailedToLogin(message: String?) {
if (message != null) {
Snackbar.make(findViewById(android.R.id.content), message.toString(), Snackbar.LENGTH_SHORT,).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MainActivity : AppCompatActivity() {
val bottomBarButtons = listOf(
bottomAppBar.homeButton,
bottomAppBar.scheduleButton,
bottomAppBar.leaderboard,
bottomAppBar.shop,
bottomAppBar.profile,
)

Expand All @@ -88,6 +88,7 @@ class MainActivity : AppCompatActivity() {
bottomAppBar.homeButton -> switchFragment(HomeFragment(), false)
bottomAppBar.scheduleButton -> switchFragment(ScheduleFragment(), false)
bottomAppBar.leaderboard -> switchFragment(ShopFragment(), false)
bottomAppBar.shop -> switchFragment(LeaderboardFragment(), false)
bottomAppBar.profile -> switchFragment(ProfileFragment(), false)
else -> return@setOnClickListener
}
Expand All @@ -110,7 +111,7 @@ class MainActivity : AppCompatActivity() {
val bottomBarButtons = listOf(
bottomAppBar.homeButton,
bottomAppBar.scheduleButton,
bottomAppBar.leaderboard,
bottomAppBar.shop,
bottomAppBar.profile,
)
val unselectedIconColor = ContextCompat.getColor(this, R.color.unselectedAppBarIcon)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package org.hackillinois.android.view.schedule

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.event_tile.view.*
import kotlinx.android.synthetic.main.time_list_item.view.*
import org.hackillinois.android.API
import org.hackillinois.android.App
import org.hackillinois.android.R
import org.hackillinois.android.common.FavoritesManager
import org.hackillinois.android.database.entity.Event
import org.hackillinois.android.model.event.EventId
import org.hackillinois.android.model.user.FavoritesResponse
import org.hackillinois.android.view.MainActivity
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class EventsAdapter(
private var itemList: List<ScheduleListItem>,
private val eventClickListener: EventClickListener
private val eventClickListener: EventClickListener,
) : RecyclerView.Adapter<EventsAdapter.ViewHolder>(), EventClickListener {
private lateinit var context: Context

Expand Down Expand Up @@ -103,13 +111,29 @@ class EventsAdapter(
starButton.setOnClickListener { button ->
button.isSelected = !button.isSelected

val api: API = App.getAPI()
val call: Call<FavoritesResponse>
if (button.isSelected) {
FavoritesManager.favoriteEvent(context, event)
call = api.followEvent(EventId(event.eventId))
val toast = Toast.makeText(context, R.string.schedule_snackbar_notifications_on, Toast.LENGTH_SHORT)
toast.show()
} else {
FavoritesManager.unfavoriteEvent(context, event)
call = api.unfollowEvent(EventId(event.eventId))
}

call.enqueue(object : Callback<FavoritesResponse> {
override fun onResponse(call: Call<FavoritesResponse>, response: Response<FavoritesResponse>) {
if (response.isSuccessful) {
val responseData: FavoritesResponse? = response.body()
}
}

override fun onFailure(call: Call<FavoritesResponse>, t: Throwable) {
Log.d("FOLLOW/UNFOLLOW FAILURE", t.toString())
}
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package org.hackillinois.android.viewmodel

import android.app.Application
import android.util.Log
import android.widget.Toast
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import org.hackillinois.android.API
import org.hackillinois.android.App
import org.hackillinois.android.R
import org.hackillinois.android.common.FavoritesManager
import org.hackillinois.android.database.entity.Event
import org.hackillinois.android.database.entity.Roles
import org.hackillinois.android.model.event.EventId
import org.hackillinois.android.model.user.FavoritesResponse
import org.hackillinois.android.repository.EventRepository
import org.hackillinois.android.repository.rolesRepository
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class EventInfoViewModel(val app: Application) : AndroidViewModel(app) {

Expand All @@ -37,10 +47,29 @@ class EventInfoViewModel(val app: Application) : AndroidViewModel(app) {

isFavorited.postValue(favorited)

val api: API = App.getAPI()
val call: Call<FavoritesResponse>
if (favorited) {
FavoritesManager.favoriteEvent(app.applicationContext, event.value)
call = api.followEvent(EventId(event.value!!.eventId))

// show notification toast
val toast = Toast.makeText(app.applicationContext, R.string.schedule_snackbar_notifications_on, Toast.LENGTH_SHORT)
toast.show()
} else {
FavoritesManager.unfavoriteEvent(app.applicationContext, event.value)
call = api.unfollowEvent(EventId(event.value!!.eventId))
}
call.enqueue(object : Callback<FavoritesResponse> {
override fun onResponse(call: Call<FavoritesResponse>, response: Response<FavoritesResponse>) {
if (response.isSuccessful) {
val responseData: FavoritesResponse? = response.body()
}
}

override fun onFailure(call: Call<FavoritesResponse>, t: Throwable) {
Log.d("FOLLOW/UNFOLLOW FAILURE", t.toString())
}
})
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="1024"
android:viewportHeight="1022">
<group android:scaleY="0.9980469"
android:translateY="0.9980469">
<group>
<clip-path
android:pathData="M0,0h1024v1024h-1024z"/>
<path
android:pathData="M1024,0H0V1024H1024V0Z"
android:fillColor="#5B619B"/>
</group>
</group>
</vector>
Loading

0 comments on commit 78c68bf

Please sign in to comment.