This commit is contained in:
tom79 2019-06-04 11:02:15 +02:00
parent 68355363e2
commit bbb57c4c0c
7 changed files with 169 additions and 69 deletions

View File

@ -169,6 +169,7 @@ public abstract class BaseMainActivity extends BaseActivity
public static HashMap<Integer, Fragment> mPageReferenceMap = new HashMap<>(); public static HashMap<Integer, Fragment> mPageReferenceMap = new HashMap<>();
private static boolean notificationChecked = false; private static boolean notificationChecked = false;
public static HashMap<String, Integer> poll_limits = new HashMap<>();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { 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) if( apiResponse.getInstance() == null || apiResponse.getInstance().getVersion() == null || apiResponse.getInstance().getVersion().trim().length() == 0)
return; return;
poll_limits = apiResponse.getInstance().getPoll_limits();
Version currentVersion = new Version(apiResponse.getInstance().getVersion()); Version currentVersion = new Version(apiResponse.getInstance().getVersion());
Version minVersion = new Version("1.6"); Version minVersion = new Version("1.6");
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);

View File

@ -230,7 +230,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
public static boolean autocomplete; public static boolean autocomplete;
private String newContent; private String newContent;
private TextWatcher textWatcher; private TextWatcher textWatcher;
private int pollCountItem;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -2801,8 +2801,62 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
Spinner poll_duration = view.findViewById(R.id.poll_duration); Spinner poll_duration = view.findViewById(R.id.poll_duration);
EditText choice_1 = view.findViewById(R.id.choice_1); EditText choice_1 = view.findViewById(R.id.choice_1);
EditText choice_2 = view.findViewById(R.id.choice_2); EditText choice_2 = view.findViewById(R.id.choice_2);
EditText choice_3 = view.findViewById(R.id.choice_3); ImageButton add = view.findViewById(R.id.add_poll_item);
EditText choice_4 = view.findViewById(R.id.choice_4); 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, ArrayAdapter<CharSequence> pollduration = ArrayAdapter.createFromResource(TootActivity.this,
R.array.poll_duration, android.R.layout.simple_spinner_item); R.array.poll_duration, android.R.layout.simple_spinner_item);
@ -2815,23 +2869,23 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
if( poll != null){ if( poll != null){
int i = 1; int i = 1;
for(PollOptions pollOptions: poll.getOptionsList()){ for(PollOptions pollOptions: poll.getOptionsList()){
switch (i){ if( i == 1){
case 1: if( pollOptions.getTitle() != null)
if( pollOptions.getTitle() != null) choice_1.setText(pollOptions.getTitle());
choice_1.setText(pollOptions.getTitle()); }else if(i == 2){
break; if( pollOptions.getTitle() != null)
case 2: choice_2.setText(pollOptions.getTitle());
if( pollOptions.getTitle() != null) }else{
choice_2.setText(pollOptions.getTitle()); EditText poll_item = new EditText(TootActivity.this);
break; fArray = new InputFilter[1];
case 3: fArray[0] = new InputFilter.LengthFilter(finalMax_length);
if( pollOptions.getTitle() != null) poll_item.setFilters(fArray);
choice_3.setText(pollOptions.getTitle()); poll_item.setHint(getString(R.string.poll_choice_s,(pollCountItem+1)));
break; if( pollOptions.getTitle() != null){
case 4: poll_item.setText(pollOptions.getTitle());
if( pollOptions.getTitle() != null) }
choice_4.setText(pollOptions.getTitle()); poll_items_container.addView(poll_item);
break; pollCountItem++;
} }
i++; i++;
} }
@ -2884,8 +2938,6 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
int poll_choice_pos = poll_choice.getSelectedItemPosition(); int poll_choice_pos = poll_choice.getSelectedItemPosition();
String choice1 = choice_1.getText().toString().trim(); String choice1 = choice_1.getText().toString().trim();
String choice2 = choice_2.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()){ if( choice1.isEmpty() && choice2.isEmpty()){
Toasty.error(getApplicationContext(), getString(R.string.poll_invalid_choices), Toast.LENGTH_SHORT).show(); 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); pollOption2.setTitle(choice2);
pollOptions.add(pollOption2); pollOptions.add(pollOption2);
PollOptions pollOption3 = new PollOptions(); int childCount = poll_items_container.getChildCount();
pollOption3.setTitle(choice3); if( childCount > 2){
pollOptions.add(pollOption3); 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); poll.setOptionsList(pollOptions);
dialog.dismiss(); dialog.dismiss();

View File

@ -4288,8 +4288,18 @@ public class API {
instance.setDescription(resobj.get("description").toString()); instance.setDescription(resobj.get("description").toString());
instance.setEmail(resobj.get("email").toString()); instance.setEmail(resobj.get("email").toString());
instance.setVersion(resobj.get("version").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) { } catch (JSONException e) {
setDefaultError(e); e.printStackTrace();
} }
return instance; return instance;
} }

