mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-15 11:10:38 +01:00
fixed #642
This commit is contained in:
parent
9c999c5a8b
commit
84da183021
@ -0,0 +1,92 @@
|
||||
package org.mariotaku.twidere.model.tab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.BoolRes;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/11/28.
|
||||
*/
|
||||
|
||||
public abstract class BooleanHolder implements Parcelable {
|
||||
|
||||
public abstract boolean createBoolean(Context context);
|
||||
|
||||
public static BooleanHolder resource(@BoolRes int resourceId) {
|
||||
return new Resource(resourceId);
|
||||
}
|
||||
|
||||
public static BooleanHolder constant(boolean value) {
|
||||
return new Constant(value);
|
||||
}
|
||||
|
||||
private static class Constant extends BooleanHolder implements Parcelable {
|
||||
|
||||
private final boolean constant;
|
||||
|
||||
private Constant(boolean constant) {
|
||||
this.constant = constant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createBoolean(Context context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeByte((byte) (constant ? 1 : 0));
|
||||
}
|
||||
|
||||
public static final Creator<Constant> CREATOR = new Creator<Constant>() {
|
||||
public Constant createFromParcel(Parcel source) {
|
||||
return new Constant(source.readByte() == 1);
|
||||
}
|
||||
|
||||
public Constant[] newArray(int size) {
|
||||
return new Constant[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class Resource extends BooleanHolder implements Parcelable {
|
||||
|
||||
@BoolRes
|
||||
private final int resourceId;
|
||||
|
||||
Resource(@BoolRes int resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createBoolean(Context context) {
|
||||
return context.getResources().getBoolean(resourceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(resourceId);
|
||||
}
|
||||
|
||||
public static final Creator<Resource> CREATOR = new Creator<Resource>() {
|
||||
public Resource createFromParcel(Parcel source) {
|
||||
return new Resource(source.readInt());
|
||||
}
|
||||
|
||||
public Resource[] newArray(int size) {
|
||||
return new Resource[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -19,9 +19,10 @@ public abstract class StringHolder implements Parcelable {
|
||||
|
||||
private static class Resource extends StringHolder implements Parcelable {
|
||||
|
||||
@StringRes
|
||||
private final int resourceId;
|
||||
|
||||
Resource(int resourceId) {
|
||||
Resource(@StringRes int resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
|
@ -8,16 +8,12 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.annotation.CustomTabType;
|
||||
import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.Tab;
|
||||
import org.mariotaku.twidere.model.tab.impl.DMTabConfiguration;
|
||||
import org.mariotaku.twidere.model.tab.impl.FavoriteTimelineTabConfiguration;
|
||||
@ -139,7 +135,9 @@ public abstract class TabConfiguration {
|
||||
private StringHolder headerTitle;
|
||||
private int position;
|
||||
private boolean mutable;
|
||||
|
||||
private Context context;
|
||||
private View view;
|
||||
|
||||
protected ExtraConfiguration(String key) {
|
||||
this.key = key;
|
||||
@ -219,100 +217,21 @@ public abstract class TabConfiguration {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void onViewCreated(@NonNull Context context, @NonNull View view, @NonNull TabEditorDialogFragment fragment) {
|
||||
public View getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
public void onViewCreated(@NonNull Context context, @NonNull View view, @NonNull TabEditorDialogFragment fragment) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class BooleanExtraConfiguration extends ExtraConfiguration {
|
||||
public void onAccountSelectionChanged(@Nullable AccountDetails account) {
|
||||
|
||||
private final boolean def;
|
||||
private CheckBox checkBox;
|
||||
|
||||
public BooleanExtraConfiguration(String key, boolean def) {
|
||||
super(key);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateView(Context context, ViewGroup parent) {
|
||||
return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_checkbox, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull Context context, @NonNull View view, @NonNull TabEditorDialogFragment fragment) {
|
||||
final TextView titleView = (TextView) view.findViewById(android.R.id.title);
|
||||
titleView.setText(getTitle().createString(context));
|
||||
|
||||
checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
|
||||
checkBox.setVisibility(View.VISIBLE);
|
||||
checkBox.setChecked(def);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkBox.toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setValue(boolean value) {
|
||||
checkBox.setChecked(value);
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return checkBox.isChecked();
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringExtraConfiguration extends ExtraConfiguration {
|
||||
|
||||
private final String def;
|
||||
private int maxLines;
|
||||
|
||||
private EditText editText;
|
||||
|
||||
public StringExtraConfiguration(String key, String def) {
|
||||
super(key);
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateView(Context context, ViewGroup parent) {
|
||||
return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_text, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull Context context, @NonNull View view, @NonNull final TabEditorDialogFragment fragment) {
|
||||
editText = (EditText) view.findViewById(R.id.editText);
|
||||
editText.setHint(getTitle().createString(context));
|
||||
editText.setText(def);
|
||||
}
|
||||
|
||||
public StringExtraConfiguration maxLines(int maxLines) {
|
||||
setMaxLines(maxLines);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxLines(int maxLines) {
|
||||
this.maxLines = maxLines;
|
||||
}
|
||||
|
||||
public int getMaxLines() {
|
||||
return maxLines;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return editText.getText().toString();
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
editText.setText(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.mariotaku.twidere.model.Tab;
|
||||
import org.mariotaku.twidere.model.tab.DrawableHolder;
|
||||
import org.mariotaku.twidere.model.tab.StringHolder;
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration;
|
||||
import org.mariotaku.twidere.model.tab.conf.BooleanExtraConfiguration;
|
||||
import org.mariotaku.twidere.model.tab.extra.HomeTabExtras;
|
||||
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_HIDE_QUOTES;
|
||||
|
@ -1,17 +1,28 @@
|
||||
package org.mariotaku.twidere.model.tab.impl;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.extension.model.AccountDetailsExtensionsKt;
|
||||
import org.mariotaku.twidere.fragment.InteractionsTimelineFragment;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.Tab;
|
||||
import org.mariotaku.twidere.model.tab.BooleanHolder;
|
||||
import org.mariotaku.twidere.model.tab.DrawableHolder;
|
||||
import org.mariotaku.twidere.model.tab.StringHolder;
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration;
|
||||
import org.mariotaku.twidere.model.tab.conf.BooleanExtraConfiguration;
|
||||
import org.mariotaku.twidere.model.tab.extra.InteractionsTabExtras;
|
||||
import org.mariotaku.twidere.model.util.AccountUtils;
|
||||
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_MENTIONS_ONLY;
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_MY_FOLLOWING_ONLY;
|
||||
@ -44,7 +55,7 @@ public class InteractionsTabConfiguration extends TabConfiguration {
|
||||
public ExtraConfiguration[] getExtraConfigurations(Context context) {
|
||||
return new ExtraConfiguration[]{
|
||||
new BooleanExtraConfiguration(EXTRA_MY_FOLLOWING_ONLY, false).title(R.string.following_only).mutable(true),
|
||||
new BooleanExtraConfiguration(EXTRA_MENTIONS_ONLY, false).title(R.string.mentions_only).mutable(true),
|
||||
new MentionsOnlyExtraConfiguration(EXTRA_MENTIONS_ONLY).title(R.string.mentions_only).mutable(true),
|
||||
};
|
||||
}
|
||||
|
||||
@ -87,4 +98,76 @@ public class InteractionsTabConfiguration extends TabConfiguration {
|
||||
public Class<? extends Fragment> getFragmentClass() {
|
||||
return InteractionsTimelineFragment.class;
|
||||
}
|
||||
|
||||
private static class MentionsOnlyExtraConfiguration extends BooleanExtraConfiguration {
|
||||
|
||||
private boolean valueBackup;
|
||||
|
||||
MentionsOnlyExtraConfiguration(@NotNull String key) {
|
||||
super(key, new HasOfficialBooleanHolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountSelectionChanged(@Nullable AccountDetails account) {
|
||||
final boolean hasOfficial;
|
||||
if (account == null || account.dummy) {
|
||||
hasOfficial = AccountUtils.hasOfficialKeyAccount(getContext());
|
||||
} else {
|
||||
hasOfficial = AccountDetailsExtensionsKt.isOfficial(account, getContext());
|
||||
}
|
||||
((HasOfficialBooleanHolder) getDefaultValue()).hasOfficial = hasOfficial;
|
||||
final View view = getView();
|
||||
final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
|
||||
final TextView titleView = (TextView) view.findViewById(android.R.id.title);
|
||||
view.setEnabled(hasOfficial);
|
||||
titleView.setEnabled(hasOfficial);
|
||||
checkBox.setEnabled(hasOfficial);
|
||||
if (hasOfficial) {
|
||||
checkBox.setChecked(valueBackup);
|
||||
} else {
|
||||
valueBackup = checkBox.isChecked();
|
||||
checkBox.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getValue() {
|
||||
if (((HasOfficialBooleanHolder) getDefaultValue()).hasOfficial) {
|
||||
return super.getValue();
|
||||
}
|
||||
return valueBackup;
|
||||
}
|
||||
|
||||
private static class HasOfficialBooleanHolder extends BooleanHolder implements Parcelable {
|
||||
|
||||
private boolean hasOfficial;
|
||||
|
||||
@Override
|
||||
public boolean createBoolean(Context context) {
|
||||
return hasOfficial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
}
|
||||
|
||||
public static final Creator<HasOfficialBooleanHolder> CREATOR = new Creator<HasOfficialBooleanHolder>() {
|
||||
@Override
|
||||
public HasOfficialBooleanHolder createFromParcel(Parcel in) {
|
||||
return new HasOfficialBooleanHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HasOfficialBooleanHolder[] newArray(int size) {
|
||||
return new HasOfficialBooleanHolder[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.mariotaku.twidere.model.tab.DrawableHolder;
|
||||
import org.mariotaku.twidere.model.tab.StringHolder;
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration;
|
||||
import org.mariotaku.twidere.model.tab.argument.TextQueryArguments;
|
||||
import org.mariotaku.twidere.model.tab.conf.StringExtraConfiguration;
|
||||
|
||||
import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_QUERY;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package org.mariotaku.twidere.model.util;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
@ -10,6 +11,7 @@ import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.annotation.AccountType;
|
||||
import org.mariotaku.twidere.annotation.AuthTypeInt;
|
||||
import org.mariotaku.twidere.extension.AccountExtensionsKt;
|
||||
import org.mariotaku.twidere.extension.model.AccountDetailsExtensionsKt;
|
||||
import org.mariotaku.twidere.model.AccountDetails;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.account.cred.Credentials;
|
||||
@ -93,6 +95,15 @@ public class AccountUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasOfficialKeyAccount(Context context) {
|
||||
for (AccountDetails details : getAllAccountDetails(AccountManager.get(context))) {
|
||||
if (AccountDetailsExtensionsKt.isOfficial(details, context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getAccountTypeIcon(@Nullable String accountType) {
|
||||
if (accountType == null) return R.drawable.ic_account_logo_twitter;
|
||||
switch (accountType) {
|
||||
|
@ -43,6 +43,7 @@ import android.widget.AdapterView.OnItemClickListener
|
||||
import com.afollestad.appthemeengine.ATEActivity
|
||||
import com.afollestad.appthemeengine.Config
|
||||
import com.mobeta.android.dslv.SimpleDragSortCursorAdapter
|
||||
import kotlinx.android.synthetic.main.layout_actionbar_message_user_picker.view.*
|
||||
import kotlinx.android.synthetic.main.layout_draggable_list_with_empty_view.*
|
||||
import kotlinx.android.synthetic.main.list_item_section_header.view.*
|
||||
import org.mariotaku.ktextension.Bundle
|
||||
@ -368,6 +369,24 @@ class CustomTabsFragment : BaseSupportFragment(), LoaderCallbacks<Cursor?>, Mult
|
||||
extraConfigContainer.addView(view)
|
||||
}
|
||||
|
||||
accountSpinner.onItemSelectedListener = object :AdapterView.OnItemSelectedListener {
|
||||
|
||||
private fun updateExtraTabs(account: AccountDetails?) {
|
||||
extraConfigurations.forEach {
|
||||
it.onAccountSelectionChanged(account)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, pos: Int, id: Long) {
|
||||
val account = parent.selectedItem as? AccountDetails
|
||||
updateExtraTabs(account)
|
||||
}
|
||||
|
||||
override fun onNothingSelected(view: AdapterView<*>) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
positiveButton.setOnClickListener {
|
||||
tab.name = tabName.text.toString()
|
||||
tab.icon = (iconSpinner.selectedItem as DrawableHolder).persistentKey
|
||||
|
@ -0,0 +1,43 @@
|
||||
package org.mariotaku.twidere.model.tab.conf
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.TextView
|
||||
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.fragment.CustomTabsFragment
|
||||
import org.mariotaku.twidere.model.tab.BooleanHolder
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/5.
|
||||
*/
|
||||
open class BooleanExtraConfiguration(key: String, val defaultValue: BooleanHolder) : TabConfiguration.ExtraConfiguration(key) {
|
||||
open var value: Boolean
|
||||
get() = checkBox.isChecked
|
||||
set(value) {
|
||||
checkBox.isChecked = value
|
||||
}
|
||||
|
||||
private lateinit var checkBox: CheckBox
|
||||
|
||||
constructor(key: String, def: Boolean) : this(key, BooleanHolder.constant(def))
|
||||
|
||||
override fun onCreateView(context: Context, parent: ViewGroup): View {
|
||||
return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_checkbox, parent, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(context: Context, view: View, fragment: CustomTabsFragment.TabEditorDialogFragment) {
|
||||
super.onViewCreated(context, view, fragment)
|
||||
val titleView = view.findViewById(android.R.id.title) as TextView
|
||||
titleView.text = title.createString(context)
|
||||
|
||||
checkBox = view.findViewById(android.R.id.checkbox) as CheckBox
|
||||
checkBox.visibility = View.VISIBLE
|
||||
checkBox.isChecked = defaultValue.createBoolean(context)
|
||||
view.setOnClickListener { checkBox.toggle() }
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.mariotaku.twidere.model.tab.conf
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.fragment.CustomTabsFragment
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/5.
|
||||
*/
|
||||
class StringExtraConfiguration(key: String, private val def: String) : TabConfiguration.ExtraConfiguration(key) {
|
||||
var maxLines: Int = 0
|
||||
|
||||
var value: String
|
||||
get() = editText.text.toString()
|
||||
set(value) = editText.setText(value)
|
||||
|
||||
private lateinit var editText: EditText
|
||||
|
||||
override fun onCreateView(context: Context, parent: ViewGroup): View {
|
||||
return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_text, parent, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(context: Context, view: View, fragment: CustomTabsFragment.TabEditorDialogFragment) {
|
||||
super.onViewCreated(context, view, fragment)
|
||||
editText = view.findViewById(R.id.editText) as EditText
|
||||
editText.hint = title.createString(context)
|
||||
editText.setText(def)
|
||||
}
|
||||
|
||||
fun maxLines(maxLines: Int): StringExtraConfiguration {
|
||||
this.maxLines = maxLines
|
||||
return this
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@ class UserExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration(
|
||||
}
|
||||
|
||||
override fun onViewCreated(context: Context, view: View, fragment: TabEditorDialogFragment) {
|
||||
super.onViewCreated(context, view, fragment)
|
||||
view.setOnClickListener {
|
||||
val account = fragment.account ?: return@setOnClickListener
|
||||
val intent = Intent(INTENT_ACTION_SELECT_USER)
|
||||
|
@ -40,6 +40,7 @@ class UserListExtraConfiguration(key: String) : TabConfiguration.ExtraConfigurat
|
||||
}
|
||||
|
||||
override fun onViewCreated(context: Context, view: View, fragment: TabEditorDialogFragment) {
|
||||
super.onViewCreated(context, view, fragment)
|
||||
view.setOnClickListener {
|
||||
val account = fragment.account ?: return@setOnClickListener
|
||||
val intent = Intent(INTENT_ACTION_SELECT_USER_LIST)
|
||||
|
Loading…
x
Reference in New Issue
Block a user