-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: #183 - Data sharing UI and data agreement policy
- Loading branch information
1 parent
7fe1674
commit c7911bf
Showing
30 changed files
with
1,592 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
PrivacyDashboard/src/main/java/com/github/privacyDashboard/DataSharingUI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package com.github.privacyDashboard | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.github.privacyDashboard.modules.dataSharing.BBConsentDataSharingActivity | ||
import com.github.privacyDashboard.modules.home.BBConsentDashboardActivity | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ACCESS_TOKEN | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_BASE_URL | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_DATA_AGREEMENT_ID | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_ASK_ME | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_ATTRIBUTE_LEVEL_CONSENT | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ENABLE_USER_REQUEST | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_ORG_ID | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_TOKEN | ||
import com.github.privacyDashboard.utils.BBConsentDataUtils.EXTRA_TAG_USERID | ||
import com.github.privacyDashboard.utils.BBConsentLocaleHelper | ||
|
||
object DataSharingUI { | ||
|
||
private var mUserId: String? = null | ||
private var mApiKey: String? = null | ||
private var mAccessToken: String? = null | ||
private var mDataAgreementId: String? = null | ||
private var mBaseUrl: String? = "" | ||
private var mLocale: String? = "" | ||
|
||
private var mDataSharingUIIntent: Intent? = null | ||
|
||
fun showDataSharingUI(): DataSharingUI { | ||
mDataSharingUIIntent = Intent() | ||
return this | ||
} | ||
|
||
/** | ||
* Set user id for igrant sdk. | ||
* | ||
* @param userId | ||
*/ | ||
fun withUserId(userId: String?): DataSharingUI { | ||
this.mUserId = if (userId == "") null else userId | ||
return this | ||
} | ||
|
||
/** | ||
* Set Api key for the iGrant Sdk. | ||
* | ||
* @param apiKey | ||
*/ | ||
fun withApiKey(apiKey: String?): DataSharingUI { | ||
this.mApiKey = if (apiKey == "") null else apiKey | ||
return this | ||
} | ||
|
||
/** | ||
* Set Access token for the iGrant Sdk. | ||
* | ||
* @param accessToken | ||
*/ | ||
fun withAccessToken(accessToken: String?): DataSharingUI { | ||
this.mAccessToken = if (accessToken == "") null else accessToken | ||
return this | ||
} | ||
|
||
/** | ||
* Set data agreement id id for the iGrant Sdk. | ||
* | ||
* @param dataAgreementId | ||
*/ | ||
fun withDataAgreementId(dataAgreementId: String?): DataSharingUI { | ||
this.mDataAgreementId = dataAgreementId | ||
return this | ||
} | ||
|
||
/** | ||
* Set base url for the iGrant Sdk. | ||
* | ||
* @param baseUrl | ||
*/ | ||
fun withBaseUrl(baseUrl: String?): DataSharingUI { | ||
this.mBaseUrl = baseUrl | ||
return this | ||
} | ||
|
||
/** | ||
* Set other application details for the iGrant Sdk. | ||
* | ||
* @param applicationName | ||
* @param logoUrl | ||
*/ | ||
fun withOtherApplication(applicationName: String?, logoUrl: String?): DataSharingUI { | ||
mDataSharingUIIntent?.putExtra( | ||
BBConsentDataSharingActivity.TAG_EXTRA_OTHER_APPLICATION_NAME, | ||
applicationName | ||
) | ||
mDataSharingUIIntent?.putExtra( | ||
BBConsentDataSharingActivity.TAG_EXTRA_OTHER_APPLICATION_LOGO, | ||
logoUrl | ||
) | ||
return this | ||
} | ||
|
||
/** | ||
* Set secondaryButtonText for the iGrant Sdk. | ||
* | ||
* @param text | ||
*/ | ||
fun secondaryButtonText(text: String?): DataSharingUI { | ||
mDataSharingUIIntent?.putExtra( | ||
BBConsentDataSharingActivity.TAG_EXTRA_SECONDARY_BUTTON_TEXT, | ||
text | ||
) | ||
return this | ||
} | ||
|
||
/** | ||
* Set Language code for the iGrant Sdk. | ||
* | ||
* @param languageCode | ||
*/ | ||
fun withLocale(languageCode: String): DataSharingUI { | ||
this.mLocale = languageCode | ||
return this | ||
} | ||
|
||
/** | ||
* Send the Intent from an Activity | ||
* | ||
* @param activity Activity to start activity | ||
*/ | ||
fun get(activity: Activity): Intent? { | ||
if (mAccessToken != null || (mApiKey != null && mUserId != null)) | ||
if (mDataAgreementId != null) { | ||
return getIntent(activity) | ||
} | ||
|
||
return null | ||
} | ||
|
||
/** | ||
* Send the Intent from an Activity with a custom request code | ||
* | ||
* @param context Context to start activity | ||
*/ | ||
fun get(context: Context): Intent? { | ||
if (mAccessToken != null || (mApiKey != null && mUserId != null)) | ||
if (mDataAgreementId != null) { | ||
return getIntent(context) | ||
} | ||
|
||
return null | ||
} | ||
|
||
/** | ||
* Get Intent to start [BBConsentDashboardActivity] | ||
* | ||
* @return Intent for [BBConsentDashboardActivity] | ||
*/ | ||
private fun getIntent(context: Context): Intent? { | ||
mDataSharingUIIntent?.setClass(context, BBConsentDataSharingActivity::class.java) | ||
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_BASE_URL, this.mBaseUrl) | ||
BBConsentDataUtils.saveStringValues( | ||
context, | ||
EXTRA_TAG_DATA_AGREEMENT_ID, | ||
this.mDataAgreementId | ||
) | ||
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_USERID, this.mUserId) | ||
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_TOKEN, this.mApiKey) | ||
BBConsentDataUtils.saveStringValues(context, EXTRA_TAG_ACCESS_TOKEN, this.mAccessToken) | ||
BBConsentLocaleHelper.setLocale(context, mLocale ?: "en") | ||
return mDataSharingUIIntent | ||
} | ||
|
||
fun setLocale(context: Context, languageCode: String) { | ||
BBConsentLocaleHelper.setLocale(context, languageCode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...a/com/github/privacyDashboard/communication/repositories/GetDataAgreementApiRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.privacyDashboard.communication.repositories | ||
|
||
import com.github.privacyDashboard.communication.BBConsentAPIServices | ||
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementResponseV2 | ||
import com.github.privacyDashboard.models.v2.dataAgreement.DataAgreementsResponseV2 | ||
|
||
class GetDataAgreementApiRepository(private val apiService: BBConsentAPIServices) { | ||
|
||
suspend fun getDataAgreement( | ||
userId: String?, | ||
dataAgreementId: String? | ||
): Result<DataAgreementResponseV2?> { | ||
return try { | ||
val dataAgreementRecord = apiService.getDataAgreementV2(userId, dataAgreementId) | ||
|
||
if (dataAgreementRecord?.isSuccessful == true) { | ||
val data = dataAgreementRecord.body() | ||
if (data != null) { | ||
Result.success(data) | ||
} else { | ||
Result.failure(Exception("Response body is null")) | ||
} | ||
} else { | ||
Result.failure(Exception("Request failed with code: ${dataAgreementRecord?.code()}")) | ||
} | ||
} catch (e: Exception) { | ||
Result.failure(e) | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...github/privacyDashboard/communication/repositories/GetDataAgreementRecordApiRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.privacyDashboard.communication.repositories | ||
|
||
import com.github.privacyDashboard.communication.BBConsentAPIServices | ||
import com.github.privacyDashboard.models.v2.consent.ConsentStatusRequestV2 | ||
import com.github.privacyDashboard.models.v2.dataAgreement.dataAgreementRecords.DataAgreementLatestRecordResponseV2 | ||
import retrofit2.Response | ||
|
||
class GetDataAgreementRecordApiRepository(private val apiService: BBConsentAPIServices) { | ||
|
||
suspend fun getDataAgreementRecord( | ||
userId: String?, | ||
dataAgreementId: String? | ||
): Result<DataAgreementLatestRecordResponseV2?> { | ||
return try { | ||
val dataAgreementRecord = apiService.getDataAgreementRecordV2(userId, dataAgreementId) | ||
|
||
if (dataAgreementRecord?.isSuccessful == true) { | ||
val data = dataAgreementRecord.body() | ||
if (data != null) { | ||
Result.success(data) | ||
} else { | ||
Result.failure(Exception("Response body is null")) | ||
} | ||
} else { | ||
Result.failure(Exception("Request failed with code: ${dataAgreementRecord?.code()}")) | ||
} | ||
} catch (e: Exception) { | ||
Result.failure(e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
PrivacyDashboard/src/main/java/com/github/privacyDashboard/models/DataAgreementPolicyList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.github.privacyDashboard.models | ||
|
||
class DataAgreementPolicyList : ArrayList<ArrayList<DataAgreementPolicyModel>>() { | ||
} |
10 changes: 10 additions & 0 deletions
10
...acyDashboard/src/main/java/com/github/privacyDashboard/models/DataAgreementPolicyModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.privacyDashboard.models | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class DataAgreementPolicyModel( | ||
@SerializedName("name") | ||
var name: String? = null, | ||
@SerializedName("value") | ||
var value: String? = null | ||
) |
9 changes: 4 additions & 5 deletions
9
.../main/java/com/github/privacyDashboard/models/v2/dataAgreement/DataAgreementResponseV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package com.github.privacyDashboard.models.v2.dataAgreement | ||
|
||
import com.github.privacyDashboard.models.v2.PaginationV2 | ||
import com.google.gson.annotations.SerializedName | ||
|
||
class DataAgreementResponseV2( | ||
@SerializedName("dataAgreements") var dataAgreements: ArrayList<DataAgreementV2> = arrayListOf(), | ||
@SerializedName("pagination") var pagination: PaginationV2? = PaginationV2() | ||
) | ||
class DataAgreementResponseV2 { | ||
@SerializedName("dataAgreement") | ||
var dataAgreement: DataAgreementV2? = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...main/java/com/github/privacyDashboard/models/v2/dataAgreement/DataAgreementsResponseV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.github.privacyDashboard.models.v2.dataAgreement | ||
|
||
import com.github.privacyDashboard.models.v2.PaginationV2 | ||
import com.google.gson.annotations.SerializedName | ||
|
||
class DataAgreementsResponseV2( | ||
@SerializedName("dataAgreements") var dataAgreements: ArrayList<DataAgreementV2> = arrayListOf(), | ||
@SerializedName("pagination") var pagination: PaginationV2? = PaginationV2() | ||
) |
Oops, something went wrong.