Commit f5393797 authored by Matthieu's avatar Matthieu
Browse files

Merge branch 'notifications' into 'master'

Notifications

See merge request !371
parents 717ed496 5c97fe09
Pipeline #814 failed with stages
in 18 minutes and 31 seconds
......@@ -16,6 +16,7 @@ android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
......@@ -100,6 +101,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
/**
* AndroidX dependencies:
*/
......@@ -123,7 +126,8 @@ 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"
implementation "androidx.work:work-runtime-ktx:2.6.0"
implementation 'androidx.work:work-testing:2.6.0'
// Use the most recent version of CameraX
def cameraX_version = '1.0.1'
......@@ -158,9 +162,9 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
implementation 'io.reactivex.rxjava3:rxjava:3.1.1'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.github.connyduck:sparkbutton:4.1.0'
......@@ -180,14 +184,14 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.mikepenz:materialdrawer:8.4.2'
implementation 'com.mikepenz:materialdrawer:8.4.3'
// Add for NavController support
implementation 'com.mikepenz:materialdrawer-nav:8.4.2'
//iconics
implementation "com.mikepenz:iconics-core:5.3.0"
implementation 'com.mikepenz:iconics-core:5.3.1'
implementation 'com.mikepenz:materialdrawer-iconics:8.4.2'
implementation "com.mikepenz:iconics-views:5.3.0"
implementation 'com.mikepenz:iconics-views:5.3.1'
implementation 'com.mikepenz:google-material-typeface:4.0.0.1-kotlin@aar'
......
......@@ -544,6 +544,12 @@
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-testing:+
name: work-testing
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.6.0
- artifact: androidx.work:work-runtime-ktx:+
name: work-runtime-ktx
copyrightHolder: Google Inc.
......@@ -628,8 +634,8 @@
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/square/retrofit
- artifact: com.squareup.retrofit2:adapter-rxjava2:+
name: adapter-rxjava2
- artifact: com.squareup.retrofit2:adapter-rxjava3:+
name: adapter-rxjava3
copyrightHolder: Square, Inc.
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
......@@ -646,13 +652,13 @@
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://square.github.io/okhttp/
- artifact: io.reactivex.rxjava2:rxandroid:+
- artifact: io.reactivex.rxjava3:rxandroid:+
name: rxandroid
copyrightHolder: Netflix, Inc
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/ReactiveX/RxAndroid
- artifact: io.reactivex.rxjava2:rxjava:+
- artifact: io.reactivex.rxjava3:rxjava:+
name: rxjava
copyrightHolder: Netflix, Inc.
license: The Apache Software License, Version 2.0
......
......@@ -30,6 +30,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.Timeout
import org.junit.runner.RunWith
import java.time.Instant
@RunWith(AndroidJUnit4::class)
......@@ -73,12 +74,12 @@ class IntentTest {
"https://testing2.pixeldroid.org/storage/avatars/default.jpg?v=0",
"https://testing2.pixeldroid.org/storage/avatars/default.jpg?v=0",
"", "", false, emptyList(), null,
"2021-02-11T23:44:03.000000Z", 0, 1, 2,
Instant.parse("2021-02-11T23:44:03.000000Z"), 0, 1, 2,
null, null, false, null)
val expectedIntent: Matcher<Intent> = CoreMatchers.allOf(
IntentMatchers.hasExtra(ACCOUNT_TAG, account)
)
"2021-02-11T23:44:03.000000Z"
waitForView(R.id.description)
//Click the mention
......
......@@ -11,6 +11,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.android.material.tabs.TabLayout
import org.hamcrest.CoreMatchers.anyOf
import org.pixeldroid.app.testUtility.*
import org.pixeldroid.app.utils.db.AppDatabase
import org.junit.After
......@@ -81,7 +82,11 @@ class MockedServerTest {
waitForView(R.id.username)
onView(withId(R.id.username)).check(matches(withSubstring("User ")))
onView(withId(R.id.username)).check(matches(anyOf(
withSubstring("User "),
withSubstring("PixelDroid Developer"),
withSubstring("Testi Testo")
)))
}
@Test
......
package org.pixeldroid.app
import android.content.Context
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.*
import androidx.work.ListenableWorker
import androidx.work.testing.TestListenableWorkerBuilder
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.pixeldroid.app.settings.AboutActivity
import org.pixeldroid.app.testUtility.*
import org.pixeldroid.app.utils.api.objects.Account
import org.pixeldroid.app.utils.api.objects.Notification
import org.pixeldroid.app.utils.db.AppDatabase
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker
import java.time.Instant
@RunWith(JUnit4::class)
class NotificationWorkerTest {
private lateinit var context: Context
private lateinit var activityScenario: ActivityScenario<AboutActivity>
private val uiDevice by lazy { UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) }
private lateinit var db: AppDatabase
private val secondToLatestNotification: Notification =
Notification(
id = "1",
type = Notification.NotificationType.follow,
created_at = Instant.parse("2021-09-19T19:23:30Z"),
account = Account(
id = "344399325768278017",
username = "pixeldroid",
acct = "pixeldroid",
url = "https://testing.pixeldroid.org/pixeldroid",
display_name = "PixelDroid",
note = "",
avatar = "https://testing.pixeldroid.org/storage/avatars/default.jpg?v=0",
avatar_static = null,
header = null,
header_static = null,
locked = false,
emojis = null,
discoverable = null,
created_at = Instant.parse("1970-01-01T00:00:00Z"),
statuses_count = 0,
followers_count = 0,
following_count = 1,
moved = null,
fields = null,
bot = null,
source = null
),
status = null,
user_id = "344399082242686977",
instance_uri = "https://testing.pixeldroid.org"
)
@Before
fun setup() {
context = ApplicationProvider.getApplicationContext()
db = initDB(context)
db.clearAllTables()
db.instanceDao().insertInstance(
testiTestoInstance
)
db.userDao().insertUser(
testiTesto
)
runBlocking {
db.notificationDao().insertAll(listOf(secondToLatestNotification))
}
db.close()
activityScenario = ActivityScenario.launch(AboutActivity::class.java)
}
@Test
fun testNotificationWorker() {
val expectedAppName = context.getString(R.string.app_name)
val expectedText = "user1 followed you"
// Run the worker synchronously
val worker = TestListenableWorkerBuilder<NotificationsWorker>(context).build()
val result = worker.startWork().get()
// Check worker returns success (which doesn't mean much, but is a good start)
MatcherAssert.assertThat(result, CoreMatchers.`is`(ListenableWorker.Result.success()))
//Open notification shade
uiDevice.openNotification()
uiDevice.wait(Until.hasObject(By.textStartsWith(expectedAppName)), 5000)
val text: UiObject2 = uiDevice.findObject(By.textStartsWith(expectedText))
text.click()
uiDevice.wait(Until.hasObject(By.textStartsWith(expectedText)), 5000)
waitForView(R.id.notification_type)
onView(first(withId(R.id.notification_type)))
.check(matches(withText(expectedText)))
}
}
\ No newline at end of file
......@@ -27,6 +27,9 @@ import org.junit.*
import org.junit.rules.Timeout
import org.junit.runner.RunWith
import java.text.SimpleDateFormat
import java.time.Instant
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
@RunWith(AndroidJUnit4::class)
......@@ -40,7 +43,7 @@ class PostTest {
@Before
fun before(){
context = InstrumentationRegistry.getInstrumentation().targetContext
context = getInstrumentation().targetContext
db = initDB(context)
db.clearAllTables()
db.instanceDao().insertInstance(
......@@ -66,7 +69,8 @@ class PostTest {
username = "SQDFSQDF",
url = "$INSTANCE_URI/pixeldroid",
),
media_attachments = listOf(attachment)
media_attachments = listOf(attachment),
created_at = Instant.now().minusSeconds(3600)
)
val intent = Intent(context, PostActivity::class.java)
intent.putExtra(Status.POST_TAG, post)
......@@ -102,7 +106,8 @@ class PostTest {
username = "douze",
url = "$INSTANCE_URI/pixeldroid",
),
media_attachments = listOf(attachment1, attachment2)
media_attachments = listOf(attachment1, attachment2),
created_at = Instant.now().minusSeconds(3600)
)
val intent = Intent(context, PostActivity::class.java)
intent.putExtra(Status.POST_TAG, post)
......@@ -134,7 +139,8 @@ class PostTest {
username = "douze",
url = "$INSTANCE_URI/pixeldroid",
),
media_attachments = listOf(attachment)
media_attachments = listOf(attachment),
created_at = Instant.now().minusSeconds(3600)
)
val intent = Intent(context, PostActivity::class.java)
intent.putExtra(Status.POST_TAG, post)
......@@ -165,7 +171,8 @@ class PostTest {
username = "douze",
url = "$INSTANCE_URI/pixeldroid",
),
media_attachments = listOf(attachment1, attachment2)
media_attachments = listOf(attachment1, attachment2),
created_at = Instant.now().minusSeconds(3600)
)
val intent = Intent(context, PostActivity::class.java)
intent.putExtra(Status.POST_TAG, post)
......@@ -181,13 +188,13 @@ class PostTest {
@Test
fun getNLikesReturnsCorrectFormat() {
val status = Status(id="140364967936397312", uri="https://pixelfed.de/p/Miike/140364967936397312",
created_at= SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.hhmmss'Z'").parse("2020-03-03T08:00:16.000000Z"),
created_at= OffsetDateTime.parse("2020-03-03T08:00:16+00:00").toInstant(),
account= Account(id="115114166443970560", username="Miike", acct="Miike",
url="https://pixelfed.de/Miike", display_name="Miike Duart", note="",
avatar="https://pixelfed.de/storage/avatars/011/511/416/644/397/056/0/ZhaopLJWTWJ3hsVCS5pS_avatar.png?v=d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
avatar_static="https://pixelfed.de/storage/avatars/011/511/416/644/397/056/0/ZhaopLJWTWJ3hsVCS5pS_avatar.png?v=d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
header="", header_static="", locked=false, emojis= emptyList(), discoverable=false,
created_at="2019-12-24T15:42:35.000000Z", statuses_count=71, followers_count=14,
created_at=Instant.parse("2019-12-24T15:42:35.000000Z"), statuses_count=71, followers_count=14,
following_count=0, moved=null, fields=null, bot=false, source=null),
content="""Day 8 <a href="https://pixelfed.de/discover/tags/rotavicentina?src=hash" title="#rotavicentina" class="u-url hashtag" rel="external nofollow noopener">#rotavicentina</a> <a href="https://pixelfed.de/discover/tags/hiking?src=hash" title="#hiking" class="u-url hashtag" rel="external nofollow noopener">#hiking</a> <a href="https://pixelfed.de/discover/tags/nature?src=hash" title="#nature" class="u-url hashtag" rel="external nofollow noopener">#nature</a>""",
visibility=Status.Visibility.public, sensitive=false, spoiler_text="",
......@@ -208,13 +215,13 @@ class PostTest {
@Test
fun getNSharesReturnsCorrectFormat() {
val status = Status(id="140364967936397312", uri="https://pixelfed.de/p/Miike/140364967936397312",
created_at= SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.hhmmss'Z'").parse("2020-03-03T08:00:16.000000Z"),
created_at= Instant.parse("2020-03-03T08:00:16.00Z"),
account= Account(id="115114166443970560", username="Miike", acct="Miike",
url="https://pixelfed.de/Miike", display_name="Miike Duart", note="",
avatar="https://pixelfed.de/storage/avatars/011/511/416/644/397/056/0/ZhaopLJWTWJ3hsVCS5pS_avatar.png?v=d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
avatar_static="https://pixelfed.de/storage/avatars/011/511/416/644/397/056/0/ZhaopLJWTWJ3hsVCS5pS_avatar.png?v=d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
header="", header_static="", locked=false, emojis= emptyList(), discoverable=false,
created_at="2019-12-24T15:42:35.000000Z", statuses_count=71, followers_count=14,
created_at=Instant.parse("2019-12-24T15:42:35.000000Z"), statuses_count=71, followers_count=14,
following_count=0, moved=null, fields=null, bot=false, source=null),
content="""Day 8 <a href="https://pixelfed.de/discover/tags/rotavicentina?src=hash" title="#rotavicentina" class="u-url hashtag" rel="external nofollow noopener">#rotavicentina</a> <a href="https://pixelfed.de/discover/tags/hiking?src=hash" title="#hiking" class="u-url hashtag" rel="external nofollow noopener">#hiking</a> <a href="https://pixelfed.de/discover/tags/nature?src=hash" title="#nature" class="u-url hashtag" rel="external nofollow noopener">#nature</a>""",
visibility=Status.Visibility.public, sensitive=false, spoiler_text="",
......
......@@ -19,6 +19,7 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.time.Instant
@RunWith(AndroidJUnit4::class)
class ProfileTest {
......@@ -37,7 +38,7 @@ class ProfileTest {
db.close()
val intent = Intent(context, ProfileActivity::class.java)
val account = Account(id = "265472486651596800", username = "pixeldroid", acct = "pixeldroid", url = "https://testing2.pixeldroid.org/pixeldroid", display_name = "PixelDroid Developer", avatar = "https://testing2.pixeldroid.org/storage/avatars/default.jpg?v=0", avatar_static = "https://testing2.pixeldroid.org/storage/avatars/default.jpg?v=0", locked = false, emojis = arrayListOf(), discoverable = null, created_at = "2021-02-11T13:32:53.000000Z", statuses_count = 1, followers_count = 1, following_count = 1, moved = null, fields = null, bot = false, source = null)
val account = Account(id="344399325768278017", username="pixeldroid", acct="pixeldroid", url="https://testing.pixeldroid.org/pixeldroid", display_name="PixelDroid Developer", note="", avatar="https://testing.pixeldroid.org/storage/avatars/default.jpg?v=0", avatar_static="https://testing.pixeldroid.org/storage/avatars/default.jpg?v=0", header="", header_static="", locked=false, emojis= emptyList(), discoverable=null, created_at=Instant.parse("2021-09-17T08:39:57Z"), statuses_count=0, followers_count=1, following_count=1, moved=null, fields=null, bot=false, source=null)
intent.putExtra(Account.ACCOUNT_TAG, account)
activityScenario = ActivityScenario.launch(intent)
onView(withId(R.id.profileRefreshLayout)).perform(swipeDown())
......@@ -86,7 +87,7 @@ class ProfileTest {
waitForView(R.id.account_entry_username)
// Open follower's profile
onView(ViewMatchers.withText("testi testo")).perform((ViewActions.click()))
onView(ViewMatchers.withText("Testi Testo")).perform((ViewActions.click()))
waitForView(R.id.editButton)
......
......@@ -9,6 +9,8 @@ import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.lifecycle.lifecycleScope
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import org.pixeldroid.app.databinding.ActivityLoginBinding
import org.pixeldroid.app.utils.*
import org.pixeldroid.app.utils.api.PixelfedAPI
......@@ -16,8 +18,13 @@ import org.pixeldroid.app.utils.api.objects.*
import org.pixeldroid.app.utils.db.addUser
import org.pixeldroid.app.utils.db.storeInstance
import kotlinx.coroutines.*
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker
import org.pixeldroid.app.utils.notificationsWorker.makeChannelGroupId
import org.pixeldroid.app.utils.notificationsWorker.makeNotificationChannels
import retrofit2.HttpException
import java.io.IOException
import java.lang.IllegalArgumentException
import java.lang.NullPointerException
/**
Overview of the flow of the login process: (boxes are requests done in parallel,
......@@ -310,14 +317,40 @@ class LoginActivity : BaseActivity() {
clientSecret = clientSecret
)
apiHolder.setToCurrentUser()
val intent = Intent(this@LoginActivity, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
} catch (exception: IOException) {
return failedRegistration(getString(R.string.verify_credentials))
} catch (exception: HttpException) {
return failedRegistration(getString(R.string.verify_credentials))
}
fetchNotifications()
val intent = Intent(this@LoginActivity, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
}
// Fetch the latest notifications of this account, to avoid launching old notifications
private suspend fun fetchNotifications() {
val user = db.userDao().getActiveUser()!!
try {
val notifications = apiHolder.api!!.notifications()
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) {
return failedRegistration(getString(R.string.login_notifications))
}
makeNotificationChannels(
applicationContext,
user.fullHandle,
makeChannelGroupId(user)
)
}
}
......@@ -41,10 +41,15 @@ import org.pixeldroid.app.searchDiscover.SearchDiscoverFragment
import org.pixeldroid.app.settings.SettingsActivity
import org.pixeldroid.app.utils.BaseActivity
import org.pixeldroid.app.utils.db.addUser
import org.pixeldroid.app.utils.notificationsWorker.enablePullNotifications
import org.pixeldroid.app.utils.db.entities.HomeStatusDatabaseEntity
import org.pixeldroid.app.utils.db.entities.PublicFeedStatusDatabaseEntity
import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
import org.pixeldroid.app.utils.hasInternet
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.INSTANCE_NOTIFICATION_TAG
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.SHOW_NOTIFICATION_TAG
import org.pixeldroid.app.utils.notificationsWorker.NotificationsWorker.Companion.USER_NOTIFICATION_TAG
import org.pixeldroid.app.utils.notificationsWorker.removeNotificationChannelsFromAccount
import retrofit2.HttpException
import java.io.IOException
......@@ -56,6 +61,7 @@ class MainActivity : BaseActivity() {
companion object {
const val ADD_ACCOUNT_IDENTIFIER: Long = -13
const val LOG_OUT_REQUESTED = "LOG_OUT_REQUESTED"
}
private lateinit var binding: ActivityMainBinding
......@@ -70,6 +76,8 @@ class MainActivity : BaseActivity() {
//get the currently active user
user = db.userDao().getActiveUser()
if (notificationFromOtherUser()) return
//Check if we have logged in and gotten an access token
if (user == null) {
finish()
......@@ -96,7 +104,41 @@ class MainActivity : BaseActivity() {
}
)
setupTabs(tabs)
val showNotification: Boolean = intent.getBooleanExtra(SHOW_NOTIFICATION_TAG, false)
if(showNotification){
binding.viewPager.currentItem = 3
}
enablePullNotifications(this)
}
}
// Checks if the activity was launched from a notification from another account than the
// current active one, and if so switches to that account
private fun notificationFromOtherUser(): Boolean {
val userOfNotification: String? = intent.extras?.getString(USER_NOTIFICATION_TAG)
val instanceOfNotification: String? = intent.extras?.getString(INSTANCE_NOTIFICATION_TAG)
if (userOfNotification != null && instanceOfNotification != null
&& (userOfNotification != user?.user_id
|| instanceOfNotification != user?.instance_uri)
) {
switchUser(userOfNotification)
val newIntent = Intent(this, MainActivity::class.java)
newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
if (intent.getBooleanExtra(SHOW_NOTIFICATION_TAG, false)) {
newIntent.putExtra(SHOW_NOTIFICATION_TAG, true)
}
finish()
startActivity(newIntent)
return true
}
return false
}
private fun setupDrawer() {
......@@ -173,6 +215,9 @@ class MainActivity : BaseActivity() {
private fun logOut(){
finish()
removeNotificationChannelsFromAccount(applicationContext, user)
db.runInTransaction {
db.userDao().deleteActiveUsers()
......@@ -225,9 +270,8 @@ class MainActivity : BaseActivity() {
return false
}
db.userDao().deActivateActiveUsers()
db.userDao().activateUser(profile.identifier.toString())
apiHolder.setToCurrentUser()
switchUser(profile.identifier.toString())
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
......@@ -237,6 +281,12 @@ class MainActivity : BaseActivity() {
return false
}
private fun switchUser(userId: String) {
db.userDao().deActivateActiveUsers()
db.userDao().activateUser(userId)
apiHolder.setToCurrentUser()
}
private inline fun primaryDrawerItem(block: PrimaryDrawerItem.() -> Unit): PrimaryDrawerItem {
return PrimaryDrawerItem()
.apply {
......@@ -262,7 +312,7 @@ class MainActivity : BaseActivity() {
iconUrl = user.avatar_static
isNameShown = true
identifier = user.user_id.toLong()
descriptionText = "@${user.username}@${user.instance_uri.removePrefix("https://")}"
descriptionText = user.fullHandle
}
}.toMutableList()
......
......@@ -22,6 +22,9 @@ import androidx.core.net.toFile
import androidx.core.net.toUri
import androidx.lifecycle.lifecycleScope
import com.google.android.material.snackbar.Snackbar
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import org.pixeldroid.app.MainActivity
import org.pixeldroid.app.R
import org.pixeldroid.app.databinding.ActivityPostCreationBinding
......@@ -33,9 +36,6 @@ import org.pixeldroid.app.utils.BaseActivity
import org.pixeldroid.app.utils.api.objects.Attachment
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import okhttp3.MultipartBody
import retrofit2.HttpException
import java.io.File
......
package org.pixeldroid.app.postCreation
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.PublishSubject
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
......
......@@ -10,7 +10,6 @@ import android.text.style.URLSpan
import android.util.Log
import android.view.View
import android.widget.TextView