diff --git a/app/src/main/java/com/github/gotify/messages/provider/ApplicationHolder.java b/app/src/main/java/com/github/gotify/messages/provider/ApplicationHolder.java index be85b2a0..9c023620 100644 --- a/app/src/main/java/com/github/gotify/messages/provider/ApplicationHolder.java +++ b/app/src/main/java/com/github/gotify/messages/provider/ApplicationHolder.java @@ -13,6 +13,7 @@ public class ApplicationHolder { private List state; private Runnable onUpdate; + private Runnable onUpdateFailed; private Activity activity; private ApiClient client; @@ -35,11 +36,12 @@ public void request() { private void onReceiveApps(List 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 get() { @@ -49,4 +51,8 @@ public List get() { public void onUpdate(Runnable runnable) { this.onUpdate = runnable; } + + public void onUpdateFailed(Runnable runnable) { + this.onUpdateFailed = runnable; + } } diff --git a/app/src/main/java/com/github/gotify/sharing/ShareActivity.java b/app/src/main/java/com/github/gotify/sharing/ShareActivity.java index 065a096f..dcd29940 100644 --- a/app/src/main/java/com/github/gotify/sharing/ShareActivity.java +++ b/app/src/main/java/com/github/gotify/sharing/ShareActivity.java @@ -6,7 +6,9 @@ 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 @@ protected void onCreate(Bundle savedInstanceState) { ApiClient client = ClientFactory.clientToken(settings.url(), settings.sslSettings(), settings.token()); appsHolder = new ApplicationHolder(this, client); - appsHolder.onUpdate(() -> populateSpinner(appsHolder.get())); + appsHolder.onUpdate( + () -> { + List 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 void pushMessage(View view) { } 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(); diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 00000000..8da7666d --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_share.xml b/app/src/main/res/layout/activity_share.xml index 1c20d6bd..47086a5c 100644 --- a/app/src/main/res/layout/activity_share.xml +++ b/app/src/main/res/layout/activity_share.xml @@ -1,92 +1,134 @@ - + android:layout_height="match_parent"> - - - + android:orientation="vertical"> + + - - - - + android:layout_margin="20dp"> + + + - - - - + android:layout_marginHorizontal="20dp" + android:layout_marginBottom="20dp"> - + + + - + android:layout_marginHorizontal="20dp" + android:layout_marginBottom="20dp"> - + + + + + + + + + - - - - + android:layout_marginHorizontal="20dp" + android:layout_marginBottom="20dp" + android:gravity="center" + android:orientation="horizontal" + android:paddingStart="10dp" + android:paddingEnd="10dp" + android:visibility="gone"> -