Bottom navigation, pull to refresh, layout changes

This commit is contained in:
Stefan Schueller 2018-03-03 23:08:18 +01:00
parent 69d2dcb7fe
commit 39b1138ad7
14 changed files with 160 additions and 29 deletions

View File

@ -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'

View File

@ -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<VideoList> 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<VideoList>() {
@Override
public void onResponse(@NonNull Call<VideoList> call, @NonNull Response<VideoList> 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);
}
});
}

View File

@ -43,7 +43,10 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
.into(holder.thumb);
holder.name.setText(videoList.get(position).getName());
holder.description.setText(videoList.get(position).getDescription());
holder.videoMeta.setText(videoList.get(position).getAccountName()
.concat("@")
.concat(videoList.get(position).getServerHost()).concat(" - ")
.concat(videoList.get(position).getViews()+" Views"));
}
public void setData(ArrayList<Video> data) {
@ -51,6 +54,11 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
this.notifyDataSetChanged();
}
public void clearData() {
videoList.clear();
this.notifyDataSetChanged();
}
@Override
public int getItemCount() {
return videoList.size();
@ -58,14 +66,14 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
class VideoViewHolder extends RecyclerView.ViewHolder {
TextView name, description;
TextView name, videoMeta;
ImageView thumb;
VideoViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.name);
thumb = itemView.findViewById(R.id.thumb);
description = itemView.findViewById(R.id.description);
videoMeta = itemView.findViewById(R.id.videoMeta);
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>

View File

@ -13,20 +13,41 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:layout_below="@+id/appbar"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:layout_below="@+id/tool_bar"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
android:layout_gravity="bottom" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -17,22 +17,24 @@
<ImageView
android:id="@+id/thumb"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:contentDescription="" />
<TextView
android:layout_marginStart="75dp"
android:id="@+id/name"
android:layout_margin="5dp"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="username"/>
/>
<TextView
android:id="@+id/description"
android:layout_marginStart="75dp"
android:id="@+id/videoMeta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
/>
</LinearLayout>

View File

@ -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" />

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_trending" />
<item
android:id="@+id/navigation_subscriptions"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_subscriptions" />
</menu>

View File

@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ColorPrimary">#FF5722</color>
<color name="ColorPrimaryDark">#E64A19</color>
<color name="colorPrimary">#F50057</color>
<color name="colorPrimaryDark">#F50057</color>
<color name="colorPrimary">#f1680d</color>
<color name="colorPrimaryDark">#E64A19</color>
<color name="colorAccent">#FF4081</color>
<color name="viewBg">#f1f5f8</color>
<color name="album_title">#4c4c4c</color>

View File

@ -14,4 +14,9 @@
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
<string name="title_home">Home</string>
<string name="title_trending">Trending</string>
<string name="title_subscriptions">Subscriptions</string>
</resources>

View File

@ -2,8 +2,8 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

View File

@ -19,6 +19,10 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
}