server selection, wip

This commit is contained in:
Stefan Schüller 2019-02-17 16:26:17 +01:00
parent b607e08f0e
commit 9ee638b868
12 changed files with 373 additions and 80 deletions

View File

@ -78,4 +78,6 @@ android {
dependencies {
implementation 'com.android.support.constraint:constraint-layout:+'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
}

View File

@ -2,73 +2,65 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="net.schueller.peertube">
<!-- connect to peertube server -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- required for torrent downloading -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- required to play video in background via notification -->
<uses-permission android:name="android.permission.INTERNET" /> <!-- required for torrent downloading -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- required to play video in background via notification -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:name=".application.AppApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
android:name=".application.AppApplication">
<activity android:name=".activity.VideoListActivity"
android:theme="@style/AppTheme.NoActionBar"
android:launchMode="singleTop">
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".activity.VideoListActivity"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable">
</meta-data>
android:resource="@xml/searchable"></meta-data>
</activity>
<activity
android:name=".activity.LoginActivity"
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/title_activity_login" />
android:label="@string/title_activity_login"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.VideoPlayActivity"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:label="@string/title_activity_video_play"
android:launchMode="singleTop" />
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/title_activity_settings" />
<activity android:name=".activity.SelectServerActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".activity.MeActivity"
android:label="@string/title_activity_settings"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.SelectServerActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.MeActivity"
android:label="@string/title_activity_account"
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".activity.AccountActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<!-- Content provider for search suggestions -->
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.AccountActivity"
android:theme="@style/AppTheme.NoActionBar" /> <!-- Content provider for search suggestions -->
<provider
android:name=".provider.SearchSuggestionsProvider"
android:authorities="net.schueller.peertube.provider.SearchSuggestionsProvider"
android:enabled="true"
android:exported="false" />
<service android:name=".service.VideoPlayerService" />
</application>
</manifest>

View File

@ -1,61 +1,152 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* License: GPL-3.0+
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.schueller.peertube.activity;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import net.schueller.peertube.R;
import net.schueller.peertube.model.ServerList;
import net.schueller.peertube.network.GetServerListDataService;
import net.schueller.peertube.network.RetrofitInstance;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import net.schueller.peertube.R;
import net.schueller.peertube.adapter.ServerAdapter;
import net.schueller.peertube.adapter.VideoAdapter;
import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.model.ServerList;
import net.schueller.peertube.model.VideoList;
import net.schueller.peertube.network.GetServerListDataService;
import net.schueller.peertube.network.GetVideoDataService;
import net.schueller.peertube.network.RetrofitInstance;
import java.util.ArrayList;
public class SelectServerActivity extends AppCompatActivity {
private ServerAdapter serverAdapter;
private SwipeRefreshLayout swipeRefreshLayout;
private int currentStart = 0;
private int count = 12;
private TextView emptyView;
private RecyclerView recyclerView;
private boolean isLoading = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_server);
setContentView(R.layout.activity_server_selection);
// get list of peertube servers
loadList();
}
// TODO: Get here via settings, get data from API, add to adapter and show in recycle view, upon selection fill settings field
GetServerListDataService service = RetrofitInstance.getRetrofitInstance("https://instances.joinpeertube.org/api/v1/").create(GetServerListDataService.class);
Call<ServerList> call = service.getInstancesData(0, 500);
call.enqueue(new Callback<ServerList>() {
private void loadList() {
recyclerView = findViewById(R.id.serverRecyclerView);
swipeRefreshLayout = findViewById(R.id.serversSwipeRefreshLayout);
emptyView = findViewById(R.id.empty_server_selection_view);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(SelectServerActivity.this);
recyclerView.setLayoutManager(layoutManager);
serverAdapter = new ServerAdapter(new ArrayList<>(), SelectServerActivity.this);
recyclerView.setAdapter(serverAdapter);
loadServers(currentStart, count);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onResponse(@NonNull Call<ServerList> call, @NonNull Response<ServerList> response) {
// response.body().getVideoArrayList();
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onFailure(@NonNull Call<ServerList> call, @NonNull Throwable t) {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
// is at end of list?
if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
if (!isLoading) {
currentStart = currentStart + count;
loadServers(currentStart, count);
}
}
}
}
});
swipeRefreshLayout.setOnRefreshListener(() -> {
// Refresh items
if (!isLoading) {
currentStart = 0;
loadServers(currentStart, count);
}
});
}
private void loadServers(int start, int count) {
isLoading = true;
GetServerListDataService service = RetrofitInstance.getRetrofitInstance(
APIUrlHelper.getServerIndexUrl(SelectServerActivity.this)
).create(GetServerListDataService.class);
Call<ServerList> call;
call = service.getInstancesData(start, count);
Log.d("URL Called", call.request().url() + "");
call.enqueue(new Callback<ServerList>() {
@Override
public void onResponse(@NonNull Call<ServerList> call, @NonNull Response<ServerList> response) {
if (currentStart == 0) {
serverAdapter.clearData();
}
if (response.body() != null) {
serverAdapter.setData(response.body().getServerArrayList());
}
// no results show no results message
if (currentStart == 0 && serverAdapter.getItemCount() == 0) {
emptyView.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
emptyView.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
isLoading = false;
swipeRefreshLayout.setRefreshing(false);
}
@Override
public void onFailure(@NonNull Call<ServerList> call, @NonNull Throwable t) {
Log.wtf("err", t.fillInStackTrace());
Toast.makeText(SelectServerActivity.this, getString(R.string.api_error), Toast.LENGTH_SHORT).show();
isLoading = false;
swipeRefreshLayout.setRefreshing(false);
}
});
}
}

