Less crashing for bad json, other bug fixes
This commit is contained in:
parent
a28be0edf4
commit
5dd5057479
@ -15,17 +15,19 @@ import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
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.objects.Application
|
||||
import org.pixeldroid.app.utils.api.objects.Instance
|
||||
import org.pixeldroid.app.utils.api.objects.NodeInfo
|
||||
import org.pixeldroid.app.utils.db.addUser
|
||||
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.makeNotificationChannels
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import org.pixeldroid.app.utils.openUrl
|
||||
import org.pixeldroid.app.utils.validDomain
|
||||
|
||||
/**
|
||||
Overview of the flow of the login process: (boxes are requests done in parallel,
|
||||
@ -139,9 +141,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||
pixelfedAPI.registerApplication(
|
||||
appName, "$oauthScheme://$PACKAGE_ID", SCOPE, "https://pixeldroid.org"
|
||||
)
|
||||
} catch (exception: IOException) {
|
||||
return@async null
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return@async null
|
||||
}
|
||||
}
|
||||
@ -163,9 +163,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||
}?.href ?: return@launch failedRegistration(getString(R.string.instance_error))
|
||||
|
||||
nodeInfoSchema(normalizedDomain, clientId, nodeInfoSchemaUrl)
|
||||
} catch (exception: IOException) {
|
||||
return@launch failedRegistration()
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return@launch failedRegistration()
|
||||
}
|
||||
}
|
||||
@ -179,12 +177,9 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||
|
||||
val nodeInfo: NodeInfo = try {
|
||||
pixelfedAPI.nodeInfoSchema(nodeInfoSchemaUrl)
|
||||
} catch (exception: IOException) {
|
||||
return@coroutineScope failedRegistration(getString(R.string.instance_error))
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return@coroutineScope failedRegistration(getString(R.string.instance_error))
|
||||
}
|
||||
|
||||
val domain: String = try {
|
||||
if (nodeInfo.hasInstanceEndpointInfo()) {
|
||||
preferences.edit().putString("nodeInfo", Gson().toJson(nodeInfo)).remove("instance").apply()
|
||||
@ -192,9 +187,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||
} else {
|
||||
val instance: Instance = try {
|
||||
pixelfedAPI.instance()
|
||||
} catch (exception: IOException) {
|
||||
return@coroutineScope failedRegistration(getString(R.string.instance_error))
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return@coroutineScope failedRegistration(getString(R.string.instance_error))
|
||||
}
|
||||
preferences.edit().putString("instance", Gson().toJson(instance)).remove("nodeInfo").apply()
|
||||
@ -279,10 +272,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||
domain
|
||||
)
|
||||
wipeSharedSettings()
|
||||
} catch (exception: IOException) {
|
||||
return@launch failedRegistration(getString(R.string.token_error))
|
||||
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return@launch failedRegistration(getString(R.string.token_error))
|
||||
}
|
||||
}
|
||||
@ -324,9 +314,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||
clientSecret = clientSecret
|
||||
)
|
||||
apiHolder.setToCurrentUser()
|
||||
} catch (exception: IOException) {
|
||||
return failedRegistration(getString(R.string.verify_credentials))
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
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}
|
||||
|
||||
db.notificationDao().insertAll(notifications)
|
||||
} catch (exception: IOException) {
|
||||
return failedRegistration(getString(R.string.login_notifications))
|
||||
} catch (exception: HttpException) {
|
||||
return failedRegistration(getString(R.string.login_notifications))
|
||||
} catch (exception: NullPointerException) {
|
||||
} catch (exception: Exception) {
|
||||
return failedRegistration(getString(R.string.login_notifications))
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
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.enablePullNotifications
|
||||
import org.pixeldroid.app.utils.notificationsWorker.removeNotificationChannelsFromAccount
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.time.Instant
|
||||
|
||||
|
||||
@ -278,9 +275,7 @@ class MainActivity : BaseThemedWithoutBarActivity() {
|
||||
val account = api.verifyCredentials()
|
||||
addUser(db, account, domain, accessToken = accessToken, refreshToken = refreshToken, clientId = clientId, clientSecret = clientSecret)
|
||||
fillDrawerAccountInfo(account.id!!)
|
||||
} catch (exception: IOException) {
|
||||
Log.e("ACCOUNT UPDATE:", exception.toString())
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
Log.e("ACCOUNT UPDATE:", exception.toString())
|
||||
}
|
||||
}
|
||||
@ -446,14 +441,9 @@ class MainActivity : BaseThemedWithoutBarActivity() {
|
||||
}
|
||||
val numberOfNewNotifications = if((filtered?.size ?: 20) >= 20) null else filtered?.size
|
||||
if(filtered?.isNotEmpty() == true ) setNotificationBadge(true, numberOfNewNotifications)
|
||||
} catch (exception: IOException) {
|
||||
return@repeatOnLifecycle
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return@repeatOnLifecycle
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -260,15 +260,6 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
//TODO make the activity launch this instead (and surrounding toasts too)
|
||||
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) {
|
||||
Toast.makeText(getApplication(), getApplication<PixelDroidApplication>().getString(R.string.upload_post_failed),
|
||||
Toast.LENGTH_SHORT).show()
|
||||
@ -278,7 +269,16 @@ class PostSubmissionViewModel(application: Application, photodata: ArrayList<Pho
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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.VIEW_COMMENTS_TAG
|
||||
import org.pixeldroid.app.utils.displayDimensionsInPx
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class PostActivity : BaseThemedWithBarActivity() {
|
||||
private lateinit var binding: ActivityPostBinding
|
||||
@ -100,7 +98,7 @@ class PostActivity : BaseThemedWithBarActivity() {
|
||||
val nonNullText = textIn.toString()
|
||||
status.id.let {
|
||||
try {
|
||||
val response = api.postStatus(nonNullText, it)
|
||||
api.postStatus(nonNullText, it)
|
||||
binding.commentIn.visibility = View.GONE
|
||||
|
||||
//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),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
Log.e("COMMENT ERROR", exception.toString())
|
||||
Toast.makeText(
|
||||
binding.root.context, binding.root.context.getString(R.string.comment_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ import org.pixeldroid.app.R
|
||||
import org.pixeldroid.app.databinding.ActivityReportBinding
|
||||
import org.pixeldroid.app.utils.BaseThemedWithBarActivity
|
||||
import org.pixeldroid.app.utils.api.objects.Status
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class ReportActivity : BaseThemedWithBarActivity() {
|
||||
|
||||
@ -44,9 +42,7 @@ class ReportActivity : BaseThemedWithBarActivity() {
|
||||
)
|
||||
|
||||
reportStatus(true)
|
||||
} catch (exception: IOException) {
|
||||
reportStatus(false)
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
reportStatus(false)
|
||||
}
|
||||
}
|
||||
|
@ -297,10 +297,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
//Update shown share count
|
||||
binding.nshares.text = resp.getNShares(binding.root.context)
|
||||
binding.reblogger.isChecked = resp.reblogged!!
|
||||
} catch (exception: HttpException) {
|
||||
Log.e("RESPONSE_CODE", exception.code().toString())
|
||||
binding.reblogger.isChecked = false
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
Log.e("REBLOG ERROR", exception.toString())
|
||||
binding.reblogger.isChecked = false
|
||||
}
|
||||
@ -319,7 +316,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
} catch (exception: HttpException) {
|
||||
Log.e("RESPONSE_CODE", exception.code().toString())
|
||||
binding.reblogger.isChecked = true
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
Log.e("REBLOG ERROR", exception.toString())
|
||||
binding.reblogger.isChecked = true
|
||||
}
|
||||
@ -732,12 +729,12 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||
//Update shown like count and internal like toggle
|
||||
binding.nlikes.text = resp.getNLikes(binding.root.context)
|
||||
binding.liker.isChecked = resp.favourited ?: false
|
||||
} catch (exception: IOException) {
|
||||
Log.e("LIKE ERROR", exception.toString())
|
||||
binding.liker.isChecked = false
|
||||
} catch (exception: HttpException) {
|
||||
Log.e("RESPONSE_CODE", exception.code().toString())
|
||||
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
|
||||
binding.nlikes.text = resp.getNLikes(binding.root.context)
|
||||
binding.liker.isChecked = resp.favourited ?: false
|
||||
} catch (exception: IOException) {
|
||||
Log.e("UNLIKE ERROR", exception.toString())
|
||||
binding.liker.isChecked = true
|
||||
} catch (exception: HttpException) {
|
||||
Log.e("RESPONSE_CODE", exception.code().toString())
|
||||
binding.liker.isChecked = true
|
||||
} catch (exception: Exception) {
|
||||
Log.e("UNLIKE ERROR", exception.toString())
|
||||
binding.liker.isChecked = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ import androidx.room.withTransaction
|
||||
import org.pixeldroid.app.utils.db.AppDatabase
|
||||
import org.pixeldroid.app.utils.di.PixelfedAPIHolder
|
||||
import org.pixeldroid.app.utils.api.objects.Notification
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
import java.lang.NullPointerException
|
||||
import javax.inject.Inject
|
||||
@ -74,11 +72,7 @@ class NotificationsRemoteMediator @Inject constructor(
|
||||
db.notificationDao().insertAll(apiResponse)
|
||||
}
|
||||
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
|
||||
} catch (exception: IOException) {
|
||||
return MediatorResult.Error(exception)
|
||||
} catch (exception: HttpException) {
|
||||
return MediatorResult.Error(exception)
|
||||
} catch (exception: Exception){
|
||||
} catch (exception: Exception){
|
||||
return MediatorResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import androidx.room.withTransaction
|
||||
import org.pixeldroid.app.utils.db.AppDatabase
|
||||
import org.pixeldroid.app.utils.di.PixelfedAPIHolder
|
||||
import org.pixeldroid.app.utils.db.entities.HomeStatusDatabaseEntity
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.lang.NullPointerException
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -59,9 +57,7 @@ class HomeFeedRemoteMediator @Inject constructor(
|
||||
db.homePostDao().insertAll(dbObjects)
|
||||
}
|
||||
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
|
||||
} catch (exception: IOException) {
|
||||
return MediatorResult.Error(exception)
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return MediatorResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ import androidx.room.withTransaction
|
||||
import org.pixeldroid.app.utils.db.AppDatabase
|
||||
import org.pixeldroid.app.utils.db.entities.PublicFeedStatusDatabaseEntity
|
||||
import org.pixeldroid.app.utils.di.PixelfedAPIHolder
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.lang.NullPointerException
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -74,9 +72,7 @@ class PublicFeedRemoteMediator @Inject constructor(
|
||||
db.publicPostDao().insertAll(dbObjects)
|
||||
}
|
||||
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
|
||||
} catch (exception: IOException) {
|
||||
return MediatorResult.Error(exception)
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return MediatorResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import androidx.paging.PagingState
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
import org.pixeldroid.app.utils.api.objects.Account
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class FollowersPagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
@ -58,9 +57,7 @@ class FollowersPagingSource(
|
||||
prevKey = null,
|
||||
nextKey = if (accounts.isEmpty() || nextPosition.isEmpty() || nextPosition == position) null else nextPosition
|
||||
)
|
||||
} catch (exception: IOException) {
|
||||
LoadResult.Error(exception)
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
import org.pixeldroid.app.utils.api.objects.Status
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class CommentPagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
@ -23,9 +21,7 @@ class CommentPagingSource(
|
||||
prevKey = null,
|
||||
nextKey = null
|
||||
)
|
||||
} catch (exception: HttpException) {
|
||||
LoadResult.Error(exception)
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,7 @@ class HashTagPagingSource(
|
||||
prevKey = null,
|
||||
nextKey = if(nextKey == position) null else nextKey
|
||||
)
|
||||
} catch (exception: HttpException) {
|
||||
LoadResult.Error(exception)
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
import org.pixeldroid.app.utils.api.objects.Collection
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class CollectionsPagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
@ -21,9 +19,7 @@ class CollectionsPagingSource(
|
||||
//TODO pagination. For now, don't paginate
|
||||
nextKey = null
|
||||
)
|
||||
} catch (exception: HttpException) {
|
||||
LoadResult.Error(exception)
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
import org.pixeldroid.app.utils.api.objects.Status
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class ProfilePagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
@ -45,9 +43,7 @@ class ProfilePagingSource(
|
||||
if(posts.isEmpty()) null else (params.key?.toIntOrNull()?.plus(1))?.toString()
|
||||
} else if(nextKey == position) null else nextKey
|
||||
)
|
||||
} catch (exception: HttpException) {
|
||||
LoadResult.Error(exception)
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import androidx.paging.PagingState
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
import org.pixeldroid.app.utils.api.objects.FeedContent
|
||||
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]
|
||||
@ -41,9 +39,7 @@ class SearchPagingSource<T: FeedContent>(
|
||||
prevKey = null,
|
||||
nextKey = if(nextKey == position) null else nextKey
|
||||
)
|
||||
} catch (exception: HttpException) {
|
||||
LoadResult.Error(exception)
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ import org.pixeldroid.app.profile.ProfileFeedFragment.Companion.COLLECTION_ID
|
||||
import org.pixeldroid.app.utils.BaseThemedWithBarActivity
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
import org.pixeldroid.app.utils.api.objects.Collection
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
|
||||
class CollectionActivity : BaseThemedWithBarActivity() {
|
||||
private lateinit var binding: ActivityCollectionBinding
|
||||
@ -43,7 +42,6 @@ class CollectionActivity : BaseThemedWithBarActivity() {
|
||||
|
||||
collection = intent.getSerializableExtra(COLLECTION_TAG) as Collection
|
||||
|
||||
|
||||
addCollection = intent.getBooleanExtra(ADD_COLLECTION_TAG, false)
|
||||
deleteFromCollection = intent.getBooleanExtra(DELETE_FROM_COLLECTION_TAG, false)
|
||||
|
||||
@ -90,9 +88,9 @@ class CollectionActivity : BaseThemedWithBarActivity() {
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
// Relaunch same activity, to avoid duplicates in history
|
||||
super.onNewIntent(intent);
|
||||
finish();
|
||||
startActivity(intent);
|
||||
super.onNewIntent(intent)
|
||||
finish()
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
@ -108,10 +106,11 @@ class CollectionActivity : BaseThemedWithBarActivity() {
|
||||
api.deleteCollection(collection.id)
|
||||
// Deleted, exit activity
|
||||
finish()
|
||||
} catch (exception: IOException) {
|
||||
TODO("Error")
|
||||
} catch (exception: HttpException) {
|
||||
TODO("Error")
|
||||
} catch (exception: Exception) {
|
||||
Snackbar.make(
|
||||
binding.root, getString(R.string.something_went_wrong),
|
||||
Snackbar.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import android.net.Uri
|
||||
import android.provider.OpenableColumns
|
||||
import android.text.Editable
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.net.toFile
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
@ -19,21 +18,12 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import org.pixeldroid.app.R
|
||||
import org.pixeldroid.app.postCreation.ProgressRequestBody
|
||||
import org.pixeldroid.app.posts.fromHtml
|
||||
import org.pixeldroid.app.utils.PixelDroidApplication
|
||||
import org.pixeldroid.app.utils.api.objects.Account
|
||||
import org.pixeldroid.app.utils.api.objects.Attachment
|
||||
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
|
||||
|
||||
class EditProfileViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@ -69,17 +59,7 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
|
||||
error = false
|
||||
)
|
||||
}
|
||||
} catch (exception: IOException) {
|
||||
_uiState.update { currentUiState ->
|
||||
currentUiState.copy(
|
||||
sendingProfile = false,
|
||||
profileSent = false,
|
||||
loadingProfile = false,
|
||||
profileLoaded = false,
|
||||
error = true
|
||||
)
|
||||
}
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
_uiState.update { currentUiState ->
|
||||
currentUiState.copy(
|
||||
sendingProfile = false,
|
||||
@ -120,7 +100,7 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
|
||||
oldProfile = account
|
||||
_uiState.update { currentUiState ->
|
||||
currentUiState.copy(
|
||||
bio = account.note,
|
||||
bio = account.source?.note ?: account.note?.let {fromHtml(it).toString()},
|
||||
name = account.display_name,
|
||||
profilePictureUri = account.anyAvatar()?.toUri(),
|
||||
privateAccount = account.locked,
|
||||
@ -131,42 +111,22 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
|
||||
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) {
|
||||
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?) {
|
||||
_uiState.update { currentUiState ->
|
||||
currentUiState.copy(bio = bio.toString())
|
||||
@ -193,8 +153,12 @@ class EditProfileViewModel(application: Application) : AndroidViewModel(applicat
|
||||
|
||||
fun madeChanges(): Boolean =
|
||||
with(uiState.value) {
|
||||
oldProfile?.locked != privateAccount
|
||||
|| oldProfile?.display_name != name || oldProfile?.note != bio
|
||||
val bioUnchanged: Boolean = oldProfile?.source?.note?.let { it != 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() {
|
||||
|
@ -4,34 +4,24 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.TabLayoutMediator
|
||||
import kotlinx.coroutines.launch
|
||||
import org.pixeldroid.app.R
|
||||
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.utils.*
|
||||
import org.pixeldroid.app.utils.BaseThemedWithBarActivity
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
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.setProfileImageFromURL
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
@ -151,19 +141,13 @@ class ProfileActivity : BaseThemedWithBarActivity() {
|
||||
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
|
||||
val myAccount: Account = try {
|
||||
api.verifyCredentials()
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
Log.e("ProfileActivity:", exception.toString())
|
||||
Toast.makeText(
|
||||
applicationContext, "Could not get your profile",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@launchWhenResumed
|
||||
} catch (exception: HttpException) {
|
||||
Toast.makeText(
|
||||
applicationContext, "Could not get your profile",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@launchWhenResumed
|
||||
}
|
||||
setViews(myAccount)
|
||||
}
|
||||
@ -304,17 +288,12 @@ class ProfileActivity : BaseThemedWithBarActivity() {
|
||||
val rel = api.follow(account.id.orEmpty())
|
||||
if(rel.following == true) setOnClickUnfollow(account, rel.requested == true)
|
||||
else setOnClickFollow(account)
|
||||
} catch (exception: IOException) {
|
||||
} catch (exception: Exception) {
|
||||
Log.e("FOLLOW ERROR", exception.toString())
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.follow_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} catch (exception: HttpException) {
|
||||
Toast.makeText(
|
||||
applicationContext, getString(R.string.follow_error),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,6 @@ import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
|
||||
import org.pixeldroid.app.utils.displayDimensionsInPx
|
||||
import org.pixeldroid.app.utils.openUrl
|
||||
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.
|
||||
@ -84,6 +82,7 @@ class ProfileFeedFragment : UncachedFeedFragment<FeedContent>() {
|
||||
collections = false
|
||||
bookmarks = false
|
||||
}
|
||||
|
||||
adapter = ProfilePostsAdapter()
|
||||
|
||||
//get the currently active user
|
||||
@ -302,10 +301,7 @@ class ProfilePostsViewHolder(binding: FragmentProfilePostsBinding) : RecyclerVie
|
||||
putExtra(CollectionActivity.COLLECTION_TAG, collection)
|
||||
}
|
||||
postPreview.context.startActivity(intent)
|
||||
} catch (exception: IOException) {
|
||||
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_add_post_to_collection),
|
||||
Snackbar.LENGTH_LONG).show()
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_add_post_to_collection),
|
||||
Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
@ -322,10 +318,7 @@ class ProfilePostsViewHolder(binding: FragmentProfilePostsBinding) : RecyclerVie
|
||||
putExtra(CollectionActivity.COLLECTION_TAG, collection)
|
||||
}
|
||||
postPreview.context.startActivity(intent)
|
||||
} catch (exception: IOException) {
|
||||
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_remove_post_from_collection),
|
||||
Snackbar.LENGTH_LONG).show()
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
Snackbar.make(postPreview, postPreview.context.getString(R.string.error_remove_post_from_collection),
|
||||
Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
|
@ -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.Tag
|
||||
import org.pixeldroid.app.utils.setSquareImageFromURL
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class TrendingActivity : BaseThemedWithBarActivity() {
|
||||
|
||||
@ -95,9 +93,7 @@ class TrendingActivity : BaseThemedWithBarActivity() {
|
||||
}
|
||||
trendingAdapter.addPosts(content)
|
||||
showError(show = false)
|
||||
} catch (exception: IOException) {
|
||||
showError()
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
showError()
|
||||
}
|
||||
}
|
||||
|
@ -108,9 +108,7 @@ class NotificationsWorker(
|
||||
since_id = previouslyLatestNotification?.id
|
||||
)
|
||||
}
|
||||
} catch (exception: IOException) {
|
||||
return Result.failure()
|
||||
} catch (exception: HttpException) {
|
||||
} catch (exception: Exception) {
|
||||
return Result.failure()
|
||||
}
|
||||
}
|
||||
|
@ -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_name">Your Name</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="profile_saved">Changes saved!</string>
|
||||
<string name="error_profile">Something went wrong. Tap to retry</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user