add alert

This commit is contained in:
tom79 2019-03-23 17:23:02 +01:00
parent 29fd46fe94
commit c0f6352604
6 changed files with 262 additions and 0 deletions

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses>. */
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<PollOptions> 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<PollOptions> getOptionsList() {
return optionsList;
}
public void setOptionsList(List<PollOptions> 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<PollOptions>();
in.readList(this.optionsList, PollOptions.class.getClassLoader());
}
public static final Parcelable.Creator<Poll> CREATOR = new Parcelable.Creator<Poll>() {
@Override
public Poll createFromParcel(Parcel source) {
return new Poll(source);
}
@Override
public Poll[] newArray(int size) {
return new Poll[size];
}
};
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M4,14h4v-4L4,10v4zM4,19h4v-4L4,15v4zM4,9h4L8,5L4,5v4zM9,14h12v-4L9,10v4zM9,19h12v-4L9,15v4zM9,5v4h12L21,5L9,5z"/>
</vector>

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<EditText
android:id="@+id/choice_1"
android:hint="@string/poll_choice_1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<EditText
android:id="@+id/choice_2"
android:hint="@string/poll_choice_2"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<EditText
android:id="@+id/choice_3"
android:hint="@string/poll_choice_3"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<EditText
android:id="@+id/choice_4"
android:hint="@string/poll_choice_4"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Spinner>
</LinearLayout>
</LinearLayout>

View File

@ -16,6 +16,11 @@
android:title="@string/camera"
android:icon="@drawable/ic_photo_camera"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_poll"
android:title="@string/poll"
android:icon="@drawable/ic_view_list_poll"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_contacts"
android:title="@string/contact"

View File

@ -901,6 +901,12 @@
<string name="featured_hashtags">Featured hashtags</string>
<string name="filter_timeline_with_a_tag">Filter timeline with tags</string>
<string name="no_tags">No tags</string>
<string name="poll">Poll</string>
<string name="create_poll">Create a poll</string>
<string name="poll_choice_1">Choice 1</string>
<string name="poll_choice_2">Choice 2</string>
<string name="poll_choice_3">Choice 3</string>
<string name="poll_choice_4">Choice 4</string>
<!-- end languages -->