Skip to content

Commit 08648ca

Browse files
author
Christian Schabesberger
committed
fixed landscape layout problem & added watch with kodi function
1 parent b6b0cf1 commit 08648ca

14 files changed

Lines changed: 80 additions & 18 deletions

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import android.content.Context;
55
import android.content.DialogInterface;
66
import android.content.Intent;
7+
import android.content.SharedPreferences;
78
import android.net.Uri;
9+
import android.preference.Preference;
810
import android.preference.PreferenceManager;
911
import android.support.v4.view.MenuItemCompat;
1012
import android.support.v7.app.ActionBar;
@@ -40,6 +42,8 @@
4042

4143
public class ActionBarHandler {
4244
private static final String TAG = ActionBarHandler.class.toString();
45+
private static final String KORE_PACKET = "org.xbmc.kore";
46+
4347
private static ActionBarHandler handler = null;
4448

4549
private Context context = null;
@@ -49,6 +53,8 @@ public class ActionBarHandler {
4953
private int selectedStream = -1;
5054
private String videoTitle = "";
5155

56+
SharedPreferences defaultPreferences = null;
57+
5258
public static ActionBarHandler getHandler() {
5359
if(handler == null) {
5460
handler = new ActionBarHandler();
@@ -73,7 +79,7 @@ public void setStreams(VideoInfo.Stream[] streams) {
7379
this.streams = streams;
7480
selectedStream = 0;
7581
String[] itemArray = new String[streams.length];
76-
String defaultResolution = PreferenceManager.getDefaultSharedPreferences(context)
82+
String defaultResolution = defaultPreferences
7783
.getString(context.getString(R.string.defaultResolutionPreference),
7884
context.getString(R.string.defaultResolutionListItem));
7985
int defaultResolutionPos = 0;
@@ -104,15 +110,21 @@ public boolean setupMenu(Menu menu, MenuInflater inflater, Context context) {
104110
// CAUTION set item properties programmatically otherwise it would not be accepted by
105111
// appcompat itemsinflater.inflate(R.menu.videoitem_detail, menu);
106112

113+
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(context);
114+
107115
inflater.inflate(R.menu.videoitem_detail, menu);
108116
MenuItem playItem = menu.findItem(R.id.menu_item_play);
109117
MenuItem shareItem = menu.findItem(R.id.menu_item_share);
118+
MenuItem castItem = menu.findItem(R.id.action_play_with_kodi);
110119

111120
MenuItemCompat.setShowAsAction(playItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS
112121
| MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
113122
MenuItemCompat.setShowAsAction(shareItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
114123
| MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
115124

125+
castItem.setVisible(defaultPreferences
126+
.getBoolean(context.getString(R.string.showPlayWidthKodiPreference), false));
127+
116128
return true;
117129
}
118130

@@ -143,6 +155,10 @@ public boolean onItemSelected(MenuItem item, Context context) {
143155
Intent intent = new Intent(context, SettingsActivity.class);
144156
context.startActivity(intent);
145157
}
158+
break;
159+
case R.id.action_play_with_kodi:
160+
playWithKodi();
161+
break;
146162
default:
147163
Log.e(TAG, "Menu Item not known");
148164
}
@@ -216,8 +232,7 @@ public void downloadVideo() {
216232
DownloadManager.Request request = new DownloadManager.Request(
217233
Uri.parse(streams[selectedStream].url));
218234
request.setDestinationUri(Uri.fromFile(new File(
219-
PreferenceManager.getDefaultSharedPreferences(context)
220-
.getString("download_path_preference", "/storage/emulated/0/NewPipe")
235+
defaultPreferences.getString("download_path_preference", "/storage/emulated/0/NewPipe")
221236
+ "/" + videoTitle + suffix)));
222237
try {
223238
dm.enqueue(request);
@@ -236,4 +251,35 @@ public void openInBrowser() {
236251
context.startActivity(Intent.createChooser(intent, context.getString(R.string.chooseBrowser)));
237252
}
238253
}
254+
255+
public void playWithKodi() {
256+
if(!videoTitle.isEmpty()) {
257+
try {
258+
Intent intent = new Intent(Intent.ACTION_VIEW);
259+
intent.setPackage(KORE_PACKET);
260+
intent.setData(Uri.parse(webisteUrl.replace("https", "http")));
261+
context.startActivity(intent);
262+
} catch (Exception e) {
263+
e.printStackTrace();
264+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
265+
builder.setMessage(R.string.koreNotFound)
266+
.setPositiveButton(R.string.installeKore, new DialogInterface.OnClickListener() {
267+
@Override
268+
public void onClick(DialogInterface dialog, int which) {
269+
Intent intent = new Intent();
270+
intent.setAction(Intent.ACTION_VIEW);
271+
intent.setData(Uri.parse(context.getString(R.string.fdroidKoreUrl)));
272+
context.startActivity(intent);
273+
}
274+
})
275+
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
276+
@Override
277+
public void onClick(DialogInterface dialog, int which) {
278+
279+
}
280+
});
281+
builder.create().show();
282+
}
283+
}
284+
}
239285
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ public void updateInfo(VideoInfo info) {
156156
ImageView uploaderThumbnailView = (ImageView) a.findViewById(R.id.detailUploaderThumbnailView);
157157
ImageView thumbsUpPic = (ImageView) a.findViewById(R.id.detailThumbsUpImgView);
158158
ImageView thumbsDownPic = (ImageView) a.findViewById(R.id.detailThumbsDownImgView);
159+
View textSeperationLine = a.findViewById(R.id.textSeperationLine);
159160

161+
if(textSeperationLine != null) {
162+
textSeperationLine.setVisibility(View.VISIBLE);
163+
}
160164
progressBar.setVisibility(View.GONE);
161165
videoTitleView.setVisibility(View.VISIBLE);
162166
uploaderView.setVisibility(View.VISIBLE);
-1.4 KB
Binary file not shown.
-1.97 KB
Binary file not shown.
869 Bytes
Loading
320 Bytes
Loading
888 Bytes
Loading

app/src/main/res/layout-sw600dp/fragment_videoitem_detail.xml renamed to app/src/main/res/layout-land/fragment_videoitem_detail.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
android:visibility="invisible"
6060
android:text="Herr von Gurken" />
6161

62-
<View
62+
<View android:id="@+id/textSeperationLine"
6363
android:layout_width="fill_parent"
6464
android:layout_height="1dp"
6565
android:background="@android:color/darker_gray"

app/src/main/res/menu/videoitem_detail.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<item android:id="@+id/menu_item_play"
55
android:title="@string/play"
66
app:showAsAction="always"
7-
android:icon="@drawable/ai_play"/>
7+
android:icon="@drawable/ic_play_arrow_black"/>
88

99
<item android:id="@+id/menu_item_share"
1010
android:title="@string/share"
1111
app:showAsAction="ifRoom"
12-
android:icon="@drawable/ai_share"/>
12+
android:icon="@drawable/ic_share_black"/>
1313

1414
<item android:id="@+id/menu_item_openInBrowser"
1515
app:showAsAction="never"
@@ -22,4 +22,9 @@
2222
<item android:id="@+id/action_settings"
2323
app:showAsAction="never"
2424
android:title="@string/settings"/>
25+
26+
<item android:id="@+id/action_play_with_kodi"
27+
android:title="@string/playWithKodiTitle"
28+
app:showAsAction="ifRoom"
29+
android:icon="@drawable/ic_cast_black"/>
2530
</menu>

app/src/main/res/values-de/strings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@
2828
<string name="autoPlayThroughIntentTitle">Automatisch abspielen durch Intent.</string>
2929
<string name="autoPlayThroughIntentSummary">Startet ein Video automatisch wenn es von einer anderen App aufgerufen wurde.</string>
3030
<string name="defaultResolutionPreferenceTitle">Standard Auflösung</string>
31+
<string name="playWithKodiTitle">Mit Kodi abspielen</string>
32+
<string name="koreNotFound">Kore app wurde nicht gefunden. Kore wird benötigt, um Videos mit Kodi wieder zu geben.</string>
33+
<string name="installeKore">Kore installieren</string>
34+
<string name="fdroidKoreUrl">https://f-droid.org/repository/browse/?fdfilter=Kore&amp;fdid=org.xbmc.kore</string>
35+
<string name="showPlayWithKodiTitle">Zeige \"Mit Kodi abspielen\" Option</string>
36+
<string name="showPlayWithKodiSummary">Zeigt eine Option an, über die man Videos mit dem Kodi Mediacenter abspielen kann.</string>
3137
</resources>

0 commit comments

Comments
 (0)