Fix coverage stat, update dependencies, remove useless db passing

This commit is contained in:
Matthieu 2021-04-20 12:07:18 +00:00
parent bccf57f918
commit b25262db2f
25 changed files with 91 additions and 120 deletions

View File

@ -52,6 +52,7 @@ emulatorTest:
- cat app/build/reports/jacoco/jacocoTestReport/html/index.html | grep -o 'Total[^%]*%' - cat app/build/reports/jacoco/jacocoTestReport/html/index.html | grep -o 'Total[^%]*%'
artifacts: artifacts:
when: always
paths: paths:
- ./app/build/reports/jacoco/jacocoTestReport/ - ./app/build/reports/jacoco/jacocoTestReport/
expire_in: 1 week expire_in: 1 week

View File

@ -136,17 +136,17 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
//Dagger (dependency injection) //Dagger (dependency injection)
implementation 'com.google.dagger:dagger-android:2.30.1' implementation 'com.google.dagger:dagger-android:2.34.1'
implementation 'com.google.dagger:dagger-android-support:2.30.1' implementation 'com.google.dagger:dagger-android-support:2.34.1'
// if you use the support libraries // if you use the support libraries
kapt 'com.google.dagger:dagger-android-processor:2.30.1' kapt 'com.google.dagger:dagger-android-processor:2.34.1'
kapt 'com.google.dagger:dagger-compiler:2.30.1' kapt 'com.google.dagger:dagger-compiler:2.34.1'
implementation 'com.squareup.okhttp3:okhttp:4.9.0' implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.20' implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.github.connyduck:sparkbutton:4.1.0' implementation 'com.github.connyduck:sparkbutton:4.1.0'
@ -154,26 +154,26 @@ dependencies {
implementation 'info.androidhive:imagefilters:1.0.7' implementation 'info.androidhive:imagefilters:1.0.7'
implementation 'com.github.yalantis:ucrop:2.2.6-native' implementation 'com.github.yalantis:ucrop:2.2.6-native'
implementation("com.github.bumptech.glide:glide:4.11.0") { implementation('com.github.bumptech.glide:glide:4.12.0') {
exclude group: "com.android.support" exclude group: "com.android.support"
} }
implementation "com.github.bumptech.glide:okhttp-integration:4.11.0" implementation 'com.github.bumptech.glide:okhttp-integration:4.12.0'
implementation("com.github.bumptech.glide:recyclerview-integration:4.11.0") { implementation('com.github.bumptech.glide:recyclerview-integration:4.12.0') {
// Excludes the support library because it's already included by Glide. // Excludes the support library because it's already included by Glide.
transitive = false transitive = false
} }
kapt 'com.github.bumptech.glide:compiler:4.11.0' kapt 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "com.mikepenz:materialdrawer:8.1.8" implementation 'com.mikepenz:materialdrawer:8.4.0'
// Add for NavController support // Add for NavController support
implementation "com.mikepenz:materialdrawer-nav:8.1.5" implementation 'com.mikepenz:materialdrawer-nav:8.4.0'
//iconics //iconics
implementation "com.mikepenz:iconics-core:5.0.3" implementation "com.mikepenz:iconics-core:5.2.8"
implementation "com.mikepenz:materialdrawer-iconics:8.1.8" implementation 'com.mikepenz:materialdrawer-iconics:8.4.0'
implementation "com.mikepenz:iconics-views:5.0.3" implementation "com.mikepenz:iconics-views:5.0.3"
implementation 'com.mikepenz:google-material-typeface:3.0.1.4.original-kotlin@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.4.original-kotlin@aar'
@ -196,7 +196,7 @@ dependencies {
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.27.2' testImplementation 'com.github.tomakehurst:wiremock-jre8:2.27.2'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation 'junit:junit:4.13.1' testImplementation 'junit:junit:4.13.2'
testImplementation "androidx.room:room-testing:$room_version" testImplementation "androidx.room:room-testing:$room_version"
@ -227,10 +227,10 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['connectedStagingAndroidTe
} }
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def kotlinDebugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) def kotlinTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/staging", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java" def mainSrc = "$project.projectDir/src/main/java"
getSourceDirectories().from(files([mainSrc])) getSourceDirectories().from(files([mainSrc]))
getClassDirectories().from(files([kotlinDebugTree])) getClassDirectories().from(files([kotlinTree]))
getExecutionData().from(fileTree(dir: project.buildDir, includes: [ getExecutionData().from(fileTree(dir: project.buildDir, includes: [
'outputs/code_coverage/stagingAndroidTest/connected/*coverage.ec', 'outputs/code_coverage/stagingAndroidTest/connected/*coverage.ec',

View File

@ -16,12 +16,12 @@
license: The Apache Software License, Version 2.0 license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/mikepenz/MaterialDrawer url: https://github.com/mikepenz/MaterialDrawer
- artifact: org.jetbrains.kotlin:kotlin-android-extensions-runtime:+ - artifact: androidx.startup:startup-runtime:+
name: kotlin-android-extensions-runtime name: startup-runtime
copyrightHolder: JetBrains s.r.o. and contributors copyrightHolder: Google Inc.
license: The Apache License, Version 2.0 license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://kotlinlang.org/ url: https://developer.android.com/jetpack/androidx/releases/startup#1.0.0
- artifact: com.mikepenz:iconics-views:+ - artifact: com.mikepenz:iconics-views:+
name: iconics-views name: iconics-views
copyrightHolder: Mike Penz and contributors copyrightHolder: Mike Penz and contributors
@ -793,4 +793,4 @@
copyrightHolder: Google Inc copyrightHolder: Google Inc
license: The Apache Software License, Version 2.0 license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://developer.android.com/jetpack/androidx/releases/tracing#1.0.0 url: https://developer.android.com/jetpack/androidx/releases/tracing#1.0.0

View File

@ -818,9 +818,9 @@
</div> </div>
<div class="library"> <div class="library">
<!-- https://opensource.org/licenses/Apache-2.0 --> <!-- https://opensource.org/licenses/Apache-2.0 -->
<h1 class="title">kotlin-android-extensions-runtime</h1> <h1 class="title">startup-runtime</h1>
<p class="notice">Copyright &copy; JetBrains s.r.o. and contributors. All rights reserved.</p> <p class="notice">Copyright &copy; Google Inc. All rights reserved.</p>
<p><a href="https://kotlinlang.org/">https://kotlinlang.org/</a></p> <p><a href="https://developer.android.com/jetpack/androidx/releases/startup#1.0.0">https://developer.android.com/jetpack/androidx/releases/startup#1.0.0</a></p>
<input type="checkbox"><label></label> <input type="checkbox"><label></label>
<div class="license"> <div class="license">
<h2> <h2>

View File

@ -25,14 +25,13 @@ Overview of the flow of the login process: (boxes are requests done in parallel,
since they do not depend on each other) since they do not depend on each other)
_________________________________ _________________________________
|[PixelfedAPI.registerApplicationAsync]| |[PixelfedAPI.registerApplication]|
|[PixelfedAPI.wellKnownNodeInfo] | |[PixelfedAPI.wellKnownNodeInfo] |
̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅ +----> [PixelfedAPI.nodeInfoSchema] ̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
+----> [promptOAuth] +----> [PixelfedAPI.nodeInfoSchema] (and then [PixelfedAPI.instance] if needed)
+---->____________________________ +----> [promptOAuth]
|[PixelfedAPI.instance] | +----> [PixelfedAPI.obtainToken]
|[PixelfedAPI.obtainToken] | +----> [PixelfedAPI.verifyCredentials]
̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅ +----> [PixelfedAPI.verifyCredentials]
*/ */
@ -311,7 +310,7 @@ class LoginActivity : BaseActivity() {
clientId = clientId, clientId = clientId,
clientSecret = clientSecret clientSecret = clientSecret
) )
apiHolder.setDomainToCurrentUser(db) apiHolder.setToCurrentUser()
val intent = Intent(this@LoginActivity, MainActivity::class.java) val intent = Intent(this@LoginActivity, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent) startActivity(intent)

View File

@ -177,7 +177,7 @@ class MainActivity : BaseActivity() {
} else { } else {
val newActive = remainingUsers.first() val newActive = remainingUsers.first()
db.userDao().activateUser(newActive.user_id) db.userDao().activateUser(newActive.user_id)
apiHolder.setDomainToCurrentUser(db) apiHolder.setToCurrentUser()
//relaunch the app //relaunch the app
launchActivity(MainActivity(), firstTime = true) launchActivity(MainActivity(), firstTime = true)
} }
@ -193,7 +193,7 @@ class MainActivity : BaseActivity() {
val refreshToken = user?.refreshToken val refreshToken = user?.refreshToken
val clientId = user?.clientId.orEmpty() val clientId = user?.clientId.orEmpty()
val clientSecret = user?.clientSecret.orEmpty() val clientSecret = user?.clientSecret.orEmpty()
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val account = api.verifyCredentials() val account = api.verifyCredentials()
addUser(db, account, domain, accessToken = accessToken, refreshToken = refreshToken, clientId = clientId, clientSecret = clientSecret) addUser(db, account, domain, accessToken = accessToken, refreshToken = refreshToken, clientId = clientId, clientSecret = clientSecret)
@ -221,7 +221,7 @@ class MainActivity : BaseActivity() {
db.userDao().deActivateActiveUsers() db.userDao().deActivateActiveUsers()
db.userDao().activateUser(profile.identifier.toString()) db.userDao().activateUser(profile.identifier.toString())
apiHolder.setDomainToCurrentUser(db) apiHolder.setToCurrentUser()
val intent = Intent(this, MainActivity::class.java) val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent) startActivity(intent)

View File

@ -332,7 +332,7 @@ class PostCreationActivity : BaseActivity() {
val description = data.imageDescription?.let { MultipartBody.Part.createFormData("description", it) } val description = data.imageDescription?.let { MultipartBody.Part.createFormData("description", it) }
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val inter = api.mediaUpload(description, requestBody.parts[0]) val inter = api.mediaUpload(description, requestBody.parts[0])
postSub = inter postSub = inter
@ -375,7 +375,7 @@ class PostCreationActivity : BaseActivity() {
enableButton(false) enableButton(false)
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
try { try {
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
api.postStatus( api.postStatus(
statusText = description, statusText = description,

View File

@ -17,7 +17,6 @@ import com.h.pixeldroid.R
import com.h.pixeldroid.utils.api.PixelfedAPI import com.h.pixeldroid.utils.api.PixelfedAPI
import com.h.pixeldroid.utils.api.objects.Account.Companion.openAccountFromId import com.h.pixeldroid.utils.api.objects.Account.Companion.openAccountFromId
import com.h.pixeldroid.utils.api.objects.Mention import com.h.pixeldroid.utils.api.objects.Mention
import com.h.pixeldroid.utils.db.AppDatabase
import com.h.pixeldroid.utils.di.PixelfedAPIHolder import com.h.pixeldroid.utils.di.PixelfedAPIHolder
import java.net.URI import java.net.URI
import java.net.URISyntaxException import java.net.URISyntaxException
@ -55,7 +54,6 @@ fun parseHTMLText(
apiHolder: PixelfedAPIHolder, apiHolder: PixelfedAPIHolder,
context: Context, context: Context,
lifecycleScope: LifecycleCoroutineScope, lifecycleScope: LifecycleCoroutineScope,
db: AppDatabase
) : Spanned { ) : Spanned {
//Convert text to spannable //Convert text to spannable
val content = fromHtml(text) val content = fromHtml(text)
@ -108,7 +106,7 @@ fun parseHTMLText(
Log.e("MENTION", "CLICKED") Log.e("MENTION", "CLICKED")
//Retrieve the account for the given profile //Retrieve the account for the given profile
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
openAccountFromId(accountId, api, context) openAccountFromId(accountId, api, context)
} }
} }

View File

@ -107,12 +107,11 @@ class PostActivity : BaseActivity() {
itemBinding.user.text = commentUsername itemBinding.user.text = commentUsername
itemBinding.commentText.text = parseHTMLText( itemBinding.commentText.text = parseHTMLText(
commentContent, commentContent,
mentions, mentions,
apiHolder, apiHolder,
context, context,
lifecycleScope, lifecycleScope
db
) )
} }

View File

@ -33,7 +33,7 @@ class ReportActivity : BaseActivity() {
binding.textInputLayout.editText?.isEnabled = false binding.textInputLayout.editText?.isEnabled = false
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
try { try {

View File

@ -180,19 +180,17 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
private fun setDescription( private fun setDescription(
apiHolder: PixelfedAPIHolder, apiHolder: PixelfedAPIHolder,
lifecycleScope: LifecycleCoroutineScope, lifecycleScope: LifecycleCoroutineScope,
db: AppDatabase
) { ) {
binding.description.apply { binding.description.apply {
if (status?.content.isNullOrBlank()) { if (status?.content.isNullOrBlank()) {
visibility = View.GONE visibility = View.GONE
} else { } else {
text = parseHTMLText( text = parseHTMLText(
status?.content.orEmpty(), status?.content.orEmpty(),
status?.mentions, status?.mentions,
apiHolder, apiHolder,
binding.root.context, binding.root.context,
lifecycleScope, lifecycleScope
db
) )
movementMethod = LinkMovementMethod.getInstance() movementMethod = LinkMovementMethod.getInstance()
} }
@ -206,14 +204,14 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
isActivity: Boolean isActivity: Boolean
){ ){
//Set the special HTML text //Set the special HTML text
setDescription(apiHolder, lifecycleScope, db) setDescription(apiHolder, lifecycleScope)
//Activate onclickListeners //Activate onclickListeners
activateLiker( activateLiker(
apiHolder, status?.favourited ?: false, lifecycleScope, db apiHolder, status?.favourited ?: false, lifecycleScope
) )
activateReblogger( activateReblogger(
apiHolder, status?.reblogged ?: false, lifecycleScope, db apiHolder, status?.reblogged ?: false, lifecycleScope
) )
if(isActivity){ if(isActivity){
@ -240,7 +238,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
apiHolder: PixelfedAPIHolder, apiHolder: PixelfedAPIHolder,
isReblogged: Boolean, isReblogged: Boolean,
lifecycleScope: LifecycleCoroutineScope, lifecycleScope: LifecycleCoroutineScope,
db: AppDatabase
) { ) {
binding.reblogger.apply { binding.reblogger.apply {
//Set initial button state //Set initial button state
@ -249,7 +246,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
//Activate the button //Activate the button
setEventListener { _, buttonState -> setEventListener { _, buttonState ->
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
if (buttonState) { if (buttonState) {
// Button is active // Button is active
undoReblogPost(api) undoReblogPost(api)
@ -386,7 +383,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
db.homePostDao().delete(id, user.user_id, user.instance_uri) db.homePostDao().delete(id, user.user_id, user.instance_uri)
db.publicPostDao().delete(id, user.user_id, user.instance_uri) db.publicPostDao().delete(id, user.user_id, user.instance_uri)
try { try {
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
api.deleteStatus(id) api.deleteStatus(id)
binding.root.visibility = View.GONE binding.root.visibility = View.GONE
} catch (exception: HttpException) { } catch (exception: HttpException) {
@ -434,7 +431,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
apiHolder: PixelfedAPIHolder, apiHolder: PixelfedAPIHolder,
isLiked: Boolean, isLiked: Boolean,
lifecycleScope: LifecycleCoroutineScope, lifecycleScope: LifecycleCoroutineScope,
db: AppDatabase
) { ) {
binding.liker.apply { binding.liker.apply {
@ -444,7 +440,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
//Activate the liker //Activate the liker
setEventListener { _, buttonState -> setEventListener { _, buttonState ->
lifecycleScope.launchWhenCreated { lifecycleScope.launchWhenCreated {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
if (buttonState) { if (buttonState) {
// Button is active, unlike // Button is active, unlike
unLikePostCall(api) unLikePostCall(api)
@ -466,7 +462,7 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
if(binding.sensitiveWarning.visibility == View.GONE) { if(binding.sensitiveWarning.visibility == View.GONE) {
//Check for double click //Check for double click
if(clicked) { if(clicked) {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
if (binding.liker.isChecked) { if (binding.liker.isChecked) {
// Button is active, unlike // Button is active, unlike
binding.liker.isChecked = false binding.liker.isChecked = false

View File

@ -30,7 +30,6 @@ import com.h.pixeldroid.profile.ProfileActivity
import com.h.pixeldroid.utils.api.objects.Account import com.h.pixeldroid.utils.api.objects.Account
import com.h.pixeldroid.utils.api.objects.Notification import com.h.pixeldroid.utils.api.objects.Notification
import com.h.pixeldroid.utils.api.objects.Status import com.h.pixeldroid.utils.api.objects.Status
import com.h.pixeldroid.utils.db.AppDatabase
import com.h.pixeldroid.utils.di.PixelfedAPIHolder import com.h.pixeldroid.utils.di.PixelfedAPIHolder
@ -41,7 +40,7 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
adapter = NotificationsAdapter(apiHolder, db) adapter = NotificationsAdapter(apiHolder)
} }
@ExperimentalPagingApi @ExperimentalPagingApi
@ -166,7 +165,6 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
notification: Notification?, notification: Notification?,
api: PixelfedAPIHolder, api: PixelfedAPIHolder,
lifecycleScope: LifecycleCoroutineScope, lifecycleScope: LifecycleCoroutineScope,
db: AppDatabase
) { ) {
this.notification = notification this.notification = notification
@ -203,12 +201,11 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
//Convert HTML to clickable text //Convert HTML to clickable text
postDescription.text = postDescription.text =
parseHTMLText( parseHTMLText(
notification?.status?.content ?: "", notification?.status?.content ?: "",
notification?.status?.mentions, notification?.status?.mentions,
api, api,
itemView.context, itemView.context,
lifecycleScope, lifecycleScope
db
) )
} }
@ -225,7 +222,6 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
inner class NotificationsAdapter( inner class NotificationsAdapter(
private val apiHolder: PixelfedAPIHolder, private val apiHolder: PixelfedAPIHolder,
private val db: AppDatabase
) : PagingDataAdapter<Notification, RecyclerView.ViewHolder>( ) : PagingDataAdapter<Notification, RecyclerView.ViewHolder>(
object : DiffUtil.ItemCallback<Notification>() { object : DiffUtil.ItemCallback<Notification>() {
override fun areItemsTheSame( override fun areItemsTheSame(
@ -255,10 +251,9 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
val uiModel = getItem(position) val uiModel = getItem(position)
uiModel.let { uiModel.let {
(holder as NotificationViewHolder).bind( (holder as NotificationViewHolder).bind(
it, it,
apiHolder, apiHolder,
lifecycleScope, lifecycleScope
db
) )
} }
} }

View File

@ -58,7 +58,7 @@ class NotificationsRemoteMediator @Inject constructor(
try { try {
val user = db.userDao().getActiveUser() val user = db.userDao().getActiveUser()
?: return MediatorResult.Error(NullPointerException("No active user exists")) ?: return MediatorResult.Error(NullPointerException("No active user exists"))
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val apiResponse = api.notifications( val apiResponse = api.notifications(
max_id = max_id, max_id = max_id,

View File

@ -43,7 +43,7 @@ class HomeFeedRemoteMediator @Inject constructor(
try { try {
val user = db.userDao().getActiveUser() val user = db.userDao().getActiveUser()
?: return MediatorResult.Error(NullPointerException("No active user exists")) ?: return MediatorResult.Error(NullPointerException("No active user exists"))
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val apiResponse = api.timelineHome( val apiResponse = api.timelineHome(
max_id= max_id, max_id= max_id,

View File

@ -58,7 +58,7 @@ class PublicFeedRemoteMediator @Inject constructor(
try { try {
val user = db.userDao().getActiveUser() val user = db.userDao().getActiveUser()
?: return MediatorResult.Error(NullPointerException("No active user exists")) ?: return MediatorResult.Error(NullPointerException("No active user exists"))
val api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val apiResponse = api.timelinePublic( val apiResponse = api.timelinePublic(
max_id = max_id, max_id = max_id,

View File

@ -54,7 +54,7 @@ class AccountListFragment : UncachedFeedFragment<Account>() {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
viewModel = ViewModelProvider(this, ViewModelFactory( viewModel = ViewModelProvider(this, ViewModelFactory(
FollowersContentRepository( FollowersContentRepository(
apiHolder.setDomainToCurrentUser(db), apiHolder.setToCurrentUser(),
id, id,
following following
) )

View File

@ -39,7 +39,7 @@ class SearchAccountFragment : UncachedFeedFragment<Account>() {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
viewModel = ViewModelProvider(this, ViewModelFactory( viewModel = ViewModelProvider(this, ViewModelFactory(
SearchContentRepository<Account>( SearchContentRepository<Account>(
apiHolder.setDomainToCurrentUser(db), apiHolder.setToCurrentUser(),
Results.SearchType.accounts, Results.SearchType.accounts,
query query
) )

View File

@ -46,7 +46,7 @@ class SearchHashtagFragment : UncachedFeedFragment<Tag>() {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
viewModel = ViewModelProvider(this, ViewModelFactory( viewModel = ViewModelProvider(this, ViewModelFactory(
SearchContentRepository<Tag>( SearchContentRepository<Tag>(
apiHolder.setDomainToCurrentUser(db), apiHolder.setToCurrentUser(),
Results.SearchType.hashtags, Results.SearchType.hashtags,
query query
) )

View File

@ -43,7 +43,7 @@ class SearchPostsFragment : UncachedFeedFragment<Status>() {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
viewModel = ViewModelProvider(this, ViewModelFactory( viewModel = ViewModelProvider(this, ViewModelFactory(
SearchContentRepository<Status>( SearchContentRepository<Status>(
apiHolder.setDomainToCurrentUser(db), apiHolder.setToCurrentUser(),
Results.SearchType.statuses, Results.SearchType.statuses,
query query
) )

View File

@ -73,7 +73,7 @@ class ProfileActivity : BaseActivity() {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
viewModel = ViewModelProvider(this, ProfileViewModelFactory( viewModel = ViewModelProvider(this, ProfileViewModelFactory(
ProfileContentRepository( ProfileContentRepository(
apiHolder.setDomainToCurrentUser(db), apiHolder.setToCurrentUser(),
accountId accountId
) )
) )
@ -119,7 +119,7 @@ class ProfileActivity : BaseActivity() {
setViews(account) setViews(account)
} else { } else {
lifecycleScope.launchWhenResumed { lifecycleScope.launchWhenResumed {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
val myAccount: Account = try { val myAccount: Account = try {
api.verifyCredentials() api.verifyCredentials()
} catch (exception: IOException) { } catch (exception: IOException) {
@ -158,10 +158,9 @@ class ProfileActivity : BaseActivity() {
) )
binding.descriptionTextView.text = parseHTMLText( binding.descriptionTextView.text = parseHTMLText(
account.note ?: "", emptyList(), apiHolder, account.note ?: "", emptyList(), apiHolder,
applicationContext, applicationContext,
lifecycleScope, lifecycleScope
db
) )
val displayName = account.getDisplayName() val displayName = account.getDisplayName()
@ -232,7 +231,7 @@ class ProfileActivity : BaseActivity() {
// Get relationship between the two users (credential and this) and set followButton accordingly // Get relationship between the two users (credential and this) and set followButton accordingly
lifecycleScope.launch { lifecycleScope.launch {
try { try {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
val relationship = api.checkRelationships( val relationship = api.checkRelationships(
listOf(account.id.orEmpty()) listOf(account.id.orEmpty())
).firstOrNull() ).firstOrNull()
@ -266,7 +265,7 @@ class ProfileActivity : BaseActivity() {
setOnClickListener { setOnClickListener {
lifecycleScope.launchWhenResumed { lifecycleScope.launchWhenResumed {
try { try {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
val rel = api.follow(account.id.orEmpty()) val rel = api.follow(account.id.orEmpty())
if(rel.following == true) setOnClickUnfollow(account, rel.requested == true) if(rel.following == true) setOnClickUnfollow(account, rel.requested == true)
else setOnClickFollow(account) else setOnClickFollow(account)
@ -297,7 +296,7 @@ class ProfileActivity : BaseActivity() {
fun unfollow() { fun unfollow() {
lifecycleScope.launchWhenResumed { lifecycleScope.launchWhenResumed {
try { try {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
val rel = api.unfollow(account.id.orEmpty()) val rel = api.unfollow(account.id.orEmpty())
if(rel.following == false && rel.requested == false) setOnClickFollow(account) if(rel.following == false && rel.requested == false) setOnClickFollow(account)
else setOnClickUnfollow(account, rel.requested == true) else setOnClickUnfollow(account, rel.requested == true)

View File

@ -59,7 +59,7 @@ class SearchDiscoverFragment : BaseFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
api = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db) api = apiHolder.api ?: apiHolder.setToCurrentUser()
getDiscover() getDiscover()

View File

@ -67,7 +67,7 @@ class TokenAuthenticator(val user: UserDatabaseEntity, val db: AppDatabase, val
newAccessToken.refresh_token, newAccessToken.refresh_token,
user.user_id, user.instance_uri user.user_id, user.instance_uri
) )
apiHolder.setDomainToCurrentUser(db) apiHolder.setToCurrentUser()
} }
// Add new header to rejected request and retry it // Add new header to rejected request and retry it
@ -77,18 +77,17 @@ class TokenAuthenticator(val user: UserDatabaseEntity, val db: AppDatabase, val
} }
} }
class PixelfedAPIHolder(db: AppDatabase?){ class PixelfedAPIHolder(private val db: AppDatabase){
private val intermediate: Retrofit.Builder = Retrofit.Builder() private val intermediate: Retrofit.Builder = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
var api: PixelfedAPI? = var api: PixelfedAPI? =
db?.userDao()?.getActiveUser()?.let { db.userDao().getActiveUser()?.let {
setDomainToCurrentUser(db, it) setToCurrentUser(it)
} }
fun setDomainToCurrentUser( fun setToCurrentUser(
db: AppDatabase,
user: UserDatabaseEntity = db.userDao().getActiveUser()!! user: UserDatabaseEntity = db.userDao().getActiveUser()!!
): PixelfedAPI { ): PixelfedAPI {
val newAPI = intermediate val newAPI = intermediate

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.h.pixeldroid.postCreation.SquareLayout <com.h.pixeldroid.postCreation.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:foreground="?selectableItemBackground" android:foreground="?selectableItemBackground"

View File

@ -1,18 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.31' ext.kotlin_version = '1.4.32'
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
jcenter {
content {
// org.jetbrains.trove4j is only available in JCenter
//TODO remove JCenter repo:
// see issue https://gitlab.shinice.net/pixeldroid/PixelDroid/-/issues/278
includeGroup("org.jetbrains.trove4j")
}
}
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.3' classpath 'com.android.tools.build:gradle:4.1.3'
@ -34,11 +26,6 @@ allprojects {
//TODO remove JCenter repo: //TODO remove JCenter repo:
// see issue https://gitlab.shinice.net/pixeldroid/PixelDroid/-/issues/278 // see issue https://gitlab.shinice.net/pixeldroid/PixelDroid/-/issues/278
includeGroup("info.androidhive") includeGroup("info.androidhive")
// org.jetbrains.trove4j is only available in JCenter
//TODO remove JCenter repo:
// see issue https://gitlab.shinice.net/pixeldroid/PixelDroid/-/issues/278
includeGroup("org.jetbrains.trove4j")
} }
} }
} }

View File

@ -1,6 +1,6 @@
#Fri Aug 21 12:53:39 CEST 2020 #Tue Apr 20 12:38:34 CEST 2021
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip