forked from sk22/megalodon
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
281 additions
and
16 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
mastodon/src/main/java/org/joinmastodon/android/api/requests/lists/CreateList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.joinmastodon.android.api.requests.lists; | ||
|
||
import org.joinmastodon.android.api.MastodonAPIRequest; | ||
import org.joinmastodon.android.model.ListTimeline; | ||
|
||
public class CreateList extends MastodonAPIRequest<ListTimeline> { | ||
public CreateList(String title, ListTimeline.RepliesPolicy repliesPolicy) { | ||
super(HttpMethod.POST, "/lists", ListTimeline.class); | ||
Request req = new Request(); | ||
req.title = title; | ||
req.repliesPolicy = repliesPolicy; | ||
setRequestBody(req); | ||
} | ||
|
||
public static class Request { | ||
public String title; | ||
public ListTimeline.RepliesPolicy repliesPolicy; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
mastodon/src/main/java/org/joinmastodon/android/api/requests/lists/UpdateList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.joinmastodon.android.api.requests.lists; | ||
|
||
import org.joinmastodon.android.api.MastodonAPIRequest; | ||
import org.joinmastodon.android.model.ListTimeline; | ||
|
||
public class UpdateList extends MastodonAPIRequest<ListTimeline> { | ||
public UpdateList(String id, String title, ListTimeline.RepliesPolicy repliesPolicy) { | ||
super(HttpMethod.PUT, "/lists/" + id, ListTimeline.class); | ||
CreateList.Request req = new CreateList.Request(); | ||
req.title = title; | ||
req.repliesPolicy = repliesPolicy; | ||
setRequestBody(req); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
mastodon/src/main/java/org/joinmastodon/android/ui/views/ListTimelineEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.joinmastodon.android.ui.views; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.MenuItem; | ||
import android.widget.Button; | ||
import android.widget.LinearLayout; | ||
import android.widget.PopupMenu; | ||
|
||
import org.joinmastodon.android.R; | ||
import org.joinmastodon.android.model.ListTimeline; | ||
|
||
public class ListTimelineEditor extends LinearLayout { | ||
private ListTimeline.RepliesPolicy policy = null; | ||
private TextInputFrameLayout input; | ||
private Button button; | ||
|
||
@SuppressLint("ClickableViewAccessibility") | ||
public ListTimelineEditor(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
LayoutInflater.from(context).inflate(R.layout.list_timeline_editor, this); | ||
|
||
button = findViewById(R.id.button); | ||
input = findViewById(R.id.input); | ||
|
||
PopupMenu popupMenu = new PopupMenu(context, button, Gravity.CENTER_HORIZONTAL); | ||
popupMenu.inflate(R.menu.list_reply_policies); | ||
popupMenu.setOnMenuItemClickListener(this::onMenuItemClick); | ||
|
||
button.setOnTouchListener(popupMenu.getDragToOpenListener()); | ||
button.setOnClickListener(v->popupMenu.show()); | ||
input.getEditText().setHint(context.getString(R.string.sk_list_name_hint)); | ||
|
||
setRepliesPolicy(ListTimeline.RepliesPolicy.LIST); | ||
} | ||
|
||
public void applyList(ListTimeline list) { | ||
policy = list.repliesPolicy; | ||
input.getEditText().setText(list.title); | ||
setRepliesPolicy(list.repliesPolicy); | ||
} | ||
|
||
public String getTitle() { | ||
return input.getEditText().getText().toString(); | ||
} | ||
|
||
public ListTimeline.RepliesPolicy getRepliesPolicy() { | ||
return policy; | ||
} | ||
|
||
public void setRepliesPolicy(ListTimeline.RepliesPolicy policy) { | ||
this.policy = policy; | ||
switch (policy) { | ||
case FOLLOWED -> button.setText(R.string.sk_list_replies_policy_followed); | ||
case LIST -> button.setText(R.string.sk_list_replies_policy_list); | ||
case NONE -> button.setText(R.string.sk_list_replies_policy_none); | ||
} | ||
} | ||
|
||
private boolean onMenuItemClick(MenuItem i) { | ||
if (i.getItemId() == R.id.reply_policy_none) { | ||
setRepliesPolicy(ListTimeline.RepliesPolicy.NONE); | ||
} else if (i.getItemId() == R.id.reply_policy_followed) { | ||
setRepliesPolicy(ListTimeline.RepliesPolicy.FOLLOWED); | ||
} else if (i.getItemId() == R.id.reply_policy_list) { | ||
setRepliesPolicy(ListTimeline.RepliesPolicy.LIST); | ||
} | ||
return true; | ||
} | ||
|
||
public ListTimelineEditor(Context context, AttributeSet attrs, int defStyleAttr) { | ||
this(context, attrs, defStyleAttr, 0); | ||
} | ||
|
||
public ListTimelineEditor(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public ListTimelineEditor(Context context) { | ||
this(context, null); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
mastodon/src/main/java/org/joinmastodon/android/ui/views/TextInputFrameLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.joinmastodon.android.ui.views; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.ViewGroup; | ||
import android.widget.EditText; | ||
import android.widget.FrameLayout; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import me.grishka.appkit.utils.V; | ||
|
||
public class TextInputFrameLayout extends FrameLayout { | ||
private final EditText editText; | ||
|
||
public TextInputFrameLayout(@NonNull Context context, CharSequence hint, CharSequence text) { | ||
this(context, null, 0, 0, hint, text); | ||
} | ||
|
||
public TextInputFrameLayout(@NonNull Context context) { | ||
this(context, null); | ||
} | ||
|
||
public TextInputFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public TextInputFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
this(context, attrs, defStyleAttr, 0); | ||
} | ||
|
||
public TextInputFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
this(context, attrs, defStyleAttr, defStyleRes, null, null); | ||
} | ||
|
||
public TextInputFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes, CharSequence hint, CharSequence text) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
editText = new EditText(context); | ||
editText.setHint(hint); | ||
editText.setText(text); | ||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
params.setMargins(V.dp(24), V.dp(4), V.dp(24), V.dp(16)); | ||
editText.setLayoutParams(params); | ||
addView(editText); | ||
} | ||
|
||
public EditText getEditText() { | ||
return editText; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
mastodon/src/main/res/drawable/ic_fluent_channel_add_24_regular.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> | ||
<path android:pathData="M17.75 3c1.733 0 3.15 1.356 3.245 3.066L21 6.25v5.772c-0.463-0.297-0.966-0.536-1.5-0.709V6.25c0-0.918-0.707-1.671-1.606-1.744L17.75 4.5H6.25c-0.6 0-1.13 0.302-1.445 0.763C4.491 5.095 4.132 5 3.75 5 3.57 5 3.393 5.021 3.224 5.062 3.677 3.909 4.77 3.078 6.066 3.005L6.25 3h11.5zm-6.437 16.5c0.173 0.534 0.412 1.037 0.709 1.5H6.25c-1.733 0-3.15-1.357-3.245-3.066L3 17.75V9.372C3.235 9.455 3.487 9.5 3.75 9.5S4.266 9.455 4.5 9.372v8.378c0 0.918 0.707 1.671 1.607 1.744L6.25 19.5h5.063zm0.418-4.997c0.286-0.55 0.65-1.056 1.076-1.5h-4.06l-0.1 0.007c-0.367 0.05-0.65 0.363-0.65 0.743 0 0.414 0.337 0.75 0.75 0.75h2.984zm3.521-5.007c0.415 0 0.75 0.336 0.75 0.75 0 0.38-0.282 0.694-0.648 0.743l-0.102 0.007H8.748c-0.414 0-0.75-0.336-0.75-0.75 0-0.38 0.282-0.693 0.648-0.743l0.102-0.007h6.504zM3.75 6C4.44 6 5 6.56 5 7.25S4.44 8.5 3.75 8.5 2.5 7.94 2.5 7.25 3.06 6 3.75 6zM23 17.5c0-3.038-2.462-5.5-5.5-5.5S12 14.462 12 17.5s2.462 5.5 5.5 5.5 5.5-2.462 5.5-5.5zM18 18l0.001 2.503c0 0.277-0.224 0.5-0.5 0.5s-0.5-0.223-0.5-0.5V18h-2.505c-0.276 0-0.5-0.224-0.5-0.5s0.224-0.5 0.5-0.5H17v-2.5c0-0.277 0.224-0.5 0.5-0.5s0.5 0.223 0.5 0.5V17h2.497c0.276 0 0.5 0.224 0.5 0.5s-0.224 0.5-0.5 0.5H18z" android:fillColor="@color/fluent_default_icon_tint"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<org.joinmastodon.android.ui.views.AutoOrientationLinearLayout | ||
android:orientation="horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginHorizontal="24dp"> | ||
<TextView | ||
android:id="@+id/text" | ||
android:text="@string/sk_list_replies_policy" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:layout_marginEnd="8dp" | ||
android:paddingVertical="8dp" | ||
android:gravity="center_vertical" | ||
android:textColor="?android:textColorPrimary" | ||
android:textSize="16sp" /> | ||
|
||
<Button | ||
android:id="@+id/button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="32dp" | ||
android:layout_weight="0" | ||
android:maxWidth="140dp" | ||
android:background="@drawable/bg_inline_button" | ||
android:elevation="0dp" | ||
android:ellipsize="middle" | ||
android:fontFamily="sans-serif-medium" | ||
android:singleLine="true" | ||
android:stateListAnimator="@null" | ||
android:textColor="?android:textColorPrimary" | ||
android:textSize="16sp" /> | ||
</org.joinmastodon.android.ui.views.AutoOrientationLinearLayout> | ||
|
||
<org.joinmastodon.android.ui.views.TextInputFrameLayout | ||
android:id="@+id/input" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:id="@+id/reply_policy_list" android:title="@string/sk_list_replies_policy_list" /> | ||
<item android:id="@+id/reply_policy_followed" android:title="@string/sk_list_replies_policy_followed" /> | ||
<item android:id="@+id/reply_policy_none" android:title="@string/sk_list_replies_policy_none" /> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:id="@+id/create" | ||
android:title="@string/sk_create" | ||
android:icon="@drawable/ic_fluent_channel_add_24_regular" | ||
android:showAsAction="always" /> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters