Added refresh button and control disabling.

This commit is contained in:
2021-01-05 11:18:55 +03:00
parent 6f4ef43481
commit 2e8cdd9e41
2 changed files with 28 additions and 2 deletions
@@ -61,15 +61,25 @@ public class MainActivity extends AppCompatActivity {
}
public void onSwitchClick(View view) {
System.out.println("### click: " + view);
System.out.println("### switch clicked: " + view);
new DownloadFilesTask(this).execute((SwitchMaterial) view);
}
public void onRefreshButtonClick(View view) {
System.out.println("### refresh clicked: " + view);
new DownloadFilesTask(this).execute();
}
private static class DownloadFilesTask extends AsyncTask<SwitchMaterial, Void, List<String>> {
private MainActivity context;
public DownloadFilesTask(MainActivity context) {
context.findViewById(R.id.switchTab).setEnabled(false);
context.findViewById(R.id.switchTv).setEnabled(false);
context.findViewById(R.id.switchAlisa).setEnabled(false);
context.findViewById(R.id.button_refresh).setEnabled(false);
this.context = context;
}
@@ -77,7 +87,7 @@ public class MainActivity extends AppCompatActivity {
protected List<String> doInBackground(SwitchMaterial... switches) {
List<String> result = new ArrayList<>();
Socket s = null;
Socket s;
try {
s = new Socket(InetAddress.getByName("192.168.100.1"), 23);
@@ -175,6 +185,11 @@ public class MainActivity extends AppCompatActivity {
switchAlisa.setChecked(false);
}
context.findViewById(R.id.switchTab).setEnabled(true);
context.findViewById(R.id.switchTv).setEnabled(true);
context.findViewById(R.id.switchAlisa).setEnabled(true);
context.findViewById(R.id.button_refresh).setEnabled(true);
Toast.makeText(context, "Статус обновлён!", Toast.LENGTH_LONG).show();
}
+11
View File
@@ -9,10 +9,19 @@
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="@+id/button_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onRefreshButtonClick"
android:text="Обновить" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switchTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onSwitchClick"
android:text="Tab"
app:useMaterialThemeColors="true" />
@@ -21,6 +30,7 @@
android:id="@+id/switchTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onSwitchClick"
android:text="TV"
app:useMaterialThemeColors="true" />
@@ -29,6 +39,7 @@
android:id="@+id/switchAlisa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:onClick="onSwitchClick"
android:text="Alisa"
app:useMaterialThemeColors="true" />