From a13dd300dbcca6c8fa4e16ff1d0ec56906da7789 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sat, 27 Jun 2015 17:43:54 +0800 Subject: [PATCH] bug fixes moved settings --- .../activity/support/MediaViewerActivity.java | 29 ++--- .../support/CursorStatusesFragment.java | 1 + .../NetworkUsageSummaryPreferences.java | 20 +--- .../layout_preference_network_usage.xml | 83 ++++++++++++--- .../res/layout/list_item_two_line_checked.xml | 2 + .../res/menu/menu_media_viewer_image_page.xml | 14 ++- .../res/menu/menu_media_viewer_video_page.xml | 16 ++- twidere/src/main/res/values/strings.xml | 4 + .../res/xml/preferences_advanced_network.xml | 90 ++++++++++++++++ .../src/main/res/xml/preferences_content.xml | 40 +++---- .../src/main/res/xml/preferences_network.xml | 100 +++--------------- twidere/src/main/res/xml/settings_headers.xml | 16 +-- 12 files changed, 234 insertions(+), 181 deletions(-) create mode 100644 twidere/src/main/res/xml/preferences_advanced_network.xml diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java index 4a13056a2..7617d8693 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java @@ -35,11 +35,9 @@ import android.support.v4.app.FragmentTransaction; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.Loader; import android.support.v4.util.Pair; -import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.support.v7.app.ActionBar; -import android.support.v7.widget.ShareActionProvider; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; @@ -133,7 +131,7 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements mPagerAdapter = new MediaPagerAdapter(this); mViewPager.setAdapter(mPagerAdapter); mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.element_spacing_normal)); - mViewPager.setOnPageChangeListener(this); + mViewPager.addOnPageChangeListener(this); final Intent intent = getIntent(); final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1); final ParcelableMedia[] media = Utils.newParcelableArray(intent.getParcelableArrayExtra(EXTRA_MEDIA), ParcelableMedia.CREATOR); @@ -427,13 +425,12 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements if (callback.first.isDetached()) return; final Menu menu = callback.second; final boolean hasImage = result.first; - MenuUtils.setMenuItemAvailability(menu, R.id.refresh, !hasImage && !isLoading); - MenuUtils.setMenuItemAvailability(menu, R.id.share, hasImage && !isLoading); - MenuUtils.setMenuItemAvailability(menu, R.id.save, hasImage && !isLoading); + MenuUtils.setMenuItemAvailability(menu, MENU_REFRESH, !hasImage && !isLoading); + MenuUtils.setMenuItemAvailability(menu, MENU_SHARE, hasImage && !isLoading); + MenuUtils.setMenuItemAvailability(menu, MENU_SAVE, hasImage && !isLoading); if (!hasImage) return; - final MenuItem shareItem = menu.findItem(R.id.share); - final ShareActionProvider shareProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem); - shareProvider.setShareIntent(result.second); + final MenuItem shareItem = menu.findItem(MENU_SHARE); + shareItem.setIntent(Intent.createChooser(result.second, callback.first.getString(R.string.share))); } }; checkState.setParams(mImageFile); @@ -445,9 +442,6 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_media_viewer_image_page, menu); - final MenuItem shareItem = menu.findItem(R.id.share); - final ShareActionProvider shareProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem); - shareProvider.setShareHistoryFileName(null); } @@ -889,12 +883,11 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements final Pair linkAndType = mVideoUrlAndType; final boolean isLoading = linkAndType != null && mVideoLoader.isLoading(linkAndType.first); final boolean hasVideo = file != null && file.exists() && linkAndType != null; - MenuUtils.setMenuItemAvailability(menu, R.id.refresh, !hasVideo && !isLoading); - MenuUtils.setMenuItemAvailability(menu, R.id.share, hasVideo && !isLoading); - MenuUtils.setMenuItemAvailability(menu, R.id.save, hasVideo && !isLoading); + MenuUtils.setMenuItemAvailability(menu, MENU_REFRESH, !hasVideo && !isLoading); + MenuUtils.setMenuItemAvailability(menu, MENU_SHARE, hasVideo && !isLoading); + MenuUtils.setMenuItemAvailability(menu, MENU_SAVE, hasVideo && !isLoading); if (!hasVideo) return; - final MenuItem shareItem = menu.findItem(R.id.share); - final ShareActionProvider shareProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem); + final MenuItem shareItem = menu.findItem(MENU_SHARE); final Intent intent = new Intent(Intent.ACTION_SEND); final Uri fileUri = Uri.fromFile(file); intent.setDataAndType(fileUri, linkAndType.second); @@ -905,7 +898,7 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements intent.putExtra(Intent.EXTRA_TEXT, Utils.getStatusShareText(activity, status)); intent.putExtra(Intent.EXTRA_SUBJECT, Utils.getStatusShareSubject(activity, status)); } - shareProvider.setShareIntent(intent); + shareItem.setIntent(Intent.createChooser(intent, getString(R.string.share))); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java index 0e0cbd470..07cf63d45 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java @@ -181,6 +181,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment } protected void reloadStatuses() { + if (getActivity() == null || isDetached()) return; final Bundle args = new Bundle(), fragmentArgs = getArguments(); if (fragmentArgs != null) { args.putAll(fragmentArgs); diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/NetworkUsageSummaryPreferences.java b/twidere/src/main/java/org/mariotaku/twidere/preference/NetworkUsageSummaryPreferences.java index 993de6994..1baf7137b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/NetworkUsageSummaryPreferences.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/NetworkUsageSummaryPreferences.java @@ -30,7 +30,6 @@ import android.view.ViewGroup; import android.widget.TextView; import com.db.chart.model.BarSet; -import com.db.chart.model.ChartSet; import com.db.chart.view.AxisController; import com.db.chart.view.StackBarChartView; import com.desmond.asyncmanager.AsyncManager; @@ -42,7 +41,6 @@ import org.mariotaku.twidere.model.RequestType; import org.mariotaku.twidere.util.MathUtils; import org.mariotaku.twidere.util.Utils; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -51,9 +49,8 @@ import java.util.Date; */ public class NetworkUsageSummaryPreferences extends Preference { - private StackBarChartView mChartView; private NetworkUsageInfo mUsage; - private TextView mTotalUsage; + private TextView mTotalUsage, mTotalUsageSent, mTotalUsageReceived; private TextView mDayUsageMax; private TextView mDayMin, mDayMid, mDayMax; @@ -74,17 +71,14 @@ public class NetworkUsageSummaryPreferences extends Preference { @Override protected View onCreateView(ViewGroup parent) { final View view = super.onCreateView(parent); - mChartView = (StackBarChartView) view.findViewById(R.id.chart); mTotalUsage = (TextView) view.findViewById(R.id.total_usage); + mTotalUsageSent = (TextView) view.findViewById(R.id.total_usage_sent); + mTotalUsageReceived = (TextView) view.findViewById(R.id.total_usage_received); mDayUsageMax = (TextView) view.findViewById(R.id.day_usage_max); mDayMin = (TextView) view.findViewById(R.id.day_min); mDayMid = (TextView) view.findViewById(R.id.day_mid); mDayMax = (TextView) view.findViewById(R.id.day_max); - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); - paint.setColor(0x20000000); - mChartView.setYLabels(AxisController.LabelPosition.NONE); - mChartView.setXLabels(AxisController.LabelPosition.NONE); return view; } @@ -150,13 +144,9 @@ public class NetworkUsageSummaryPreferences extends Preference { mediaSet.setColor(Color.GREEN); usageStatisticsSet.setColor(Color.BLUE); - final ArrayList data = new ArrayList<>(); - data.add(apiSet); - data.add(mediaSet); - data.add(usageStatisticsSet); - mChartView.addData(data); - mChartView.show(); mTotalUsage.setText(Utils.calculateProperSize((usage.getTotalSent() + usage.getTotalReceived()) * 1024)); + mTotalUsageSent.setText(Utils.calculateProperSize(usage.getTotalSent() * 1024)); + mTotalUsageReceived.setText(Utils.calculateProperSize(usage.getTotalReceived() * 1024)); mDayUsageMax.setText(Utils.calculateProperSize((usage.getDayUsageMax()) * 1024)); mDayMin.setText(String.valueOf(usage.getDayMin())); mDayMid.setText(String.valueOf((usage.getDayMin() + usage.getDayMax()) / 2)); diff --git a/twidere/src/main/res/layout/layout_preference_network_usage.xml b/twidere/src/main/res/layout/layout_preference_network_usage.xml index a3c649b11..ede4031e6 100644 --- a/twidere/src/main/res/layout/layout_preference_network_usage.xml +++ b/twidere/src/main/res/layout/layout_preference_network_usage.xml @@ -26,20 +26,79 @@ android:padding="@dimen/element_spacing_normal"> - - - + android:layout_margin="@dimen/element_spacing_large" + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + @@ -63,6 +64,7 @@ android:layout_height="wrap_content" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceSmall" + android:textColor="?android:textColorSecondary" tools:text="text2" /> diff --git a/twidere/src/main/res/menu/menu_media_viewer_image_page.xml b/twidere/src/main/res/menu/menu_media_viewer_image_page.xml index 6d513ca18..86be46cbb 100644 --- a/twidere/src/main/res/menu/menu_media_viewer_image_page.xml +++ b/twidere/src/main/res/menu/menu_media_viewer_image_page.xml @@ -1,5 +1,4 @@ - - + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" /> + app:showAsAction="ifRoom" /> + android:title="@string/save_to_gallery" /> + android:title="@string/open_in_browser" /> \ No newline at end of file diff --git a/twidere/src/main/res/menu/menu_media_viewer_video_page.xml b/twidere/src/main/res/menu/menu_media_viewer_video_page.xml index 10e8ad6d8..4ac187390 100644 --- a/twidere/src/main/res/menu/menu_media_viewer_video_page.xml +++ b/twidere/src/main/res/menu/menu_media_viewer_video_page.xml @@ -1,5 +1,4 @@ - - + xmlns:app="http://schemas.android.com/apk/res-auto"> + android:title="@string/refresh" + app:showAsAction="ifRoom" /> + android:title="@string/share" + app:showAsAction="ifRoom" /> + android:title="@string/save_to_gallery" /> \ 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 31ed81ae7..5c7354827 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -764,4 +764,8 @@ Twidere needs location permission when you send tweet containing location. Scrapyard Crop image + Sent + Received + This month + Media preload \ No newline at end of file diff --git a/twidere/src/main/res/xml/preferences_advanced_network.xml b/twidere/src/main/res/xml/preferences_advanced_network.xml new file mode 100644 index 000000000..805eb31ad --- /dev/null +++ b/twidere/src/main/res/xml/preferences_advanced_network.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/res/xml/preferences_content.xml b/twidere/src/main/res/xml/preferences_content.xml index 33bbd65b1..8cdb2cddb 100644 --- a/twidere/src/main/res/xml/preferences_content.xml +++ b/twidere/src/main/res/xml/preferences_content.xml @@ -4,27 +4,6 @@ android:key="settings_content" android:title="@string/content_and_storage"> - - - - - - - - - - @@ -38,12 +17,6 @@ app:min="10" app:step="5" /> - - + + + + + diff --git a/twidere/src/main/res/xml/preferences_network.xml b/twidere/src/main/res/xml/preferences_network.xml index 805eb31ad..9a042c2da 100644 --- a/twidere/src/main/res/xml/preferences_network.xml +++ b/twidere/src/main/res/xml/preferences_network.xml @@ -1,90 +1,22 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + \ No newline at end of file diff --git a/twidere/src/main/res/xml/settings_headers.xml b/twidere/src/main/res/xml/settings_headers.xml index 28252412c..6f5da7765 100644 --- a/twidere/src/main/res/xml/settings_headers.xml +++ b/twidere/src/main/res/xml/settings_headers.xml @@ -43,6 +43,14 @@ android:name="resid" android:value="@xml/preferences_notifications" /> +
+ +
-
- -