added poll vote button, layout fix, added error message

This commit is contained in:
nuclearfog 2023-02-17 21:59:15 +01:00
parent 87f16753d9
commit 0e3111bed2
No known key found for this signature in database
GPG Key ID: 03488A185C476379
13 changed files with 67 additions and 20 deletions

View File

@ -114,6 +114,16 @@ public abstract class ConnectionException extends Exception {
*/
public static final int SERVICE_UNAVAILABLE = 20;
/**
* network connection not available
*/
public static final int NETWORK_CONNECTION = 21;
/**
* error parsing json format
*/
public static final int JSON_FORMAT = 22;
/**
*
*/

View File

@ -34,6 +34,11 @@ public class MastodonException extends ConnectionException {
*/
private static final int ERROR_NETWORK = -2;
/**
* error caused by parsing json format
*/
private static final int ERROR_JSON = -3;
private int errorCode = UNKNOWN_ERROR;
private String errorMessage = "";
@ -46,6 +51,8 @@ public class MastodonException extends ConnectionException {
super(e);
if (e instanceof UnknownHostException) {
errorCode = ERROR_NETWORK;
} else if (e instanceof JSONException) {
errorCode = ERROR_JSON;
}
}
@ -101,7 +108,10 @@ public class MastodonException extends ConnectionException {
return SERVICE_UNAVAILABLE;
case ERROR_NETWORK:
return ERROR_NETWORK;
return NETWORK_CONNECTION;
case ERROR_JSON:
return JSON_FORMAT;
default:
case UNKNOWN_ERROR:

View File

@ -36,8 +36,10 @@ public class MastodonPoll implements Poll {
exTime = StringTools.getTime(exTimeStr, StringTools.TIME_MASTODON);
expired = json.getBoolean("expired");
voted = json.optBoolean("voted", false);
voteCount = json.getInt("voters_count");
multipleChoice = json.getBoolean("multiple");
if (!json.isNull("voters_count")) {
voteCount = json.getInt("voters_count");
}
options = new MastodonOption[optionsJson.length()];
for (int i = 0; i < optionsJson.length(); i++) {

View File

@ -67,7 +67,6 @@ public class MastodonStatus implements Status {
String replyIdStr = json.optString("in_reply_to_id", "0");
String replyUserIdStr = json.optString("in_reply_to_account_id", "0");
String idStr = json.getString("id");
String url = json.optString("url", "");
author = new MastodonUser(json.getJSONObject("account"), currentUserId);
createdAt = StringTools.getTime(json.optString("created_at"), StringTools.TIME_MASTODON);
@ -86,8 +85,8 @@ public class MastodonStatus implements Status {
if (embeddedJson != null) {
embeddedStatus = new MastodonStatus(embeddedJson, currentUserId);
this.url = embeddedStatus.getUrl();
} else if (!url.equals("null")) {
this.url = url;
} else if (!json.isNull("url")) {
this.url = json.optString("url", "");
}
if (pollJson != null) {
poll = new MastodonPoll(pollJson);

View File

@ -38,6 +38,7 @@ public class ErrorHandler {
}
return context.getString(R.string.error_rate_limit);
case ConnectionException.NETWORK_CONNECTION:
case ConnectionException.SERVICE_UNAVAILABLE:
return context.getString(R.string.error_service_unavailable);
@ -98,6 +99,9 @@ public class ErrorHandler {
case ConnectionException.ERROR_API_ACCESS_DENIED:
return context.getString(R.string.error_api_access_limited);
case ConnectionException.JSON_FORMAT:
return context.getString(R.string.error_json_format);
case ConnectionException.ERROR_NOT_DEFINED:
if (error.getMessage() != null && !error.getMessage().isEmpty()) {
return error.getMessage();

View File

@ -657,7 +657,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
@Override
public void onPollOptionClick(Poll poll, int selection) {
public void onVoteClick(Poll poll, int[] selection) {
// todo add implementation
}

View File

@ -92,4 +92,15 @@ public class OptionsAdapter extends RecyclerView.Adapter<Optionholder> implement
limitVotes = poll.getLimit();
notifyDataSetChanged();
}
/**
* @return a set of selection position
*/
public int[] getSelection() {
int pos = 0;
int[] result = new int[selection.size()];
for (Integer index : selection)
result[pos++] = index;
return result;
}
}

View File

@ -142,10 +142,10 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
}
break;
case OnHolderClickListener.POLL_ITEM:
case OnHolderClickListener.POLL_VOTE:
if (item instanceof Poll && extras.length == 1) {
Poll poll = (Poll) item;
listener.onPollOptionClick(poll, extras[0]);
listener.onVoteClick(poll, extras);
}
break;
@ -208,8 +208,8 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
* called on poll option click
*
* @param poll poll containing the clicked option
* @param selection poll option index
* @param selection selected poll options
*/
void onPollOptionClick(Poll poll, int selection);
void onVoteClick(Poll poll, int[] selection);
}
}

View File

@ -41,11 +41,9 @@ public interface OnHolderClickListener {
int CARD_LINK = 16;
int POLL_ITEM = 17;
int POLL_OPTION = 17;
int POLL_OPTION = 18;
int POLL_VOTE = 19;
int POLL_VOTE = 18;
/**
* called when an item was clicked

View File

@ -60,7 +60,10 @@ public class PollHolder extends ViewHolder implements OnClickListener {
if (v.getId() == R.id.item_poll_vote_button) {
int pos = getLayoutPosition();
if (pos != RecyclerView.NO_POSITION) {
listener.onItemClick(pos, OnHolderClickListener.POLL_VOTE);
int[] selection = adapter.getSelection();
if (selection.length > 0) {
listener.onItemClick(pos, OnHolderClickListener.POLL_VOTE, selection);
}
}
}
}

View File

@ -14,7 +14,10 @@
android:id="@+id/item_poll_options_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
android:layout_weight="1"
android:layout_marginBottom="@dimen/item_poll_layout_margin"
android:descendantFocusability="blocksDescendants"
android:nestedScrollingEnabled="true"/>
<LinearLayout
android:layout_width="match_parent"
@ -23,18 +26,22 @@
<TextView
android:id="@+id/item_poll_votes_count"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="@dimen/item_poll_text_size"
android:lines="1" />
android:lines="1"
android:layout_weight="1" />
<Button
android:id="@+id/item_poll_vote_button"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="@dimen/item_poll_button_height"
android:visibility="invisible"
android:drawablePadding="@dimen/item_poll_drawable_padding"
android:lines="1"
android:textSize="@dimen/item_poll_text_size"
android:layout_weight="1"
android:text="@string/item_poll_option_vote"
style="@style/FeedbackButton" />
</LinearLayout>

View File

@ -258,7 +258,8 @@
<!-- dimens of item_poll.xml -->
<dimen name="item_poll_layout_padding">5dp</dimen>
<dimen name="item_poll_text_size">11sp</dimen>
<dimen name="item_poll_layout_margin">3dp</dimen>
<dimen name="item_poll_text_size">13sp</dimen>
<dimen name="item_poll_button_height">16sp</dimen>
<dimen name="item_poll_drawable_padding">5dp</dimen>

View File

@ -98,6 +98,7 @@
<string name="error_acc_loading">Error while loading login information!</string>
<string name="error_api_access_denied">Error, API access denied! Please check your API Keys.</string>
<string name="error_api_access_limited">Error, API access limited by Twitter!</string>
<string name="error_json_format">Error while parsing JSON response!</string>
<string name="error_api_key_expired">Error, API Keys expired! Please update app!</string>
<string name="error_result_cancelled">Error, result cancelled!</string>
<string name="error_twitter_search">Error, search query is too long or contains illegal characters!</string>
@ -246,6 +247,7 @@
<string name="settings_description_enable_twitter_alt">use nitter.net for links</string>
<string name="item_load_more">load more</string>
<string name="item_image_save">save image</string>
<string name="item_poll_option_vote">vote</string>
<string name="settings_enable_proxy">enable proxy</string>
<string name="settings_enable_proxy_auth">enable proxy authentication</string>
<string name="tweet_sensitive_media">sensitive content</string>