From 39b1138ad7f08742d9211247ccf80265d9e6454a Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sat, 3 Mar 2018 23:08:18 +0100 Subject: [PATCH] Bottom navigation, pull to refresh, layout changes --- app/build.gradle | 4 ++ .../peertube/activity/VideoListActivity.java | 45 ++++++++++++++++++- .../peertube/adapter/VideoAdapter.java | 14 ++++-- .../res/drawable/ic_dashboard_black_24dp.xml | 9 ++++ .../main/res/drawable/ic_home_black_24dp.xml | 9 ++++ .../drawable/ic_notifications_black_24dp.xml | 9 ++++ .../main/res/layout/activity_video_list.xml | 39 ++++++++++++---- app/src/main/res/layout/row_video.xml | 18 ++++---- app/src/main/res/layout/tool_bar.xml | 2 +- app/src/main/res/menu/navigation.xml | 20 +++++++++ app/src/main/res/values/colors.xml | 7 +-- app/src/main/res/values/strings.xml | 5 +++ app/src/main/res/values/styles.xml | 4 +- build.gradle | 4 ++ 14 files changed, 160 insertions(+), 29 deletions(-) create mode 100644 app/src/main/res/drawable/ic_dashboard_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_home_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_notifications_black_24dp.xml create mode 100644 app/src/main/res/menu/navigation.xml diff --git a/app/build.gradle b/app/build.gradle index b104e0a..55e5f66 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,6 +40,10 @@ dependencies { implementation 'org.webrtc:google-webrtc:1.0.+' implementation 'com.android.support:design:27.1.0' + + implementation 'com.blackboardtheory:android-iconify-fontawesome:3.0.1-SNAPSHOT' + + 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/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index 7516ccb..c9b871a 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -2,6 +2,8 @@ package net.schueller.peertube.activity; import android.app.Activity; import android.support.annotation.NonNull; +import android.support.design.widget.BottomNavigationView; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; @@ -33,8 +35,11 @@ import retrofit2.Response; public class VideoListActivity extends AppCompatActivity { + private String TAG = "VideoListActivity"; + private VideoAdapter videoAdapter; private RecyclerView recyclerView; + private SwipeRefreshLayout swipeRefreshLayout; private Toolbar toolbar; private int currentStart = 0; @@ -43,6 +48,22 @@ public class VideoListActivity extends AppCompatActivity { private boolean isLoading = false; + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener + = item -> { + switch (item.getItemId()) { + case R.id.navigation_home: + Log.v(TAG, "navigation_home"); + return true; + case R.id.navigation_trending: + Log.v(TAG, "navigation_trending"); + return true; + case R.id.navigation_subscriptions: + Log.v(TAG, "navigation_subscriptions"); + return true; + } + return false; + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -56,6 +77,10 @@ public class VideoListActivity extends AppCompatActivity { // fix android trying to use SSLv3 for handshake updateAndroidSecurityProvider(this); + // Bottom Navigation + BottomNavigationView navigation = findViewById(R.id.navigation); + navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + createList(); } @@ -88,6 +113,7 @@ public class VideoListActivity extends AppCompatActivity { private void createList() { recyclerView = findViewById(R.id.recyclerView); + swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(VideoListActivity.this); recyclerView.setLayoutManager(layoutManager); @@ -118,6 +144,15 @@ public class VideoListActivity extends AppCompatActivity { } }); + + swipeRefreshLayout.setOnRefreshListener(() -> { + // Refresh items + if (!isLoading) { + currentStart = 0; + loadVideos(currentStart, count, sort); + } + }); + } private void loadVideos(int start, int count, String sort) { @@ -129,13 +164,20 @@ public class VideoListActivity extends AppCompatActivity { Call call = service.getVideoData(start, count, sort); /*Log the URL called*/ - Log.wtf("URL Called", call.request().url() + ""); + Log.d("URL Called", call.request().url() + ""); + Toast.makeText(VideoListActivity.this, "URL Called: " + call.request().url(), Toast.LENGTH_SHORT).show(); call.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { + + if (currentStart == 0) { + videoAdapter.clearData(); + } + videoAdapter.setData(response.body().getVideoArrayList()); isLoading = false; + swipeRefreshLayout.setRefreshing(false); } @Override @@ -143,6 +185,7 @@ public class VideoListActivity extends AppCompatActivity { Log.wtf("err", t.fillInStackTrace()); Toast.makeText(VideoListActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show(); isLoading = false; + swipeRefreshLayout.setRefreshing(false); } }); } 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 e1550ee..7848470 100644 --- a/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java +++ b/app/src/main/java/net/schueller/peertube/adapter/VideoAdapter.java @@ -43,7 +43,10 @@ public class VideoAdapter extends RecyclerView.Adapter data) { @@ -51,6 +54,11 @@ public class VideoAdapter extends RecyclerView.Adapter + + diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml new file mode 100644 index 0000000..0c36320 --- /dev/null +++ b/app/src/main/res/drawable/ic_home_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_notifications_black_24dp.xml b/app/src/main/res/drawable/ic_notifications_black_24dp.xml new file mode 100644 index 0000000..0262382 --- /dev/null +++ b/app/src/main/res/drawable/ic_notifications_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_video_list.xml b/app/src/main/res/layout/activity_video_list.xml index 7c38208..d01e148 100644 --- a/app/src/main/res/layout/activity_video_list.xml +++ b/app/src/main/res/layout/activity_video_list.xml @@ -13,20 +13,41 @@ android:layout_height="wrap_content" android:orientation="vertical" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> - - - - - + android:layout_above="@+id/navigation" + android:layout_below="@+id/appbar" + android:layout_weight="1" + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_video.xml b/app/src/main/res/layout/row_video.xml index 1036da9..4d12807 100644 --- a/app/src/main/res/layout/row_video.xml +++ b/app/src/main/res/layout/row_video.xml @@ -17,22 +17,24 @@ + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:scaleType="fitXY" + android:contentDescription="" /> + /> diff --git a/app/src/main/res/layout/tool_bar.xml b/app/src/main/res/layout/tool_bar.xml index d8abe41..e70513a 100644 --- a/app/src/main/res/layout/tool_bar.xml +++ b/app/src/main/res/layout/tool_bar.xml @@ -3,6 +3,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" - android:background="@color/ColorPrimary" + android:background="@color/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" android:elevation="4dp" /> \ No newline at end of file diff --git a/app/src/main/res/menu/navigation.xml b/app/src/main/res/menu/navigation.xml new file mode 100644 index 0000000..d84cb9c --- /dev/null +++ b/app/src/main/res/menu/navigation.xml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2996f0d..274bad0 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,10 +1,7 @@ - #FF5722 - #E64A19 - - #F50057 - #F50057 + #f1680d + #E64A19 #FF4081 #f1f5f8 #4c4c4c diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f8dcaf..8b7fbed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,4 +14,9 @@ "Contacts permissions are needed for providing email completions." + + Home + Trending + Subscriptions + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c312a39..26cfc0d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -2,8 +2,8 @@ diff --git a/build.gradle b/build.gradle index e6b32bc..d2752b6 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,10 @@ allprojects { repositories { google() jcenter() + mavenCentral() + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots' + } } }