From 6ad70932c550cc274d87c0417ea79a4626ea786b Mon Sep 17 00:00:00 2001 From: Benard Mathu Date: Thu, 28 Apr 2022 18:23:44 +0300 Subject: [PATCH] Refactor: notification models (#4866) * Refactor: move notification modesl to data.models.notification * Refactor: move notification models to notifications/models --- ...4ea0-80c5-e30b8285c75610074820572125241785.jpg | 0 .../contributions/ContributionsFragment.java | 2 +- .../commons/notification/NotificatinAdapter.kt | 1 + .../notification/NotificationActivity.java | 1 + .../notification/NotificationAdapterDelegates.kt | 1 + .../commons/notification/NotificationClient.java | 1 + .../notification/NotificationController.java | 1 + .../notification/NotificationWorkerFragment.java | 1 + .../notification/{ => models}/Notification.kt | 15 ++++++++------- .../{ => models}/NotificationType.java | 2 +- .../ContributionsFragmentUnitTests.kt | 4 ++-- .../notification/NotificationActivityUnitTests.kt | 2 ++ .../notification/NotificationControllerTest.kt | 1 + .../notification/NotificationHelperUnitTests.kt | 2 ++ 14 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 app/CommonsContributions/e998b507-60b6-4ea0-80c5-e30b8285c75610074820572125241785.jpg rename app/src/main/java/fr/free/nrw/commons/notification/{ => models}/Notification.kt (67%) rename app/src/main/java/fr/free/nrw/commons/notification/{ => models}/NotificationType.java (92%) diff --git a/app/CommonsContributions/e998b507-60b6-4ea0-80c5-e30b8285c75610074820572125241785.jpg b/app/CommonsContributions/e998b507-60b6-4ea0-80c5-e30b8285c75610074820572125241785.jpg new file mode 100644 index 000000000..e69de29bb diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java index 9703dcd14..5f0d25eb9 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java @@ -29,7 +29,7 @@ import androidx.fragment.app.FragmentTransaction; import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.auth.SessionManager; -import fr.free.nrw.commons.notification.Notification; +import fr.free.nrw.commons.notification.models.Notification; import fr.free.nrw.commons.notification.NotificationController; import fr.free.nrw.commons.profile.ProfileActivity; import fr.free.nrw.commons.theme.BaseActivity; diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificatinAdapter.kt b/app/src/main/java/fr/free/nrw/commons/notification/NotificatinAdapter.kt index dd5ab0452..6ad6876a3 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificatinAdapter.kt +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificatinAdapter.kt @@ -1,5 +1,6 @@ package fr.free.nrw.commons.notification +import fr.free.nrw.commons.notification.models.Notification import fr.free.nrw.commons.upload.categories.BaseDelegateAdapter internal class NotificatinAdapter(onNotificationClicked: (Notification) -> Unit) : diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java index c8791feab..39a918ddc 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java @@ -23,6 +23,7 @@ import butterknife.ButterKnife; import com.google.android.material.snackbar.Snackbar; import fr.free.nrw.commons.R; import fr.free.nrw.commons.Utils; +import fr.free.nrw.commons.notification.models.Notification; import fr.free.nrw.commons.theme.BaseActivity; import fr.free.nrw.commons.utils.NetworkUtils; import fr.free.nrw.commons.utils.ViewUtil; diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterDelegates.kt b/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterDelegates.kt index 01d12ae3e..34065791a 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterDelegates.kt +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterDelegates.kt @@ -1,6 +1,7 @@ package fr.free.nrw.commons.notification import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding +import fr.free.nrw.commons.notification.models.Notification import fr.free.nrw.commons.databinding.ItemNotificationBinding import org.wikipedia.util.StringUtil diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.java index 8643ceaf4..9c035b8b6 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationClient.java @@ -1,5 +1,6 @@ package fr.free.nrw.commons.notification; +import fr.free.nrw.commons.notification.models.Notification; import org.wikipedia.csrf.CsrfTokenClient; import org.wikipedia.dataclient.Service; diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationController.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationController.java index e158bd215..de1f372d2 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationController.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationController.java @@ -1,5 +1,6 @@ package fr.free.nrw.commons.notification; +import fr.free.nrw.commons.notification.models.Notification; import java.util.List; import javax.inject.Inject; diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationWorkerFragment.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationWorkerFragment.java index 97a7763b3..ffee5eac2 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationWorkerFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationWorkerFragment.java @@ -5,6 +5,7 @@ import android.os.Bundle; import androidx.annotation.Nullable; +import fr.free.nrw.commons.notification.models.Notification; import java.util.List; /** diff --git a/app/src/main/java/fr/free/nrw/commons/notification/Notification.kt b/app/src/main/java/fr/free/nrw/commons/notification/models/Notification.kt similarity index 67% rename from app/src/main/java/fr/free/nrw/commons/notification/Notification.kt rename to app/src/main/java/fr/free/nrw/commons/notification/models/Notification.kt index ddba47bd0..955addfdc 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/Notification.kt +++ b/app/src/main/java/fr/free/nrw/commons/notification/models/Notification.kt @@ -1,4 +1,4 @@ -package fr.free.nrw.commons.notification +package fr.free.nrw.commons.notification.models import org.wikipedia.util.DateUtil @@ -6,18 +6,19 @@ import org.wikipedia.util.DateUtil * Created by root on 18.12.2017. */ data class Notification(var notificationType: NotificationType, - var notificationText: String, - var date: String, - var link: String, - var iconUrl: String, - var notificationId: String) { + var notificationText: String, + var date: String, + var link: String, + var iconUrl: String, + var notificationId: String) { companion object { @JvmStatic fun from(wikiNotification: org.wikipedia.notifications.Notification): Notification { val contents = wikiNotification.contents val notificationLink = if (contents == null || contents.links == null || contents.links!!.primary == null) "" else contents.links!!.primary!!.url - return Notification(NotificationType.UNKNOWN, + return Notification( + NotificationType.UNKNOWN, contents?.compactHeader ?: "", DateUtil.getMonthOnlyDateString(wikiNotification.timestamp), notificationLink, diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationType.java b/app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java similarity index 92% rename from app/src/main/java/fr/free/nrw/commons/notification/NotificationType.java rename to app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java index 0386ead95..1b825f071 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationType.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/models/NotificationType.java @@ -1,4 +1,4 @@ -package fr.free.nrw.commons.notification; +package fr.free.nrw.commons.notification.models; public enum NotificationType { THANK_YOU_EDIT("thank-you-edit"), diff --git a/app/src/test/kotlin/fr/free/nrw/commons/contributions/ContributionsFragmentUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/contributions/ContributionsFragmentUnitTests.kt index 6ba0d9645..3aadb3084 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/contributions/ContributionsFragmentUnitTests.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/contributions/ContributionsFragmentUnitTests.kt @@ -17,9 +17,9 @@ import fr.free.nrw.commons.kvstore.JsonKvStore import fr.free.nrw.commons.media.MediaDetailPagerFragment import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient import fr.free.nrw.commons.nearby.NearbyNotificationCardView -import fr.free.nrw.commons.notification.Notification +import fr.free.nrw.commons.notification.models.Notification import fr.free.nrw.commons.notification.NotificationController -import fr.free.nrw.commons.notification.NotificationType +import fr.free.nrw.commons.notification.models.NotificationType import io.reactivex.Single import io.reactivex.disposables.CompositeDisposable import org.junit.Assert diff --git a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationActivityUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationActivityUnitTests.kt index 2fb1a400b..c8afe4061 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationActivityUnitTests.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationActivityUnitTests.kt @@ -8,6 +8,8 @@ import fr.free.nrw.commons.R import fr.free.nrw.commons.ShadowActionBar import fr.free.nrw.commons.TestAppAdapter import fr.free.nrw.commons.TestCommonsApplication +import fr.free.nrw.commons.notification.models.Notification +import fr.free.nrw.commons.notification.models.NotificationType import fr.free.nrw.commons.utils.NetworkUtils import org.junit.Assert import org.junit.Before diff --git a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationControllerTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationControllerTest.kt index 8bd764b25..b329bb788 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationControllerTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationControllerTest.kt @@ -1,5 +1,6 @@ package fr.free.nrw.commons.notification +import fr.free.nrw.commons.notification.models.Notification import org.junit.Before import org.junit.Test import org.mockito.ArgumentMatchers diff --git a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt index 4d95f4f5f..d68c79e12 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt @@ -4,6 +4,8 @@ import android.app.NotificationManager import android.content.Context import android.content.Intent import fr.free.nrw.commons.TestCommonsApplication +import fr.free.nrw.commons.notification.models.Notification +import fr.free.nrw.commons.notification.models.NotificationType import org.junit.Assert import org.junit.Before import org.junit.Test