mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2024-12-12 08:36:14 +01:00
added empty view for tabs list
This commit is contained in:
parent
27e11c8085
commit
0c1bbaa04a
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
package org.mariotaku.twidere.activity;
|
package org.mariotaku.twidere.activity;
|
||||||
|
|
||||||
import static org.mariotaku.twidere.util.CustomTabUtils.getHomeTabs;
|
|
||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -32,50 +30,52 @@ import org.mariotaku.twidere.model.SupportTabSpec;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mariotaku.twidere.util.CustomTabUtils.getHomeTabs;
|
||||||
|
|
||||||
public class CustomTabsActivity extends BasePreferenceActivity {
|
public class CustomTabsActivity extends BasePreferenceActivity {
|
||||||
|
|
||||||
private final List<SupportTabSpec> mCustomTabs = new ArrayList<SupportTabSpec>();
|
private final List<SupportTabSpec> mCustomTabs = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
final List<SupportTabSpec> tabs = getHomeTabs(this);
|
final List<SupportTabSpec> tabs = getHomeTabs(this);
|
||||||
setResult(isTabsChanged(tabs) && !tabs.isEmpty() ? RESULT_OK : RESULT_CANCELED);
|
setResult(isTabsChanged(tabs) && !tabs.isEmpty() ? RESULT_OK : RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_HOME: {
|
case MENU_HOME: {
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
final ActionBar ab = getActionBar();
|
final ActionBar ab = getActionBar();
|
||||||
if (ab != null) {
|
if (ab != null) {
|
||||||
ab.setDisplayHomeAsUpEnabled(true);
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
final FragmentManager fm = getFragmentManager();
|
final FragmentManager fm = getFragmentManager();
|
||||||
fm.beginTransaction().replace(android.R.id.content, new CustomTabsFragment()).commit();
|
fm.beginTransaction().replace(android.R.id.content, new CustomTabsFragment()).commit();
|
||||||
initTabs();
|
initTabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTabs() {
|
private void initTabs() {
|
||||||
mCustomTabs.clear();
|
mCustomTabs.clear();
|
||||||
mCustomTabs.addAll(getHomeTabs(this));
|
mCustomTabs.addAll(getHomeTabs(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTabsChanged(final List<SupportTabSpec> tabs) {
|
private boolean isTabsChanged(final List<SupportTabSpec> tabs) {
|
||||||
if (mCustomTabs.size() != tabs.size()) return true;
|
if (mCustomTabs.size() != tabs.size()) return true;
|
||||||
for (int i = 0, size = mCustomTabs.size(); i < size; i++) {
|
for (int i = 0, size = mCustomTabs.size(); i < size; i++) {
|
||||||
if (!mCustomTabs.get(i).equals(tabs.get(i))) return true;
|
if (!mCustomTabs.get(i).equals(tabs.get(i))) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.PorterDuff.Mode;
|
import android.graphics.PorterDuff.Mode;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.content.res.ResourcesCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -44,6 +45,8 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.mobeta.android.dslv.DragSortListView;
|
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.CustomTabUtils.isTabTypeValid;
|
||||||
import static org.mariotaku.twidere.util.Utils.getAccountIds;
|
import static org.mariotaku.twidere.util.Utils.getAccountIds;
|
||||||
|
|
||||||
public class CustomTabsFragment extends BaseListFragment implements LoaderCallbacks<Cursor>,
|
public class CustomTabsFragment extends BaseFragment implements LoaderCallbacks<Cursor>,
|
||||||
MultiChoiceModeListener, DropListener {
|
MultiChoiceModeListener, DropListener, OnItemClickListener {
|
||||||
|
|
||||||
private ContentResolver mResolver;
|
private ContentResolver mResolver;
|
||||||
|
|
||||||
private DragSortListView mListView;
|
|
||||||
|
|
||||||
private CustomTabsAdapter mAdapter;
|
private CustomTabsAdapter mAdapter;
|
||||||
|
|
||||||
|
private DragSortListView mListView;
|
||||||
|
private View mEmptyView;
|
||||||
|
private View mListContainer, mProgressContainer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(final int from, final int to) {
|
public void drop(final int from, final int to) {
|
||||||
mAdapter.drop(from, to);
|
mAdapter.drop(from, to);
|
||||||
@ -112,19 +117,49 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba
|
|||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
mResolver = getContentResolver();
|
mResolver = getContentResolver();
|
||||||
final Activity activity = getActivity();
|
final View view = getView();
|
||||||
final Context context = getView().getContext();
|
if (view == null) throw new AssertionError();
|
||||||
|
final Context context = view.getContext();
|
||||||
mAdapter = new CustomTabsAdapter(context);
|
mAdapter = new CustomTabsAdapter(context);
|
||||||
setListAdapter(mAdapter);
|
|
||||||
setEmptyText(getString(R.string.no_tab_hint));
|
|
||||||
mListView = (DragSortListView) getListView();
|
|
||||||
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
|
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
|
||||||
mListView.setMultiChoiceModeListener(this);
|
mListView.setMultiChoiceModeListener(this);
|
||||||
mListView.setDropListener(this);
|
mListView.setDropListener(this);
|
||||||
|
mListView.setOnItemClickListener(this);
|
||||||
|
mListView.setAdapter(mAdapter);
|
||||||
|
mListView.setEmptyView(mEmptyView);
|
||||||
getLoaderManager().initLoader(0, null, this);
|
getLoaderManager().initLoader(0, null, this);
|
||||||
setListShown(false);
|
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
|
@Override
|
||||||
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
@ -174,12 +209,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||||
final View view = inflater.inflate(android.R.layout.list_content, null, false);
|
return inflater.inflate(R.layout.fragment_custom_tabs, container, 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -193,19 +223,6 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba
|
|||||||
updateTitle(mode);
|
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
|
@Override
|
||||||
public void onLoaderReset(final Loader<Cursor> loader) {
|
public void onLoaderReset(final Loader<Cursor> loader) {
|
||||||
@ -246,7 +263,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba
|
|||||||
final SubMenu subMenu = itemAdd.getSubMenu();
|
final SubMenu subMenu = itemAdd.getSubMenu();
|
||||||
subMenu.clear();
|
subMenu.clear();
|
||||||
final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap();
|
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());
|
map.entrySet());
|
||||||
Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON);
|
Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON);
|
||||||
for (final Entry<String, CustomTabConfiguration> entry : tabs) {
|
for (final Entry<String, CustomTabConfiguration> entry : tabs) {
|
||||||
@ -268,7 +285,7 @@ public class CustomTabsFragment extends BaseListFragment implements LoaderCallba
|
|||||||
&& account_ids.length == 0;
|
&& account_ids.length == 0;
|
||||||
subItem.setVisible(!shouldDisable);
|
subItem.setVisible(!shouldDisable);
|
||||||
subItem.setEnabled(!shouldDisable);
|
subItem.setEnabled(!shouldDisable);
|
||||||
final Drawable icon = res.getDrawable(conf.getDefaultIcon());
|
final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null);
|
||||||
subItem.setIcon(icon);
|
subItem.setIcon(icon);
|
||||||
subItem.setIntent(intent);
|
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
|
final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3
|
||||||
+ res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
|
+ res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
|
||||||
itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
|
itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
|
||||||
|
itemDecoration.setDecorationEndOffset(1);
|
||||||
mRecyclerView.addItemDecoration(itemDecoration);
|
mRecyclerView.addItemDecoration(itemDecoration);
|
||||||
getLoaderManager().initLoader(0, null, this);
|
getLoaderManager().initLoader(0, null, this);
|
||||||
setListShown(false);
|
setListShown(false);
|
||||||
|
@ -17,24 +17,73 @@
|
|||||||
~ You should have received a copy of the GNU General Public License
|
~ You should have received a copy of the GNU General Public License
|
||||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
|
<FrameLayout
|
||||||
<com.mobeta.android.dslv.DragSortListView
|
|
||||||
android:id="@android:id/list"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:collapsed_height="2dp"
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
app:drag_enabled="true"
|
|
||||||
app:drag_handle_id="@+id/drag_handle"
|
|
||||||
app:drag_scroll_start="0.33"
|
<FrameLayout
|
||||||
app:float_alpha="0.6"
|
android:layout_width="match_parent"
|
||||||
app:float_background_color="@android:color/transparent"
|
android:layout_height="match_parent"
|
||||||
app:max_drag_scroll_speed="0.5"
|
android:id="@+id/list_container">
|
||||||
app:remove_enabled="false"
|
|
||||||
app:slide_shuffle_speed="0.3"
|
<com.mobeta.android.dslv.DragSortListView
|
||||||
app:sort_enabled="true"
|
android:id="@android:id/list"
|
||||||
app:track_drag_sort="true"
|
android:layout_width="match_parent"
|
||||||
app:use_default_controller="true"
|
android:layout_height="match_parent"
|
||||||
tools:context=".fragment.CustomTabsFragment"/>
|
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="designer_name">Uucky Lee</string>
|
||||||
<string name="import_export_settings">Import/Export settings</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="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>
|
</resources>
|
Loading…
Reference in New Issue
Block a user