added empty view for tabs list
This commit is contained in:
parent
27e11c8085
commit
0c1bbaa04a
|
@ -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<SupportTabSpec> mCustomTabs = new ArrayList<SupportTabSpec>();
|
||||
private final List<SupportTabSpec> mCustomTabs = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final List<SupportTabSpec> tabs = getHomeTabs(this);
|
||||
setResult(isTabsChanged(tabs) && !tabs.isEmpty() ? RESULT_OK : RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final List<SupportTabSpec> 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<SupportTabSpec> 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<SupportTabSpec> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Cursor>,
|
||||
MultiChoiceModeListener, DropListener {
|
||||
public class CustomTabsFragment extends BaseFragment implements LoaderCallbacks<Cursor>,
|
||||
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<Cursor> loader) {
|
||||
|
@ -246,7 +263,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba
|
|||
final SubMenu subMenu = itemAdd.getSubMenu();
|
||||
subMenu.clear();
|
||||
final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap();
|
||||
final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<Entry<String, CustomTabConfiguration>>(
|
||||
final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<>(
|
||||
map.entrySet());
|
||||
Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON);
|
||||
for (final Entry<String, CustomTabConfiguration> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -17,24 +17,73 @@
|
|||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
android:id="@android:id/list"
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
android:layout_height="match_parent"
|
||||
app:collapsed_height="2dp"
|
||||
app:drag_enabled="true"
|
||||
app:drag_handle_id="@+id/drag_handle"
|
||||
app:drag_scroll_start="0.33"
|
||||
app:float_alpha="0.6"
|
||||
app:float_background_color="@android:color/transparent"
|
||||
app:max_drag_scroll_speed="0.5"
|
||||
app:remove_enabled="false"
|
||||
app:slide_shuffle_speed="0.3"
|
||||
app:sort_enabled="true"
|
||||
app:track_drag_sort="true"
|
||||
app:use_default_controller="true"
|
||||
tools:context=".fragment.CustomTabsFragment"/>
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/list_container">
|
||||
|
||||
<com.mobeta.android.dslv.DragSortListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:collapsed_height="2dp"
|
||||
tools:visibility="gone"
|
||||
app:drag_enabled="true"
|
||||
app:drag_handle_id="@+id/drag_handle"
|
||||
app:drag_scroll_start="0.33"
|
||||
app:float_alpha="0.6"
|
||||
app:float_background_color="@android:color/transparent"
|
||||
app:max_drag_scroll_speed="0.5"
|
||||
app:remove_enabled="false"
|
||||
app:slide_shuffle_speed="0.3"
|
||||
app:sort_enabled="true"
|
||||
app:track_drag_sort="true"
|
||||
app:use_default_controller="true"
|
||||
tools:context=".fragment.CustomTabsFragment"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
tools:visibility="visible">
|
||||
|
||||
<org.mariotaku.twidere.view.ActionIconView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:color="?android:textColorSecondary"
|
||||
android:src="@drawable/ic_info_tab"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="@dimen/element_spacing_normal"
|
||||
android:gravity="center"
|
||||
android:text="@string/no_tab"
|
||||
android:textAppearance="?android:textAppearanceMedium"/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/progress_container">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@android:id/progress"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
|
@ -731,5 +731,6 @@
|
|||
<string name="designer_name">Uucky Lee</string>
|
||||
<string name="import_export_settings">Import/Export settings</string>
|
||||
<string name="usage_statistics_header_summary">Twidere took part in some research project, join these projects will make Twidere and some other application better.</string>
|
||||
<string name="no_tab">No tab</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue