From 81fec069df5eb9c279e748dcb9b2f61577f0fe87 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 4 Mar 2018 01:06:32 +0100 Subject: [PATCH] Fontawesome, video play activity, misc --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 8 +- .../peertube/activity/VideoListActivity.java | 54 +++++- .../peertube/activity/VideoPlayActivity.java | 173 ++++++++++++++++++ .../peertube/adapter/VideoAdapter.java | 18 ++ .../main/res/layout/activity_vide_play.xml | 50 +++++ app/src/main/res/menu/navigation.xml | 3 - app/src/main/res/values/attrs.xml | 12 ++ app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/values/styles.xml | 12 ++ 11 files changed, 326 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java create mode 100644 app/src/main/res/layout/activity_vide_play.xml create mode 100644 app/src/main/res/values/attrs.xml diff --git a/app/build.gradle b/app/build.gradle index 55e5f66..7ae9a98 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,6 +44,7 @@ dependencies { implementation 'com.blackboardtheory:android-iconify-fontawesome:3.0.1-SNAPSHOT' + implementation 'com.android.support:support-v4:27.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 002a8d3..825e7d4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,8 +25,12 @@ - + android:label="@string/title_activity_login"> + \ No newline at end of file diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index c9b871a..ac458e6 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -1,6 +1,7 @@ package net.schueller.peertube.activity; import android.app.Activity; +import android.content.Intent; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v4.widget.SwipeRefreshLayout; @@ -12,6 +13,7 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; 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.GooglePlayServicesUtil; 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.adapter.VideoAdapter; @@ -37,6 +43,8 @@ public class VideoListActivity extends AppCompatActivity { private String TAG = "VideoListActivity"; + public static final String EXTRA_VIDEOID = "VIDEOID "; + private VideoAdapter videoAdapter; private RecyclerView recyclerView; private SwipeRefreshLayout swipeRefreshLayout; @@ -52,10 +60,24 @@ public class VideoListActivity extends AppCompatActivity { = item -> { switch (item.getItemId()) { 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; 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; case R.id.navigation_subscriptions: Log.v(TAG, "navigation_subscriptions"); @@ -69,6 +91,9 @@ public class VideoListActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_list); + // Init icons + Iconify.with(new FontAwesomeModule()); + // Attaching the layout to the toolbar object toolbar = findViewById(R.id.tool_bar); // Setting toolbar as the ActionBar with setSupportActionBar() call @@ -79,6 +104,13 @@ public class VideoListActivity extends AppCompatActivity { // Bottom 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); createList(); @@ -87,11 +119,19 @@ public class VideoListActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); + MenuInflater inflater = getMenuInflater(); + 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; } + @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will @@ -101,8 +141,10 @@ public class VideoListActivity extends AppCompatActivity { switch (item.getItemId()) { // action with ID action_refresh was selected case R.id.action_user: - Toast.makeText(this, "Login Selected", Toast.LENGTH_SHORT) - .show(); +// Toast.makeText(this, "Login Selected", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(this, LoginActivity.class); + this.startActivity(intent); + return true; default: break; diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java new file mode 100644 index 0000000..2739daa --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -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); + } +} diff --git a/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java b/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java index 7848470..bb4ff4f 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java @@ -1,8 +1,10 @@ package net.schueller.peertube.adapter; import android.content.Context; +import android.content.Intent; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -12,10 +14,13 @@ import android.widget.TextView; import com.squareup.picasso.Picasso; import net.schueller.peertube.R; +import net.schueller.peertube.activity.VideoPlayActivity; import net.schueller.peertube.model.Video; import java.util.ArrayList; +import static net.schueller.peertube.activity.VideoListActivity.EXTRA_VIDEOID; + public class VideoAdapter extends RecyclerView.Adapter { @@ -47,6 +52,17 @@ public class VideoAdapter extends RecyclerView.Adapter { + + // 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