Less crashing for bad json, other bug fixes

This commit is contained in:
Matthieu 2022-11-28 00:10:23 +01:00
parent a28be0edf4
commit 5dd5057479
22 changed files with 81 additions and 228 deletions

View File

@ -15,17 +15,19 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.databinding.ActivityLoginBinding import org.pixeldroid.app.databinding.ActivityLoginBinding
import org.pixeldroid.app.utils.* import org.pixeldroid.app.utils.BaseThemedWithoutBarActivity
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Application import org.pixeldroid.app.utils.api.objects.Application
import org.pixeldroid.app.utils.api.objects.Instance import org.pixeldroid.app.utils.api.objects.Instance
import org.pixeldroid.app.utils.api.objects.NodeInfo import org.pixeldroid.app.utils.api.objects.NodeInfo
import org.pixeldroid.app.utils.db.addUser import org.pixeldroid.app.utils.db.addUser
import org.pixeldroid.app.utils.db.storeInstance import org.pixeldroid.app.utils.db.storeInstance
import org.pixeldroid.app.utils.hasInternet
import org.pixeldroid.app.utils.normalizeDomain
import org.pixeldroid.app.utils.notificationsWorker.makeChannelGroupId import org.pixeldroid.app.utils.notificationsWorker.makeChannelGroupId
import org.pixeldroid.app.utils.notificationsWorker.makeNotificationChannels import org.pixeldroid.app.utils.notificationsWorker.makeNotificationChannels
import retrofit2.HttpException import org.pixeldroid.app.utils.openUrl
import java.io.IOException import org.pixeldroid.app.utils.validDomain
/** /**
Overview of the flow of the login process: (boxes are requests done in parallel, Overview of the flow of the login process: (boxes are requests done in parallel,
@ -139,9 +141,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
pixelfedAPI.registerApplication( pixelfedAPI.registerApplication(
appName, "$oauthScheme://$PACKAGE_ID", SCOPE, "https://pixeldroid.org" appName, "$oauthScheme://$PACKAGE_ID", SCOPE, "https://pixeldroid.org"
) )
} catch (exception: IOException) { } catch (exception: Exception) {
return@async null
} catch (exception: HttpException) {
return@async null return@async null
} }
} }
@ -163,9 +163,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
}?.href ?: return@launch failedRegistration(getString(R.string.instance_error)) }?.href ?: return@launch failedRegistration(getString(R.string.instance_error))
nodeInfoSchema(normalizedDomain, clientId, nodeInfoSchemaUrl) nodeInfoSchema(normalizedDomain, clientId, nodeInfoSchemaUrl)
} catch (exception: IOException) { } catch (exception: Exception) {
return@launch failedRegistration()
} catch (exception: HttpException) {
return@launch failedRegistration() return@launch failedRegistration()
} }
} }
@ -179,12 +177,9 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
val nodeInfo: NodeInfo = try { val nodeInfo: NodeInfo = try {
pixelfedAPI.nodeInfoSchema(nodeInfoSchemaUrl) pixelfedAPI.nodeInfoSchema(nodeInfoSchemaUrl)
} catch (exception: IOException) { } catch (exception: Exception) {
return@coroutineScope failedRegistration(getString(R.string.instance_error))
} catch (exception: HttpException) {
return@coroutineScope failedRegistration(getString(R.string.instance_error)) return@coroutineScope failedRegistration(getString(R.string.instance_error))
} }
val domain: String = try { val domain: String = try {
if (nodeInfo.hasInstanceEndpointInfo()) { if (nodeInfo.hasInstanceEndpointInfo()) {
preferences.edit().putString("nodeInfo", Gson().toJson(nodeInfo)).remove("instance").apply() preferences.edit().putString("nodeInfo", Gson().toJson(nodeInfo)).remove("instance").apply()
@ -192,9 +187,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
} else { } else {
val instance: Instance = try { val instance: Instance = try {
pixelfedAPI.instance() pixelfedAPI.instance()
} catch (exception: IOException) { } catch (exception: Exception) {
return@coroutineScope failedRegistration(getString(R.string.instance_error))
} catch (exception: HttpException) {
return@coroutineScope failedRegistration(getString(R.string.instance_error)) return@coroutineScope failedRegistration(getString(R.string.instance_error))
} }
preferences.edit().putString("instance", Gson().toJson(instance)).remove("nodeInfo").apply() preferences.edit().putString("instance", Gson().toJson(instance)).remove("nodeInfo").apply()
@ -279,10 +272,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
domain domain
) )
wipeSharedSettings() wipeSharedSettings()
} catch (exception: IOException) { } catch (exception: Exception) {
return@launch failedRegistration(getString(R.string.token_error))
} catch (exception: HttpException) {
return@launch failedRegistration(getString(R.string.token_error)) return@launch failedRegistration(getString(R.string.token_error))
} }
} }
@ -324,9 +314,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
clientSecret = clientSecret clientSecret = clientSecret
) )
apiHolder.setToCurrentUser() apiHolder.setToCurrentUser()
} catch (exception: IOException) { } catch (exception: Exception) {
return failedRegistration(getString(R.string.verify_credentials))
} catch (exception: HttpException) {
return failedRegistration(getString(R.string.verify_credentials)) return failedRegistration(getString(R.string.verify_credentials))
} }
@ -345,11 +333,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
notifications.forEach{it.user_id = user.user_id; it.instance_uri = user.instance_uri} notifications.forEach{it.user_id = user.user_id; it.instance_uri = user.instance_uri}
db.notificationDao().insertAll(notifications) db.notificationDao().insertAll(notifications)
} catch (exception: IOException) { } catch (exception: Exception) {
return failedRegistration(getString(R.string.login_notifications))
} catch (exception: HttpException) {
return failedRegistration(getString(R.string.login_notifications))
} catch (exception: NullPointerException) {
return failedRegistration(getString(R.string.login_notifications)) return failedRegistration(getString(R.string.login_notifications))
} }

View File

@ -13,7 +13,6 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -63,8 +62,6 @@ import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companio
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.USER_NOTIFICATION_TAG import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.USER_NOTIFICATION_TAG
import org.pixeldroid.app.utils.notificationsWorker.enablePullNotifications import org.pixeldroid.app.utils.notificationsWorker.enablePullNotifications
import org.pixeldroid.app.utils.notificationsWorker.removeNotificationChannelsFromAccount import org.pixeldroid.app.utils.notificationsWorker.removeNotificationChannelsFromAccount
import retrofit2.HttpException
import java.io.IOException
import java.time.Instant import java.time.Instant
@ -278,9 +275,7 @@ class MainActivity : BaseThemedWithoutBarActivity() {
val account = api.verifyCredentials() val account = api.verifyCredentials()
addUser(db, account, domain, accessToken = accessToken, refreshToken = refreshToken, clientId = clientId, clientSecret = clientSecret) addUser(db, account, domain, accessToken = accessToken, refreshToken = refreshToken, clientId = clientId, clientSecret = clientSecret)
fillDrawerAccountInfo(account.id!!) fillDrawerAccountInfo(account.id!!)
} catch (exception: IOException) { } catch (exception: Exception) {
Log.e("ACCOUNT UPDATE:", exception.toString())
} catch (exception: HttpException) {
Log.e("ACCOUNT UPDATE:", exception.toString()) Log.e("ACCOUNT UPDATE:", exception.toString())
} }
} }
@ -446,14 +441,9 @@ class MainActivity : BaseThemedWithoutBarActivity() {
} }
val numberOfNewNotifications = if((filtered?.size ?: 20) >= 20) null else filtered?.size val numberOfNewNotifications = if((filtered?.size ?: 20) >= 20) null else filtered?.size
if(filtered?.isNotEmpty() == true ) setNotificationBadge(true, numberOfNewNotifications) if(filtered?.isNotEmpty() == true ) setNotificationBadge(true, numberOfNewNotifications)
} catch (exception: IOException) { } catch (exception: Exception) {
return@repeatOnLifecycle
} catch (exception: HttpException) {
return@repeatOnLifecycle return@repeatOnLifecycle
} }
} }
} }
} }

View File

@ -260,15 +260,6 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
//TODO make the activity launch this instead (and surrounding toasts too) //TODO make the activity launch this instead (and surrounding toasts too)
getApplication<PixelDroidApplication>().startActivity(intent) getApplication<PixelDroidApplication>().startActivity(intent)
} catch (exception: IOException) {
Toast.makeText(getApplication(), getApplication<PixelDroidApplication>().getString(R.string.upload_post_error),
Toast.LENGTH_SHORT).show()
Log.e(TAG, exception.toString())
_uiState.update { currentUiState ->
currentUiState.copy(
postCreationSendButtonEnabled = true
)
}
} catch (exception: HttpException) { } catch (exception: HttpException) {
Toast.makeText(getApplication(), getApplication<PixelDroidApplication>().getString(R.string.upload_post_failed), Toast.makeText(getApplication(), getApplication<PixelDroidApplication>().getString(R.string.upload_post_failed),
Toast.LENGTH_SHORT).show() Toast.LENGTH_SHORT).show()
@ -278,7 +269,16 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
postCreationSendButtonEnabled = true postCreationSendButtonEnabled = true
) )
} }
} finally { } catch (exception: Exception) {
Toast.makeText(getApplication(), getApplication<PixelDroidApplication>().getString(R.string.upload_post_error),
Toast.LENGTH_SHORT).show()
Log.e(TAG, exception.toString())
_uiState.update { currentUiState ->
currentUiState.copy(
postCreationSendButtonEnabled = true
)
}
}finally {
apiHolder.api = null apiHolder.api = null
} }
} }

View File

@ -18,8 +18,6 @@ import org.pixeldroid.app.utils.api.objects.Status.Companion.POST_COMMENT_TAG
import org.pixeldroid.app.utils.api.objects.Status.Companion.POST_TAG import org.pixeldroid.app.utils.api.objects.Status.Companion.POST_TAG
import org.pixeldroid.app.utils.api.objects.Status.Companion.VIEW_COMMENTS_TAG import org.pixeldroid.app.utils.api.objects.Status.Companion.VIEW_COMMENTS_TAG
import org.pixeldroid.app.utils.displayDimensionsInPx import org.pixeldroid.app.utils.displayDimensionsInPx
import retrofit2.HttpException
import java.io.IOException
class PostActivity : BaseThemedWithBarActivity() { class PostActivity : BaseThemedWithBarActivity() {
private lateinit var binding: ActivityPostBinding private lateinit var binding: ActivityPostBinding
@ -100,7 +98,7 @@ class PostActivity : BaseThemedWithBarActivity() {
val nonNullText = textIn.toString() val nonNullText = textIn.toString()
status.id.let { status.id.let {
try { try {
val response = api.postStatus(nonNullText, it) api.postStatus(nonNullText, it)
binding.commentIn.visibility = View.GONE binding.commentIn.visibility = View.GONE
//Reload to add the comment to the comment section //Reload to add the comment to the comment section
@ -111,18 +109,12 @@ class PostActivity : BaseThemedWithBarActivity() {
binding.root.context.getString(R.string.comment_posted).format(textIn), binding.root.context.getString(R.string.comment_posted).format(textIn),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} catch (exception: IOException) { } catch (exception: Exception) {
Log.e("COMMENT ERROR", exception.toString()) Log.e("COMMENT ERROR", exception.toString())
Toast.makeText( Toast.makeText(
binding.root.context, binding.root.context.getString(R.string.comment_error), binding.root.context, binding.root.context.getString(R.string.comment_error),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} catch (exception: HttpException) {
Toast.makeText(
binding.root.context, binding.root.context.getString(R.string.comment_error),
Toast.LENGTH_SHORT
).show()
Log.e("ERROR_CODE", exception.code().toString())
} }
} }
} }

View File

@ -7,8 +7,6 @@ import org.pixeldroid.app.R
import org.pixeldroid.app.databinding.ActivityReportBinding import org.pixeldroid.app.databinding.ActivityReportBinding
import org.pixeldroid.app.utils.BaseThemedWithBarActivity import org.pixeldroid.app.utils.BaseThemedWithBarActivity
import org.pixeldroid.app.utils.api.objects.Status import org.pixeldroid.app.utils.api.objects.Status
import retrofit2.HttpException
import java.io.IOException
class ReportActivity : BaseThemedWithBarActivity() { class ReportActivity : BaseThemedWithBarActivity() {
@ -44,9 +42,7 @@ class ReportActivity : BaseThemedWithBarActivity() {
) )
reportStatus(true) reportStatus(true)
} catch (exception: IOException) { } catch (exception: Exception) {
reportStatus(false)
} catch (exception: HttpException) {
reportStatus(false) reportStatus(false)
} }
} }

View File

@ -297,10 +297,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
//Update shown share count //Update shown share count
binding.nshares.text = resp.getNShares(binding.root.context) binding.nshares.text = resp.getNShares(binding.root.context)
binding.reblogger.isChecked = resp.reblogged!! binding.reblogger.isChecked = resp.reblogged!!
} catch (exception: HttpException) { } catch (exception: Exception) {
Log.e("RESPONSE_CODE", exception.code().toString())
binding.reblogger.isChecked = false
} catch (exception: IOException) {
Log.e("REBLOG ERROR", exception.toString()) Log.e("REBLOG ERROR", exception.toString())
binding.reblogger.isChecked = false binding.reblogger.isChecked = false
} }
@ -319,7 +316,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
} catch (exception: HttpException) { } catch (exception: HttpException) {
Log.e("RESPONSE_CODE", exception.code().toString()) Log.e("RESPONSE_CODE", exception.code().toString())
binding.reblogger.isChecked = true binding.reblogger.isChecked = true
} catch (exception: IOException) { } catch (exception: Exception) {
Log.e("REBLOG ERROR", exception.toString()) Log.e("REBLOG ERROR", exception.toString())
binding.reblogger.isChecked = true binding.reblogger.isChecked = true
} }
@ -732,12 +729,12 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
//Update shown like count and internal like toggle //Update shown like count and internal like toggle
binding.nlikes.text = resp.getNLikes(binding.root.context) binding.nlikes.text = resp.getNLikes(binding.root.context)
binding.liker.isChecked = resp.favourited ?: false binding.liker.isChecked = resp.favourited ?: false
} catch (exception: IOException) {
Log.e("LIKE ERROR", exception.toString())
binding.liker.isChecked = false
} catch (exception: HttpException) { } catch (exception: HttpException) {
Log.e("RESPONSE_CODE", exception.code().toString()) Log.e("RESPONSE_CODE", exception.code().toString())
binding.liker.isChecked = false binding.liker.isChecked = false
} catch (exception: Exception) {
Log.e("LIKE ERROR", exception.toString())
binding.liker.isChecked = false
} }
} }
} }
@ -752,12 +749,12 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
//Update shown like count and internal like toggle //Update shown like count and internal like toggle
binding.nlikes.text = resp.getNLikes(binding.root.context) binding.nlikes.text = resp.getNLikes(binding.root.context)
binding.liker.isChecked = resp.favourited ?: false binding.liker.isChecked = resp.favourited ?: false
} catch (exception: IOException) {
Log.e("UNLIKE ERROR", exception.toString())
binding.liker.isChecked = true
} catch (exception: HttpException) { } catch (exception: HttpException) {
Log.e("RESPONSE_CODE", exception.code().toString()) Log.e("RESPONSE_CODE", exception.code().toString())
binding.liker.isChecked = true binding.liker.isChecked = true
} catch (exception: Exception) {
Log.e("UNLIKE ERROR", exception.toString())
binding.liker.isChecked = true
} }
} }
} }

View File

@ -21,8 +21,6 @@ import androidx.room.withTransaction
import org.pixeldroid.app.utils.db.AppDatabase import org.pixeldroid.app.utils.db.AppDatabase
import org.pixeldroid.app.utils.di.PixelfedAPIHolder import org.pixeldroid.app.utils.di.PixelfedAPIHolder
import org.pixeldroid.app.utils.api.objects.Notification import org.pixeldroid.app.utils.api.objects.Notification
import retrofit2.HttpException
import java.io.IOException
import java.lang.Exception import java.lang.Exception
import java.lang.NullPointerException import java.lang.NullPointerException
import javax.inject.Inject import javax.inject.Inject
@ -74,11 +72,7 @@ class NotificationsRemoteMediator @Inject constructor(
db.notificationDao().insertAll(apiResponse) db.notificationDao().insertAll(apiResponse)
} }
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
} catch (exception: IOException) { } catch (exception: Exception){
return MediatorResult.Error(exception)
} catch (exception: HttpException) {
return MediatorResult.Error(exception)
} catch (exception: Exception){
return MediatorResult.Error(exception) return MediatorResult.Error(exception)
} }
} }

View File

@ -5,8 +5,6 @@ import androidx.room.withTransaction
import org.pixeldroid.app.utils.db.AppDatabase import org.pixeldroid.app.utils.db.AppDatabase
import org.pixeldroid.app.utils.di.PixelfedAPIHolder import org.pixeldroid.app.utils.di.PixelfedAPIHolder
import org.pixeldroid.app.utils.db.entities.HomeStatusDatabaseEntity import org.pixeldroid.app.utils.db.entities.HomeStatusDatabaseEntity
import retrofit2.HttpException
import java.io.IOException
import java.lang.NullPointerException import java.lang.NullPointerException
import javax.inject.Inject import javax.inject.Inject
@ -59,9 +57,7 @@ class HomeFeedRemoteMediator @Inject constructor(
db.homePostDao().insertAll(dbObjects) db.homePostDao().insertAll(dbObjects)
} }
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
} catch (exception: IOException) { } catch (exception: Exception) {
return MediatorResult.Error(exception)
} catch (exception: HttpException) {
return MediatorResult.Error(exception) return MediatorResult.Error(exception)
} }
} }

View File

@ -21,8 +21,6 @@ import androidx.room.withTransaction
import org.pixeldroid.app.utils.db.AppDatabase import org.pixeldroid.app.utils.db.AppDatabase
import org.pixeldroid.app.utils.db.entities.PublicFeedStatusDatabaseEntity import org.pixeldroid.app.utils.db.entities.PublicFeedStatusDatabaseEntity
import org.pixeldroid.app.utils.di.PixelfedAPIHolder import org.pixeldroid.app.utils.di.PixelfedAPIHolder
import retrofit2.HttpException
import java.io.IOException
import java.lang.NullPointerException import java.lang.NullPointerException
import javax.inject.Inject import javax.inject.Inject
@ -74,9 +72,7 @@ class PublicFeedRemoteMediator @Inject constructor(
db.publicPostDao().insertAll(dbObjects) db.publicPostDao().insertAll(dbObjects)
} }
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached) return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
} catch (exception: IOException) { } catch (exception: Exception) {
return MediatorResult.Error(exception)
} catch (exception: HttpException) {
return MediatorResult.Error(exception) return MediatorResult.Error(exception)
} }
} }

View File

@ -5,7 +5,6 @@ import androidx.paging.PagingState
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Account import org.pixeldroid.app.utils.api.objects.Account
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException
class FollowersPagingSource( class FollowersPagingSource(
private val api: PixelfedAPI, private val api: PixelfedAPI,
@ -58,9 +57,7 @@ class FollowersPagingSource(
prevKey = null, prevKey = null,
nextKey = if (accounts.isEmpty() || nextPosition.isEmpty() || nextPosition == position) null else nextPosition nextKey = if (accounts.isEmpty() || nextPosition.isEmpty() || nextPosition == position) null else nextPosition
) )
} catch (exception: IOException) { } catch (exception: Exception) {
LoadResult.Error(exception)
} catch (exception: HttpException) {
LoadResult.Error(exception) LoadResult.Error(exception)
} }
} }

View File

@ -4,8 +4,6 @@ import androidx.paging.PagingSource
import androidx.paging.PagingState import androidx.paging.PagingState
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Status import org.pixeldroid.app.utils.api.objects.Status
import retrofit2.HttpException
import java.io.IOException
class CommentPagingSource( class CommentPagingSource(
private val api: PixelfedAPI, private val api: PixelfedAPI,
@ -23,9 +21,7 @@ class CommentPagingSource(
prevKey = null, prevKey = null,
nextKey = null nextKey = null
) )
} catch (exception: HttpException) { } catch (exception: Exception) {
LoadResult.Error(exception)
} catch (exception: IOException) {
LoadResult.Error(exception) LoadResult.Error(exception)
} }
} }

View File

@ -30,9 +30,7 @@ class HashTagPagingSource(
prevKey = null, prevKey = null,
nextKey = if(nextKey == position) null else nextKey nextKey = if(nextKey == position) null else nextKey
) )
} catch (exception: HttpException) { } catch (exception: Exception) {
LoadResult.Error(exception)
} catch (exception: IOException) {
LoadResult.Error(exception) LoadResult.Error(exception)
} }
} }

View File

@ -4,8 +4,6 @@ import androidx.paging.PagingSource
import androidx.paging.PagingState import androidx.paging.PagingState
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Collection import org.pixeldroid.app.utils.api.objects.Collection
import retrofit2.HttpException
import java.io.IOException
class CollectionsPagingSource( class CollectionsPagingSource(
private val api: PixelfedAPI, private val api: PixelfedAPI,
@ -21,9 +19,7 @@ class CollectionsPagingSource(
//TODO pagination. For now, don't paginate //TODO pagination. For now, don't paginate
nextKey = null nextKey = null
) )
} catch (exception: HttpException) { } catch (exception: Exception) {
LoadResult.Error(exception)
} catch (exception: IOException) {
LoadResult.Error(exception) LoadResult.Error(exception)
} }
} }

View File

@ -4,8 +4,6 @@ import androidx.paging.PagingSource
import androidx.paging.PagingState import androidx.paging.PagingState
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Status import org.pixeldroid.app.utils.api.objects.Status
import retrofit2.HttpException
import java.io.IOException
class ProfilePagingSource( class ProfilePagingSource(
private val api: PixelfedAPI, private val api: PixelfedAPI,
@ -45,9 +43,7 @@ class ProfilePagingSource(
if(posts.isEmpty()) null else (params.key?.toIntOrNull()?.plus(1))?.toString() if(posts.isEmpty()) null else (params.key?.toIntOrNull()?.plus(1))?.toString()
} else if(nextKey == position) null else nextKey } else if(nextKey == position) null else nextKey
) )
} catch (exception: HttpException) { } catch (exception: Exception) {
LoadResult.Error(exception)
} catch (exception: IOException) {
LoadResult.Error(exception) LoadResult.Error(exception)
} }
} }

View File

@ -5,8 +5,6 @@ import androidx.paging.PagingState
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.FeedContent import org.pixeldroid.app.utils.api.objects.FeedContent
import org.pixeldroid.app.utils.api.objects.Results import org.pixeldroid.app.utils.api.objects.Results
import retrofit2.HttpException
import java.io.IOException
/** /**
* Provides the PagingSource for search feeds. Is used in [SearchContentRepository] * Provides the PagingSource for search feeds. Is used in [SearchContentRepository]
@ -41,9 +39,7 @@ class SearchPagingSource<T: FeedContent>(
prevKey = null, prevKey = null,
nextKey = if(nextKey == position) null else nextKey nextKey = if(nextKey == position) null else nextKey
) )
} catch (exception: HttpException) { } catch (exception: Exception) {
LoadResult.Error(exception)
} catch (exception: IOException) {
LoadResult.Error(exception) LoadResult.Error(exception)
} }
} }

View File

@ -16,8 +16,7 @@ import org.pixeldroid.app.profile.ProfileFeedFragment.Companion.COLLECTION_ID
import org.pixeldroid.app.utils.BaseThemedWithBarActivity import org.pixeldroid.app.utils.BaseThemedWithBarActivity
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Collection import org.pixeldroid.app.utils.api.objects.Collection
import retrofit2.HttpException import java.lang.Exception
import java.io.IOException
class CollectionActivity : BaseThemedWithBarActivity() { class CollectionActivity : BaseThemedWithBarActivity() {
private lateinit var binding: ActivityCollectionBinding private lateinit var binding: ActivityCollectionBinding
@ -43,7 +42,6 @@ class CollectionActivity : BaseThemedWithBarActivity() {
collection = intent.getSerializableExtra(COLLECTION_TAG) as Collection collection = intent.getSerializableExtra(COLLECTION_TAG) as Collection
addCollection = intent.getBooleanExtra(ADD_COLLECTION_TAG, false) addCollection = intent.getBooleanExtra(ADD_COLLECTION_TAG, false)
deleteFromCollection = intent.getBooleanExtra(DELETE_FROM_COLLECTION_TAG, false) deleteFromCollection = intent.getBooleanExtra(DELETE_FROM_COLLECTION_TAG, false)
@ -90,9 +88,9 @@ class CollectionActivity : BaseThemedWithBarActivity() {
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
// Relaunch same activity, to avoid duplicates in history // Relaunch same activity, to avoid duplicates in history
super.onNewIntent(intent); super.onNewIntent(intent)
finish(); finish()
startActivity(intent); startActivity(intent)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -108,10 +106,11 @@ class CollectionActivity : BaseThemedWithBarActivity() {
api.deleteCollection(collection.id) api.deleteCollection(collection.id)
// Deleted, exit activity // Deleted, exit activity
finish() finish()
} catch (exception: IOException) { } catch (exception: Exception) {
TODO("Error") Snackbar.make(
} catch (exception: HttpException) { binding.root, getString(R.string.something_went_wrong),
TODO("Error") Snackbar.LENGTH_LONG
).show()
} }
} }
} }

View File

@ -5,7 +5,6 @@ import android.net.Uri
import android.provider.OpenableColumns import android.provider.OpenableColumns
import android.text.Editable import android.text.Editable
import android.util.Log import android.util.Log
import android.widget.Toast
import androidx.core.net.toFile import androidx.core.net.toFile
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
@ -19,21 +18,12 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody import okhttp3.MultipartBody
import okhttp3.RequestBody
import org.pixeldroid.app.R
import org.pixeldroid.app.postCreation.ProgressRequestBody import org.pixeldroid.app.postCreation.ProgressRequestBody
import org.pixeldroid.app.posts.fromHtml
import org.pixeldroid.app.utils.PixelDroidApplication import org.pixeldroid.app.utils.PixelDroidApplication
import org.pixeldroid.app.utils.api.objects.Account import org.pixeldroid.app.utils.api.objects.Account
import org.pixeldroid.app.utils.api.objects.Attachment
import org.pixeldroid.app.utils.di.PixelfedAPIHolder import org.pixeldroid.app.utils.di.PixelfedAPIHolder
import retrofit2.HttpException
import java.io.File
import java.io.IOException
import java.lang.Exception
import java.net.URI
import javax.inject.Inject import javax.inject.Inject
class EditProfileViewModel(application: Application) : AndroidViewModel(application) { class EditProfileViewModel(application: Application) : AndroidViewModel(application) {
@ -69,17 +59,7 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
error = false error = false
) )
} }
} catch (exception: IOException) { } catch (exception: Exception) {
_uiState.update { currentUiState ->
currentUiState.copy(
sendingProfile = false,
profileSent = false,
loadingProfile = false,
profileLoaded = false,
error = true
)
}
} catch (exception: HttpException) {
_uiState.update { currentUiState -> _uiState.update { currentUiState ->
currentUiState.copy( currentUiState.copy(
sendingProfile = false, sendingProfile = false,
@ -120,7 +100,7 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
oldProfile = account oldProfile = account
_uiState.update { currentUiState -> _uiState.update { currentUiState ->
currentUiState.copy( currentUiState.copy(
bio = account.note, bio = account.source?.note ?: account.note?.let {fromHtml(it).toString()},
name = account.display_name, name = account.display_name,
profilePictureUri = account.anyAvatar()?.toUri(), profilePictureUri = account.anyAvatar()?.toUri(),
privateAccount = account.locked, privateAccount = account.locked,
@ -131,42 +111,22 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
error = false error = false
) )
} }
} catch (exception: IOException) {
Log.e("TAG", exception.toString())
_uiState.update { currentUiState ->
currentUiState.copy(
sendingProfile = false,
profileSent = false,
loadingProfile = false,
profileLoaded = false,
error = true
)
}
} catch (exception: HttpException) {
Log.e("TAG", exception.toString())
_uiState.update { currentUiState ->
currentUiState.copy(
sendingProfile = false,
profileSent = false,
loadingProfile = false,
profileLoaded = false,
error = true
)
}
} catch (exception: Exception) { } catch (exception: Exception) {
Log.e("TAG", exception.toString()) Log.e("TAG", exception.toString())
_uiState.update { currentUiState ->
currentUiState.copy(
sendingProfile = false,
profileSent = false,
loadingProfile = false,
profileLoaded = false,
error = true
)
}
} }
} }
} }
} }
fun errorShown() {
_uiState.update { currentUiState ->
currentUiState.copy(error = false)
}
}
fun updateBio(bio: Editable?) { fun updateBio(bio: Editable?) {
_uiState.update { currentUiState -> _uiState.update { currentUiState ->
currentUiState.copy(bio = bio.toString()) currentUiState.copy(bio = bio.toString())
@ -193,8 +153,12 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
fun madeChanges(): Boolean = fun madeChanges(): Boolean =
with(uiState.value) { with(uiState.value) {
oldProfile?.locked != privateAccount val bioUnchanged: Boolean = oldProfile?.source?.note?.let { it != bio }
|| oldProfile?.display_name != name || oldProfile?.note != bio // If source note is null, check note
?: oldProfile?.note?.let { fromHtml(it).toString() != bio }
?: true
oldProfile?.locked != privateAccount || oldProfile?.display_name != name
|| bioUnchanged
} }
fun clickedCard() { fun clickedCard() {

View File

@ -4,34 +4,24 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.pixeldroid.app.R import org.pixeldroid.app.R
import org.pixeldroid.app.databinding.ActivityProfileBinding import org.pixeldroid.app.databinding.ActivityProfileBinding
import org.pixeldroid.app.databinding.FragmentProfilePostsBinding
import org.pixeldroid.app.posts.PostActivity
import org.pixeldroid.app.posts.parseHTMLText import org.pixeldroid.app.posts.parseHTMLText
import org.pixeldroid.app.utils.* import org.pixeldroid.app.utils.BaseThemedWithBarActivity
import org.pixeldroid.app.utils.api.PixelfedAPI import org.pixeldroid.app.utils.api.PixelfedAPI
import org.pixeldroid.app.utils.api.objects.Account import org.pixeldroid.app.utils.api.objects.Account
import org.pixeldroid.app.utils.api.objects.Attachment
import org.pixeldroid.app.utils.api.objects.Status
import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
import org.pixeldroid.app.utils.setProfileImageFromURL
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException import java.io.IOException
@ -151,19 +141,13 @@ class ProfileActivity : BaseThemedWithBarActivity() {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser() val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
val myAccount: Account = try { val myAccount: Account = try {
api.verifyCredentials() api.verifyCredentials()
} catch (exception: IOException) { } catch (exception: Exception) {
Log.e("ProfileActivity:", exception.toString()) Log.e("ProfileActivity:", exception.toString())
Toast.makeText( Toast.makeText(
applicationContext, "Could not get your profile", applicationContext, "Could not get your profile",
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
return@launchWhenResumed return@launchWhenResumed
} catch (exception: HttpException) {
Toast.makeText(
applicationContext, "Could not get your profile",
Toast.LENGTH_SHORT
).show()
return@launchWhenResumed
} }
setViews(myAccount) setViews(myAccount)
} }
@ -304,17 +288,12 @@ class ProfileActivity : BaseThemedWithBarActivity() {
val rel = api.follow(account.id.orEmpty()) val rel = api.follow(account.id.orEmpty())
if(rel.following == true) setOnClickUnfollow(account, rel.requested == true) if(rel.following == true) setOnClickUnfollow(account, rel.requested == true)
else setOnClickFollow(account) else setOnClickFollow(account)
} catch (exception: IOException) { } catch (exception: Exception) {
Log.e("FOLLOW ERROR", exception.toString()) Log.e("FOLLOW ERROR", exception.toString())
Toast.makeText( Toast.makeText(
applicationContext, getString(R.string.follow_error), applicationContext, getString(R.string.follow_error),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} catch (exception: HttpException) {
Toast.makeText(
applicationContext, getString(R.string.follow_error),
Toast.LENGTH_SHORT
).show()
} }
} }
} }

View File

@ -41,8 +41,6 @@ import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
import org.pixeldroid.app.utils.displayDimensionsInPx import org.pixeldroid.app.utils.displayDimensionsInPx
import org.pixeldroid.app.utils.openUrl import org.pixeldroid.app.utils.openUrl
import org.pixeldroid.app.utils.setSquareImageFromURL import org.pixeldroid.app.utils.setSquareImageFromURL
import retrofit2.HttpException
import java.io.IOException
/** /**
* Fragment to show a list of [Account]s, as a result of a search. * Fragment to show a list of [Account]s, as a result of a search.
@ -84,6 +82,7 @@ class ProfileFeedFragment : UncachedFeedFragment<FeedContent>() {
collections = false collections = false
bookmarks = false bookmarks = false
} }
adapter = ProfilePostsAdapter() adapter = ProfilePostsAdapter()
//get the currently active user //get the currently active user
@ -302,10 +301,7 @@ class ProfilePostsViewHolder(binding: FragmentProfilePostsBinding) : RecyclerVie
putExtra(CollectionActivity.COLLECTION_TAG, collection) putExtra(CollectionActivity.COLLECTION_TAG, collection)
} }
postPreview.context.startActivity(intent) postPreview.context.startActivity(intent)
} catch (exception: IOException) { } catch (exception: Exception) {
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_add_post_to_collection),
Snackbar.LENGTH_LONG).show()
} catch (exception: HttpException) {
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_add_post_to_collection), Snackbar.make(postPreview, postPreview.context.getString(R.string.error_add_post_to_collection),
Snackbar.LENGTH_LONG).show() Snackbar.LENGTH_LONG).show()
} }
@ -322,10 +318,7 @@ class ProfilePostsViewHolder(binding: FragmentProfilePostsBinding) : RecyclerVie
putExtra(CollectionActivity.COLLECTION_TAG, collection) putExtra(CollectionActivity.COLLECTION_TAG, collection)
} }
postPreview.context.startActivity(intent) postPreview.context.startActivity(intent)
} catch (exception: IOException) { } catch (exception: Exception) {
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_remove_post_from_collection),
Snackbar.LENGTH_LONG).show()
} catch (exception: HttpException) {
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_remove_post_from_collection), Snackbar.make(postPreview, postPreview.context.getString(R.string.error_remove_post_from_collection),
Snackbar.LENGTH_LONG).show() Snackbar.LENGTH_LONG).show()
} }

View File

@ -23,8 +23,6 @@ import org.pixeldroid.app.utils.api.objects.FeedContent
import org.pixeldroid.app.utils.api.objects.Status import org.pixeldroid.app.utils.api.objects.Status
import org.pixeldroid.app.utils.api.objects.Tag import org.pixeldroid.app.utils.api.objects.Tag
import org.pixeldroid.app.utils.setSquareImageFromURL import org.pixeldroid.app.utils.setSquareImageFromURL
import retrofit2.HttpException
import java.io.IOException
class TrendingActivity : BaseThemedWithBarActivity() { class TrendingActivity : BaseThemedWithBarActivity() {
@ -95,9 +93,7 @@ class TrendingActivity : BaseThemedWithBarActivity() {
} }
trendingAdapter.addPosts(content) trendingAdapter.addPosts(content)
showError(show = false) showError(show = false)
} catch (exception: IOException) { } catch (exception: Exception) {
showError()
} catch (exception: HttpException) {
showError() showError()
} }
} }

View File

@ -108,9 +108,7 @@ class NotificationsWorker(
since_id = previouslyLatestNotification?.id since_id = previouslyLatestNotification?.id
) )
} }
} catch (exception: IOException) { } catch (exception: Exception) {
return Result.failure()
} catch (exception: HttpException) {
return Result.failure() return Result.failure()
} }
} }

View File

@ -319,7 +319,7 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="your_bio">Your bio</string> <string name="your_bio">Your bio</string>
<string name="your_name">Your Name</string> <string name="your_name">Your Name</string>
<string name="profile_save_changes">You did not save your changes. Exit?</string> <string name="profile_save_changes">You did not save your changes. Exit?</string>
<string name="fetching_profile">Fetching your profile...</string> <string name="fetching_profile">Fetching your profile</string>
<string name="saving_profile">Saving your profile</string> <string name="saving_profile">Saving your profile</string>
<string name="profile_saved">Changes saved!</string> <string name="profile_saved">Changes saved!</string>
<string name="error_profile">Something went wrong. Tap to retry</string> <string name="error_profile">Something went wrong. Tap to retry</string>