Skip to content

Commit b7e8657

Browse files
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent a76e728 commit b7e8657

3 files changed

Lines changed: 149 additions & 95 deletions

File tree

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

Lines changed: 4 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,10 @@
4343
import android.view.View;
4444
import android.view.ViewTreeObserver;
4545
import android.view.WindowManager;
46-
import android.widget.AdapterView;
47-
import android.widget.ArrayAdapter;
4846

4947
import com.google.android.material.appbar.AppBarLayout;
5048
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
5149
import com.google.android.material.snackbar.Snackbar;
52-
import com.nextcloud.android.lib.resources.tos.GetTermsRemoteOperation;
53-
import com.nextcloud.android.lib.resources.tos.SignTermRemoteOperation;
54-
import com.nextcloud.android.lib.resources.tos.Term;
55-
import com.nextcloud.android.lib.resources.tos.Terms;
5650
import com.nextcloud.appReview.InAppReviewHelper;
5751
import com.nextcloud.client.account.User;
5852
import com.nextcloud.client.appinfo.AppInfo;
@@ -69,20 +63,17 @@
6963
import com.nextcloud.client.network.ClientFactory;
7064
import com.nextcloud.client.preferences.AppPreferences;
7165
import com.nextcloud.client.utils.IntentUtil;
72-
import com.nextcloud.common.NextcloudClient;
7366
import com.nextcloud.model.WorkerState;
7467
import com.nextcloud.model.WorkerStateLiveData;
7568
import com.nextcloud.utils.BuildHelper;
7669
import com.nextcloud.utils.extensions.ActivityExtensionsKt;
7770
import com.nextcloud.utils.extensions.BundleExtensionsKt;
7871
import com.nextcloud.utils.extensions.FileExtensionsKt;
7972
import com.nextcloud.utils.extensions.IntentExtensionsKt;
80-
import com.nextcloud.utils.extensions.TextViewExtensionsKt;
8173
import com.nextcloud.utils.fileNameValidator.FileNameValidator;
8274
import com.nextcloud.utils.view.FastScrollUtils;
8375
import com.owncloud.android.MainApp;
8476
import com.owncloud.android.R;
85-
import com.owncloud.android.databinding.DialogShowTosBinding;
8677
import com.owncloud.android.databinding.FilesBinding;
8778
import com.owncloud.android.datamodel.FileDataStorageManager;
8879
import com.owncloud.android.datamodel.MediaFolderType;
@@ -117,6 +108,7 @@
117108
import com.owncloud.android.ui.dialog.SendShareDialog;
118109
import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
119110
import com.owncloud.android.ui.dialog.StoragePermissionDialogFragment;
111+
import com.owncloud.android.ui.dialog.TermsOfServiceDialog;
120112
import com.owncloud.android.ui.events.SearchEvent;
121113
import com.owncloud.android.ui.events.SyncEventFinished;
122114
import com.owncloud.android.ui.events.TokenPushEvent;
@@ -157,7 +149,6 @@
157149
import java.util.ArrayList;
158150
import java.util.Collection;
159151
import java.util.List;
160-
import java.util.Map;
161152
import java.util.Optional;
162153

