Merge branch 'logout_bugfix' into 'master'
Fix #271 Closes #271 See merge request pixeldroid/PixelDroid!282
This commit is contained in:
commit
1a2a971de6
@ -6,7 +6,6 @@ import android.content.Intent
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
@ -19,13 +18,12 @@ import com.h.pixeldroid.utils.hasInternet
|
|||||||
import com.h.pixeldroid.utils.normalizeDomain
|
import com.h.pixeldroid.utils.normalizeDomain
|
||||||
import com.h.pixeldroid.utils.openUrl
|
import com.h.pixeldroid.utils.openUrl
|
||||||
import kotlinx.android.synthetic.main.activity_login.*
|
import kotlinx.android.synthetic.main.activity_login.*
|
||||||
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.supervisorScope
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import retrofit2.Call
|
|
||||||
import retrofit2.Callback
|
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import retrofit2.Response
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,17 +130,24 @@ class LoginActivity : BaseActivity() {
|
|||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
val credentialsDeferred = async {
|
supervisorScope { }
|
||||||
pixelfedAPI.registerApplication(
|
val credentialsDeferred: Deferred<Application?> = async {
|
||||||
appName, "$oauthScheme://$PACKAGE_ID", SCOPE
|
try {
|
||||||
)
|
pixelfedAPI.registerApplication(
|
||||||
|
appName, "$oauthScheme://$PACKAGE_ID", SCOPE
|
||||||
|
)
|
||||||
|
} catch (exception: IOException) {
|
||||||
|
return@async null
|
||||||
|
} catch (exception: HttpException) {
|
||||||
|
return@async null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val nodeInfoJRD = pixelfedAPI.wellKnownNodeInfo()
|
val nodeInfoJRD = pixelfedAPI.wellKnownNodeInfo()
|
||||||
|
|
||||||
val credentials = credentialsDeferred.await()
|
val credentials = credentialsDeferred.await()
|
||||||
|
|
||||||
val clientId = credentials.client_id ?: return@launch failedRegistration()
|
val clientId = credentials?.client_id ?: return@launch failedRegistration()
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
.putString("domain", normalizedDomain)
|
.putString("domain", normalizedDomain)
|
||||||
.putString("clientID", clientId)
|
.putString("clientID", clientId)
|
||||||
|
@ -14,6 +14,7 @@ import androidx.core.view.GravityCompat
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.paging.ExperimentalPagingApi
|
import androidx.paging.ExperimentalPagingApi
|
||||||
|
import androidx.room.withTransaction
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
@ -167,21 +168,21 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun logOut(){
|
private fun logOut(){
|
||||||
db.userDao().deleteActiveUsers()
|
db.runInTransaction {
|
||||||
|
db.userDao().deleteActiveUsers()
|
||||||
|
|
||||||
val remainingUsers = db.userDao().getAll()
|
val remainingUsers = db.userDao().getAll()
|
||||||
if (remainingUsers.isEmpty()){
|
if (remainingUsers.isEmpty()){
|
||||||
//no more users, start first-time login flow
|
//no more users, start first-time login flow
|
||||||
launchActivity(LoginActivity(), firstTime = true)
|
launchActivity(LoginActivity(), firstTime = true)
|
||||||
} else {
|
} else {
|
||||||
val newActive = remainingUsers.first()
|
val newActive = remainingUsers.first()
|
||||||
db.userDao().activateUser(newActive.user_id)
|
db.userDao().activateUser(newActive.user_id)
|
||||||
//relaunch the app
|
apiHolder.setDomainToCurrentUser(db)
|
||||||
launchActivity(MainActivity(), firstTime = true)
|
//relaunch the app
|
||||||
|
launchActivity(MainActivity(), firstTime = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private fun getUpdatedAccount() {
|
private fun getUpdatedAccount() {
|
||||||
if (hasInternet(applicationContext)) {
|
if (hasInternet(applicationContext)) {
|
||||||
|
@ -42,7 +42,7 @@ open class CachedFeedFragment<T: FeedContentDatabase> : BaseFragment() {
|
|||||||
internal fun launch() {
|
internal fun launch() {
|
||||||
// Make sure we cancel the previous job before creating a new one
|
// Make sure we cancel the previous job before creating a new one
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
job = lifecycleScope.launch {
|
job = lifecycleScope.launchWhenStarted {
|
||||||
viewModel.flow().collectLatest {
|
viewModel.flow().collectLatest {
|
||||||
adapter.submitData(it)
|
adapter.submitData(it)
|
||||||
}
|
}
|
||||||
@ -88,8 +88,8 @@ open class CachedFeedFragment<T: FeedContentDatabase> : BaseFragment() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory that creates ViewModel from a [FeedContentRepository], to be used in cached feeds to
|
* Factory that creates ViewModel from a [FeedContentRepository], to be used in cached feeds to
|
||||||
* fetch the ViewModel that is responsible for preparing and managing the data for
|
* fetch the ViewModel that is responsible for preparing and managing the data
|
||||||
* an Activity or a Fragment
|
* for a CachedFeedFragment
|
||||||
*/
|
*/
|
||||||
class ViewModelFactory<U: FeedContentDatabase> @ExperimentalPagingApi constructor(private val db: AppDatabase?,
|
class ViewModelFactory<U: FeedContentDatabase> @ExperimentalPagingApi constructor(private val db: AppDatabase?,
|
||||||
private val dao: FeedContentDao<U>?,
|
private val dao: FeedContentDao<U>?,
|
||||||
|
@ -39,9 +39,9 @@ class FeedContentRepository<T: FeedContentDatabase> @ExperimentalPagingApi
|
|||||||
*/
|
*/
|
||||||
@ExperimentalPagingApi
|
@ExperimentalPagingApi
|
||||||
fun stream(): Flow<PagingData<T>> {
|
fun stream(): Flow<PagingData<T>> {
|
||||||
|
val user = db.userDao().getActiveUser()!!
|
||||||
|
|
||||||
val pagingSourceFactory = {
|
val pagingSourceFactory = {
|
||||||
val user = db.userDao().getActiveUser()!!
|
|
||||||
dao.feedContent(user.user_id, user.instance_uri)
|
dao.feedContent(user.user_id, user.instance_uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.h.pixeldroid.utils.di.PixelfedAPIHolder
|
|||||||
import com.h.pixeldroid.utils.api.objects.Notification
|
import com.h.pixeldroid.utils.api.objects.Notification
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.NullPointerException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +56,8 @@ class NotificationsRemoteMediator @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val user = db.userDao().getActiveUser()!!
|
val user = db.userDao().getActiveUser()
|
||||||
|
?: return MediatorResult.Error(NullPointerException("No active user exists"))
|
||||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||||
val accessToken = user.accessToken
|
val accessToken = user.accessToken
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import com.h.pixeldroid.utils.di.PixelfedAPIHolder
|
|||||||
import com.h.pixeldroid.utils.db.entities.HomeStatusDatabaseEntity
|
import com.h.pixeldroid.utils.db.entities.HomeStatusDatabaseEntity
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.NullPointerException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +41,8 @@ class HomeFeedRemoteMediator @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val user = db.userDao().getActiveUser()!!
|
val user = db.userDao().getActiveUser()
|
||||||
|
?: return MediatorResult.Error(NullPointerException("No active user exists"))
|
||||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||||
val accessToken = user.accessToken
|
val accessToken = user.accessToken
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.h.pixeldroid.utils.db.entities.PublicFeedStatusDatabaseEntity
|
|||||||
import com.h.pixeldroid.utils.di.PixelfedAPIHolder
|
import com.h.pixeldroid.utils.di.PixelfedAPIHolder
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.NullPointerException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +56,8 @@ class PublicFeedRemoteMediator @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val user = db.userDao().getActiveUser()!!
|
val user = db.userDao().getActiveUser()
|
||||||
|
?: return MediatorResult.Error(NullPointerException("No active user exists"))
|
||||||
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
||||||
|
|
||||||
val apiResponse = api.timelinePublic(
|
val apiResponse = api.timelinePublic(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user