This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3247 from vector-im/feature/im_3225
Handle Terms and condition approval for integration manager
- Loading branch information
Showing
24 changed files
with
949 additions
and
29 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
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
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
56 changes: 56 additions & 0 deletions
56
vector/src/main/java/im/vector/activity/ReviewTermsActivity.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,56 @@ | ||
/* | ||
* Copyright 2019 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package im.vector.activity | ||
|
||
import android.arch.lifecycle.ViewModelProviders | ||
import android.content.Context | ||
import android.content.Intent | ||
import im.vector.R | ||
import im.vector.fragments.terms.AcceptTermsFragment | ||
import im.vector.fragments.terms.AcceptTermsViewModel | ||
import im.vector.fragments.terms.ServiceTermsArgs | ||
import org.matrix.androidsdk.features.terms.TermsManager | ||
|
||
|
||
class ReviewTermsActivity : SimpleFragmentActivity() { | ||
|
||
override fun initUiAndData() { | ||
super.initUiAndData() | ||
if (supportFragmentManager.fragments.isEmpty()) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.container, AcceptTermsFragment.newInstance()) | ||
.commitNow() | ||
} | ||
|
||
val viewModel = ViewModelProviders.of(this).get(AcceptTermsViewModel::class.java) | ||
viewModel.termsArgs = intent.getParcelableExtra(EXTRA_INFO) | ||
|
||
mSession = getSession(intent) | ||
|
||
viewModel.initSession(session) | ||
} | ||
|
||
companion object { | ||
|
||
private const val EXTRA_INFO = "EXTRA_INFO" | ||
|
||
fun intent(context: Context, serviceType: TermsManager.ServiceType, baseUrl: String, token: String?): Intent { | ||
return Intent(context, ReviewTermsActivity::class.java).also { | ||
it.putExtra(EXTRA_INFO, ServiceTermsArgs(serviceType, baseUrl, token)) | ||
} | ||
} | ||
} | ||
} |
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
149 changes: 149 additions & 0 deletions
149
vector/src/main/java/im/vector/fragments/terms/AcceptTermsFragment.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,149 @@ | ||
/* | ||
* Copyright 2019 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package im.vector.fragments.terms | ||
|
||
import android.app.Activity | ||
import android.arch.lifecycle.Observer | ||
import android.arch.lifecycle.ViewModelProviders | ||
import android.os.Bundle | ||
import android.support.v7.app.AlertDialog | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.ProgressBar | ||
import androidx.core.view.isVisible | ||
import butterknife.BindView | ||
import butterknife.OnClick | ||
import com.airbnb.epoxy.EpoxyRecyclerView | ||
import im.vector.R | ||
import im.vector.fragments.VectorBaseFragment | ||
import im.vector.util.openUrlInExternalBrowser | ||
import im.vector.util.state.MxAsync | ||
import org.matrix.androidsdk.features.terms.TermsManager | ||
|
||
class AcceptTermsFragment : VectorBaseFragment(), TermsController.Listener { | ||
|
||
|
||
lateinit var viewModel: AcceptTermsViewModel | ||
|
||
override fun getLayoutResId(): Int = R.layout.fragment_accept_terms | ||
|
||
private lateinit var termsController: TermsController | ||
|
||
@BindView(R.id.terms_recycler_view) | ||
lateinit var termsList: EpoxyRecyclerView | ||
|
||
@BindView(R.id.terms_bottom_accept) | ||
lateinit var acceptButton: Button | ||
|
||
@BindView(R.id.termsLoadingIndicator) | ||
lateinit var progressBar: ProgressBar | ||
|
||
@BindView(R.id.termsBottomBar) | ||
lateinit var bottomBar: ViewGroup | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
|
||
viewModel = ViewModelProviders.of(requireActivity()).get(AcceptTermsViewModel::class.java) | ||
|
||
val description = when (viewModel.termsArgs.type) { | ||
TermsManager.ServiceType.IdentityService -> getString(R.string.terms_description_for_identity_server) | ||
TermsManager.ServiceType.IntegrationManager -> getString(R.string.terms_description_for_integration_manager) | ||
} | ||
|
||
termsController = TermsController(description, this) | ||
termsList.setController(termsController) | ||
|
||
viewModel.loadTerms(getString(R.string.resources_language)) | ||
|
||
viewModel.termsList.observe(this, Observer { terms -> | ||
when (terms) { | ||
is MxAsync.Loading -> { | ||
bottomBar.isVisible = false | ||
progressBar.isVisible = true | ||
} | ||
is MxAsync.Error -> { | ||
progressBar.isVisible = false | ||
terms.stringResId.let { stringRes -> | ||
AlertDialog.Builder(requireActivity()) | ||
.setMessage(stringRes) | ||
.setPositiveButton(R.string.ok) { dialog, which -> | ||
activity?.finish() | ||
} | ||
.show() | ||
} | ||
} | ||
is MxAsync.Success -> { | ||
updateState(terms.value) | ||
progressBar.isVisible = false | ||
bottomBar.isVisible = true | ||
acceptButton.isEnabled = terms.value.all { it.accepted } | ||
} | ||
} | ||
}) | ||
|
||
viewModel.acceptTerms.observe(this, Observer { request -> | ||
when (request) { | ||
is MxAsync.Loading -> { | ||
progressBar.isVisible = true | ||
} | ||
is MxAsync.Error -> { | ||
progressBar.isVisible = false | ||
request.stringResId.let { stringRes -> | ||
AlertDialog.Builder(requireActivity()) | ||
.setMessage(stringRes) | ||
.setPositiveButton(R.string.ok, null) | ||
.show() | ||
} | ||
} | ||
is MxAsync.Success -> { | ||
activity?.setResult(Activity.RESULT_OK) | ||
activity?.finish() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
private fun updateState(terms: List<Term>) { | ||
termsController.setData(terms) | ||
} | ||
|
||
companion object { | ||
fun newInstance(): AcceptTermsFragment { | ||
return AcceptTermsFragment() | ||
} | ||
} | ||
|
||
|
||
override fun setChecked(term: Term, isChecked: Boolean) { | ||
viewModel.markTermAsAccepted(term.url, isChecked) | ||
} | ||
|
||
override fun review(term: Term) { | ||
openUrlInExternalBrowser(this.requireContext(), term.url) | ||
} | ||
|
||
@OnClick(R.id.terms_bottom_accept) | ||
fun onAcceptButton() { | ||
viewModel.acceptTerms() | ||
} | ||
|
||
|
||
@OnClick(R.id.terms_bottom_decline) | ||
fun onDeclineButton() { | ||
activity?.finish() | ||
} | ||
} |
Oops, something went wrong.