Skip to content

Commit d81b571

Browse files
authored
Merge pull request #12348 from Isira-Seneviratne/Merge-dev-to-refactor
2 parents f16becc + 6efb92a commit d81b571

31 files changed

+705
-41
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@
88
<p align="center"><a href="https://f-droid.org/packages/org.schabi.newpipe/"><img src="https://fdroid.gitlab.io/artwork/badge/get-it-on-en.svg" alt="Get it on F-Droid" height=80/></a></p>
99

1010
<p align="center">
11-
<a href="https://github.com/TeamNewPipe/NewPipe/releases" alt="GitHub release"><img src="https://img.shields.io/github/release/TeamNewPipe/NewPipe.svg" ></a>
11+
<a href="https://github.com/TeamNewPipe/NewPipe/releases" alt="GitHub NewPipe releases"><img src="https://img.shields.io/github/release/TeamNewPipe/NewPipe.svg" ></a>
12+
<a href="https://github.com/TeamNewPipe/NewPipe-nightly/releases" alt="GitHub NewPipe nightly releases">
13+
<img src="https://img.shields.io/github/release/TeamNewPipe/NewPipe-nightly.svg?labelColor=purple&label=dev%20nightly" >
14+
</a>
15+
<a href="https://github.com/TeamNewPipe/NewPipe-refactor-nightly/releases" alt="GitHub NewPipe refactor nightly releases">
16+
<img src="https://img.shields.io/github/release/TeamNewPipe/NewPipe-refactor-nightly.svg?labelColor=purple&label=refactor%20nightly" >
17+
</a>
1218
<a href="https://www.gnu.org/licenses/gpl-3.0" alt="License: GPLv3"><img src="https://img.shields.io/badge/License-GPL%20v3-blue.svg"></a>
13-
<a href="https://github.com/TeamNewPipe/NewPipe/actions" alt="Build Status"><img src="https://github.com/TeamNewPipe/NewPipe/workflows/CI/badge.svg?branch=dev&event=push"></a>
19+
<a href="https://github.com/TeamNewPipe/NewPipe/actions" alt="Build Status"><img src="https://github.com/TeamNewPipe/NewPipe/actions/workflows/ci.yml/badge.svg?branch=dev&event=push"></a>
1420
<a href="https://hosted.weblate.org/engage/newpipe/" alt="Translation Status"><img src="https://hosted.weblate.org/widgets/newpipe/-/svg-badge.svg"></a>
21+
</p>
22+
23+
<p align="center">
1524
<a href="https://web.libera.chat/#newpipe" alt="IRC channel: #newpipe"><img src="https://img.shields.io/badge/IRC%20chat-%23newpipe-brightgreen.svg"></a>
1625
<a href="https://matrix.to/#/#newpipe:matrix.newpipe-ev.de" alt="Matrix channel: #newpipe"><img src="https://img.shields.io/badge/Matrix%20chat-%23newpipe-blue"></a>
1726
</p>
27+
1828
<hr>
1929
<p align="center"><a href="#screenshots">Screenshots</a> &bull; <a href="#supported-services">Supported Services</a> &bull; <a href="#description">Description</a> &bull; <a href="#features">Features</a> &bull; <a href="#installation-and-updates">Installation and updates</a> &bull; <a href="#contribution">Contribution</a> &bull; <a href="#donate">Donate</a> &bull; <a href="#license">License</a></p>
2030
<p align="center"><a href="https://newpipe.net">Website</a> &bull; <a href="https://newpipe.net/blog/">Blog</a> &bull; <a href="https://newpipe.net/FAQ/">FAQ</a> &bull; <a href="https://newpipe.net/press/">Press</a></p>

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public class MainActivity extends AppCompatActivity {
122122
private static final int ITEM_ID_ABOUT = 2;
123123

124124
private static final int ORDER = 0;
125+
public static final String KEY_IS_IN_BACKGROUND = "is_in_background";
125126

127+
private SharedPreferences sharedPreferences;
128+
private SharedPreferences.Editor sharedPrefEditor;
126129
/*//////////////////////////////////////////////////////////////////////////
127130
// Activity's LifeCycle
128131
//////////////////////////////////////////////////////////////////////////*/
@@ -152,6 +155,8 @@ protected void onCreate(final Bundle savedInstanceState) {
152155

153156
assureCorrectAppLanguage(this);
154157
super.onCreate(savedInstanceState);
158+
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
159+
sharedPrefEditor = sharedPreferences.edit();
155160

156161
mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
157162
drawerLayoutBinding = mainBinding.drawerLayout;
@@ -195,16 +200,29 @@ protected void onPostCreate(final Bundle savedInstanceState) {
195200
super.onPostCreate(savedInstanceState);
196201

197202
final App app = App.getInstance();
198-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
199203

200-
if (prefs.getBoolean(app.getString(R.string.update_app_key), false)
201-
&& prefs.getBoolean(app.getString(R.string.update_check_consent_key), false)) {
204+
if (sharedPreferences.getBoolean(app.getString(R.string.update_app_key), false)
205+
&& sharedPreferences
206+
.getBoolean(app.getString(R.string.update_check_consent_key), false)) {
202207
// Start the worker which is checking all conditions
203208
// and eventually searching for a new version.
204209
NewVersionWorker.enqueueNewVersionCheckingWork(app, false);
205210
}
206211
}
207212

213+
@Override
214+
protected void onStart() {
215+
super.onStart();
216+
sharedPrefEditor.putBoolean(KEY_IS_IN_BACKGROUND, false).apply();
217+
Log.d(TAG, "App moved to foreground");
218+
}
219+
220+
@Override
221+
protected void onStop() {
222+
super.onStop();
223+
sharedPrefEditor.putBoolean(KEY_IS_IN_BACKGROUND, true).apply();
224+
Log.d(TAG, "App moved to background");
225+
}
208226
private void setupDrawer() throws ExtractionException {
209227
addDrawerMenuForCurrentService();
210228

@@ -504,21 +522,19 @@ protected void onResume() {
504522
ErrorUtil.showUiErrorSnackbar(this, "Setting up service toggle", e);
505523
}
506524

507-
final SharedPreferences sharedPreferences =
508-
PreferenceManager.getDefaultSharedPreferences(this);
509525
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
510526
if (DEBUG) {
511527
Log.d(TAG, "Theme has changed, recreating activity...");
512528
}
513-
sharedPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, false).apply();
529+
sharedPrefEditor.putBoolean(Constants.KEY_THEME_CHANGE, false).apply();
514530
ActivityCompat.recreate(this);
515531
}
516532

517533
if (sharedPreferences.getBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false)) {
518534
if (DEBUG) {
519535
Log.d(TAG, "main page has changed, recreating main fragment...");
520536
}
521-
sharedPreferences.edit().putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply();
537+
sharedPrefEditor.putBoolean(Constants.KEY_MAIN_PAGE_CHANGE, false).apply();
522538
NavigationHelper.openMainActivity(this);
523539
}
524540

app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import androidx.core.app.NotificationCompat
1111
import androidx.core.app.NotificationManagerCompat
1212
import androidx.core.app.PendingIntentCompat
1313
import androidx.fragment.app.Fragment
14+
import androidx.preference.PreferenceManager
1415
import com.google.android.material.snackbar.Snackbar
16+
import org.schabi.newpipe.MainActivity
1517
import org.schabi.newpipe.R
1618

1719
/**
@@ -35,12 +37,20 @@ class ErrorUtil {
3537
* activity (since the workflow would be interrupted anyway in that case). So never use this
3638
* for background services.
3739
*
40+
* If the crashed occurred while the app was in the background open a notification instead
41+
*
3842
* @param context the context to use to start the new activity
3943
* @param errorInfo the error info to be reported
4044
*/
4145
@JvmStatic
4246
fun openActivity(context: Context, errorInfo: ErrorInfo) {
43-
context.startActivity(getErrorActivityIntent(context, errorInfo))
47+
if (PreferenceManager.getDefaultSharedPreferences(context)
48+
.getBoolean(MainActivity.KEY_IS_IN_BACKGROUND, true)
49+
) {
50+
createNotification(context, errorInfo)
51+
} else {
52+
context.startActivity(getErrorActivityIntent(context, errorInfo))
53+
}
4454
}
4555

4656
/**

app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,12 @@ class FeedFragment : BaseStateFragment<FeedState>() {
274274
@Deprecated("Deprecated in Java")
275275
override fun onDestroyOptionsMenu() {
276276
super.onDestroyOptionsMenu()
277-
activity?.supportActionBar?.subtitle = null
277+
if (
278+
(groupName != "") &&
279+
(activity?.supportActionBar?.subtitle == groupName)
280+
) {
281+
activity?.supportActionBar?.subtitle = null
282+
}
278283
}
279284

280285
override fun onDestroy() {
@@ -286,7 +291,13 @@ class FeedFragment : BaseStateFragment<FeedState>() {
286291
}
287292

288293
super.onDestroy()
289-
activity?.supportActionBar?.subtitle = null
294+
295+
if (
296+
(groupName != "") &&
297+
(activity?.supportActionBar?.subtitle == groupName)
298+
) {
299+
activity?.supportActionBar?.subtitle = null
300+
}
290301
}
291302

292303
override fun onDestroyView() {
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
package org.schabi.newpipe.settings;
2+
3+
import android.content.DialogInterface;
4+
import android.os.Bundle;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.ImageView;
9+
import android.widget.ProgressBar;
10+
import android.widget.TextView;
11+
12+
import androidx.annotation.NonNull;
13+
import androidx.annotation.Nullable;
14+
import androidx.fragment.app.DialogFragment;
15+
import androidx.recyclerview.widget.LinearLayoutManager;
16+
import androidx.recyclerview.widget.RecyclerView;
17+
18+
import org.schabi.newpipe.NewPipeDatabase;
19+
import org.schabi.newpipe.R;
20+
import org.schabi.newpipe.database.AppDatabase;
21+
import org.schabi.newpipe.database.feed.model.FeedGroupEntity;
22+
import org.schabi.newpipe.error.ErrorUtil;
23+
import org.schabi.newpipe.util.ThemeHelper;
24+
25+
import java.util.List;
26+
import java.util.Vector;
27+
28+
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
29+
import io.reactivex.rxjava3.core.Observer;
30+
import io.reactivex.rxjava3.disposables.Disposable;
31+
import io.reactivex.rxjava3.schedulers.Schedulers;
32+
33+
/**
34+
* Created by Christian Schabesberger on 26.09.17.
35+
* SelectChannelFragment.java is part of NewPipe.
36+
* <p>
37+
* NewPipe is free software: you can redistribute it and/or modify
38+
* it under the terms of the GNU General Public License as published by
39+
* the Free Software Foundation, either version 3 of the License, or
40+
* (at your option) any later version.
41+
* </p>
42+
* <p>
43+
* NewPipe is distributed in the hope that it will be useful,
44+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
45+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46+
* GNU General Public License for more details.
47+
* </p>
48+
* <p>
49+
* You should have received a copy of the GNU General Public License
50+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
51+
* </p>
52+
*/
53+
54+
public class SelectFeedGroupFragment extends DialogFragment {
55+
56+
private OnSelectedListener onSelectedListener = null;
57+
private OnCancelListener onCancelListener = null;
58+
59+
private ProgressBar progressBar;
60+
private TextView emptyView;
61+
private RecyclerView recyclerView;
62+
63+
private List<FeedGroupEntity> feedGroups = new Vector<>();
64+
65+
public void setOnSelectedListener(final OnSelectedListener listener) {
66+
onSelectedListener = listener;
67+
}
68+
69+
public void setOnCancelListener(final OnCancelListener listener) {
70+
onCancelListener = listener;
71+
}
72+
73+
/*//////////////////////////////////////////////////////////////////////////
74+
// Init
75+
//////////////////////////////////////////////////////////////////////////*/
76+
77+
@Override
78+
public void onCreate(@Nullable final Bundle savedInstanceState) {
79+
super.onCreate(savedInstanceState);
80+
setStyle(STYLE_NO_TITLE, ThemeHelper.getMinWidthDialogTheme(requireContext()));
81+
}
82+
83+
@Override
84+
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
85+
final Bundle savedInstanceState) {
86+
final View v = inflater.inflate(R.layout.select_feed_group_fragment, container, false);
87+
recyclerView = v.findViewById(R.id.items_list);
88+
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
89+
final SelectFeedGroupAdapter feedGroupAdapter = new SelectFeedGroupAdapter();
90+
recyclerView.setAdapter(feedGroupAdapter);
91+
92+
progressBar = v.findViewById(R.id.progressBar);
93+
emptyView = v.findViewById(R.id.empty_state_view);
94+
progressBar.setVisibility(View.VISIBLE);
95+
recyclerView.setVisibility(View.GONE);
96+
emptyView.setVisibility(View.GONE);
97+
98+
99+
final AppDatabase database = NewPipeDatabase.getInstance(requireContext());
100+
database.feedGroupDAO().getAll().toObservable()
101+
.subscribeOn(Schedulers.io())
102+
.observeOn(AndroidSchedulers.mainThread())
103+
.subscribe(getFeedGroupObserver());
104+
105+
return v;
106+
}
107+
108+
/*//////////////////////////////////////////////////////////////////////////
109+
// Handle actions
110+
//////////////////////////////////////////////////////////////////////////*/
111+
112+
@Override
113+
public void onCancel(@NonNull final DialogInterface dialogInterface) {
114+
super.onCancel(dialogInterface);
115+
if (onCancelListener != null) {
116+
onCancelListener.onCancel();
117+
}
118+
}
119+
120+
private void clickedItem(final int position) {
121+
if (onSelectedListener != null) {
122+
final FeedGroupEntity entry = feedGroups.get(position);
123+
onSelectedListener
124+
.onFeedGroupSelected(entry.getUid(), entry.getName(),
125+
entry.getIcon().getDrawableResource());
126+
}
127+
dismiss();
128+
}
129+
130+
/*//////////////////////////////////////////////////////////////////////////
131+
// Item handling
132+
//////////////////////////////////////////////////////////////////////////*/
133+
134+
private void displayFeedGroups(final List<FeedGroupEntity> newFeedGroups) {
135+
this.feedGroups = newFeedGroups;
136+
progressBar.setVisibility(View.GONE);
137+
if (newFeedGroups.isEmpty()) {
138+
emptyView.setVisibility(View.VISIBLE);
139+
return;
140+
}
141+
recyclerView.setVisibility(View.VISIBLE);
142+
143+
}
144+
145+
private Observer<List<FeedGroupEntity>> getFeedGroupObserver() {
146+
return new Observer<List<FeedGroupEntity>>() {
147+
@Override
148+
public void onSubscribe(@NonNull final Disposable disposable) { }
149+
150+
@Override
151+
public void onNext(@NonNull final List<FeedGroupEntity> newGroups) {
152+
displayFeedGroups(newGroups);
153+
}
154+
155+
@Override
156+
public void onError(@NonNull final Throwable exception) {
157+
ErrorUtil.showUiErrorSnackbar(SelectFeedGroupFragment.this,
158+
"Loading Feed Groups", exception);
159+
}
160+
161+
@Override
162+
public void onComplete() { }
163+
};
164+
}
165+
166+
/*//////////////////////////////////////////////////////////////////////////
167+
// Interfaces
168+
//////////////////////////////////////////////////////////////////////////*/
169+
170+
public interface OnSelectedListener {
171+
void onFeedGroupSelected(Long groupId, String name, int icon);
172+
}
173+
174+
public interface OnCancelListener {
175+
void onCancel();
176+
}
177+
178+
private class SelectFeedGroupAdapter
179+
extends RecyclerView.Adapter<SelectFeedGroupAdapter.SelectFeedGroupItemHolder> {
180+
@NonNull
181+
@Override
182+
public SelectFeedGroupItemHolder onCreateViewHolder(final ViewGroup parent,
183+
final int viewType) {
184+
final View item = LayoutInflater.from(parent.getContext())
185+
.inflate(R.layout.select_feed_group_item, parent, false);
186+
return new SelectFeedGroupItemHolder(item);
187+
}
188+
189+
@Override
190+
public void onBindViewHolder(final SelectFeedGroupItemHolder holder, final int position) {
191+
final FeedGroupEntity entry = feedGroups.get(position);
192+
holder.titleView.setText(entry.getName());
193+
holder.view.setOnClickListener(view -> clickedItem(position));
194+
holder.thumbnailView.setImageResource(entry.getIcon().getDrawableResource());
195+
}
196+
197+
@Override
198+
public int getItemCount() {
199+
return feedGroups.size();
200+
}
201+
202+
public class SelectFeedGroupItemHolder extends RecyclerView.ViewHolder {
203+
public final View view;
204+
final ImageView thumbnailView;
205+
final TextView titleView;
206+
SelectFeedGroupItemHolder(final View v) {
207+
super(v);
208+
this.view = v;
209+
thumbnailView = v.findViewById(R.id.itemThumbnailView);
210+
titleView = v.findViewById(R.id.itemTitleView);
211+
}
212+
}
213+
}
214+
}

0 commit comments

Comments
 (0)