@@ -13,6 +13,7 @@ import java.util.List;
|
||||
public class ApplicationHolder {
|
||||
private List<Application> state;
|
||||
private Runnable onUpdate;
|
||||
private Runnable onUpdateFailed;
|
||||
private Activity activity;
|
||||
private ApiClient client;
|
||||
|
||||
@@ -35,11 +36,12 @@ public class ApplicationHolder {
|
||||
|
||||
private void onReceiveApps(List<Application> apps) {
|
||||
state = apps;
|
||||
onUpdate.run();
|
||||
if (onUpdate != null) onUpdate.run();
|
||||
}
|
||||
|
||||
private void onFailedApps(ApiException e) {
|
||||
Utils.showSnackBar(activity, "Could not request applications, see logs.");
|
||||
if (onUpdateFailed != null) onUpdateFailed.run();
|
||||
}
|
||||
|
||||
public List<Application> get() {
|
||||
@@ -49,4 +51,8 @@ public class ApplicationHolder {
|
||||
public void onUpdate(Runnable runnable) {
|
||||
this.onUpdate = runnable;
|
||||
}
|
||||
|
||||
public void onUpdateFailed(Runnable runnable) {
|
||||
this.onUpdateFailed = runnable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
@@ -46,6 +48,12 @@ public class ShareActivity extends AppCompatActivity {
|
||||
@BindView(R.id.appSpinner)
|
||||
Spinner appSpinner;
|
||||
|
||||
@BindView(R.id.push_button)
|
||||
Button pushMessageButton;
|
||||
|
||||
@BindView(R.id.missingAppsContainer)
|
||||
LinearLayout missingAppsInfo;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -73,7 +81,16 @@ public class ShareActivity extends AppCompatActivity {
|
||||
ApiClient client =
|
||||
ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token());
|
||||
appsHolder = new ApplicationHolder(this, client);
|
||||
appsHolder.onUpdate(() -> populateSpinner(appsHolder.get()));
|
||||
appsHolder.onUpdate(
|
||||
() -> {
|
||||
List<Application> apps = appsHolder.get();
|
||||
populateSpinner(apps);
|
||||
|
||||
boolean appsAvailable = !apps.isEmpty();
|
||||
pushMessageButton.setEnabled(appsAvailable);
|
||||
missingAppsInfo.setVisibility(appsAvailable ? View.GONE : View.VISIBLE);
|
||||
});
|
||||
appsHolder.onUpdateFailed(() -> pushMessageButton.setEnabled(false));
|
||||
appsHolder.request();
|
||||
}
|
||||
|
||||
@@ -98,6 +115,11 @@ public class ShareActivity extends AppCompatActivity {
|
||||
} else if (priority.isEmpty()) {
|
||||
Toast.makeText(this, "Priority should be number.", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
} else if (appIndex == Spinner.INVALID_POSITION) {
|
||||
// For safety, e.g. loading the apps needs too much time (maybe a timeout) and
|
||||
// the user tries to push without an app selected.
|
||||
Toast.makeText(this, "An app must be selected.", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Message message = new Message();
|
||||
|
||||
9
app/src/main/res/drawable/ic_info.xml
Normal file
9
app/src/main/res/drawable/ic_info.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/icons"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
|
||||
</vector>
|
||||
@@ -1,7 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
@@ -81,12 +87,48 @@
|
||||
android:textSize="18sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/missingAppsContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/missingAppsIcon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
app:srcCompat="@drawable/ic_info" />
|
||||
|
||||
<Space
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/missingAppsText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/push_missing_app_info"
|
||||
android:textAlignment="center"
|
||||
android:visibility="visible" />
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/push_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|center_horizontal"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:text="@string/push_button" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@@ -81,5 +81,6 @@
|
||||
<string name="push_title_hint">Title</string>
|
||||
<string name="push_content_hint">Content</string>
|
||||
<string name="push_priority_hint">Priority</string>
|
||||
<string name="push_missing_app_info">There are no applications available on the server to push a message to.</string>
|
||||
<string name="message_copied_to_clipboard">Content copied to clipboard</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user