Fix issue #183
This commit is contained in:
parent
68355363e2
commit
bbb57c4c0c
|
@ -169,6 +169,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
public static HashMap<Integer, Fragment> mPageReferenceMap = new HashMap<>();
|
||||
private static boolean notificationChecked = false;
|
||||
public static HashMap<String, Integer> poll_limits = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -1766,6 +1767,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
if( apiResponse.getInstance() == null || apiResponse.getInstance().getVersion() == null || apiResponse.getInstance().getVersion().trim().length() == 0)
|
||||
return;
|
||||
poll_limits = apiResponse.getInstance().getPoll_limits();
|
||||
Version currentVersion = new Version(apiResponse.getInstance().getVersion());
|
||||
Version minVersion = new Version("1.6");
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
|
|
|
@ -230,7 +230,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
public static boolean autocomplete;
|
||||
private String newContent;
|
||||
private TextWatcher textWatcher;
|
||||
|
||||
private int pollCountItem;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -2801,8 +2801,62 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
Spinner poll_duration = view.findViewById(R.id.poll_duration);
|
||||
EditText choice_1 = view.findViewById(R.id.choice_1);
|
||||
EditText choice_2 = view.findViewById(R.id.choice_2);
|
||||
EditText choice_3 = view.findViewById(R.id.choice_3);
|
||||
EditText choice_4 = view.findViewById(R.id.choice_4);
|
||||
ImageButton add = view.findViewById(R.id.add_poll_item);
|
||||
ImageButton remove = view.findViewById(R.id.remove_poll_item);
|
||||
LinearLayout poll_items_container = view.findViewById(R.id.poll_items_container);
|
||||
int max_entry = 4;
|
||||
int max_length = 25;
|
||||
pollCountItem = 2;
|
||||
if( MainActivity.poll_limits != null && MainActivity.poll_limits.containsKey("max_options")){
|
||||
max_entry = MainActivity.poll_limits.get("max_options")!=null?MainActivity.poll_limits.get("max_options"):4;
|
||||
}
|
||||
if( MainActivity.poll_limits != null && MainActivity.poll_limits.containsKey("max_option_chars")){
|
||||
max_length = MainActivity.poll_limits.get("max_option_chars")!=null?MainActivity.poll_limits.get("max_option_chars"):25;
|
||||
}
|
||||
InputFilter[] fArray = new InputFilter[1];
|
||||
fArray[0] = new InputFilter.LengthFilter(max_length);
|
||||
choice_1.setFilters(fArray);
|
||||
choice_2.setFilters(fArray);
|
||||
|
||||
int finalMax_entry = max_entry;
|
||||
int finalMax_length = max_length;
|
||||
add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( pollCountItem < finalMax_entry){
|
||||
EditText poll_item = new EditText(TootActivity.this);
|
||||
InputFilter[] fArray = new InputFilter[1];
|
||||
fArray[0] = new InputFilter.LengthFilter(finalMax_length);
|
||||
poll_item.setFilters(fArray);
|
||||
poll_item.setHint(getString(R.string.poll_choice_s,(pollCountItem+1)));
|
||||
poll_items_container.addView(poll_item);
|
||||
}
|
||||
pollCountItem++;
|
||||
if( pollCountItem >= finalMax_entry){
|
||||
add.setVisibility(View.GONE);
|
||||
}else{
|
||||
add.setVisibility(View.VISIBLE);
|
||||
}
|
||||
remove.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
remove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( pollCountItem > 2){
|
||||
int childCount = poll_items_container.getChildCount();
|
||||
poll_items_container.removeViewAt(childCount -1);
|
||||
}
|
||||
pollCountItem--;
|
||||
if( pollCountItem <= 2){
|
||||
remove.setVisibility(View.GONE);
|
||||
}else{
|
||||
remove.setVisibility(View.VISIBLE);
|
||||
}
|
||||
add.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
ArrayAdapter<CharSequence> pollduration = ArrayAdapter.createFromResource(TootActivity.this,
|
||||
R.array.poll_duration, android.R.layout.simple_spinner_item);
|
||||
|
||||
|
@ -2815,23 +2869,23 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
if( poll != null){
|
||||
int i = 1;
|
||||
for(PollOptions pollOptions: poll.getOptionsList()){
|
||||
switch (i){
|
||||
case 1:
|
||||
if( pollOptions.getTitle() != null)
|
||||
choice_1.setText(pollOptions.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
if( pollOptions.getTitle() != null)
|
||||
choice_2.setText(pollOptions.getTitle());
|
||||
break;
|
||||
case 3:
|
||||
if( pollOptions.getTitle() != null)
|
||||
choice_3.setText(pollOptions.getTitle());
|
||||
break;
|
||||
case 4:
|
||||
if( pollOptions.getTitle() != null)
|
||||
choice_4.setText(pollOptions.getTitle());
|
||||
break;
|
||||
if( i == 1){
|
||||
if( pollOptions.getTitle() != null)
|
||||
choice_1.setText(pollOptions.getTitle());
|
||||
}else if(i == 2){
|
||||
if( pollOptions.getTitle() != null)
|
||||
choice_2.setText(pollOptions.getTitle());
|
||||
}else{
|
||||
EditText poll_item = new EditText(TootActivity.this);
|
||||
fArray = new InputFilter[1];
|
||||
fArray[0] = new InputFilter.LengthFilter(finalMax_length);
|
||||
poll_item.setFilters(fArray);
|
||||
poll_item.setHint(getString(R.string.poll_choice_s,(pollCountItem+1)));
|
||||
if( pollOptions.getTitle() != null){
|
||||
poll_item.setText(pollOptions.getTitle());
|
||||
}
|
||||
poll_items_container.addView(poll_item);
|
||||
pollCountItem++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -2884,8 +2938,6 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
int poll_choice_pos = poll_choice.getSelectedItemPosition();
|
||||
String choice1 = choice_1.getText().toString().trim();
|
||||
String choice2 = choice_2.getText().toString().trim();
|
||||
String choice3 = choice_3.getText().toString().trim();
|
||||
String choice4 = choice_4.getText().toString().trim();
|
||||
|
||||
if( choice1.isEmpty() && choice2.isEmpty()){
|
||||
Toasty.error(getApplicationContext(), getString(R.string.poll_invalid_choices), Toast.LENGTH_SHORT).show();
|
||||
|
@ -2929,13 +2981,15 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
|
|||
pollOption2.setTitle(choice2);
|
||||
pollOptions.add(pollOption2);
|
||||
|
||||
PollOptions pollOption3 = new PollOptions();
|
||||
pollOption3.setTitle(choice3);
|
||||
pollOptions.add(pollOption3);
|
||||
int childCount = poll_items_container.getChildCount();
|
||||
if( childCount > 2){
|
||||
for( int i = 2 ; i < childCount; i++){
|
||||
PollOptions pollItem = new PollOptions();
|
||||
pollItem.setTitle(((EditText)poll_items_container.getChildAt(i)).getText().toString());
|
||||
pollOptions.add(pollItem);
|
||||
}
|
||||
}
|
||||
|
||||
PollOptions pollOption4 = new PollOptions();
|
||||
pollOption4.setTitle(choice4);
|
||||
pollOptions.add(pollOption4);
|
||||
poll.setOptionsList(pollOptions);
|
||||
|
||||
dialog.dismiss();
|
||||
|
|
|
@ -4288,8 +4288,18 @@ public class API {
|
|||
instance.setDescription(resobj.get("description").toString());
|
||||
instance.setEmail(resobj.get("email").toString());
|
||||
instance.setVersion(resobj.get("version").toString());
|
||||
|
||||
if(resobj.has("poll_limits")){
|
||||
HashMap<String, Integer> poll_limits = new HashMap<>();
|
||||
JSONObject polllimits = resobj.getJSONObject("poll_limits");
|
||||
poll_limits.put("min_expiration",polllimits.getInt("min_expiration"));
|
||||
poll_limits.put("max_options",polllimits.getInt("max_options"));
|
||||
poll_limits.put("max_option_chars",polllimits.getInt("max_option_chars"));
|
||||
poll_limits.put("max_expiration",polllimits.getInt("max_expiration"));
|
||||
instance.setPoll_limits(poll_limits);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package app.fedilab.android.client.Entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 05/06/2017.
|
||||
* Describes instance
|
||||
|
@ -26,6 +28,7 @@ public class Instance {
|
|||
private String description;
|
||||
private String email;
|
||||
private String version;
|
||||
private HashMap<String, Integer> poll_limits;
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
|
@ -66,4 +69,12 @@ public class Instance {
|
|||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getPoll_limits() {
|
||||
return poll_limits;
|
||||
}
|
||||
|
||||
public void setPoll_limits(HashMap<String, Integer> poll_limits) {
|
||||
this.poll_limits = poll_limits;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M19,13H5v-2h14v2z"/>
|
||||
</vector>
|
|
@ -23,46 +23,63 @@
|
|||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:layout_height="match_parent">
|
||||
<EditText
|
||||
android:id="@+id/choice_1"
|
||||
android:hint="@string/poll_choice_1"
|
||||
android:singleLine="true"
|
||||
android:maxLength="25"
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/poll_items_container"
|
||||
android:layout_height="wrap_content">
|
||||
<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"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
<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"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
<EditText
|
||||
android:id="@+id/choice_2"
|
||||
android:hint="@string/poll_choice_2"
|
||||
android:maxLength="25"
|
||||
android:singleLine="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
<EditText
|
||||
android:id="@+id/choice_3"
|
||||
android:hint="@string/poll_choice_3"
|
||||
android:maxLength="25"
|
||||
android:singleLine="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
<EditText
|
||||
android:id="@+id/choice_4"
|
||||
android:hint="@string/poll_choice_4"
|
||||
android:maxLength="25"
|
||||
android:singleLine="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:layout_marginBottom="10dp"
|
||||
/>
|
||||
android:orientation="horizontal">
|
||||
<ImageButton
|
||||
android:id="@+id/add_poll_item"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@color/transparent"
|
||||
android:contentDescription="@string/add_poll_item"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_add" />
|
||||
<ImageButton
|
||||
android:id="@+id/remove_poll_item"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@color/transparent"
|
||||
android:contentDescription="@string/remove_poll_item"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_remove_white" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -907,8 +907,7 @@
|
|||
<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>
|
||||
<string name="poll_choice_s">Choice %d</string>
|
||||
<string name="poll_invalid_choices">You need two choices at least for the poll!</string>
|
||||
<string name="done">Done</string>
|
||||
<string name="poll_finish_at">end at %s</string>
|
||||
|
@ -978,6 +977,8 @@
|
|||
<string name="opacity">Opacity</string>
|
||||
<string name="label_crop">Crop</string>
|
||||
<string name="set_photo_editor">Enable photo editor</string>
|
||||
<string name="add_poll_item">Add a poll item</string>
|
||||
<string name="remove_poll_item">Remove last poll item</string>
|
||||
<plurals name="number_of_vote">
|
||||
<item quantity="one">%d vote</item>
|
||||
<item quantity="other">%d votes</item>
|
||||
|
|
Loading…
Reference in New Issue