163154
import javax.inject.Inject;
@@ -1448,7 +1439,7 @@ public void onReceive(Context context, Intent intent) {
14481439
break;
14491440

14501441
case SIGNING_TOS_NEEDED:
1451-
showDialog();
1442+
showTermsOfServiceDialog();
14521443

14531444
break;
14541445

@@ -1495,90 +1486,8 @@ public void onReceive(Context context, Intent intent) {
14951486
}
14961487
}
14971488
}
1498-
1499-
private void showDialog() {
1500-
new Thread(() -> {
1501-
try {
1502-
NextcloudClient client =
1503-
clientFactory.createNextcloudClient(accountManager.getUser());
1504-
RemoteOperationResult<Terms> result = new GetTermsRemoteOperation()
1505-
.execute(client);
1506-
1507-
if (result.isSuccess() &&
1508-
!result.getResultData().getHasSigned() &&
1509-
!result.getResultData().getTerms().isEmpty()) {
1510-
Map<String, String> languages = result.getResultData().getLanguages();
1511-
List<Term> terms = result.getResultData().getTerms();
1512-
1513-
runOnUiThread(() -> {
1514-
DialogShowTosBinding binding = DialogShowTosBinding.inflate(getLayoutInflater());
1515-
MaterialAlertDialogBuilder builder =
1516-
// custom XML
1517-
new MaterialAlertDialogBuilder(binding.getRoot().getContext())
1518-
.setView(binding.getRoot())
1519-
.setTitle(R.string.terms_of_service_title)
1520-
.setNegativeButton(R.string.dialog_close, (dialog, which) -> {
1521-
finishAffinity();
1522-
})
1523-
.setPositiveButton(R.string.terms_of_services_agree, (dialog, which) -> {
1524-
dialog.dismiss();
1525-
1526-
new Thread(() -> {
1527-
int id = binding.languageDropdown.getSelectedItemPosition();
1528-
RemoteOperationResult<Void> signResult = new SignTermRemoteOperation(terms.get(id).getId()).execute(client);
1529-
if (signResult.isSuccess()) {
1530-
tosIsShown = false;
1531-
} else {
1532-
runOnUiThread(() -> showInfoBox(R.string.sign_tos_failed));
1533-
}
1534-
}).start();
1535-
});
1536-
1537-
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.getRoot().getContext(),
1538-
builder);
1539-
1540-
builder.create();
1541-
1542-
TextViewExtensionsKt.setHtmlContent(binding.message, terms.get(0).getRenderedBody());
1543-
1544-
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(binding.getRoot().getContext(),
1545-
android.R.layout.simple_spinner_item);
1546-
1547-
for (Term term: terms) {
1548-
arrayAdapter.add(languages.get(term.getLanguageCode()));
1549-
}
1550-
1551-
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
1552-
1553-
1554-
binding.languageDropdown.setAdapter(arrayAdapter);
1555-
binding.languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
1556-
@Override
1557-
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
1558-
TextViewExtensionsKt.setHtmlContent(binding.message,
1559-
terms.get(position).getRenderedBody());
1560-
}
1561-
1562-
@Override
1563-
public void onNothingSelected(AdapterView<?> adapterView) {
1564-
// nothing to do
1565-
}
1566-
});
1567-
1568-
if (terms.size() == 1) {
1569-
binding.languageDropdown.setVisibility(View.GONE);
1570-
}
1571-
1572-
if (!tosIsShown) {
1573-
tosIsShown = true;
1574-
builder.create().show();
1575-
}
1576-
});
1577-
}
1578-
} catch (ClientFactory.CreationException e) {
1579-
showInfoBox(R.string.sign_tos_failed);
1580-
}
1581-
}).start();
1489+
private void showTermsOfServiceDialog() {
1490+
new TermsOfServiceDialog().show(getSupportFragmentManager(), "tos");
15821491
}
15831492

