diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/CustomTabsActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/CustomTabsActivity.java index a9f22d133..982549a9f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/CustomTabsActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/CustomTabsActivity.java @@ -19,8 +19,6 @@ package org.mariotaku.twidere.activity; -import static org.mariotaku.twidere.util.CustomTabUtils.getHomeTabs; - import android.app.ActionBar; import android.app.FragmentManager; import android.os.Bundle; @@ -32,50 +30,52 @@ import org.mariotaku.twidere.model.SupportTabSpec; import java.util.ArrayList; import java.util.List; +import static org.mariotaku.twidere.util.CustomTabUtils.getHomeTabs; + public class CustomTabsActivity extends BasePreferenceActivity { - private final List mCustomTabs = new ArrayList(); + private final List mCustomTabs = new ArrayList<>(); - @Override - public void onBackPressed() { - final List tabs = getHomeTabs(this); - setResult(isTabsChanged(tabs) && !tabs.isEmpty() ? RESULT_OK : RESULT_CANCELED); - finish(); - } + @Override + public void onBackPressed() { + final List tabs = getHomeTabs(this); + setResult(isTabsChanged(tabs) && !tabs.isEmpty() ? RESULT_OK : RESULT_CANCELED); + finish(); + } - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - switch (item.getItemId()) { - case MENU_HOME: { - onBackPressed(); - return true; - } - } - return super.onOptionsItemSelected(item); - } + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + switch (item.getItemId()) { + case MENU_HOME: { + onBackPressed(); + return true; + } + } + return super.onOptionsItemSelected(item); + } - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final ActionBar ab = getActionBar(); - if (ab != null) { - ab.setDisplayHomeAsUpEnabled(true); - } - final FragmentManager fm = getFragmentManager(); - fm.beginTransaction().replace(android.R.id.content, new CustomTabsFragment()).commit(); - initTabs(); - } + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final ActionBar ab = getActionBar(); + if (ab != null) { + ab.setDisplayHomeAsUpEnabled(true); + } + final FragmentManager fm = getFragmentManager(); + fm.beginTransaction().replace(android.R.id.content, new CustomTabsFragment()).commit(); + initTabs(); + } - private void initTabs() { - mCustomTabs.clear(); - mCustomTabs.addAll(getHomeTabs(this)); - } + private void initTabs() { + mCustomTabs.clear(); + mCustomTabs.addAll(getHomeTabs(this)); + } - private boolean isTabsChanged(final List tabs) { - if (mCustomTabs.size() != tabs.size()) return true; - for (int i = 0, size = mCustomTabs.size(); i < size; i++) { - if (!mCustomTabs.get(i).equals(tabs.get(i))) return true; - } - return false; - } + private boolean isTabsChanged(final List tabs) { + if (mCustomTabs.size() != tabs.size()) return true; + for (int i = 0, size = mCustomTabs.size(); i < size; i++) { + if (!mCustomTabs.get(i).equals(tabs.get(i))) return true; + } + return false; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java index cdb77ff98..7aca10823 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/CustomTabsFragment.java @@ -33,6 +33,7 @@ import android.graphics.Paint; import android.graphics.PorterDuff.Mode; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.support.v4.content.res.ResourcesCompat; import android.text.TextUtils; import android.view.ActionMode; import android.view.LayoutInflater; @@ -44,6 +45,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AbsListView.MultiChoiceModeListener; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import com.mobeta.android.dslv.DragSortListView; @@ -76,15 +79,17 @@ import static org.mariotaku.twidere.util.CustomTabUtils.isTabAdded; import static org.mariotaku.twidere.util.CustomTabUtils.isTabTypeValid; import static org.mariotaku.twidere.util.Utils.getAccountIds; -public class CustomTabsFragment extends BaseListFragment implements LoaderCallbacks, - MultiChoiceModeListener, DropListener { +public class CustomTabsFragment extends BaseFragment implements LoaderCallbacks, + MultiChoiceModeListener, DropListener, OnItemClickListener { private ContentResolver mResolver; - private DragSortListView mListView; - private CustomTabsAdapter mAdapter; + private DragSortListView mListView; + private View mEmptyView; + private View mListContainer, mProgressContainer; + @Override public void drop(final int from, final int to) { mAdapter.drop(from, to); @@ -112,19 +117,49 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); mResolver = getContentResolver(); - final Activity activity = getActivity(); - final Context context = getView().getContext(); + final View view = getView(); + if (view == null) throw new AssertionError(); + final Context context = view.getContext(); mAdapter = new CustomTabsAdapter(context); - setListAdapter(mAdapter); - setEmptyText(getString(R.string.no_tab_hint)); - mListView = (DragSortListView) getListView(); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setMultiChoiceModeListener(this); mListView.setDropListener(this); + mListView.setOnItemClickListener(this); + mListView.setAdapter(mAdapter); + mListView.setEmptyView(mEmptyView); getLoaderManager().initLoader(0, null, this); setListShown(false); } + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + final Cursor c = mAdapter.getCursor(); + c.moveToPosition(mAdapter.getCursorPosition(position)); + final Intent intent = new Intent(INTENT_ACTION_EDIT_TAB); + intent.setClass(getActivity(), CustomTabEditorActivity.class); + intent.putExtra(EXTRA_ID, c.getLong(c.getColumnIndex(Tabs._ID))); + intent.putExtra(EXTRA_TYPE, c.getString(c.getColumnIndex(Tabs.TYPE))); + intent.putExtra(EXTRA_NAME, c.getString(c.getColumnIndex(Tabs.NAME))); + intent.putExtra(EXTRA_ICON, c.getString(c.getColumnIndex(Tabs.ICON))); + intent.putExtra(EXTRA_EXTRAS, c.getString(c.getColumnIndex(Tabs.EXTRAS))); + startActivityForResult(intent, REQUEST_EDIT_TAB); + } + + private void setListShown(boolean shown) { + mListContainer.setVisibility(shown ? View.VISIBLE : View.GONE); + mProgressContainer.setVisibility(shown ? View.GONE : View.VISIBLE); + } + + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + mListView = (DragSortListView) view.findViewById(android.R.id.list); + mEmptyView = view.findViewById(android.R.id.empty); + mListContainer = view.findViewById(R.id.list_container); + mProgressContainer = view.findViewById(R.id.progress_container); + } + @Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { @@ -174,12 +209,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - final View view = inflater.inflate(android.R.layout.list_content, null, false); - final ListView originalList = (ListView) view.findViewById(android.R.id.list); - final ViewGroup listContainer = (ViewGroup) originalList.getParent(); - listContainer.removeView(originalList); - inflater.inflate(R.layout.fragment_custom_tabs, listContainer, true); - return view; + return inflater.inflate(R.layout.fragment_custom_tabs, container, false); } @Override @@ -193,19 +223,6 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba updateTitle(mode); } - @Override - public void onListItemClick(final ListView l, final View v, final int position, final long id) { - final Cursor c = mAdapter.getCursor(); - c.moveToPosition(mAdapter.getCursorPosition(position)); - final Intent intent = new Intent(INTENT_ACTION_EDIT_TAB); - intent.setClass(getActivity(), CustomTabEditorActivity.class); - intent.putExtra(EXTRA_ID, c.getLong(c.getColumnIndex(Tabs._ID))); - intent.putExtra(EXTRA_TYPE, c.getString(c.getColumnIndex(Tabs.TYPE))); - intent.putExtra(EXTRA_NAME, c.getString(c.getColumnIndex(Tabs.NAME))); - intent.putExtra(EXTRA_ICON, c.getString(c.getColumnIndex(Tabs.ICON))); - intent.putExtra(EXTRA_EXTRAS, c.getString(c.getColumnIndex(Tabs.EXTRAS))); - startActivityForResult(intent, REQUEST_EDIT_TAB); - } @Override public void onLoaderReset(final Loader loader) { @@ -246,7 +263,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba final SubMenu subMenu = itemAdd.getSubMenu(); subMenu.clear(); final HashMap map = getConfiguraionMap(); - final List> tabs = new ArrayList>( + final List> tabs = new ArrayList<>( map.entrySet()); Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON); for (final Entry entry : tabs) { @@ -268,7 +285,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba && account_ids.length == 0; subItem.setVisible(!shouldDisable); subItem.setEnabled(!shouldDisable); - final Drawable icon = res.getDrawable(conf.getDefaultIcon()); + final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null); subItem.setIcon(icon); subItem.setIntent(intent); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java index 1edd644f6..5c700a4b4 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java @@ -256,6 +256,7 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3 + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image); itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0); + itemDecoration.setDecorationEndOffset(1); mRecyclerView.addItemDecoration(itemDecoration); getLoaderManager().initLoader(0, null, this); setListShown(false); diff --git a/twidere/src/main/res/layout/fragment_custom_tabs.xml b/twidere/src/main/res/layout/fragment_custom_tabs.xml index 4f8677ff7..f61a09959 100644 --- a/twidere/src/main/res/layout/fragment_custom_tabs.xml +++ b/twidere/src/main/res/layout/fragment_custom_tabs.xml @@ -17,24 +17,73 @@ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . --> - - + xmlns:tools="http://schemas.android.com/tools"> + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 47e5f7d69..37f9a61a0 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -731,5 +731,6 @@ Uucky Lee Import/Export settings Twidere took part in some research project, join these projects will make Twidere and some other application better. + No tab \ No newline at end of file