Skip to content

Commit

Permalink
Merge pull request #284 from PermanentOrg/VSP-1415
Browse files Browse the repository at this point in the history
"Mailchip implementation" implementation and some refactoring.
  • Loading branch information
flaviahandrea-vsp authored Jul 12, 2024
2 parents 9b8d6e8 + 198ff2e commit 0e2867c
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package org.permanent.permanent.models

import android.os.Parcel
import android.os.Parcelable
import java.util.*
import java.util.Locale

enum class ArchiveType(val backendString: String) : Parcelable {
PERSON("type.archive.person"),
FAMILY("type.archive.family"),
FAMILY("type.archive.group"), // this was previously "type.archive.family"
ORGANIZATION("type.archive.organization"),
NONPROFIT("type.archive.nonprofit");

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/permanent/permanent/models/Tags.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.permanent.permanent.models

data class Tags(
val addTags: List<String>? = null,
val removeTags: List<String>? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.permanent.permanent.models.Record
import org.permanent.permanent.models.RecordType
import org.permanent.permanent.models.Share
import org.permanent.permanent.models.Tag
import org.permanent.permanent.models.Tags
import org.permanent.permanent.network.models.AccountVO
import org.permanent.permanent.network.models.ArchiveSteward
import org.permanent.permanent.network.models.FileData
Expand Down Expand Up @@ -61,6 +62,7 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {
private val authService: IAuthService
private lateinit var authServiceWithCookies: IAuthService
private val accountService: IAccountService
private val stelaAccountService: StelaAccountService
private val fileService: IFileService
private val shareService: IShareService
private val archiveService: IArchiveService
Expand Down Expand Up @@ -149,6 +151,7 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {
storageService = retrofit.create(IStorageService::class.java)
legacyPlanningService = retrofitStelaBaseUrl.create(ILegacyPlanningService::class.java)
billingService = retrofitStelaBaseUrl.create(IBillingService::class.java)
stelaAccountService = retrofitStelaBaseUrl.create(StelaAccountService::class.java)
jsonAdapter = Moshi.Builder().build().adapter(RequestContainer::class.java)
simpleJsonAdapter = Moshi.Builder().build().adapter(SimpleRequestContainer::class.java)
profileItemsJsonAdapter =
Expand Down Expand Up @@ -397,7 +400,7 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {

fun deleteFilesOrFolders(records: MutableList<Record>): Call<ResponseVO> {
val isFolderRecordType = records[0].type == RecordType.FOLDER
val request = toJson(RequestContainer().addRecords(records, isFolderRecordType))
val request = toJson(RequestContainer().addRecords(records, isFolderRecordType))
val requestBody: RequestBody = request.toRequestBody(jsonMediaType)
return if (isFolderRecordType) {
fileService.deleteFolder(requestBody)
Expand Down Expand Up @@ -758,6 +761,8 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {
return storageService.redeemGiftCode(requestBody)
}

fun addRemoveTags(tags: Tags): Call<ResponseVO> = stelaAccountService.addRemoveTags(tags)

fun getPaymentIntent(
accountId: Int,
accountEmail: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.permanent.permanent.network

import org.permanent.permanent.models.Tags
import org.permanent.permanent.network.models.ResponseVO
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.PUT

interface StelaAccountService {

@PUT("api/v2/account/tags")
fun addRemoveTags(@Body tags: Tags): Call<ResponseVO>
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AuthenticationRepositoryImpl(val application: Application) : IAuthenticati
prefsHelper.saveAuthToken(responseVO.getSimpleVO()?.value as String?)

val account = Account(responseVO.getAccountVO())
prefsHelper.saveAccountInfo(account.id, account.primaryEmail, account.fullName)
prefsHelper.saveAccountInfo(account.id, account.primaryEmail, password, account.fullName)
prefsHelper.saveDefaultArchiveId(account.defaultArchiveId)
listener.onSuccess()
} else {
Expand Down Expand Up @@ -165,7 +165,7 @@ class AuthenticationRepositoryImpl(val application: Application) : IAuthenticati
prefsHelper.saveAuthToken(responseVO.getAuthSimpleVO()?.value)
}
val account = Account(responseVO.getAccountVO())
prefsHelper.saveAccountInfo(account.id, account.primaryEmail, account.fullName)
prefsHelper.saveAccountInfo(account.id, account.primaryEmail, "", account.fullName)
prefsHelper.saveDefaultArchiveId(account.defaultArchiveId)
listener.onSuccess()
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.permanent.permanent.repositories

import org.permanent.permanent.models.Tags
import org.permanent.permanent.network.IResponseListener

interface StelaAccountRepository {

fun addRemoveTags(tags: Tags, listener: IResponseListener)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.permanent.permanent.repositories

import android.content.Context
import org.permanent.permanent.R
import org.permanent.permanent.models.Tags
import org.permanent.permanent.network.IResponseListener
import org.permanent.permanent.network.NetworkClient
import org.permanent.permanent.network.models.ResponseVO
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class StelaAccountRepositoryImpl(context: Context) : StelaAccountRepository {

private val appContext = context.applicationContext
override fun addRemoveTags(tags: Tags, listener: IResponseListener) {

NetworkClient.instance().addRemoveTags(tags).enqueue(object : Callback<ResponseVO> {

override fun onResponse(call: Call<ResponseVO>, response: Response<ResponseVO>) {
if (response.isSuccessful) {
val newLegacyContact = response.body()
if (newLegacyContact != null) {
listener.onSuccess("")
} else {
listener.onFailed(appContext.getString(R.string.generic_error))
}
} else {
try {
listener.onFailed(response.errorBody().toString())
} catch (e: Exception) {
listener.onFailed(e.message)
}
}
}

override fun onFailure(call: Call<ResponseVO>, t: Throwable) {
listener.onFailed(t.message)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const val PREFS_PUBLIC_RECORD_FOLDER_LINK_ID = "preferences_public_record_folder
const val PREFS_PUBLIC_RECORD_ARCHIVE_NR = "preferences_public_record_archive_nr"
const val PREFS_PUBLIC_RECORD_THUMB_URL_2000 = "preferences_public_record_thumb_url_2000"
const val PREFS_ACCOUNT_EMAIL = "preferences_user_email"
const val PREFS_ACCOUNT_PASSWORD = "preferences_user_password"
const val PREFS_ACCOUNT_NAME = "preferences_user_name"
const val PREFS_DEFAULT_ARCHIVE_ID = "preferences_default_archive_id"
const val PREFS_CURRENT_ARCHIVE_ID = "preferences_current_archive_id"
Expand Down Expand Up @@ -114,7 +115,7 @@ class PreferencesHelper(private val sharedPreferences: SharedPreferences) {
return sharedPreferences.getBoolean(IS_BIOMETRICS_LOG_IN, true)
}

fun saveAccountInfo(id: Int?, email: String?, name: String?) {
fun saveAccountInfo(id: Int?, email: String?, password: String?, name: String?) {
id?.let {
with(sharedPreferences.edit()) {
putInt(PREFS_ACCOUNT_ID, it)
Expand All @@ -127,6 +128,12 @@ class PreferencesHelper(private val sharedPreferences: SharedPreferences) {
apply()
}
}
password?.let {
with(sharedPreferences.edit()) {
putString(PREFS_ACCOUNT_PASSWORD, it)
apply()
}
}
name?.let {
with(sharedPreferences.edit()) {
putString(PREFS_ACCOUNT_NAME, it)
Expand All @@ -150,6 +157,10 @@ class PreferencesHelper(private val sharedPreferences: SharedPreferences) {
return sharedPreferences.getString(PREFS_ACCOUNT_EMAIL, "")
}

fun getAccountPassword(): String? {
return sharedPreferences.getString(PREFS_ACCOUNT_PASSWORD, "")
}

fun getAccountName(): String? {
return sharedPreferences.getString(PREFS_ACCOUNT_NAME, "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
Expand All @@ -46,6 +49,8 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import org.permanent.permanent.R
import org.permanent.permanent.models.ArchiveType
import org.permanent.permanent.ui.composeComponents.CustomProgressIndicator
Expand Down Expand Up @@ -85,6 +90,10 @@ fun ArchiveOnboardingScreen(
val isSecondProgressBarEmpty by viewModel.isSecondProgressBarEmpty.collectAsState()
val isThirdProgressBarEmpty by viewModel.isThirdProgressBarEmpty.collectAsState()
val isBusyState by viewModel.isBusyState.collectAsState()
val errorMessage by viewModel.showError.collectAsState()
val coroutineScope = rememberCoroutineScope()
val snackbarEventFlow = remember { MutableSharedFlow<String>() }
val snackbarHostState = remember { SnackbarHostState() }

val goals = rememberSaveable(saver = listSaver(save = {
it.map { goal ->
Expand Down Expand Up @@ -291,6 +300,20 @@ fun ArchiveOnboardingScreen(
}
}
}

LaunchedEffect(errorMessage) {
coroutineScope.launch {
snackbarHostState.showSnackbar(errorMessage)
}
}

LaunchedEffect(snackbarEventFlow) {
snackbarEventFlow.collect { message ->
snackbarHostState.showSnackbar(message)
}
}

SnackbarHost(hostState = snackbarHostState)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ data class OnboardingGoal(
)

enum class OnboardingGoalType {
CAPTURE, DIGITIZE, COLLABORATE, CREATE_AN_ARCHIVE, SHARE, CREATE_A_PLAN, ORGANIZE, SOMETHING_ELSE
CAPTURE, DIGITIZE, COLLABORATE, PUBLISH, SHARE, LEGACY, ORGANIZE, UNDEFINED
}

val OnboardingGoalSaver: Saver<OnboardingGoal, *> = listSaver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ data class OnboardingPriority(
)

enum class OnboardingPriorityType {
ACCESS, SUPPORTING, PRESERVING, PROFESSIONAL, COLLABORATE, INTEREST
SAFE, NONPROFIT, GENEALOGY, PROFESSIONAL, COLLABORATE, DIGIPRES
}

val OnboardingPrioritySaver: Saver<OnboardingPriority, *> = listSaver(
Expand Down
Loading

0 comments on commit 0e2867c

Please sign in to comment.