Cleanup old code, expanded video info in list, moved hardcoded stuff.

This commit is contained in:
Stefan Schueller 2018-03-04 20:24:32 +01:00
parent 13d712e3e5
commit 6df4031250
5 changed files with 32 additions and 53 deletions

View File

@ -205,9 +205,9 @@ public class VideoListActivity extends AppCompatActivity {
SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE); SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
String defaultApiURL = getResources().getString(R.string.api_base_url); String defaultApiURL = getResources().getString(R.string.api_base_url);
String apiURL = sharedPref.getString(getString(R.string.api_url_key_key), defaultApiURL); String apiBaseURL = sharedPref.getString(getString(R.string.api_url_key_key), defaultApiURL);
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiURL).create(GetVideoDataService.class); GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL + "/api/v1/").create(GetVideoDataService.class);
Call<VideoList> call = service.getVideoData(start, count, sort); Call<VideoList> call = service.getVideoData(start, count, sort);

View File

@ -1,7 +1,9 @@
package net.schueller.peertube.adapter; package net.schueller.peertube.adapter;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
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.util.Log;
@ -26,6 +28,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
private ArrayList<Video> videoList; private ArrayList<Video> videoList;
private Context context; private Context context;
private String apiBaseURL;
public VideoAdapter(ArrayList<Video> videoList, Context context) { public VideoAdapter(ArrayList<Video> videoList, Context context) {
this.videoList = videoList; this.videoList = videoList;
@ -37,6 +40,11 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.row_video, parent, false); View view = layoutInflater.inflate(R.layout.row_video, parent, false);
SharedPreferences sharedPref = ((Activity) context).getPreferences(Context.MODE_PRIVATE);
String defaultApiURL = context.getResources().getString(R.string.api_base_url);
apiBaseURL = sharedPref.getString(context.getString(R.string.api_url_key_key), defaultApiURL);
return new VideoViewHolder(view); return new VideoViewHolder(view);
} }
@ -44,15 +52,21 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) { public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) {
Picasso.with(this.context) Picasso.with(this.context)
.load("https://troll.tv" + videoList.get(position).getPreviewPath()) .load(apiBaseURL + videoList.get(position).getPreviewPath())
.into(holder.thumb); .into(holder.thumb);
holder.name.setText(videoList.get(position).getName()); holder.name.setText(videoList.get(position).getName());
holder.videoMeta.setText(videoList.get(position).getAccountName()
.concat("@") // TODO: clean this up
.concat(videoList.get(position).getServerHost()).concat(" - ") // set age and view count
holder.videoMeta.setText(videoList.get(position).getCreatedAt().toString().concat(" - ")
.concat(videoList.get(position).getViews()+" Views")); .concat(videoList.get(position).getViews()+" Views"));
// set owner
holder.videoOwner.setText(videoList.get(position).getAccountName()
.concat("@")
.concat(videoList.get(position).getServerHost()));
holder.mView.setOnClickListener(v -> { holder.mView.setOnClickListener(v -> {
// Log.v("VideoAdapter", "click: " + videoList.get(position).getName()); // Log.v("VideoAdapter", "click: " + videoList.get(position).getName());
@ -82,7 +96,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
class VideoViewHolder extends RecyclerView.ViewHolder { class VideoViewHolder extends RecyclerView.ViewHolder {
TextView name, videoMeta; TextView name, videoMeta, videoOwner;
ImageView thumb; ImageView thumb;
View mView; View mView;
@ -91,6 +105,7 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHol
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);
videoOwner = itemView.findViewById(R.id.videoOwner);
mView = itemView; mView = itemView;
} }
} }

View File

@ -1,44 +0,0 @@
package net.schueller.peertube.services;
import com.google.gson.annotations.SerializedName;
import net.schueller.peertube.model.Video;
import java.io.IOException;
import java.util.List;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
public final class RecentlyAddedVideosService {
public static final String API_URL = "https://troll.tv/api/v1";
public interface RecentlyAddedVideos {
@GET("/videos/?start=0&count=12&sort=-createdAt")
@SerializedName("data")
Call<List<Video>> videos();
}
public static void main(String... args) throws IOException {
// Create a very simple REST adapter which points the PeerTube API.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Create an instance of our GitHub API interface.
RecentlyAddedVideos recentlyAddedVideos = retrofit.create(RecentlyAddedVideos.class);
// Create a call instance for looking up Retrofit contributors.
Call<List<Video>> call = recentlyAddedVideos.videos();
// Fetch and print a list of the contributors to the library.
List<Video> videos = call.execute().body();
for (Video video : videos) {
System.out.println(video.getName());
}
}
}

View File

@ -37,6 +37,14 @@
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption" android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
/> />
<TextView
android:layout_marginStart="75dp"
android:id="@+id/videoOwner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
/>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>

View File

@ -24,7 +24,7 @@
<string name="dummy_button">Dummy Button</string> <string name="dummy_button">Dummy Button</string>
<string name="dummy_content">DUMMY\nCONTENT</string> <string name="dummy_content">DUMMY\nCONTENT</string>
<string name="api_base_url" formatted="false">https://troll.tv/api/v1/</string> <string name="api_base_url" formatted="false">https://troll.tv</string>
<string name="api_url_key_key">api_url</string> <string name="api_url_key_key">api_base_url</string>
</resources> </resources>