forked from mirrors/Fedilab
Fix issues #291 #208 #277 #99 - Add error messages coming from the API with a button to edit the draft for a resend.
This commit is contained in:
parent
77f22390e1
commit
3703254c6f
5 changed files with 68 additions and 3 deletions
|
@ -48,6 +48,7 @@ import android.view.View;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -122,6 +123,7 @@ import app.fedilab.android.client.entities.app.BottomMenu;
|
|||
import app.fedilab.android.client.entities.app.DomainsBlock;
|
||||
import app.fedilab.android.client.entities.app.Pinned;
|
||||
import app.fedilab.android.client.entities.app.PinnedTimeline;
|
||||
import app.fedilab.android.client.entities.app.StatusDraft;
|
||||
import app.fedilab.android.databinding.ActivityMainBinding;
|
||||
import app.fedilab.android.databinding.NavHeaderMainBinding;
|
||||
import app.fedilab.android.exception.DBException;
|
||||
|
@ -163,6 +165,33 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
private ActivityMainBinding binding;
|
||||
private Pinned pinned;
|
||||
private BottomMenu bottomMenu;
|
||||
private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(android.content.Context context, Intent intent) {
|
||||
Bundle b = intent.getExtras();
|
||||
if (b != null) {
|
||||
if (b.getBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, false)) {
|
||||
String errorMessage = b.getString(Helper.RECEIVE_ERROR_MESSAGE);
|
||||
StatusDraft statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT);
|
||||
Snackbar snackbar = Snackbar.make(binding.getRoot(), errorMessage, 5000);
|
||||
View snackbarView = snackbar.getView();
|
||||
TextView textView = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
|
||||
textView.setMaxLines(5);
|
||||
snackbar
|
||||
.setAction(getString(R.string.open_draft), view -> {
|
||||
Intent intentCompose = new Intent(context, ComposeActivity.class);
|
||||
intentCompose.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft);
|
||||
context.startActivity(intentCompose);
|
||||
})
|
||||
.setTextColor(ThemeHelper.getAttColor(BaseMainActivity.this, R.attr.mTextColor))
|
||||
.setActionTextColor(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_accent_reference))
|
||||
.setBackgroundTint(ContextCompat.getColor(BaseMainActivity.this, R.color.cyanea_primary_dark_reference))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -877,6 +906,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
binding.toolbarSearch.setOnSearchClickListener(v -> binding.tabLayout.setVisibility(View.VISIBLE));
|
||||
//For receiving data from other activities
|
||||
LocalBroadcastManager.getInstance(BaseMainActivity.this).registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
|
||||
LocalBroadcastManager.getInstance(BaseMainActivity.this)
|
||||
.registerReceiver(broadcast_error_message,
|
||||
new IntentFilter(Helper.INTENT_COMPOSE_ERROR_MESSAGE));
|
||||
if (emojis == null || !emojis.containsKey(BaseMainActivity.currentInstance) || emojis.get(BaseMainActivity.currentInstance) == null) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
|
@ -1038,6 +1070,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
@Override
|
||||
protected void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(BaseMainActivity.this).unregisterReceiver(broadcast_data);
|
||||
LocalBroadcastManager.getInstance(BaseMainActivity.this)
|
||||
.unregisterReceiver(broadcast_error_message);
|
||||
if (networkStateReceiver != null) {
|
||||
try {
|
||||
unregisterReceiver(networkStateReceiver);
|
||||
|
|
|
@ -108,6 +108,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
private Status statusReply, statusMention;
|
||||
private StatusDraft statusDraft;
|
||||
private ComposeAdapter composeAdapter;
|
||||
|
||||
private final BroadcastReceiver imageReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(android.content.Context context, Intent intent) {
|
||||
|
@ -133,6 +134,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
private ActivityPaginationBinding binding;
|
||||
private BaseAccount account;
|
||||
private String instance, token;
|
||||
|
@ -400,6 +402,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
}
|
||||
LocalBroadcastManager.getInstance(this)
|
||||
.unregisterReceiver(imageReceiver);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -198,9 +198,11 @@ public class Helper {
|
|||
public static final String RECEIVE_REDRAW_BOTTOM = "RECEIVE_REDRAW_BOTTOM";
|
||||
|
||||
public static final String RECEIVE_STATUS_ACTION = "RECEIVE_STATUS_ACTION";
|
||||
public static final String RECEIVE_ERROR_MESSAGE = "RECEIVE_ERROR_MESSAGE";
|
||||
|
||||
public static final String RECEIVE_RECREATE_ACTIVITY = "RECEIVE_RECREATE_ACTIVITY";
|
||||
public static final String RECEIVE_NEW_MESSAGE = "RECEIVE_NEW_MESSAGE";
|
||||
public static final String RECEIVE_COMPOSE_ERROR_MESSAGE = "RECEIVE_COMPOSE_ERROR_MESSAGE";
|
||||
public static final String RECEIVE_MASTODON_LIST = "RECEIVE_MASTODON_LIST";
|
||||
public static final String RECEIVE_REDRAW_PROFILE = "RECEIVE_REDRAW_PROFILE";
|
||||
|
||||
|
@ -291,6 +293,7 @@ public class Helper {
|
|||
public static final int OPEN_NOTIFICATION = 2;
|
||||
public static final String INTENT_TARGETED_ACCOUNT = "INTENT_TARGETED_ACCOUNT";
|
||||
public static final String INTENT_SEND_MODIFIED_IMAGE = "INTENT_SEND_MODIFIED_IMAGE";
|
||||
public static final String INTENT_COMPOSE_ERROR_MESSAGE = "INTENT_COMPOSE_ERROR_MESSAGE";
|
||||
public static final String TEMP_MEDIA_DIRECTORY = "TEMP_MEDIA_DIRECTORY";
|
||||
|
||||
|
||||
|
|
|
@ -200,6 +200,13 @@ public class PostMessageService extends IntentService {
|
|||
}
|
||||
Call<Status> statusCall;
|
||||
if (error) {
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true);
|
||||
Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE);
|
||||
b.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, context.getString(R.string.media_cannot_be_uploaded));
|
||||
b.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft);
|
||||
intentBD.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBD);
|
||||
return;
|
||||
}
|
||||
String language = sharedPreferences.getString(context.getString(R.string.SET_COMPOSE_LANGUAGE) + dataPost.userId + dataPost.instance, null);
|
||||
|
@ -226,7 +233,7 @@ public class PostMessageService extends IntentService {
|
|||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!error && i >= dataPost.statusDraft.statusDraftList.size()) {
|
||||
if (i >= dataPost.statusDraft.statusDraftList.size()) {
|
||||
try {
|
||||
new StatusDraft(context).removeDraft(dataPost.statusDraft);
|
||||
} catch (DBException e) {
|
||||
|
@ -237,10 +244,26 @@ public class PostMessageService extends IntentService {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (statusResponse.errorBody() != null) {
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true);
|
||||
Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE);
|
||||
b.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft);
|
||||
b.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, statusResponse.errorBody().string());
|
||||
intentBD.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBD);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
Bundle b = new Bundle();
|
||||
b.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true);
|
||||
b.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft);
|
||||
Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE);
|
||||
b.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, e.getMessage());
|
||||
intentBD.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBD);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Call<ScheduledStatus> scheduledStatusCall = mastodonStatusesService.createScheduledStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
||||
|
@ -260,7 +283,7 @@ public class PostMessageService extends IntentService {
|
|||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!error && i >= dataPost.statusDraft.statusDraftList.size()) {
|
||||
if (i >= dataPost.statusDraft.statusDraftList.size()) {
|
||||
try {
|
||||
new StatusDraft(context).removeDraft(dataPost.statusDraft);
|
||||
} catch (DBException e) {
|
||||
|
|
|
@ -992,6 +992,8 @@
|
|||
<string name="set_your_max_char_count">Set your max char count</string>
|
||||
<string name="release_notes">Release notes</string>
|
||||
<string name="toast_token">The app failed to get a token</string>
|
||||
<string name="media_cannot_be_uploaded">Media cannot be uploaded!</string>
|
||||
<string name="open_draft">Open draft</string>
|
||||
|
||||
<string-array name="photo_editor_emoji" translatable="false">
|
||||
<!-- Smiles -->
|
||||
|
|
Loading…
Reference in a new issue