2018-12-29 14:19:54 +01:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
package net.schueller.peertube.activity;
|
|
|
|
|
2018-03-11 02:24:06 +01:00
|
|
|
import android.Manifest;
|
2018-12-02 17:28:18 +01:00
|
|
|
import android.app.SearchManager;
|
|
|
|
import android.content.Context;
|
2018-03-04 01:06:32 +01:00
|
|
|
import android.content.Intent;
|
2018-03-04 01:44:34 +01:00
|
|
|
import android.content.SharedPreferences;
|
2018-03-11 02:24:06 +01:00
|
|
|
import android.content.pm.PackageManager;
|
2018-03-11 14:51:39 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2018-12-02 17:28:18 +01:00
|
|
|
import android.provider.SearchRecentSuggestions;
|
2018-12-23 16:42:01 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|
|
|
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2018-03-03 01:10:13 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
|
2018-12-23 16:42:01 +01:00
|
|
|
import androidx.appcompat.app.AppCompatDelegate;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2018-03-03 01:10:13 +01:00
|
|
|
import android.util.Log;
|
2018-03-03 02:46:01 +01:00
|
|
|
import android.view.Menu;
|
2018-03-04 01:06:32 +01:00
|
|
|
import android.view.MenuInflater;
|
2018-03-03 02:46:01 +01:00
|
|
|
import android.view.MenuItem;
|
2018-12-02 17:28:18 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.TextView;
|
2018-03-03 01:10:13 +01:00
|
|
|
import android.widget.Toast;
|
2018-12-23 16:42:01 +01:00
|
|
|
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
|
|
|
|
import com.mikepenz.iconics.IconicsDrawable;
|
2018-03-03 01:10:13 +01:00
|
|
|
import net.schueller.peertube.R;
|
|
|
|
import net.schueller.peertube.adapter.VideoAdapter;
|
2018-03-11 14:51:39 +01:00
|
|
|
import net.schueller.peertube.helper.APIUrlHelper;
|
2018-03-03 01:10:13 +01:00
|
|
|
import net.schueller.peertube.model.VideoList;
|
2018-12-29 22:10:13 +01:00
|
|
|
import net.schueller.peertube.network.GetUserService;
|
2018-03-03 01:10:13 +01:00
|
|
|
import net.schueller.peertube.network.GetVideoDataService;
|
|
|
|
import net.schueller.peertube.network.RetrofitInstance;
|
2018-12-29 22:10:13 +01:00
|
|
|
import net.schueller.peertube.network.Session;
|
2018-12-02 17:28:18 +01:00
|
|
|
import net.schueller.peertube.provider.SearchSuggestionsProvider;
|
2018-12-26 15:24:02 +01:00
|
|
|
import net.schueller.peertube.service.VideoPlayerService;
|
2018-03-03 01:10:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2018-12-31 19:15:35 +01:00
|
|
|
import java.util.Set;
|
2018-03-03 01:10:13 +01:00
|
|
|
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
2018-12-23 16:42:01 +01:00
|
|
|
import static net.schueller.peertube.helper.Constants.DEFAULT_THEME;
|
|
|
|
import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY;
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
public class VideoListActivity extends AppCompatActivity {
|
|
|
|
|
2018-03-03 23:08:18 +01:00
|
|
|
private String TAG = "VideoListActivity";
|
|
|
|
|
2018-03-04 01:06:32 +01:00
|
|
|
public static final String EXTRA_VIDEOID = "VIDEOID ";
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
private VideoAdapter videoAdapter;
|
2018-03-03 23:08:18 +01:00
|
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
2018-03-03 01:10:13 +01:00
|
|
|
|
2018-03-03 02:02:00 +01:00
|
|
|
private int currentStart = 0;
|
|
|
|
private int count = 12;
|
|
|
|
private String sort = "-createdAt";
|
2018-12-29 15:20:06 +01:00
|
|
|
private String filter = null;
|
2018-12-02 17:28:18 +01:00
|
|
|
private String searchQuery = "";
|
2018-12-29 22:10:13 +01:00
|
|
|
private Boolean subscriptions = false;
|
2018-12-02 17:28:18 +01:00
|
|
|
|
|
|
|
private TextView emptyView;
|
|
|
|
private RecyclerView recyclerView;
|
2018-03-03 02:02:00 +01:00
|
|
|
|
|
|
|
private boolean isLoading = false;
|
|
|
|
|
2018-03-03 23:08:18 +01:00
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2018-12-23 16:42:01 +01:00
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
2018-12-21 21:59:10 +01:00
|
|
|
|
|
|
|
// Set Night Mode
|
|
|
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ?
|
|
|
|
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
|
|
|
|
|
|
|
|
// Set theme
|
|
|
|
setTheme(getResources().getIdentifier(
|
2018-12-23 16:42:01 +01:00
|
|
|
sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME),
|
2018-12-21 21:59:10 +01:00
|
|
|
"style",
|
|
|
|
getPackageName())
|
|
|
|
);
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
setContentView(R.layout.activity_video_list);
|
|
|
|
|
2018-12-29 15:20:06 +01:00
|
|
|
filter = null;
|
2018-07-01 15:11:26 +02:00
|
|
|
|
2018-12-23 16:42:01 +01:00
|
|
|
createBottomBarNavigation();
|
2018-03-04 01:06:32 +01:00
|
|
|
|
2018-03-03 02:46:01 +01:00
|
|
|
// Attaching the layout to the toolbar object
|
2018-11-10 22:40:27 +01:00
|
|
|
Toolbar toolbar = findViewById(R.id.tool_bar);
|
2018-03-03 02:46:01 +01:00
|
|
|
// Setting toolbar as the ActionBar with setSupportActionBar() call
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2018-03-11 14:51:39 +01:00
|
|
|
// load Video List
|
2018-03-03 02:02:00 +01:00
|
|
|
createList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:46:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2018-03-04 01:06:32 +01:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
2018-12-29 22:10:13 +01:00
|
|
|
inflater.inflate(R.menu.menu_top_videolist, menu);
|
2018-03-04 01:06:32 +01:00
|
|
|
|
|
|
|
// Set an icon in the ActionBar
|
2018-12-02 17:28:18 +01:00
|
|
|
menu.findItem(R.id.action_settings).setIcon(
|
2018-12-23 16:42:01 +01:00
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_cog).actionBar());
|
2018-12-02 17:28:18 +01:00
|
|
|
|
|
|
|
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
|
2018-12-23 16:42:01 +01:00
|
|
|
|
2018-12-02 17:28:18 +01:00
|
|
|
searchMenuItem.setIcon(
|
2018-12-23 16:42:01 +01:00
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_search).actionBar());
|
2018-03-04 01:06:32 +01:00
|
|
|
|
2018-12-02 17:28:18 +01:00
|
|
|
// Get the SearchView and set the searchable configuration
|
|
|
|
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
|
|
|
SearchView searchView = (SearchView) searchMenuItem.getActionView();
|
|
|
|
|
|
|
|
// Assumes current activity is the searchable activity
|
|
|
|
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
|
|
|
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
|
|
|
|
searchView.setQueryRefinementEnabled(true);
|
|
|
|
|
|
|
|
searchMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionExpand(MenuItem menuItem) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
|
|
|
|
searchQuery = "";
|
|
|
|
Log.d(TAG, "onMenuItemActionCollapse: ");
|
|
|
|
loadVideos(0, count, sort, filter);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO, this doesn't work
|
|
|
|
searchManager.setOnDismissListener(() -> {
|
|
|
|
searchQuery = "";
|
|
|
|
Log.d(TAG, "onDismiss: ");
|
|
|
|
loadVideos(0, count, sort, filter);
|
|
|
|
});
|
|
|
|
|
2018-03-03 02:46:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-26 15:24:02 +01:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
stopService(new Intent(this, VideoPlayerService.class));
|
|
|
|
}
|
2018-03-04 01:06:32 +01:00
|
|
|
|
2018-03-03 02:46:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
// action with ID action_refresh was selected
|
2018-03-14 14:33:17 +01:00
|
|
|
case R.id.action_search:
|
2018-11-10 22:40:27 +01:00
|
|
|
//Toast.makeText(this, "Search Selected", Toast.LENGTH_SHORT).show();
|
2018-03-14 14:33:17 +01:00
|
|
|
|
|
|
|
return false;
|
2018-03-11 14:51:39 +01:00
|
|
|
case R.id.action_settings:
|
2018-03-04 01:06:32 +01:00
|
|
|
// Toast.makeText(this, "Login Selected", Toast.LENGTH_SHORT).show();
|
2018-03-11 14:51:39 +01:00
|
|
|
Intent intent = new Intent(this, SettingsActivity.class);
|
2018-03-04 01:06:32 +01:00
|
|
|
this.startActivity(intent);
|
|
|
|
|
2018-03-03 02:46:01 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2018-03-03 02:02:00 +01:00
|
|
|
|
|
|
|
private void createList() {
|
2018-12-02 17:28:18 +01:00
|
|
|
recyclerView = findViewById(R.id.recyclerView);
|
2018-03-03 23:08:18 +01:00
|
|
|
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
|
2018-03-03 02:02:00 +01:00
|
|
|
|
2018-12-02 17:28:18 +01:00
|
|
|
emptyView = findViewById(R.id.empty_view);
|
|
|
|
|
2018-03-03 02:02:00 +01:00
|
|
|
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(VideoListActivity.this);
|
|
|
|
recyclerView.setLayoutManager(layoutManager);
|
|
|
|
|
|
|
|
videoAdapter = new VideoAdapter(new ArrayList<>(), VideoListActivity.this);
|
|
|
|
recyclerView.setAdapter(videoAdapter);
|
|
|
|
|
2018-07-01 15:11:26 +02:00
|
|
|
loadVideos(currentStart, count, sort, filter);
|
2018-03-03 02:02:00 +01:00
|
|
|
|
|
|
|
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
2018-11-10 22:40:27 +01:00
|
|
|
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
2018-03-03 02:02:00 +01:00
|
|
|
super.onScrollStateChanged(recyclerView, newState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-11-10 22:40:27 +01:00
|
|
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
2018-03-03 02:02:00 +01:00
|
|
|
|
|
|
|
if (dy > 0) {
|
|
|
|
// is at end of list?
|
2018-12-02 14:40:44 +01:00
|
|
|
if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
|
2018-03-03 02:02:00 +01:00
|
|
|
if (!isLoading) {
|
|
|
|
currentStart = currentStart + count;
|
2018-07-01 15:11:26 +02:00
|
|
|
loadVideos(currentStart, count, sort, filter);
|
2018-03-03 02:02:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2018-03-03 23:08:18 +01:00
|
|
|
|
|
|
|
swipeRefreshLayout.setOnRefreshListener(() -> {
|
|
|
|
// Refresh items
|
|
|
|
if (!isLoading) {
|
|
|
|
currentStart = 0;
|
2018-07-01 15:11:26 +02:00
|
|
|
loadVideos(currentStart, count, sort, filter);
|
2018-03-03 23:08:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-03 02:02:00 +01:00
|
|
|
}
|
|
|
|
|
2018-07-01 15:11:26 +02:00
|
|
|
private void loadVideos(int start, int count, String sort, String filter) {
|
2018-03-03 02:02:00 +01:00
|
|
|
|
|
|
|
isLoading = true;
|
|
|
|
|
2018-11-07 23:11:19 +01:00
|
|
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
2018-11-11 01:15:06 +01:00
|
|
|
String nsfw = sharedPref.getBoolean("pref_show_nsfw", false) ? "both" : "false";
|
2018-12-31 19:15:35 +01:00
|
|
|
Set<String> languages = sharedPref.getStringSet("pref_language", null);
|
2018-11-13 22:16:30 +01:00
|
|
|
String apiBaseURL = APIUrlHelper.getUrlWithVersion(this);
|
2018-03-04 01:44:34 +01:00
|
|
|
|
2018-11-13 22:16:30 +01:00
|
|
|
GetVideoDataService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetVideoDataService.class);
|
2018-03-03 01:10:13 +01:00
|
|
|
|
2018-12-02 17:28:18 +01:00
|
|
|
Call<VideoList> call;
|
|
|
|
if (!searchQuery.equals("")) {
|
2018-12-31 19:15:35 +01:00
|
|
|
call = service.searchVideosData(start, count, sort, nsfw, searchQuery, filter, languages);
|
2018-12-29 22:10:13 +01:00
|
|
|
} else if (subscriptions) {
|
|
|
|
GetUserService userService = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetUserService.class);
|
|
|
|
call = userService.getVideosSubscripions(start, count, sort);
|
2018-12-02 17:28:18 +01:00
|
|
|
} else {
|
2018-12-31 19:15:35 +01:00
|
|
|
call = service.getVideosData(start, count, sort, nsfw, filter, languages);
|
2018-12-02 17:28:18 +01:00
|
|
|
}
|
2018-03-03 01:10:13 +01:00
|
|
|
|
|
|
|
/*Log the URL called*/
|
2018-03-03 23:08:18 +01:00
|
|
|
Log.d("URL Called", call.request().url() + "");
|
2018-11-10 17:48:09 +01:00
|
|
|
// Toast.makeText(VideoListActivity.this, "URL Called: " + call.request().url(), Toast.LENGTH_SHORT).show();
|
2018-03-03 01:10:13 +01:00
|
|
|
|
|
|
|
call.enqueue(new Callback<VideoList>() {
|
|
|
|
@Override
|
2018-03-03 02:46:01 +01:00
|
|
|
public void onResponse(@NonNull Call<VideoList> call, @NonNull Response<VideoList> response) {
|
2018-03-03 23:08:18 +01:00
|
|
|
|
|
|
|
if (currentStart == 0) {
|
|
|
|
videoAdapter.clearData();
|
|
|
|
}
|
|
|
|
|
2018-11-07 23:11:19 +01:00
|
|
|
if (response.body() != null) {
|
|
|
|
videoAdapter.setData(response.body().getVideoArrayList());
|
|
|
|
}
|
2018-12-02 17:28:18 +01:00
|
|
|
|
|
|
|
// no results show no results message
|
|
|
|
if (currentStart == 0 && videoAdapter.getItemCount() == 0) {
|
|
|
|
emptyView.setVisibility(View.VISIBLE);
|
|
|
|
recyclerView.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:02:00 +01:00
|
|
|
isLoading = false;
|
2018-03-03 23:08:18 +01:00
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
2018-03-03 01:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-03 02:46:01 +01:00
|
|
|
public void onFailure(@NonNull Call<VideoList> call, @NonNull Throwable t) {
|
2018-03-03 01:10:13 +01:00
|
|
|
Log.wtf("err", t.fillInStackTrace());
|
|
|
|
Toast.makeText(VideoListActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
|
2018-03-03 02:02:00 +01:00
|
|
|
isLoading = false;
|
2018-03-03 23:08:18 +01:00
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
2018-03-03 01:10:13 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:42:01 +01:00
|
|
|
|
2018-03-11 02:24:06 +01:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2018-12-02 14:40:44 +01:00
|
|
|
// only check when we actually need the permission
|
|
|
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED &&
|
|
|
|
sharedPref.getBoolean("pref_torrent_player", false)) {
|
2018-03-11 02:24:06 +01:00
|
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 17:28:18 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
setIntent(intent);
|
|
|
|
handleIntent(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleIntent(Intent intent) {
|
|
|
|
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
|
|
|
String query = intent.getStringExtra(SearchManager.QUERY);
|
|
|
|
|
|
|
|
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
|
|
|
|
SearchSuggestionsProvider.AUTHORITY,
|
|
|
|
SearchSuggestionsProvider.MODE);
|
|
|
|
|
|
|
|
// Save recent searches
|
|
|
|
suggestions.saveRecentQuery(query, null);
|
|
|
|
|
|
|
|
searchQuery = query;
|
|
|
|
|
|
|
|
loadVideos(0, count, sort, filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSearchRequested() {
|
|
|
|
Bundle appData = new Bundle();
|
|
|
|
startSearch(null, false, appData, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-23 16:42:01 +01:00
|
|
|
private void createBottomBarNavigation() {
|
|
|
|
|
|
|
|
// Get Bottom Navigation
|
|
|
|
BottomNavigationView navigation = findViewById(R.id.navigation);
|
|
|
|
|
|
|
|
// Always show text label
|
|
|
|
navigation.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
|
|
|
|
|
|
|
|
// Add Icon font
|
|
|
|
Menu navMenu = navigation.getMenu();
|
|
|
|
navMenu.findItem(R.id.navigation_home).setIcon(
|
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_home));
|
|
|
|
navMenu.findItem(R.id.navigation_trending).setIcon(
|
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_fire));
|
2018-12-29 15:20:06 +01:00
|
|
|
navMenu.findItem(R.id.navigation_local).setIcon(
|
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_home));
|
2018-12-23 16:42:01 +01:00
|
|
|
navMenu.findItem(R.id.navigation_subscriptions).setIcon(
|
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_folder));
|
|
|
|
navMenu.findItem(R.id.navigation_account).setIcon(
|
|
|
|
new IconicsDrawable(this, FontAwesome.Icon.faw_user_circle));
|
|
|
|
|
|
|
|
// Click Listener
|
|
|
|
navigation.setOnNavigationItemSelectedListener(menuItem -> {
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case R.id.navigation_home:
|
|
|
|
//Log.v(TAG, "navigation_home");
|
|
|
|
|
|
|
|
if (!isLoading) {
|
|
|
|
sort = "-createdAt";
|
|
|
|
currentStart = 0;
|
2018-12-29 15:20:06 +01:00
|
|
|
filter = null;
|
2018-12-29 22:10:13 +01:00
|
|
|
subscriptions = false;
|
2018-12-23 16:42:01 +01:00
|
|
|
loadVideos(currentStart, count, sort, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
case R.id.navigation_trending:
|
|
|
|
//Log.v(TAG, "navigation_trending");
|
|
|
|
|
|
|
|
if (!isLoading) {
|
|
|
|
sort = "-trending";
|
|
|
|
currentStart = 0;
|
2018-12-29 15:20:06 +01:00
|
|
|
filter = null;
|
2018-12-29 22:10:13 +01:00
|
|
|
subscriptions = false;
|
2018-12-29 15:20:06 +01:00
|
|
|
loadVideos(currentStart, count, sort, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
case R.id.navigation_local:
|
|
|
|
//Log.v(TAG, "navigation_trending");
|
|
|
|
|
|
|
|
if (!isLoading) {
|
|
|
|
sort = "-publishedAt";
|
|
|
|
filter = "local";
|
|
|
|
currentStart = 0;
|
2018-12-29 22:10:13 +01:00
|
|
|
subscriptions = false;
|
2018-12-23 16:42:01 +01:00
|
|
|
loadVideos(currentStart, count, sort, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
case R.id.navigation_subscriptions:
|
|
|
|
//Log.v(TAG, "navigation_subscriptions");
|
|
|
|
|
2018-12-29 22:10:13 +01:00
|
|
|
if (!Session.getInstance().isLoggedIn()) {
|
|
|
|
Intent intent = new Intent(this, LoginActivity.class);
|
|
|
|
this.startActivity(intent);
|
2018-12-31 20:32:22 +01:00
|
|
|
return false;
|
2018-12-29 22:10:13 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
if (!isLoading) {
|
|
|
|
sort = "-publishedAt";
|
|
|
|
filter = null;
|
|
|
|
currentStart = 0;
|
|
|
|
subscriptions = true;
|
|
|
|
loadVideos(currentStart, count, sort, filter);
|
|
|
|
}
|
2018-12-31 20:32:22 +01:00
|
|
|
return true;
|
2018-12-29 22:10:13 +01:00
|
|
|
}
|
|
|
|
|
2018-12-23 16:42:01 +01:00
|
|
|
|
|
|
|
case R.id.navigation_account:
|
|
|
|
//Log.v(TAG, "navigation_account");
|
2018-12-29 22:10:13 +01:00
|
|
|
//Toast.makeText(VideoListActivity.this, "Account Not Implemented", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
if (!Session.getInstance().isLoggedIn()) {
|
|
|
|
Intent intent = new Intent(this, LoginActivity.class);
|
|
|
|
this.startActivity(intent);
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(this, AccountActivity.class);
|
|
|
|
this.startActivity(intent);
|
|
|
|
}
|
2018-12-23 16:42:01 +01:00
|
|
|
|
2018-12-31 20:32:22 +01:00
|
|
|
return false;
|
2018-12-23 16:42:01 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
}
|