Skip to content

Commit

Permalink
Rename and Remove delete Authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
baronhsieh2005 committed Nov 18, 2024
1 parent 2f35e44 commit 37ad439
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface NotificationAPI {

@DELETE("user/notifications/tokens/android/{token}/")
suspend fun deleteNotificationToken(
@Header("Authorization") bearerToken: String,
@Path("token") token: String,
): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.components.dialog.CustomAlertDialogue
import com.pennapps.labs.pennmobile.gsr.fragments.PottruckFragment
import com.pennapps.labs.pennmobile.home.fragments.NewsFragment
import com.pennapps.labs.pennmobile.more.viewmodels.PreferencesViewModel
import com.pennapps.labs.pennmobile.more.viewmodels.PreferenceViewModel
import com.pennapps.labs.pennmobile.showSneakerToast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -36,7 +36,7 @@ class PreferenceFragment : PreferenceFragmentCompat() {
private lateinit var mContext: Context
private lateinit var mActivity: MainActivity
private lateinit var toolbar: Toolbar
private val preferencesViewModel: PreferencesViewModel by viewModels()
private val preferenceViewModel: PreferenceViewModel by viewModels()

override fun onAttach(context: Context) {
super.onAttach(context)
Expand Down Expand Up @@ -275,14 +275,13 @@ class PreferenceFragment : PreferenceFragmentCompat() {
}

private fun deleteNotifToken(sp: SharedPreferences) {
val bearerToken = "Bearer " + sp.getString(getString(R.string.access_token), "").toString()
val notifToken = sp.getString(getString(R.string.notification_token), "").toString()
val mNotificationAPI = MainActivity.notificationAPIInstance
Log.i("Notification Token", notifToken)

lifecycleScope.launch(Dispatchers.IO) {
try {
preferencesViewModel.deleteTokenResponse(mNotificationAPI, bearerToken, notifToken)
preferenceViewModel.deleteTokenResponse(mNotificationAPI, notifToken)
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import com.pennapps.labs.pennmobile.api.NotificationAPI

// Currently only implemented the notification logic, other network logistics to be implemented

class PreferencesViewModel : ViewModel() {
class PreferenceViewModel : ViewModel() {
suspend fun deleteTokenResponse(
mNotificationAPI: NotificationAPI,
bearerToken: String,
notifToken: String,
) {
try {
val response = mNotificationAPI.deleteNotificationToken(bearerToken, notifToken)
val response = mNotificationAPI.deleteNotificationToken(notifToken)
if (response.isSuccessful) {
Log.i("Notification Token", "Successfully deleted token")
} else {
Expand Down

0 comments on commit 37ad439

Please sign in to comment.