Fontawesome, video play activity, misc

This commit is contained in:
Stefan Schueller 2018-03-04 01:06:32 +01:00
parent 39b1138ad7
commit 81fec069df
11 changed files with 326 additions and 11 deletions

View File

@ -44,6 +44,7 @@ dependencies {
implementation 'com.blackboardtheory:android-iconify-fontawesome:3.0.1-SNAPSHOT' implementation 'com.blackboardtheory:android-iconify-fontawesome:3.0.1-SNAPSHOT'
implementation 'com.android.support:support-v4:27.1.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

View File

@ -25,8 +25,12 @@
</activity> </activity>
<activity <activity
android:name=".activity.LoginActivity" android:name=".activity.LoginActivity"
android:label="@string/title_activity_login"> android:label="@string/title_activity_login"></activity>
</activity> <activity
android:name=".activity.VideoPlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_vide_play"
android:theme="@style/FullscreenTheme"></activity>
</application> </application>
</manifest> </manifest>

View File

@ -1,6 +1,7 @@
package net.schueller.peertube.activity; package net.schueller.peertube.activity;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
@ -12,6 +13,7 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
@ -19,6 +21,10 @@ import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException; import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.security.ProviderInstaller; import com.google.android.gms.security.ProviderInstaller;
import com.joanzapata.iconify.IconDrawable;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
import com.joanzapata.iconify.fonts.FontAwesomeModule;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.adapter.VideoAdapter; import net.schueller.peertube.adapter.VideoAdapter;
@ -37,6 +43,8 @@ public class VideoListActivity extends AppCompatActivity {
private String TAG = "VideoListActivity"; private String TAG = "VideoListActivity";
public static final String EXTRA_VIDEOID = "VIDEOID ";
private VideoAdapter videoAdapter; private VideoAdapter videoAdapter;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
@ -52,10 +60,24 @@ public class VideoListActivity extends AppCompatActivity {
= item -> { = item -> {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.navigation_home: case R.id.navigation_home:
Log.v(TAG, "navigation_home"); //Log.v(TAG, "navigation_home");
if (!isLoading) {
sort = "-createdAt";
currentStart = 0;
loadVideos(currentStart, count, sort);
}
return true; return true;
case R.id.navigation_trending: case R.id.navigation_trending:
Log.v(TAG, "navigation_trending"); //Log.v(TAG, "navigation_trending");
if (!isLoading) {
sort = "-views";
currentStart = 0;
loadVideos(currentStart, count, sort);
}
return true; return true;
case R.id.navigation_subscriptions: case R.id.navigation_subscriptions:
Log.v(TAG, "navigation_subscriptions"); Log.v(TAG, "navigation_subscriptions");
@ -69,6 +91,9 @@ public class VideoListActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_list); setContentView(R.layout.activity_video_list);
// Init icons
Iconify.with(new FontAwesomeModule());
// Attaching the layout to the toolbar object // Attaching the layout to the toolbar object
toolbar = findViewById(R.id.tool_bar); toolbar = findViewById(R.id.tool_bar);
// Setting toolbar as the ActionBar with setSupportActionBar() call // Setting toolbar as the ActionBar with setSupportActionBar() call
@ -79,6 +104,13 @@ public class VideoListActivity extends AppCompatActivity {
// Bottom Navigation // Bottom Navigation
BottomNavigationView navigation = findViewById(R.id.navigation); BottomNavigationView navigation = findViewById(R.id.navigation);
Menu navMenu = navigation.getMenu();
navMenu.findItem(R.id.navigation_home).setIcon(
new IconDrawable(this, FontAwesomeIcons.fa_home));
navMenu.findItem(R.id.navigation_trending).setIcon(
new IconDrawable(this, FontAwesomeIcons.fa_fire));
navMenu.findItem(R.id.navigation_subscriptions).setIcon(
new IconDrawable(this, FontAwesomeIcons.fa_folder));
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
createList(); createList();
@ -87,11 +119,19 @@ public class VideoListActivity extends AppCompatActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater = getMenuInflater();
getMenuInflater().inflate(R.menu.menu_main, menu); inflater.inflate(R.menu.menu_main, menu);
// Set an icon in the ActionBar
menu.findItem(R.id.action_user).setIcon(
new IconDrawable(this, FontAwesomeIcons.fa_user)
.colorRes(R.color.cardview_light_background)
.actionBarSize());
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will // Handle action bar item clicks here. The action bar will
@ -101,8 +141,10 @@ public class VideoListActivity extends AppCompatActivity {
switch (item.getItemId()) { switch (item.getItemId()) {
// action with ID action_refresh was selected // action with ID action_refresh was selected
case R.id.action_user: case R.id.action_user:
Toast.makeText(this, "Login Selected", Toast.LENGTH_SHORT) // Toast.makeText(this, "Login Selected", Toast.LENGTH_SHORT).show();
.show(); Intent intent = new Intent(this, LoginActivity.class);
this.startActivity(intent);
return true; return true;
default: default:
break; break;

View File

@ -0,0 +1,173 @@
package net.schueller.peertube.activity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import net.schueller.peertube.R;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*/
public class VideoPlayActivity extends AppCompatActivity {
/**
* Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* Some older devices needs a small delay between UI widget updates
* and a change of the status and navigation bar.
*/
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler();
private View mContentView;
private final Runnable mHidePart2Runnable = new Runnable() {
@SuppressLint("InlinedApi")
@Override
public void run() {
// Delayed removal of status and navigation bar
// Note that some of these constants are new as of API 16 (Jelly Bean)
// and API 19 (KitKat). It is safe to use them, as they are inlined
// at compile-time and do nothing on earlier devices.
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
};
private View mControlsView;
private final Runnable mShowPart2Runnable = new Runnable() {
@Override
public void run() {
// Delayed display of UI elements
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.show();
}
mControlsView.setVisibility(View.VISIBLE);
}
};
private boolean mVisible;
private final Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
hide();
}
};
/**
* Touch listener to use for in-layout UI controls to delay hiding the
* system UI. This is to prevent the jarring behavior of controls going away
* while interacting with activity UI.
*/
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (AUTO_HIDE) {
delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vide_play);
// get video ID
Intent intent = getIntent();
String videoID = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID);
Log.v("VideoPlayActivity", "click: " + videoID);
mVisible = true;
mControlsView = findViewById(R.id.fullscreen_content_controls);
mContentView = findViewById(R.id.fullscreen_content);
// Set up the user interaction to manually show or hide the system UI.
mContentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggle();
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide(100);
}
private void toggle() {
if (mVisible) {
hide();
} else {
show();
}
}
private void hide() {
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
mControlsView.setVisibility(View.GONE);
mVisible = false;
// Schedule a runnable to remove the status and navigation bar after a delay
mHideHandler.removeCallbacks(mShowPart2Runnable);
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
}
@SuppressLint("InlinedApi")
private void show() {
// Show the system bar
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mVisible = true;
// Schedule a runnable to display UI elements after a delay
mHideHandler.removeCallbacks(mHidePart2Runnable);
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
}
/**
* Schedules a call to hide() in delay milliseconds, canceling any
* previously scheduled calls.
*/
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}

View File

@ -1,8 +1,10 @@
package net.schueller.peertube.adapter; package net.schueller.peertube.adapter;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -12,10 +14,13 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.activity.VideoPlayActivity;
import net.schueller.peertube.model.Video; import net.schueller.peertube.model.Video;
import java.util.ArrayList; import java.util.ArrayList;
import static net.schueller.peertube.activity.VideoListActivity.EXTRA_VIDEOID;
public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHolder> { public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHolder> {
@ -47,6 +52,17 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
.concat("@") .concat("@")
.concat(videoList.get(position).getServerHost()).concat(" - ") .concat(videoList.get(position).getServerHost()).concat(" - ")
.concat(videoList.get(position).getViews()+" Views")); .concat(videoList.get(position).getViews()+" Views"));
holder.mView.setOnClickListener(v -> {
// Log.v("VideoAdapter", "click: " + videoList.get(position).getName());
Intent intent = new Intent(context, VideoPlayActivity.class);
intent.putExtra(EXTRA_VIDEOID, videoList.get(position).getUuid());
context.startActivity(intent);
});
} }
public void setData(ArrayList<Video> data) { public void setData(ArrayList<Video> data) {
@ -68,12 +84,14 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
TextView name, videoMeta; TextView name, videoMeta;
ImageView thumb; ImageView thumb;
View mView;
VideoViewHolder(View itemView) { VideoViewHolder(View itemView) {
super(itemView); super(itemView);
name = itemView.findViewById(R.id.name); name = itemView.findViewById(R.id.name);
thumb = itemView.findViewById(R.id.thumb); thumb = itemView.findViewById(R.id.thumb);
videoMeta = itemView.findViewById(R.id.videoMeta); videoMeta = itemView.findViewById(R.id.videoMeta);
mView = itemView;
} }
} }

View File

@ -0,0 +1,50 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context="net.schueller.peertube.activity.VideoPlayActivity">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold" />
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dummy_button" />
</LinearLayout>
</FrameLayout>
</FrameLayout>

View File

@ -4,17 +4,14 @@
<item <item
android:id="@+id/navigation_home" android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" /> android:title="@string/title_home" />
<item <item
android:id="@+id/navigation_trending" android:id="@+id/navigation_trending"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_trending" /> android:title="@string/title_trending" />
<item <item
android:id="@+id/navigation_subscriptions" android:id="@+id/navigation_subscriptions"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_subscriptions" /> android:title="@string/title_subscriptions" />
</menu> </menu>

View File

@ -0,0 +1,12 @@
<resources>
<!-- Declare custom theme attributes that allow changing which styles are
used for button bars depending on the API level.
?android:attr/buttonBarStyle is new as of API 11 so this is
necessary to support previous API levels. -->
<declare-styleable name="ButtonBarContainerTheme">
<attr name="metaButtonBarStyle" format="reference" />
<attr name="metaButtonBarButtonStyle" format="reference" />
</declare-styleable>
</resources>

View File

@ -5,4 +5,6 @@
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#FF4081</color>
<color name="viewBg">#f1f5f8</color> <color name="viewBg">#f1f5f8</color>
<color name="album_title">#4c4c4c</color> <color name="album_title">#4c4c4c</color>
<color name="black_overlay">#66000000</color>
</resources> </resources>

View File

@ -19,4 +19,8 @@
<string name="title_trending">Trending</string> <string name="title_trending">Trending</string>
<string name="title_subscriptions">Subscriptions</string> <string name="title_subscriptions">Subscriptions</string>
<string name="title_activity_vide_play">VidePlayActivity</string>
<string name="dummy_button">Dummy Button</string>
<string name="dummy_content">DUMMY\nCONTENT</string>
</resources> </resources>

View File

@ -7,4 +7,16 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
</resources> </resources>