diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/about/licenses/LicenseActivity.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/about/licenses/LicenseActivity.kt index 3fb4249..b052ef0 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/about/licenses/LicenseActivity.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/about/licenses/LicenseActivity.kt @@ -22,7 +22,6 @@ package at.connyduck.pixelcat.components.about.licenses import android.content.Context import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.ViewGroup import android.widget.TextView import androidx.annotation.RawRes @@ -33,7 +32,6 @@ import at.connyduck.pixelcat.R import at.connyduck.pixelcat.components.general.BaseActivity import at.connyduck.pixelcat.databinding.ActivityLicenseBinding import java.io.BufferedReader -import java.io.IOException import java.io.InputStreamReader class LicenseActivity : BaseActivity() { @@ -62,24 +60,16 @@ class LicenseActivity : BaseActivity() { private fun loadFileIntoTextView(@RawRes fileId: Int, textView: TextView) { - val sb = StringBuilder() - - val br = BufferedReader(InputStreamReader(resources.openRawResource(fileId))) - - try { - var line: String? = br.readLine() - while (line != null) { - sb.append(line) - sb.append('\n') - line = br.readLine() + textView.text = buildString { + BufferedReader(InputStreamReader(resources.openRawResource(fileId))).use { br -> + var line: String? = br.readLine() + while (line != null) { + append(line) + append('\n') + line = br.readLine() + } } - } catch (e: IOException) { - Log.w("LicenseActivity", e) } - - br.close() - - textView.text = sb.toString() } companion object { diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/accountselection/AccountSelectionBottomSheet.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/accountselection/AccountSelectionBottomSheet.kt index 13a85c5..209febb 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/accountselection/AccountSelectionBottomSheet.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/accountselection/AccountSelectionBottomSheet.kt @@ -29,6 +29,7 @@ import at.connyduck.pixelcat.components.login.LoginActivity import at.connyduck.pixelcat.components.main.MainActivity import at.connyduck.pixelcat.databinding.BottomsheetAccountsBinding import at.connyduck.pixelcat.db.AccountManager +import at.connyduck.pixelcat.util.viewBinding import com.google.android.material.bottomsheet.BottomSheetDialogFragment import kotlinx.coroutines.launch @@ -36,22 +37,18 @@ class AccountSelectionBottomSheet( private val accountManager: AccountManager ) : BottomSheetDialogFragment() { - private var _binding: BottomsheetAccountsBinding? = null - private val binding - get() = _binding!! + private val binding by viewBinding(BottomsheetAccountsBinding::bind) - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = BottomsheetAccountsBinding.inflate(inflater, container, false) - return binding.root - } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) = binding.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { lifecycleScope.launch { - binding.accountsRecyclerView.adapter = AccountSelectionAdapter(accountManager.getAllAccounts(), ::onAccountSelected, ::onNewAccount) + binding.accountsRecyclerView.adapter = + AccountSelectionAdapter( + accountManager.getAllAccounts(), + ::onAccountSelected, + ::onNewAccount + ) } } @@ -67,12 +64,6 @@ class AccountSelectionBottomSheet( } private fun onNewAccount() { - // TODO don't create intent here - startActivity(Intent(requireContext(), LoginActivity::class.java)) - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null + startActivity(LoginActivity.newIntent(requireContext())) } } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/menu/MenuBottomSheet.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/menu/MenuBottomSheet.kt index 12daccf..312d238 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/menu/MenuBottomSheet.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/bottomsheet/menu/MenuBottomSheet.kt @@ -26,22 +26,18 @@ import android.view.ViewGroup import at.connyduck.pixelcat.components.about.AboutActivity import at.connyduck.pixelcat.components.settings.SettingsActivity import at.connyduck.pixelcat.databinding.BottomsheetMenuBinding +import at.connyduck.pixelcat.util.viewBinding import com.google.android.material.bottomsheet.BottomSheetDialogFragment class MenuBottomSheet : BottomSheetDialogFragment() { - private var _binding: BottomsheetMenuBinding? = null - private val binding - get() = _binding!! + private val binding by viewBinding(BottomsheetMenuBinding::bind) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { - _binding = BottomsheetMenuBinding.inflate(inflater, container, false) - return binding.root - } + ) = binding.root override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -54,9 +50,4 @@ class MenuBottomSheet : BottomSheetDialogFragment() { dismiss() } } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/login/LoginViewModel.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/login/LoginViewModel.kt index 0f23df5..64a29cd 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/login/LoginViewModel.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/login/LoginViewModel.kt @@ -37,7 +37,7 @@ import javax.inject.Inject @FlowPreview @ExperimentalCoroutinesApi class LoginViewModel @Inject constructor( - private val fediverseApi: FediverseApi, + private val api: FediverseApi, private val accountManager: AccountManager ) : ViewModel() { @@ -67,7 +67,7 @@ class LoginViewModel @Inject constructor( loginState.send(LoginModel(input, LoginState.LOADING)) - fediverseApi.authenticateAppAsync( + api.authenticateAppAsync( domain = domainInput, clientName = "Pixelcat", clientWebsite = Config.website, @@ -88,7 +88,7 @@ class LoginViewModel @Inject constructor( viewModelScope.launch { val loginModel = loginState.value - fediverseApi.fetchOAuthToken( + api.fetchOAuthToken( domain = loginModel.domain!!, clientId = loginModel.clientId!!, clientSecret = loginModel.clientSecret!!, diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainFragmentAdapter.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainFragmentAdapter.kt index e01d5cf..5d34e3a 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainFragmentAdapter.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainFragmentAdapter.kt @@ -35,9 +35,7 @@ class MainFragmentAdapter(fragmentActivity: FragmentActivity) : FragmentStateAda 1 -> SearchFragment.newInstance() 2 -> NotificationsFragment.newInstance() 3 -> ProfileFragment.newInstance() - else -> { - throw IllegalStateException() - } + else -> throw IllegalStateException() } } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainViewModel.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainViewModel.kt index c27163f..71c6f13 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainViewModel.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/main/MainViewModel.kt @@ -27,7 +27,7 @@ import kotlinx.coroutines.launch import javax.inject.Inject class MainViewModel @Inject constructor( - private val fediverseApi: FediverseApi, + private val api: FediverseApi, private val accountManager: AccountManager ) : ViewModel() { @@ -37,7 +37,7 @@ class MainViewModel @Inject constructor( init { viewModelScope.launch { - fediverseApi.accountVerifyCredentials().fold( + api.accountVerifyCredentials().fold( { account -> accountManager.updateActiveAccount(account) }, diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/notifications/NotificationsViewModel.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/notifications/NotificationsViewModel.kt index c2ff545..2d7bc96 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/notifications/NotificationsViewModel.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/notifications/NotificationsViewModel.kt @@ -36,7 +36,7 @@ import javax.inject.Inject class NotificationsViewModel @Inject constructor( accountManager: AccountManager, private val db: AppDatabase, - private val fediverseApi: FediverseApi + private val api: FediverseApi ) : ViewModel() { @OptIn(FlowPreview::class) @@ -45,7 +45,7 @@ class NotificationsViewModel @Inject constructor( .flatMapConcat { activeAccount -> Pager( config = PagingConfig(pageSize = 10, enablePlaceholders = false), - remoteMediator = NotificationsRemoteMediator(activeAccount?.id!!, fediverseApi, db), + remoteMediator = NotificationsRemoteMediator(activeAccount?.id!!, api, db), pagingSourceFactory = { db.notificationsDao().notifications(activeAccount.id) } ).flow } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/GridSpacingItemDecoration.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/GridSpacingItemDecoration.kt index 123e6e8..ae3cf6d 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/GridSpacingItemDecoration.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/GridSpacingItemDecoration.kt @@ -43,7 +43,7 @@ class GridSpacingItemDecoration( outRect.left = column * spacing / spanCount // column * ((1f / spanCount) * spacing) outRect.right = - spacing - (column + 1) * spacing / spanCount // spacing - (column + 1) * ((1f / spanCount) * spacing) + spacing - (column + 1) * spacing / spanCount // spacing - (column + 1) * ((1f / spanCount) * spacing) if (position - topOffset >= spanCount) { outRect.top = spacing // item top } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/ProfileViewModel.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/ProfileViewModel.kt index a9c8b8c..ce4419a 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/ProfileViewModel.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/profile/ProfileViewModel.kt @@ -38,7 +38,7 @@ import kotlinx.coroutines.launch import javax.inject.Inject class ProfileViewModel @Inject constructor( - private val fediverseApi: FediverseApi, + private val api: FediverseApi, private val accountManager: AccountManager ) : ViewModel() { @@ -49,7 +49,7 @@ class ProfileViewModel @Inject constructor( @ExperimentalPagingApi val imageFlow = Pager( config = PagingConfig(pageSize = 10, enablePlaceholders = false), - pagingSourceFactory = { ProfileImagePagingSource(fediverseApi, accountId, accountManager) } + pagingSourceFactory = { ProfileImagePagingSource(api, accountId, accountManager) } ).flow .cachedIn(viewModelScope) @@ -73,7 +73,7 @@ class ProfileViewModel @Inject constructor( private fun loadAccount(reload: Boolean = false) { if (profile.value == null || reload) { viewModelScope.launch { - fediverseApi.account(getAccountId()).fold( + api.account(getAccountId()).fold( { profile.value = Success(it) }, @@ -88,7 +88,7 @@ class ProfileViewModel @Inject constructor( private fun loadRelationship(reload: Boolean = false) { if (relationship.value == null || reload) { viewModelScope.launch { - fediverseApi.relationships(listOf(getAccountId())).fold( + api.relationships(listOf(getAccountId())).fold( { relationship.value = Success(it.first()) }, diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/settings/SettingsActivity.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/settings/SettingsActivity.kt index fb13a73..4bc75b2 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/settings/SettingsActivity.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/settings/SettingsActivity.kt @@ -29,6 +29,7 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat.Type.systemBars +import androidx.fragment.app.commit import androidx.preference.PreferenceFragmentCompat import at.connyduck.pixelcat.R import at.connyduck.pixelcat.components.general.BaseActivity @@ -56,10 +57,9 @@ class SettingsActivity : BaseActivity(), SharedPreferences.OnSharedPreferenceCha WindowInsetsCompat.CONSUMED } - supportFragmentManager - .beginTransaction() - .replace(R.id.settings, SettingsFragment()) - .commit() + supportFragmentManager.commit { + replace(R.id.settings, SettingsFragment()) + } binding.settingsToolbar.setNavigationOnClickListener { onBackPressed() diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineImageAdapter.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineImageAdapter.kt index 78978ee..0ded101 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineImageAdapter.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineImageAdapter.kt @@ -42,7 +42,6 @@ class TimelineImageAdapter : RecyclerView.Adapter, position: Int) { - holder.binding.timelineImageView.load(images[position].previewUrl) } } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineViewModel.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineViewModel.kt index 3e604b9..b5e6404 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineViewModel.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/TimelineViewModel.kt @@ -38,7 +38,7 @@ import javax.inject.Inject class TimelineViewModel @Inject constructor( accountManager: AccountManager, private val db: AppDatabase, - private val fediverseApi: FediverseApi, + private val api: FediverseApi, private val useCases: TimelineUseCases ) : ViewModel() { @@ -48,7 +48,7 @@ class TimelineViewModel @Inject constructor( .flatMapConcat { activeAccount -> Pager( config = PagingConfig(pageSize = 10, enablePlaceholders = false), - remoteMediator = TimelineRemoteMediator(activeAccount?.id!!, fediverseApi, db), + remoteMediator = TimelineRemoteMediator(activeAccount?.id!!, api, db), pagingSourceFactory = { db.statusDao().statuses(activeAccount.id) } ).flow } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailViewModel.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailViewModel.kt index 62b0879..bd5b2b6 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailViewModel.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailViewModel.kt @@ -41,8 +41,7 @@ class DetailViewModel @Inject constructor( private val api: FediverseApi, private val db: AppDatabase, private val accountManager: AccountManager, - private val useCases: TimelineUseCases, - private val fediverseApi: FediverseApi + private val useCases: TimelineUseCases ) : ViewModel() { val currentStatus = MutableLiveData>() @@ -129,7 +128,7 @@ class DetailViewModel @Inject constructor( fun onReply(statusToReply: StatusEntity, replyText: String) { viewModelScope.launch { - fediverseApi.reply( + api.reply( NewStatus( status = replyText, inReplyToId = statusToReply.actionableId, diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/util/extension/ContextExtensions.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/util/extension/ContextExtensions.kt index 733caec..5e1f256 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/util/extension/ContextExtensions.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/util/extension/ContextExtensions.kt @@ -34,6 +34,7 @@ fun Context.getDisplayWidthInPx(): Int { windowManager.currentWindowMetrics.bounds.width() } else { val metrics = DisplayMetrics() + @Suppress("DEPRECATION") windowManager.defaultDisplay.getMetrics(metrics) metrics.widthPixels } diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt index ff7a679..1fede75 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt @@ -35,10 +35,9 @@ class StatusView @JvmOverloads constructor( defStyleAttr: Int = 0 ) : LinearLayout(context, attrs, defStyleAttr) { - val binding: ViewStatusBinding + val binding: ViewStatusBinding = ViewStatusBinding.inflate(LayoutInflater.from(context), this) init { - binding = ViewStatusBinding.inflate(LayoutInflater.from(context), this) gravity = Gravity.CENTER setBackgroundColor(context.getColorForAttr(R.attr.colorSurface)) orientation = VERTICAL diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/db/AccountManager.kt b/app/src/main/kotlin/at/connyduck/pixelcat/db/AccountManager.kt index 6b78f75..9809d56 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/db/AccountManager.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/db/AccountManager.kt @@ -26,11 +26,8 @@ import at.connyduck.pixelcat.model.Account /** * This class caches the account database and handles all account related operations - * @author ConnyDuck */ -// TODO check if the comments are up to date - private const val TAG = "AccountManager" class AccountManager(db: AppDatabase) { @@ -55,8 +52,8 @@ class AccountManager(db: AppDatabase) { * Adds a new empty account and makes it the active account. * More account information has to be added later with [updateActiveAccount] * or the account wont be saved to the database. - * @param accessToken the access token for the new account - * @param domain the domain of the accounts Mastodon instance + * @param domain the domain of the accounts instance + * @param authData the auth data of the new account */ suspend fun addAccount(domain: String, authData: AccountAuthData) { @@ -114,8 +111,7 @@ class AccountManager(db: AppDatabase) { } /** - * updates the current account with new information from the mastodon api - * and saves it in the database + * updates the current account with new information from the api and saves it in the database * @param account the [Account] object returned from the api */ suspend fun updateActiveAccount(account: Account) { @@ -124,9 +120,6 @@ class AccountManager(db: AppDatabase) { it.username = account.username it.displayName = account.name it.profilePictureUrl = account.avatar - // it.defaultPostPrivacy = account.source?.privacy ?: Status.Visibility.PUBLIC - it.defaultMediaSensitivity = account.source?.sensitive ?: false - // it.emojis = account.emojis ?: emptyList() Log.d(TAG, "updateActiveAccount: saving account with id " + it.id) it.id = accountDao.insertOrReplace(it) @@ -166,7 +159,7 @@ class AccountManager(db: AppDatabase) { } /** - * @return an immutable list of all accounts in the database with the active account first + * @return an immutable list of all accounts in the database */ suspend fun getAllAccounts(): List { @@ -180,13 +173,6 @@ class AccountManager(db: AppDatabase) { return accounts.toList() } - /** - * @return true if at least one account has notifications enabled - */ - fun areNotificationsEnabled(): Boolean { - return accounts.any { it.notificationsEnabled } - } - /** * Finds an account by its database id * @param accountId the id of the account diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/db/entitity/AccountEntity.kt b/app/src/main/kotlin/at/connyduck/pixelcat/db/entitity/AccountEntity.kt index 4da8bf9..38ed817 100644 --- a/app/src/main/kotlin/at/connyduck/pixelcat/db/entitity/AccountEntity.kt +++ b/app/src/main/kotlin/at/connyduck/pixelcat/db/entitity/AccountEntity.kt @@ -32,7 +32,6 @@ import androidx.room.PrimaryKey ) ] ) -// @TypeConverters(Converters::class) data class AccountEntity( @field:PrimaryKey(autoGenerate = true) var id: Long, val domain: String, @@ -41,21 +40,7 @@ data class AccountEntity( var accountId: String = "", var username: String = "", var displayName: String = "", - var profilePictureUrl: String = "", - var notificationsEnabled: Boolean = true, - var notificationsMentioned: Boolean = true, - var notificationsFollowed: Boolean = true, - var notificationsReblogged: Boolean = true, - var notificationsFavorited: Boolean = true, - var notificationSound: Boolean = true, - var notificationVibration: Boolean = true, - var notificationLight: Boolean = true, - var defaultMediaSensitivity: Boolean = false, - var alwaysShowSensitiveMedia: Boolean = false, - var mediaPreviewEnabled: Boolean = true, - var lastNotificationId: String = "0", - var activeNotifications: String = "[]", - var notificationsFilter: String = "[]" + var profilePictureUrl: String = "" ) { val identifier: String diff --git a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml deleted file mode 100644 index 85b70f1..0000000 --- a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml deleted file mode 100644 index de832bb..0000000 --- a/app/src/main/res/drawable/ic_home_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml deleted file mode 100644 index fa1d5fe..0000000 --- a/app/src/main/res/drawable/ic_notifications_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/menu/profile.xml b/app/src/main/res/menu/profile.xml deleted file mode 100644 index fe187c0..0000000 --- a/app/src/main/res/menu/profile.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml deleted file mode 100644 index 6cf9ed4..0000000 --- a/app/src/main/res/values/arrays.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - Reply - Reply to all - - - - reply - reply_all - - \ No newline at end of file