15841493
private boolean checkForRemoteOperationError(RemoteOperationResult syncResult) {
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.owncloud.android.ui.dialog
9+
10+
import android.app.Dialog
11+
import android.os.Bundle
12+
import androidx.fragment.app.DialogFragment
13+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
14+
import com.nextcloud.android.lib.resources.tos.GetTermsRemoteOperation
15+
import com.nextcloud.client.account.UserAccountManager
16+
import com.nextcloud.client.di.Injectable
17+
import com.nextcloud.client.network.ClientFactory
18+
import com.nextcloud.common.NextcloudClient
19+
import com.owncloud.android.R
20+
import com.owncloud.android.databinding.DialogShowTosBinding
21+
import javax.inject.Inject
22+
23+
class TermsOfServiceDialog : DialogFragment(), Injectable {
24+
private lateinit var binding: DialogShowTosBinding
25+
26+
@Inject
27+
lateinit var clientFactory: ClientFactory
28+
29+
@Inject
30+
lateinit var accountManager: UserAccountManager
31+
32+
override fun onCreate(savedInstanceState: Bundle?) {
33+
super.onCreate(savedInstanceState)
34+
35+
fetchTerms()
36+
}
37+
38+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
39+
binding = DialogShowTosBinding.inflate(requireActivity().layoutInflater)
40+
41+
val builder = createDialogBuilder()
42+
43+
return builder.create()
44+
}
45+
46+
private fun fetchTerms() {
47+
try {
48+
val client: NextcloudClient =
49+
clientFactory.createNextcloudClient(accountManager.getUser())
50+
val result = GetTermsRemoteOperation().execute(client)
51+
52+
if (result.isSuccess &&
53+
!result.resultData.hasSigned &&
54+
result.resultData.terms.isNotEmpty()
55+
) {
56+
val languages = result.resultData.languages
57+
val terms = result.resultData.terms
58+
}
59+
} catch (exception: ClientFactory.CreationException) {
60+
TODO("Add error handling here")
61+
}
62+
}
63+
64+
private fun createDialogBuilder(): MaterialAlertDialogBuilder {
65+
return MaterialAlertDialogBuilder(binding.root.context)
66+
.setView(binding.root)
67+
.setTitle(R.string.terms_of_service_title)
68+
.setNegativeButton(R.string.dialog_close) { dialog, which ->
69+
// TODO finishAffinity()
70+
}
71+
.setPositiveButton(R.string.terms_of_services_agree) { dialog, which ->
72+
dialog.dismiss()
73+
// Thread {
74+
// val id = binding.languageDropdown.selectedItemPosition
75+
// val signResult: RemoteOperationResult<Void> =
76+
// SignTermRemoteOperation(terms.get(id).id).execute(client)
77+
// if (signResult.isSuccess) {
78+
// tosIsShown = false
79+
// } else {
80+
// runOnUiThread(Runnable { showInfoBox(R.string.sign_tos_failed) })
81+
// }
82+
// }.start()
83+
}
84+
}
85+
86+
// private void showTermsOfServiceDialog1()
87+
// {
88+
89+
// runOnUiThread(Runnable {
90+
// viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
91+
// binding.root.context,
92+
// builder
93+
// )
94+
// builder.create()
95+
//
96+
// binding.message.setHtmlContent(terms[0].renderedBody)
97+
//
98+
// val arrayAdapter: ArrayAdapter<String> = ArrayAdapter(
99+
// binding.root.context,
100+
// android.R.layout.simple_spinner_item
101+
// )
102+
//
103+
// for ((_, _, languageCode) in terms) {
104+
// arrayAdapter.add(languages[languageCode])
105+
// }
106+
//
107+
// arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
108+
//
109+
//
110+
// binding.languageDropdown.adapter = arrayAdapter
111+
// binding.languageDropdown.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
112+
// override fun onItemSelected(
113+
// adapterView: AdapterView<*>?,
114+
// view: View,
115+
// position: Int,
116+
// l: Long
117+
// ) {
118+
// binding.message
119+
// .setHtmlContent(terms[position].renderedBody)
120+
// }
121+
//
122+
// override fun onNothingSelected(adapterView: AdapterView<*>?) {
123+
// // nothing to do
124+
// }
125+
// }
126+
//
127+
// if (terms.size == 1) {
128+
// binding.languageDropdown.visibility = View.GONE
129+
// }
130+
// if (!tosIsShown) {
131+
// tosIsShown = true
132+
// builder.create().show()
133+
// }
134+
// })
135+
// }
136+
// } catch (e: CreationException) {
137+
// showInfoBox(R.string.sign_tos_failed)
138+
// }
139+
// }.start()
140+
}

settings.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ include ':appscan'
2020
// substitute module('com.github.nextcloud:android-library') using project(':library')
2121
// }
2222
//}
23+
includeBuild('../android-library') {
24+
dependencySubstitution {
25+
substitute module('com.github.nextcloud:android-library') using project(':library')
26+
}
27+
}

0 commit comments

Comments
 (0)