View File

@ -128,6 +128,9 @@ public class VideoListActivity extends CommonActivity {
menu.findItem(R.id.action_account).setIcon(
new IconicsDrawable(this, FontAwesome.Icon.faw_user_circle).actionBar());
menu.findItem(R.id.action_server_selection).setIcon(
new IconicsDrawable(this, FontAwesome.Icon.faw_server).actionBar());
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
searchMenuItem.setIcon(
@ -200,6 +203,10 @@ public class VideoListActivity extends CommonActivity {
this.startActivity(intentMe);
}
return false;
case R.id.action_server_selection:
Intent intentServer = new Intent(this, SelectServerActivity.class);
this.startActivity(intentServer);
return false;
default:
break;
}

View File

@ -0,0 +1,119 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* License: GPL-3.0+
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.schueller.peertube.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.schueller.peertube.R;
import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.model.Server;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.AccountViewHolder> {
private ArrayList<Server> serverList;
private Context context;
private String baseUrl;
public ServerAdapter(ArrayList<Server> serverList, Context context) {
this.serverList = serverList;
this.context = context;
}
@NonNull
@Override
public AccountViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.row_server, parent, false);
baseUrl = APIUrlHelper.getUrl(context);
return new AccountViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull AccountViewHolder holder, int position) {
holder.name.setText(serverList.get(position).getName());
holder.host.setText(serverList.get(position).getHost());
holder.shortDescription.setText(serverList.get(position).getShortDescription());
//
//
// holder.moreButton.setText(R.string.video_more_icon);
// new Iconics.IconicsBuilder().ctx(context).on(holder.moreButton).build();
//
// holder.moreButton.setOnClickListener(v -> {
//
// PopupMenu popup = new PopupMenu(context, v);
// popup.setOnMenuItemClickListener(menuItem -> {
// switch (menuItem.getItemId()) {
// case R.id.menu_share:
// Intents.Share(context, serverList.get(position));
// return true;
// default:
// return false;
// }
// });
// popup.inflate(R.menu.menu_video_row_mode);
// popup.show();
//
// });
}
public void setData(ArrayList<Server> data) {
serverList.addAll(data);
this.notifyDataSetChanged();
}
public void clearData() {
serverList.clear();
this.notifyDataSetChanged();
}
@Override
public int getItemCount() {
return serverList.size();
}
class AccountViewHolder extends RecyclerView.ViewHolder {
TextView name, host, shortDescription;
AccountViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.name);
host = itemView.findViewById(R.id.host);
shortDescription = itemView.findViewById(R.id.shortDescription);
}
}
}

View File

@ -44,4 +44,8 @@ public class APIUrlHelper{
public static String getShareUrl(Context context, String videoUuid) {
return APIUrlHelper.getUrl(context) + "/videos/watch/" + videoUuid;
}
public static String getServerIndexUrl(Context context) {
return "https://instances.joinpeertube.org/api/v1/";
}
}

View File

@ -25,7 +25,7 @@ public class Server {
private String shortDescription;
private String version;
private Boolean signupAllowed;
private Integer userVideoQuota;
private Double userVideoQuota;
private Integer totalUsers;
private Integer totalVideos;
private Integer totalLocalVideos;
@ -81,11 +81,11 @@ public class Server {
this.signupAllowed = signupAllowed;
}
public Integer getUserVideoQuota() {
public Double getUserVideoQuota() {
return userVideoQuota;
}
public void setUserVideoQuota(Integer userVideoQuota) {
public void setUserVideoQuota(Double userVideoQuota) {
this.userVideoQuota = userVideoQuota;
}

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.SelectServerActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.SelectServerActivity">
<TextView
android:id="@+id/empty_server_selection_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"
android:text="@string/no_data_available" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/serversSwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/serverRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</androidx.recyclerview.widget.RecyclerView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?><!-- START*** Root Container *** -->
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dp">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="24dp"
android:paddingTop="0dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Headline" />
<TextView
android:id="@+id/host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="24dp"
android:paddingTop="0dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
<TextView
android:id="@+id/shortDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="24dp"
android:paddingTop="0dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead" />
</LinearLayout>
</androidx.cardview.widget.CardView>

View File

@ -26,4 +26,11 @@
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_server_selection"
android:orderInCategory="300"
android:title="@string/action_bar_title_server_selection"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
app:showAsAction="ifRoom" />
</menu>

View File

@ -344,5 +344,6 @@
<string name="video_rating_none" translatable="false">none</string>
<string name="video_rating_like" translatable="false">like</string>
<string name="video_rating_dislike" translatable="false">dislike</string>
<string name="action_bar_title_server_selection">Select Server</string>
</resources>