@@ -12,7 +12,6 @@ import android.os.Bundle
12
12
import android.view.View
13
13
import android.widget.AdapterView
14
14
import android.widget.ArrayAdapter
15
- import androidx.core.app.ActivityCompat.finishAffinity
16
15
import androidx.fragment.app.DialogFragment
17
16
import com.google.android.material.dialog.MaterialAlertDialogBuilder
18
17
import com.nextcloud.android.lib.resources.tos.GetTermsRemoteOperation
@@ -26,13 +25,11 @@ import com.nextcloud.utils.extensions.setHtmlContent
26
25
import com.owncloud.android.R
27
26
import com.owncloud.android.databinding.DialogShowTosBinding
28
27
import com.owncloud.android.lib.common.operations.RemoteOperationResult
29
- import com.owncloud.android.lib.common.utils.Log_OC
30
28
import com.owncloud.android.utils.DisplayUtils
31
29
import com.owncloud.android.utils.theme.ViewThemeUtils
32
30
import kotlinx.coroutines.CoroutineScope
33
31
import kotlinx.coroutines.Dispatchers
34
32
import kotlinx.coroutines.launch
35
- import kotlinx.coroutines.withContext
36
33
import javax.inject.Inject
37
34
38
35
class TermsOfServiceDialog : DialogFragment (), Injectable {
@@ -64,6 +61,11 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
64
61
}
65
62
66
63
private fun updateDialog () {
64
+ // viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
65
+ // binding.root.context,
66
+ // builder
67
+ // )
68
+
67
69
binding.message.setHtmlContent(terms[0 ].renderedBody)
68
70
69
71
val arrayAdapter: ArrayAdapter <String > = ArrayAdapter (
@@ -84,7 +86,9 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
84
86
.setHtmlContent(terms[position].renderedBody)
85
87
}
86
88
87
- override fun onNothingSelected (adapterView : AdapterView <* >? ) = Unit
89
+ override fun onNothingSelected (adapterView : AdapterView <* >? ) {
90
+ // nothing to do
91
+ }
88
92
}
89
93
90
94
if (terms.size == 1 ) {
@@ -93,7 +97,6 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
93
97
}
94
98
95
99
private fun fetchTerms () {
96
- // TODO use viewLifecycleOwner instead
97
100
CoroutineScope (Dispatchers .IO ).launch {
98
101
try {
99
102
client = clientFactory.createNextcloudClient(accountManager.getUser())
@@ -106,12 +109,12 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
106
109
languages = result.resultData.languages
107
110
terms = result.resultData.terms
108
111
109
- withContext (Dispatchers .Main ) {
112
+ CoroutineScope (Dispatchers .Main ).launch {
110
113
updateDialog()
111
114
}
112
115
}
113
116
} catch (exception: ClientFactory .CreationException ) {
114
- Log_OC .e( TAG , " Error creating client! " )
117
+ TODO ( " Add error handling here " )
115
118
}
116
119
}
117
120
}
@@ -120,10 +123,10 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
120
123
return MaterialAlertDialogBuilder (binding.root.context)
121
124
.setView(binding.root)
122
125
.setTitle(R .string.terms_of_service_title)
123
- .setNegativeButton(R .string.dialog_close) { _, _ ->
124
- activity?. let { finishAffinity(it) }
126
+ .setNegativeButton(R .string.dialog_close) { dialog, which ->
127
+ // TODO finishAffinity()
125
128
}
126
- .setPositiveButton(R .string.terms_of_services_agree) { dialog, _ ->
129
+ .setPositiveButton(R .string.terms_of_services_agree) { dialog, which ->
127
130
dialog.dismiss()
128
131
Thread {
129
132
val id = binding.languageDropdown.selectedItemPosition
@@ -136,7 +139,58 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
136
139
}
137
140
}
138
141
139
- companion object {
140
- private const val TAG = " TermsOfServiceDialog"
141
- }
142
+ // private void showTermsOfServiceDialog1()
143
+ // {
144
+
145
+ // runOnUiThread(Runnable {
146
+ // viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
147
+ // binding.root.context,
148
+ // builder
149
+ // )
150
+ // builder.create()
151
+ //
152
+ // binding.message.setHtmlContent(terms[0].renderedBody)
153
+ //
154
+ // val arrayAdapter: ArrayAdapter<String> = ArrayAdapter(
155
+ // binding.root.context,
156
+ // android.R.layout.simple_spinner_item
157
+ // )
158
+ //
159
+ // for ((_, _, languageCode) in terms) {
160
+ // arrayAdapter.add(languages[languageCode])
161
+ // }
162
+ //
163
+ // arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
164
+ //
165
+ //
166
+ // binding.languageDropdown.adapter = arrayAdapter
167
+ // binding.languageDropdown.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
168
+ // override fun onItemSelected(
169
+ // adapterView: AdapterView<*>?,
170
+ // view: View,
171
+ // position: Int,
172
+ // l: Long
173
+ // ) {
174
+ // binding.message
175
+ // .setHtmlContent(terms[position].renderedBody)
176
+ // }
177
+ //
178
+ // override fun onNothingSelected(adapterView: AdapterView<*>?) {
179
+ // // nothing to do
180
+ // }
181
+ // }
182
+ //
183
+ // if (terms.size == 1) {
184
+ // binding.languageDropdown.visibility = View.GONE
185
+ // }
186
+ // if (!tosIsShown) {
187
+ // tosIsShown = true
188
+ // builder.create().show()
189
+ // }
190
+ // })
191
+ // }
192
+ // } catch (e: CreationException) {
193
+ // showInfoBox(R.string.sign_tos_failed)
194
+ // }
195
+ // }.start()
142
196
}
0 commit comments