View File

@ -14,6 +14,8 @@
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
package app.fedilab.android.client.Entities; package app.fedilab.android.client.Entities;
import java.util.HashMap;
/** /**
* Created by Thomas on 05/06/2017. * Created by Thomas on 05/06/2017.
* Describes instance * Describes instance
@ -26,6 +28,7 @@ public class Instance {
private String description; private String description;
private String email; private String email;
private String version; private String version;
private HashMap<String, Integer> poll_limits;
public String getUri() { public String getUri() {
return uri; return uri;
@ -66,4 +69,12 @@ public class Instance {
public void setVersion(String version) { public void setVersion(String version) {
this.version = 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;
}
} }

View File

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

View File

@ -23,46 +23,63 @@
android:paddingLeft="20dp" android:paddingLeft="20dp"
android:paddingRight="20dp" android:paddingRight="20dp"
android:layout_height="match_parent"> android:layout_height="match_parent">
<EditText <ScrollView
android:id="@+id/choice_1" android:layout_width="match_parent"
android:hint="@string/poll_choice_1" android:layout_height="wrap_content">
android:singleLine="true" <LinearLayout
android:maxLength="25" 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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text" android:orientation="horizontal">
android:layout_marginBottom="10dp" <ImageButton
/> android:id="@+id/add_poll_item"
<EditText android:layout_width="28dp"
android:id="@+id/choice_2" android:layout_height="28dp"
android:hint="@string/poll_choice_2" android:layout_gravity="center"
android:maxLength="25" android:layout_marginRight="5dp"
android:singleLine="true" android:layout_marginEnd="5dp"
android:layout_width="match_parent" android:adjustViewBounds="true"
android:layout_height="wrap_content" android:background="@color/transparent"
android:inputType="text" android:contentDescription="@string/add_poll_item"
android:layout_marginBottom="10dp" android:scaleType="centerCrop"
/> android:src="@drawable/ic_add" />
<EditText <ImageButton
android:id="@+id/choice_3" android:id="@+id/remove_poll_item"
android:hint="@string/poll_choice_3" android:layout_width="28dp"
android:maxLength="25" android:layout_height="28dp"
android:singleLine="true" android:layout_gravity="center"
android:layout_width="match_parent" android:layout_marginRight="5dp"
android:layout_height="wrap_content" android:layout_marginEnd="5dp"
android:inputType="text" android:adjustViewBounds="true"
android:layout_marginBottom="10dp" android:background="@color/transparent"
/> android:contentDescription="@string/remove_poll_item"
<EditText android:scaleType="centerCrop"
android:id="@+id/choice_4" android:src="@drawable/ic_remove_white" />
android:hint="@string/poll_choice_4" </LinearLayout>
android:maxLength="25"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_marginBottom="10dp"
/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -907,8 +907,7 @@
<string name="create_poll">Create a poll</string> <string name="create_poll">Create a poll</string>
<string name="poll_choice_1">Choice 1</string> <string name="poll_choice_1">Choice 1</string>
<string name="poll_choice_2">Choice 2</string> <string name="poll_choice_2">Choice 2</string>
<string name="poll_choice_3">Choice 3</string> <string name="poll_choice_s">Choice %d</string>
<string name="poll_choice_4">Choice 4</string>
<string name="poll_invalid_choices">You need two choices at least for the poll!</string> <string name="poll_invalid_choices">You need two choices at least for the poll!</string>
<string name="done">Done</string> <string name="done">Done</string>
<string name="poll_finish_at">end at %s</string> <string name="poll_finish_at">end at %s</string>
@ -978,6 +977,8 @@
<string name="opacity">Opacity</string> <string name="opacity">Opacity</string>
<string name="label_crop">Crop</string> <string name="label_crop">Crop</string>
<string name="set_photo_editor">Enable photo editor</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"> <plurals name="number_of_vote">
<item quantity="one">%d vote</item> <item quantity="one">%d vote</item>
<item quantity="other">%d votes</item> <item quantity="other">%d votes</item>