From c0f63526047315fabe3d6ae01e420a20b623190a Mon Sep 17 00:00:00 2001 From: tom79 Date: Sat, 23 Mar 2019 17:23:02 +0100 Subject: [PATCH] add alert --- .../mastodon/activities/TootActivity.java | 32 ++++ .../etalab/mastodon/client/Entities/Poll.java | 146 ++++++++++++++++++ .../main/res/drawable/ic_view_list_poll.xml | 9 ++ app/src/main/res/layout/popup_poll.xml | 64 ++++++++ app/src/main/res/menu/main_toot.xml | 5 + app/src/main/res/values/strings.xml | 6 + 6 files changed, 262 insertions(+) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Poll.java create mode 100644 app/src/main/res/drawable/ic_view_list_poll.xml create mode 100644 app/src/main/res/layout/popup_poll.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index a7f733575..53dc3e66d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -1046,6 +1046,33 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, }); alert.show(); return true; + + case R.id.action_poll: + AlertDialog.Builder alertPoll = new AlertDialog.Builder(TootActivity.this, style); + alertPoll.setTitle(R.string.create_poll); + + alert.setView(input); + String content = tootReply.getContent(); + if(tootReply.getReblog() != null) + content = tootReply.getReblog().getContent(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + input.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + input.setText(Html.fromHtml(content)); + alert.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + dialog.dismiss(); + } + }); + alert.setNegativeButton(R.string.accounts, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + new RetrieveAccountsForReplyAsyncTask(getApplicationContext(), tootReply.getReblog() != null?tootReply.getReblog():tootReply, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dialog.dismiss(); + } + }); + alert.show(); + return true; case R.id.action_translate: final CountryPicker picker = CountryPicker.newInstance(getString(R.string.which_language)); // dialog title if( theme == Helper.THEME_LIGHT){ @@ -1593,6 +1620,11 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, if( itemViewReply != null) itemViewReply.setVisible(false); } + if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON){ + MenuItem itemPoll = menu.findItem(R.id.action_poll); + if( itemPoll != null) + itemPoll.setVisible(false); + } SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); if( theme == THEME_LIGHT) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Poll.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Poll.java new file mode 100644 index 000000000..44ff58279 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Poll.java @@ -0,0 +1,146 @@ +/* Copyright 2019 Thomas Schneider + * + * This file is a part of Mastalab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Mastalab; if not, + * see . */ +package fr.gouv.etalab.mastodon.client.Entities; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Poll implements Parcelable { + + private String id; + private Date expires_at; + private boolean expired; + private boolean multiple; + private int votes_count; + private boolean voted; + private List optionsList; + + public Date getExpires_at() { + return expires_at; + } + + public void setExpires_at(Date expires_at) { + this.expires_at = expires_at; + } + + public boolean isExpired() { + return expired; + } + + public void setExpired(boolean expired) { + this.expired = expired; + } + + public boolean isMultiple() { + return multiple; + } + + public void setMultiple(boolean multiple) { + this.multiple = multiple; + } + + public int getVotes_count() { + return votes_count; + } + + public void setVotes_count(int votes_count) { + this.votes_count = votes_count; + } + + public boolean isVoted() { + return voted; + } + + public void setVoted(boolean voted) { + this.voted = voted; + } + + public List getOptionsList() { + return optionsList; + } + + public void setOptionsList(List optionsList) { + this.optionsList = optionsList; + } + + + private class PollOptions{ + private String title; + private String votes_count; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getVotes_count() { + return votes_count; + } + + public void setVotes_count(String votes_count) { + this.votes_count = votes_count; + } + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.id); + dest.writeLong(this.expires_at != null ? this.expires_at.getTime() : -1); + dest.writeByte(this.expired ? (byte) 1 : (byte) 0); + dest.writeByte(this.multiple ? (byte) 1 : (byte) 0); + dest.writeInt(this.votes_count); + dest.writeByte(this.voted ? (byte) 1 : (byte) 0); + dest.writeList(this.optionsList); + } + + public Poll() { + } + + protected Poll(Parcel in) { + this.id = in.readString(); + long tmpExpires_at = in.readLong(); + this.expires_at = tmpExpires_at == -1 ? null : new Date(tmpExpires_at); + this.expired = in.readByte() != 0; + this.multiple = in.readByte() != 0; + this.votes_count = in.readInt(); + this.voted = in.readByte() != 0; + this.optionsList = new ArrayList(); + in.readList(this.optionsList, PollOptions.class.getClassLoader()); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Poll createFromParcel(Parcel source) { + return new Poll(source); + } + + @Override + public Poll[] newArray(int size) { + return new Poll[size]; + } + }; +} diff --git a/app/src/main/res/drawable/ic_view_list_poll.xml b/app/src/main/res/drawable/ic_view_list_poll.xml new file mode 100644 index 000000000..82fb90a2b --- /dev/null +++ b/app/src/main/res/drawable/ic_view_list_poll.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/popup_poll.xml b/app/src/main/res/layout/popup_poll.xml new file mode 100644 index 000000000..874f31828 --- /dev/null +++ b/app/src/main/res/layout/popup_poll.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main_toot.xml b/app/src/main/res/menu/main_toot.xml index b0e6a2042..ea5c00d32 100644 --- a/app/src/main/res/menu/main_toot.xml +++ b/app/src/main/res/menu/main_toot.xml @@ -16,6 +16,11 @@ android:title="@string/camera" android:icon="@drawable/ic_photo_camera" app:showAsAction="ifRoom" /> + Featured hashtags Filter timeline with tags No tags + Poll + Create a poll + Choice 1 + Choice 2 + Choice 3 + Choice 4