From ea2c9bc6db51bbf637d298e98d9c4c7c5391524e Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Thu, 1 Jul 2021 16:33:21 +0200 Subject: [PATCH 1/8] Update dependencies --- app/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 3ce9bbca..d648bf20 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -123,6 +123,7 @@ dependencies { implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation "androidx.activity:activity-ktx:1.3.1" implementation 'androidx.fragment:fragment-ktx:1.3.6' + implementation "androidx.work:work-runtime-ktx:2.5.0" // Use the most recent version of CameraX def cameraX_version = '1.0.1' @@ -187,7 +188,7 @@ dependencies { implementation "com.mikepenz:iconics-core:5.3.0" implementation 'com.mikepenz:materialdrawer-iconics:8.4.2' implementation "com.mikepenz:iconics-views:5.3.0" - implementation 'com.mikepenz:google-material-typeface:3.0.1.4.original-kotlin@aar' + implementation 'com.mikepenz:google-material-typeface:4.0.0.1-kotlin@aar' implementation 'com.karumi:dexter:6.2.3' From ebec547dd0c54a97517dbfb27de1e3630c00f8b4 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Sat, 14 Aug 2021 19:40:31 +0200 Subject: [PATCH 2/8] Only clear feed from the right user --- .../cachedFeeds/notifications/NotificationsRemoteMediator.kt | 2 +- .../feeds/cachedFeeds/postFeeds/HomeFeedRemoteMediator.kt | 2 +- .../feeds/cachedFeeds/postFeeds/PublicFeedRemoteMediator.kt | 2 +- .../pixeldroid/app/utils/db/dao/feedContent/FeedContentDao.kt | 2 +- .../app/utils/db/dao/feedContent/NotificationDao.kt | 4 ++-- .../app/utils/db/dao/feedContent/posts/HomePostDao.kt | 4 ++-- .../app/utils/db/dao/feedContent/posts/PublicPostDao.kt | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsRemoteMediator.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsRemoteMediator.kt index 7fbeff26..8ad0e03e 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsRemoteMediator.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsRemoteMediator.kt @@ -73,7 +73,7 @@ class NotificationsRemoteMediator @Inject constructor( db.withTransaction { // clear table in the database if (loadType == LoadType.REFRESH) { - db.notificationDao().clearFeedContent() + db.notificationDao().clearFeedContent(user.user_id, user.instance_uri) } db.notificationDao().insertAll(apiResponse) } diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/HomeFeedRemoteMediator.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/HomeFeedRemoteMediator.kt index cf6cad08..b5ef519c 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/HomeFeedRemoteMediator.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/HomeFeedRemoteMediator.kt @@ -59,7 +59,7 @@ class HomeFeedRemoteMediator @Inject constructor( db.withTransaction { // clear table in the database if (loadType == LoadType.REFRESH) { - db.homePostDao().clearFeedContent() + db.homePostDao().clearFeedContent(user.user_id, user.instance_uri) } db.homePostDao().insertAll(dbObjects) } diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/PublicFeedRemoteMediator.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/PublicFeedRemoteMediator.kt index bb68f3df..d832ecbc 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/PublicFeedRemoteMediator.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/postFeeds/PublicFeedRemoteMediator.kt @@ -74,7 +74,7 @@ class PublicFeedRemoteMediator @Inject constructor( db.withTransaction { // clear table in the database if (loadType == LoadType.REFRESH) { - db.publicPostDao().clearFeedContent() + db.publicPostDao().clearFeedContent(user.user_id, user.instance_uri) } db.publicPostDao().insertAll(dbObjects) } diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/FeedContentDao.kt b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/FeedContentDao.kt index d4985b07..31ef8e7d 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/FeedContentDao.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/FeedContentDao.kt @@ -9,7 +9,7 @@ interface FeedContentDao{ fun feedContent(userId: String, instanceUri: String): PagingSource - suspend fun clearFeedContent() + suspend fun clearFeedContent(userId: String, instanceUri: String) @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertAll(feedContent: List) diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/NotificationDao.kt b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/NotificationDao.kt index 0a6717df..00d93218 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/NotificationDao.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/NotificationDao.kt @@ -8,8 +8,8 @@ import org.pixeldroid.app.utils.api.objects.Notification @Dao interface NotificationDao: FeedContentDao { - @Query("DELETE FROM notifications") - override suspend fun clearFeedContent() + @Query("DELETE FROM notifications WHERE user_id=:userId AND instance_uri=:instanceUri") + override suspend fun clearFeedContent(userId: String, instanceUri: String) @Query("""SELECT * FROM notifications WHERE user_id=:userId AND instance_uri=:instanceUri ORDER BY CAST(created_at AS FLOAT) DESC""") diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/HomePostDao.kt b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/HomePostDao.kt index 2236785a..295d0b2a 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/HomePostDao.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/HomePostDao.kt @@ -12,8 +12,8 @@ interface HomePostDao: FeedContentDao { ORDER BY CAST(created_at AS FLOAT)""") override fun feedContent(userId: String, instanceUri: String): PagingSource - @Query("DELETE FROM homePosts") - override suspend fun clearFeedContent() + @Query("DELETE FROM homePosts WHERE user_id=:userId AND instance_uri=:instanceUri") + override suspend fun clearFeedContent(userId: String, instanceUri: String) @Query("DELETE FROM homePosts WHERE user_id=:userId AND instance_uri=:instanceUri AND id=:id") override suspend fun delete(id: String, userId: String, instanceUri: String) diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/PublicPostDao.kt b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/PublicPostDao.kt index 7901f0a1..8335628b 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/PublicPostDao.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/dao/feedContent/posts/PublicPostDao.kt @@ -12,8 +12,8 @@ interface PublicPostDao: FeedContentDao { ORDER BY CAST(created_at AS FLOAT)""") override fun feedContent(userId: String, instanceUri: String): PagingSource - @Query("DELETE FROM publicPosts") - override suspend fun clearFeedContent() + @Query("DELETE FROM publicPosts WHERE user_id=:userId AND instance_uri=:instanceUri") + override suspend fun clearFeedContent(userId: String, instanceUri: String) @Query("DELETE FROM publicPosts WHERE user_id=:userId AND instance_uri=:instanceUri AND id=:id") override suspend fun delete(id: String, userId: String, instanceUri: String) From 649535f8fd0fd68fe17b5eae5347443c8de9c7c4 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Thu, 19 Aug 2021 14:36:39 +0200 Subject: [PATCH 3/8] Add comment notification type --- .../notifications/NotificationsFragment.kt | 26 +++++++++---------- .../app/utils/api/objects/Notification.kt | 2 +- app/src/main/res/values/strings.xml | 6 +++++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt index 7adcb533..9d75a9fa 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt @@ -87,7 +87,8 @@ class NotificationsFragment : CachedFeedFragment() { val intent: Intent = when (type) { Notification.NotificationType.mention, Notification.NotificationType.favourite, - Notification.NotificationType.poll, Notification.NotificationType.reblog -> { + Notification.NotificationType.poll, Notification.NotificationType.reblog, + Notification.NotificationType.comment -> { openPostFromNotification() } Notification.NotificationType.follow -> { @@ -113,39 +114,38 @@ class NotificationsFragment : CachedFeedFragment() { ) { val context = textView.context val (format: String, drawable: Drawable?) = when (type) { - Notification.NotificationType.follow -> { + Notification.NotificationType.follow -> getStringAndDrawable( context, R.string.followed_notification, R.drawable.ic_follow ) - } - Notification.NotificationType.mention -> { + Notification.NotificationType.mention -> getStringAndDrawable( context, R.string.mention_notification, R.drawable.mention_at_24dp ) - } - - Notification.NotificationType.reblog -> { + Notification.NotificationType.comment -> + getStringAndDrawable( + context, + R.string.comment_notification, + R.drawable.ic_comment_empty + ) + Notification.NotificationType.reblog -> getStringAndDrawable( context, R.string.shared_notification, R.drawable.ic_reblog_blue ) - } - - Notification.NotificationType.favourite -> { + Notification.NotificationType.favourite -> getStringAndDrawable( context, R.string.liked_notification, R.drawable.ic_like_full ) - } - Notification.NotificationType.poll -> { + Notification.NotificationType.poll -> getStringAndDrawable(context, R.string.poll_notification, R.drawable.poll) - } } textView.text = format.format(username) textView.setCompoundDrawablesWithIntrinsicBounds( diff --git a/app/src/main/java/org/pixeldroid/app/utils/api/objects/Notification.kt b/app/src/main/java/org/pixeldroid/app/utils/api/objects/Notification.kt index 03b3dacc..94b73733 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/api/objects/Notification.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/api/objects/Notification.kt @@ -38,6 +38,6 @@ data class Notification( override var instance_uri: String, ): FeedContent, FeedContentDatabase { enum class NotificationType: Serializable { - follow, mention, reblog, favourite, poll + follow, mention, reblog, favourite, poll, comment } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 34cacd40..65c565cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -50,6 +50,12 @@ "%1$s's poll has ended" + + %1$s commented on your post + + + "Notification from %1$s" + "What's an instance?" "You might be confused by the text field asking for the domain of your 'instance'. From ba372a3d17a3e27fc571d8fc1f87c0cd37fc7caf Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Sat, 14 Aug 2021 19:45:27 +0200 Subject: [PATCH 4/8] Update instead of replace user to avoid CASCADE deleting all cached feeds Previously, every time database entry for the user is updated (as it is on startup of the app), the tables depending on the user will get wiped. This includes notifications, public and home feeds, so that breaks quite a bit of things in a hard to debug way. --- .../java/org/pixeldroid/app/utils/db/DBUtils.kt | 2 +- .../org/pixeldroid/app/utils/db/dao/UserDao.kt | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/DBUtils.kt b/app/src/main/java/org/pixeldroid/app/utils/db/DBUtils.kt index fea14708..df33746e 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/DBUtils.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/DBUtils.kt @@ -14,7 +14,7 @@ import java.lang.IllegalArgumentException fun addUser(db: AppDatabase, account: Account, instance_uri: String, activeUser: Boolean = true, accessToken: String, refreshToken: String?, clientId: String, clientSecret: String) { - db.userDao().insertUser( + db.userDao().insertOrUpdate( UserDatabaseEntity( user_id = account.id!!, instance_uri = normalizeDomain(instance_uri), diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/dao/UserDao.kt b/app/src/main/java/org/pixeldroid/app/utils/db/dao/UserDao.kt index 396f152e..b1a696e3 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/dao/UserDao.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/dao/UserDao.kt @@ -5,8 +5,21 @@ import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity @Dao interface UserDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - fun insertUser(user: UserDatabaseEntity) + /** + * Insert a user, if it already exists return -1 + */ + @Insert(onConflict = OnConflictStrategy.IGNORE) + fun insertUser(user: UserDatabaseEntity): Long + + @Transaction + fun insertOrUpdate(user: UserDatabaseEntity) { + if (insertUser(user) == -1L) { + updateUser(user) + } + } + + @Update + fun updateUser(user: UserDatabaseEntity) @Query("UPDATE users SET accessToken = :accessToken, refreshToken = :refreshToken WHERE user_id = :id and instance_uri = :instance_uri") fun updateAccessToken(accessToken: String, refreshToken: String, id: String, instance_uri: String) From 6e1e12af0e830fd6f43b7b7dfb23c1649ea2087f Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Thu, 19 Aug 2021 14:35:14 +0200 Subject: [PATCH 5/8] Create api from user without side effect --- .../pixeldroid/app/utils/api/PixelfedAPI.kt | 29 +++++++++++++++++++ .../org/pixeldroid/app/utils/di/APIModule.kt | 22 ++------------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/utils/api/PixelfedAPI.kt b/app/src/main/java/org/pixeldroid/app/utils/api/PixelfedAPI.kt index f1e75801..642e0624 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/api/PixelfedAPI.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/api/PixelfedAPI.kt @@ -3,6 +3,11 @@ package org.pixeldroid.app.utils.api import org.pixeldroid.app.utils.api.objects.* import io.reactivex.Observable import okhttp3.MultipartBody +import okhttp3.OkHttpClient +import org.pixeldroid.app.utils.db.AppDatabase +import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity +import org.pixeldroid.app.utils.di.PixelfedAPIHolder +import org.pixeldroid.app.utils.di.TokenAuthenticator import retrofit2.Response import retrofit2.Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory @@ -28,6 +33,30 @@ interface PixelfedAPI { .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build().create(PixelfedAPI::class.java) } + + private val intermediate: Retrofit.Builder = Retrofit.Builder() + .addConverterFactory(GsonConverterFactory.create()) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) + + + fun apiForUser( + user: UserDatabaseEntity, + db: AppDatabase, + pixelfedAPIHolder: PixelfedAPIHolder + ): PixelfedAPI = + intermediate + .baseUrl(user.instance_uri) + .client( + OkHttpClient().newBuilder().authenticator(TokenAuthenticator(user, db, pixelfedAPIHolder)) + .addInterceptor { + it.request().newBuilder().run { + header("Accept", "application/json") + header("Authorization", "Bearer ${user.accessToken}") + it.proceed(build()) + } + }.build() + ) + .build().create(PixelfedAPI::class.java) } diff --git a/app/src/main/java/org/pixeldroid/app/utils/di/APIModule.kt b/app/src/main/java/org/pixeldroid/app/utils/di/APIModule.kt index 06ff09a8..813356d9 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/di/APIModule.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/di/APIModule.kt @@ -8,9 +8,7 @@ import dagger.Module import dagger.Provides import kotlinx.coroutines.runBlocking import okhttp3.* -import retrofit2.Retrofit -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory -import retrofit2.converter.gson.GsonConverterFactory +import org.pixeldroid.app.utils.api.PixelfedAPI.Companion.apiForUser import javax.inject.Singleton @Module @@ -78,9 +76,6 @@ class TokenAuthenticator(val user: UserDatabaseEntity, val db: AppDatabase, val } class PixelfedAPIHolder(private val db: AppDatabase){ - private val intermediate: Retrofit.Builder = Retrofit.Builder() - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) var api: PixelfedAPI? = db.userDao().getActiveUser()?.let { @@ -90,21 +85,8 @@ class PixelfedAPIHolder(private val db: AppDatabase){ fun setToCurrentUser( user: UserDatabaseEntity = db.userDao().getActiveUser()!! ): PixelfedAPI { - val newAPI = intermediate - .baseUrl(user.instance_uri) - .client( - OkHttpClient().newBuilder().authenticator(TokenAuthenticator(user, db, this)) - .addInterceptor { - it.request().newBuilder().run { - header("Accept", "application/json") - header("Authorization", "Bearer ${user.accessToken}") - it.proceed(build()) - } - }.build() - ) - .build().create(PixelfedAPI::class.java) + val newAPI = apiForUser(user, db, this) api = newAPI return newAPI } - } \ No newline at end of file From 9c1187f233f5909ffe330a10b6a3a6aeba037bac Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Sat, 14 Aug 2021 20:04:02 +0200 Subject: [PATCH 6/8] Update licenses --- app/licenses.yml | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/app/licenses.yml b/app/licenses.yml index 86b165e6..954bc667 100644 --- a/app/licenses.yml +++ b/app/licenses.yml @@ -515,6 +515,47 @@ license: The Apache Software License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt url: http://developer.android.com/tools/extras/support-library.html +- artifact: androidx.constraintlayout:constraintlayout-core:+ + name: constraintlayout-core + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: http://tools.android.com +- artifact: androidx.databinding:databinding-ktx:+ + name: databinding-ktx + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt +- artifact: androidx.lifecycle:lifecycle-extensions:+ + name: lifecycle-extensions + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: https://developer.android.com/topic/libraries/architecture/index.html +- artifact: androidx.lifecycle:lifecycle-process:+ + name: lifecycle-process + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: https://developer.android.com/topic/libraries/architecture/index.html +- artifact: androidx.lifecycle:lifecycle-service:+ + name: lifecycle-service + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: https://developer.android.com/topic/libraries/architecture/index.html +- artifact: androidx.work:work-runtime-ktx:+ + name: work-runtime-ktx + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: https://developer.android.com/jetpack/androidx/releases/work#2.5.0 +- artifact: androidx.work:work-runtime:+ + name: work-runtime + copyrightHolder: Google Inc. + license: The Apache Software License, Version 2.0 + licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt + url: https://developer.android.com/jetpack/androidx/releases/work#2.5.0 - artifact: androidx.paging:paging-common:+ name: paging-common copyrightHolder: Google Inc. @@ -668,12 +709,6 @@ license: The Apache License, Version 2.0 licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt url: https://kotlinlang.org/ -- artifact: androidx.constraintlayout:constraintlayout-solver:+ - name: constraintlayout-solver - copyrightHolder: Google Inc. - license: The Apache Software License, Version 2.0 - licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt - url: http://tools.android.com - artifact: com.google.guava:listenablefuture:+ name: listenablefuture copyrightHolder: Google Inc. From 2511b9f194ac00f7467a04c9179082eb88f4c22d Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Sat, 14 Aug 2021 20:16:01 +0200 Subject: [PATCH 7/8] Fix lint error --- .../pixeldroid/app/postCreation/photoEdit/ThumbnailAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/pixeldroid/app/postCreation/photoEdit/ThumbnailAdapter.kt b/app/src/main/java/org/pixeldroid/app/postCreation/photoEdit/ThumbnailAdapter.kt index 89daa23d..af51f375 100644 --- a/app/src/main/java/org/pixeldroid/app/postCreation/photoEdit/ThumbnailAdapter.kt +++ b/app/src/main/java/org/pixeldroid/app/postCreation/photoEdit/ThumbnailAdapter.kt @@ -36,7 +36,7 @@ class ThumbnailAdapter (private val context: Context, holder.thumbnail.setImageBitmap(tbItem.image) holder.thumbnail.setOnClickListener { listener.onFilterSelected(tbItem.filter) - selectedIndex = position + selectedIndex = holder.bindingAdapterPosition notifyDataSetChanged() } From 104648af2c8065fdce4afe508e522e98ec47c0fc Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Tue, 7 Sep 2021 13:13:28 +0200 Subject: [PATCH 8/8] Prepare db migration --- app/src/main/java/org/pixeldroid/app/MainActivity.kt | 5 ++++- .../main/java/org/pixeldroid/app/posts/PostActivity.kt | 4 ++-- .../cachedFeeds/notifications/NotificationsFragment.kt | 2 +- .../java/org/pixeldroid/app/utils/db/AppDatabase.kt | 10 ++++++++++ .../java/org/pixeldroid/app/utils/di/DatabaseModule.kt | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/MainActivity.kt b/app/src/main/java/org/pixeldroid/app/MainActivity.kt index 1df075f7..8a981c20 100644 --- a/app/src/main/java/org/pixeldroid/app/MainActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/MainActivity.kt @@ -72,8 +72,8 @@ class MainActivity : BaseActivity() { //Check if we have logged in and gotten an access token if (user == null) { - launchActivity(LoginActivity(), firstTime = true) finish() + launchActivity(LoginActivity(), firstTime = true) } else { sendTraceDroidStackTracesIfExist("contact@pixeldroid.org", this) @@ -172,6 +172,7 @@ class MainActivity : BaseActivity() { } private fun logOut(){ + finish() db.runInTransaction { db.userDao().deleteActiveUsers() @@ -229,6 +230,8 @@ class MainActivity : BaseActivity() { apiHolder.setToCurrentUser() val intent = Intent(this, MainActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + + finish() startActivity(intent) return false diff --git a/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt b/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt index 2c68c62b..77c89db0 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt @@ -38,8 +38,8 @@ class PostActivity : BaseActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) status = intent.getSerializableExtra(POST_TAG) as Status - val viewComments: Boolean = (intent.getSerializableExtra(VIEW_COMMENTS_TAG) ?: false) as Boolean - val postComment: Boolean = (intent.getSerializableExtra(POST_COMMENT_TAG) ?: false) as Boolean + val viewComments: Boolean = intent.getBooleanExtra(VIEW_COMMENTS_TAG, false) + val postComment: Boolean = intent.getBooleanExtra(POST_COMMENT_TAG, false) val user = db.userDao().getActiveUser() diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt index 9d75a9fa..9ac41fd7 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/notifications/NotificationsFragment.kt @@ -249,7 +249,7 @@ class NotificationsFragment : CachedFeedFragment() { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val uiModel = getItem(position) - uiModel.let { + uiModel?.let { (holder as NotificationViewHolder).bind( it, apiHolder, diff --git a/app/src/main/java/org/pixeldroid/app/utils/db/AppDatabase.kt b/app/src/main/java/org/pixeldroid/app/utils/db/AppDatabase.kt index c2a52989..88bfea96 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/db/AppDatabase.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/db/AppDatabase.kt @@ -3,6 +3,8 @@ package org.pixeldroid.app.utils.db import androidx.room.Database import androidx.room.RoomDatabase import androidx.room.TypeConverters +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase import org.pixeldroid.app.utils.db.dao.* import org.pixeldroid.app.utils.db.dao.feedContent.NotificationDao import org.pixeldroid.app.utils.db.dao.feedContent.posts.HomePostDao @@ -29,4 +31,12 @@ abstract class AppDatabase : RoomDatabase() { abstract fun homePostDao(): HomePostDao abstract fun publicPostDao(): PublicPostDao abstract fun notificationDao(): NotificationDao +} + +val MIGRATION_3_4 = object : Migration(3, 4) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DELETE FROM homePosts") + database.execSQL("DELETE FROM publicPosts") + database.execSQL("DELETE FROM notifications") + } } \ No newline at end of file diff --git a/app/src/main/java/org/pixeldroid/app/utils/di/DatabaseModule.kt b/app/src/main/java/org/pixeldroid/app/utils/di/DatabaseModule.kt index 6b2e4dbe..bc08dec5 100644 --- a/app/src/main/java/org/pixeldroid/app/utils/di/DatabaseModule.kt +++ b/app/src/main/java/org/pixeldroid/app/utils/di/DatabaseModule.kt @@ -5,6 +5,7 @@ import androidx.room.Room import org.pixeldroid.app.utils.db.AppDatabase import dagger.Module import dagger.Provides +import org.pixeldroid.app.utils.db.MIGRATION_3_4 import javax.inject.Singleton @Module @@ -16,6 +17,6 @@ class DatabaseModule(private val context: Context) { return Room.databaseBuilder( context, AppDatabase::class.java, "pixeldroid" - ).allowMainThreadQueries().build() + ).addMigrations(MIGRATION_3_4).allowMainThreadQueries().build() } } \ No newline at end of file