From 4a19c78fa5fe8d44a10b15adf7158439a5dd56ec Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Fri, 24 Aug 2018 11:54:41 +0200 Subject: [PATCH] despaget certain parts of the new design --- .../java/org/schabi/newpipe/BaseFragment.java | 21 +++++++- .../java/org/schabi/newpipe/MainActivity.java | 7 --- .../newpipe/fragments/BaseStateFragment.java | 6 --- .../newpipe/fragments/BlankFragment.java | 18 ++----- .../list/channel/ChannelFragment.java | 10 +--- .../fragments/list/kiosk/KioskFragment.java | 17 ------ .../local/bookmark/BookmarkFragment.java | 3 -- .../newpipe/local/feed/FeedFragment.java | 53 +++++++++---------- .../history/StatisticsPlaylistFragment.java | 8 +-- .../subscription/SubscriptionFragment.java | 20 +++++-- .../schabi/newpipe/util/ServiceHelper.java | 1 - 11 files changed, 70 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index 07e40cfad..b125ab02f 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -12,7 +12,10 @@ import android.view.View; import com.nostra13.universalimageloader.core.ImageLoader; import com.squareup.leakcanary.RefWatcher; +import org.schabi.newpipe.report.UserAction; + import icepick.Icepick; +import icepick.State; public abstract class BaseFragment extends Fragment { protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()); @@ -21,6 +24,15 @@ public abstract class BaseFragment extends Fragment { protected AppCompatActivity activity; public static final ImageLoader imageLoader = ImageLoader.getInstance(); + //These values are used for controlling framgents when they are part of the frontpage + @State + protected boolean useAsFrontPage = false; + protected boolean mIsVisibleToUser = false; + + public void useAsFrontPage(boolean value) { + useAsFrontPage = value; + } + /*////////////////////////////////////////////////////////////////////////// // Fragment's Lifecycle //////////////////////////////////////////////////////////////////////////*/ @@ -73,6 +85,12 @@ public abstract class BaseFragment extends Fragment { if (refWatcher != null) refWatcher.watch(this); } + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + mIsVisibleToUser = isVisibleToUser; + } + /*////////////////////////////////////////////////////////////////////////// // Init //////////////////////////////////////////////////////////////////////////*/ @@ -89,7 +107,8 @@ public abstract class BaseFragment extends Fragment { public void setTitle(String title) { if (DEBUG) Log.d(TAG, "setTitle() called with: title = [" + title + "]"); - if (activity != null && activity.getSupportActionBar() != null) { + if((!useAsFrontPage || mIsVisibleToUser) + && (activity != null && activity.getSupportActionBar() != null)) { activity.getSupportActionBar().setTitle(title); } } diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index d9ea66870..7c77bff3d 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -23,19 +23,15 @@ package org.schabi.newpipe; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.preference.PreferenceManager; -import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.design.widget.NavigationView; import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; @@ -43,7 +39,6 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; -import android.util.TypedValue; import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; @@ -52,7 +47,6 @@ import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.Button; -import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -64,7 +58,6 @@ import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.list.search.SearchFragment; import org.schabi.newpipe.report.ErrorActivity; -import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.NavigationHelper; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 5707716bf..af16ff062 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -51,9 +51,6 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC protected Button errorButtonRetry; protected TextView errorTextView; - @State - protected boolean useAsFrontPage = false; - @Override public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); @@ -66,9 +63,6 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC wasLoading.set(isLoading.get()); } - public void useAsFrontPage(boolean value) { - useAsFrontPage = value; - } /*////////////////////////////////////////////////////////////////////////// // Init diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java index e81645202..4ee90f083 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java @@ -14,24 +14,16 @@ public class BlankFragment extends BaseFragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - if(activity != null && activity.getSupportActionBar() != null) { - activity.getSupportActionBar() - .setTitle("NewPipe"); - } + setTitle("NewPipe"); return inflater.inflate(R.layout.fragment_blank, container, false); } @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); - if(isVisibleToUser) { - if(activity != null && activity.getSupportActionBar() != null) { - activity.getSupportActionBar() - .setTitle("NewPipe"); - } - // leave this inline. Will make it harder for copy cats. - // If you are a Copy cat FUCK YOU. - // I WILL FIND YOU, AND I WILL ... - } + setTitle("NewPipe"); + // leave this inline. Will make it harder for copy cats. + // If you are a Copy cat FUCK YOU. + // I WILL FIND YOU, AND I WILL ... } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 4043cb719..01922a4f3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -519,13 +519,7 @@ public class ChannelFragment extends BaseListInfoFragment { @Override public void setTitle(String title) { - if(!useAsFrontPage) { - super.setTitle(title); - headerTitleView.setText(title); - } else { - if(mIsVisibleToUser) { - super.setTitle(title); - } - } + super.setTitle(title); + if (!useAsFrontPage) headerTitleView.setText(title); } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index d346bb31e..833d0f55e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -57,7 +57,6 @@ public class KioskFragment extends BaseListInfoFragment { protected String kioskId = ""; protected String kioskTranslatedName; - private boolean mIsVisibleToUser = false; /*////////////////////////////////////////////////////////////////////////// // Views @@ -97,7 +96,6 @@ public class KioskFragment extends BaseListInfoFragment { @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); - mIsVisibleToUser = isVisibleToUser; if(useAsFrontPage && isVisibleToUser && activity != null) { try { setTitle(kioskTranslatedName); @@ -191,19 +189,4 @@ public class KioskFragment extends BaseListInfoFragment { , "Get next page of: " + url, 0); } } - - /*////////////////////////////////////////////////////////////////////////// - // Utils - //////////////////////////////////////////////////////////////////////////*/ - - @Override - public void setTitle(String title) { - if(!useAsFrontPage) { - super.setTitle(title); - } else { - if(mIsVisibleToUser) { - super.setTitle(title); - } - } - } } diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index 6bdc631d8..99bd70f5b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -6,7 +6,6 @@ import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; -import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,11 +19,9 @@ import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.PlaylistLocalItem; import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; -import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.local.BaseLocalListFragment; import org.schabi.newpipe.local.playlist.LocalPlaylistManager; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; -import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java index de5148a75..634bea62b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.java @@ -179,19 +179,9 @@ public class FeedFragment extends BaseListFragment, Voi showLoading(); showListFooter(true); subscriptionObserver = subscriptionService.getSubscription() - .onErrorReturnItem(Collections.emptyList()) + .onErrorReturnItem(Collections.emptyList()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Consumer>() { - @Override - public void accept(List subscriptionEntities) throws Exception { - handleResult(subscriptionEntities); - } - }, new Consumer() { - @Override - public void accept(Throwable throwable) throws Exception { - onError(throwable); - } - }); + .subscribe(this::handleResult, this::onError); } @Override @@ -242,13 +232,12 @@ public class FeedFragment extends BaseListFragment, Voi if (!itemsLoaded.contains(subscriptionEntity.getServiceId() + subscriptionEntity.getUrl())) { subscriptionService.getChannelInfo(subscriptionEntity) .observeOn(AndroidSchedulers.mainThread()) - .onErrorComplete(new Predicate() { - @Override - public boolean test(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception { - return FeedFragment.super.onError(throwable); - } - }) - .subscribe(getChannelInfoObserver(subscriptionEntity.getServiceId(), subscriptionEntity.getUrl())); + .onErrorComplete( + (@io.reactivex.annotations.NonNull Throwable throwable) -> + FeedFragment.super.onError(throwable)) + .subscribe( + getChannelInfoObserver(subscriptionEntity.getServiceId(), + subscriptionEntity.getUrl())); } else { requestFeed(1); } @@ -319,7 +308,10 @@ public class FeedFragment extends BaseListFragment, Voi @Override public void onError(Throwable exception) { - showSnackBarError(exception, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(serviceId), url, 0); + showSnackBarError(exception, + UserAction.SUBSCRIPTION, + NewPipe.getNameOfService(serviceId), + url, 0); requestFeed(1); onDone(); } @@ -364,12 +356,7 @@ public class FeedFragment extends BaseListFragment, Voi delayHandler.removeCallbacksAndMessages(null); // Add a little of a delay when requesting more items because the cache is so fast, // that the view seems stuck to the user when he scroll to the bottom - delayHandler.postDelayed(new Runnable() { - @Override - public void run() { - requestFeed(FEED_LOAD_COUNT); - } - }, 300); + delayHandler.postDelayed(() -> requestFeed(FEED_LOAD_COUNT), 300); } @Override @@ -426,7 +413,9 @@ public class FeedFragment extends BaseListFragment, Voi int heightPixels = getResources().getDisplayMetrics().heightPixels; int itemHeightPixels = activity.getResources().getDimensionPixelSize(R.dimen.video_item_search_height); - int items = itemHeightPixels > 0 ? heightPixels / itemHeightPixels + OFF_SCREEN_ITEMS_COUNT : MIN_ITEMS_INITIAL_LOAD; + int items = itemHeightPixels > 0 + ? heightPixels / itemHeightPixels + OFF_SCREEN_ITEMS_COUNT + : MIN_ITEMS_INITIAL_LOAD; return Math.max(MIN_ITEMS_INITIAL_LOAD, items); } @@ -444,8 +433,14 @@ public class FeedFragment extends BaseListFragment, Voi protected boolean onError(Throwable exception) { if (super.onError(exception)) return true; - int errorId = exception instanceof ExtractionException ? R.string.parsing_error : R.string.general_error; - onUnrecoverableError(exception, UserAction.SOMETHING_ELSE, "none", "Requesting feed", errorId); + int errorId = exception instanceof ExtractionException + ? R.string.parsing_error + : R.string.general_error; + onUnrecoverableError(exception, + UserAction.SOMETHING_ELSE, + "none", + "Requesting feed", + errorId); return true; } } diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 1991590c5..add69048a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -74,7 +74,7 @@ public class StatisticsPlaylistFragment return results; case MOST_PLAYED: Collections.sort(results, (left, right) -> - ((Long) right.watchCount).compareTo(left.watchCount)); + Long.compare(right.watchCount, left.watchCount)); return results; default: return null; } @@ -141,8 +141,8 @@ public class StatisticsPlaylistFragment if (selectedItem instanceof StreamStatisticsEntry) { final StreamStatisticsEntry item = (StreamStatisticsEntry) selectedItem; NavigationHelper.openVideoDetailFragment(useAsFrontPage - ? getParentFragment().getFragmentManager() - : getFragmentManager(), + ? getParentFragment().getFragmentManager() + : getFragmentManager(), item.serviceId, item.url, item.title); @@ -356,7 +356,7 @@ public class StatisticsPlaylistFragment final Disposable onDelete = recordManager.deleteStreamHistory(entry.streamId) .observeOn(AndroidSchedulers.mainThread()) .subscribe( - howManyDelted -> { + howManyDeleted -> { if(getView() != null) { Snackbar.make(getView(), R.string.one_item_deleted, Snackbar.LENGTH_SHORT).show(); diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java index 7c5eaf6c4..fd044039b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.java @@ -210,7 +210,8 @@ public class SubscriptionFragment extends BaseStateFragment onImportPreviousSelected()); final int iconColor = ThemeHelper.isLightThemeSelected(getContext()) ? Color.BLACK : Color.WHITE; @@ -323,7 +324,9 @@ public class SubscriptionFragment extends BaseStateFragment getSubscriptionItems(List subscriptions) { List items = new ArrayList<>(); - for (final SubscriptionEntity subscription : subscriptions) items.add(subscription.toChannelInfoItem()); + for (final SubscriptionEntity subscription : subscriptions) { + items.add(subscription.toChannelInfoItem()); + } Collections.sort(items, - (InfoItem o1, InfoItem o2) -> o1.getName().compareToIgnoreCase(o2.getName())); + (InfoItem o1, InfoItem o2) -> + o1.getName().compareToIgnoreCase(o2.getName())); return items; } @@ -434,7 +440,11 @@ public class SubscriptionFragment extends BaseStateFragment