Some changes

This commit is contained in:
Thomas 2023-03-15 16:41:20 +01:00
parent ffe7dbf1dd
commit 462a9a1d44
8 changed files with 58 additions and 80 deletions

View file

@ -19,7 +19,6 @@ import android.app.Application;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.AndroidViewModel;
@ -475,19 +474,14 @@ public class StatusesVM extends AndroidViewModel {
List<Account> accounts = null; List<Account> accounts = null;
Headers headers = null; Headers headers = null;
if (accountsCall != null) { if (accountsCall != null) {
Log.v(Helper.TAG, "accountsCall: " + accountsCall.request());
try { try {
Response<List<Account>> accountsResponse = accountsCall.execute(); Response<List<Account>> accountsResponse = accountsCall.execute();
if (accountsResponse.isSuccessful()) { if (accountsResponse.isSuccessful()) {
accounts = accountsResponse.body(); accounts = accountsResponse.body();
Log.v(Helper.TAG, "accounts: " + accounts);
} else {
Log.v(Helper.TAG, "err: " + accountsResponse.errorBody().string());
} }
headers = accountsResponse.headers(); headers = accountsResponse.headers();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.v(Helper.TAG, "er: " + e.getMessage());
} }
} }
Accounts accountsPagination = new Accounts(); Accounts accountsPagination = new Accounts();

View file

@ -41,7 +41,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -54,6 +53,7 @@ import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.TooltipCompat; import androidx.appcompat.widget.TooltipCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter;
@ -61,7 +61,6 @@ import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.kobakei.ratethisapp.RateThisApp; import com.kobakei.ratethisapp.RateThisApp;
@ -118,27 +117,6 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
private DisplayOverviewFragment overviewFragment; private DisplayOverviewFragment overviewFragment;
private ActivityMainPeertubeBinding binding; private ActivityMainPeertubeBinding binding;
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
int itemId = item.getItemId();
if (itemId == R.id.navigation_discover) {
setTitleCustom(R.string.title_discover);
binding.viewpager.setCurrentItem(3);
} else if (itemId == R.id.navigation_subscription) {
binding.viewpager.setCurrentItem(4);
setTitleCustom(R.string.subscriptions);
} else if (itemId == R.id.navigation_trending) {
setTitleCustom(R.string.title_trending);
binding.viewpager.setCurrentItem(2);
} else if (itemId == R.id.navigation_recently_added) {
setTitleCustom(R.string.title_recently_added);
binding.viewpager.setCurrentItem(1);
} else if (itemId == R.id.navigation_local) {
setTitleCustom(R.string.title_local);
binding.viewpager.setCurrentItem(0);
}
return true;
};
private void setTitleCustom(int titleRId) { private void setTitleCustom(int titleRId) {
@ -178,7 +156,6 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) { if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) {
String defaultInstance = sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null); String defaultInstance = sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null);
Log.v(app.fedilab.android.mastodon.helper.Helper.TAG, "defaultInstance-->: " + defaultInstance);
if (defaultInstance == null) { if (defaultInstance == null) {
getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, PeertubeMainActivity.this, (requestKey, result) -> { getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, PeertubeMainActivity.this, (requestKey, result) -> {
new Thread(() -> { new Thread(() -> {
@ -192,9 +169,9 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
addFragment( addFragment(
getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(), getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(),
null, null, FragmentLoginPickInstancePeertube.class.getName()); null, null, FragmentLoginPickInstancePeertube.class.getName());
}
return; return;
} }
}
Toolbar toolbar = findViewById(R.id.toolbar); Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -202,8 +179,48 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
badgeCount = 0; badgeCount = 0;
headerMenuOpen = false; headerMenuOpen = false;
binding.navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); if (typeOfConnection == TypeOfConnection.NORMAL) {
binding.navView.setOnItemSelectedListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.navigation_discover) {
setTitleCustom(R.string.title_discover);
binding.viewpager.setCurrentItem(3);
} else if (itemId == R.id.navigation_subscription) {
binding.viewpager.setCurrentItem(4);
setTitleCustom(R.string.subscriptions);
} else if (itemId == R.id.navigation_trending) {
setTitleCustom(R.string.title_trending);
binding.viewpager.setCurrentItem(2);
} else if (itemId == R.id.navigation_recently_added) {
setTitleCustom(R.string.title_recently_added);
binding.viewpager.setCurrentItem(1);
} else if (itemId == R.id.navigation_local) {
setTitleCustom(R.string.title_local);
binding.viewpager.setCurrentItem(0);
}
return true;
});
startInForeground(); startInForeground();
} else {
binding.navView.setOnItemSelectedListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.navigation_discover) {
setTitleCustom(R.string.title_discover);
binding.viewpager.setCurrentItem(3);
} else if (itemId == R.id.navigation_trending) {
setTitleCustom(R.string.title_trending);
binding.viewpager.setCurrentItem(2);
} else if (itemId == R.id.navigation_recently_added) {
setTitleCustom(R.string.title_recently_added);
binding.viewpager.setCurrentItem(1);
} else if (itemId == R.id.navigation_local) {
setTitleCustom(R.string.title_local);
binding.viewpager.setCurrentItem(0);
}
return true;
});
}
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
} }
@ -232,10 +249,10 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.MOST_LIKED); bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.MOST_LIKED);
mostLikedFragment.setArguments(bundle); mostLikedFragment.setArguments(bundle);
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
currentAccount = null; currentAccount = null;
if (Helper.isLoggedIn()) { if (Helper.isLoggedIn()) {
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
new Thread(() -> { new Thread(() -> {
try { try {
if (currentToken == null) { if (currentToken == null) {
@ -313,15 +330,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
}; };
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
}).start(); }).start();
} else {
binding.navView.inflateMenu(R.menu.bottom_nav_menu_peertube);
}
headerMainBinding.instanceInfo.setVisibility(View.GONE); headerMainBinding.instanceInfo.setVisibility(View.GONE);
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager()));
if (Helper.isLoggedIn()) {
binding.drawerNavView.addHeaderView(headerMainBinding.getRoot()); binding.drawerNavView.addHeaderView(headerMainBinding.getRoot());
binding.drawerNavView.setNavigationItemSelectedListener(item -> { binding.drawerNavView.setNavigationItemSelectedListener(item -> {
if (item.getItemId() == R.id.action_settings) { if (item.getItemId() == R.id.action_settings) {
@ -377,11 +386,12 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
binding.drawerLayout.close(); binding.drawerLayout.close();
return false; return false;
}); });
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager()));
fetchRecentAccounts(PeertubeMainActivity.this, headerMainBinding);
} else { } else {
binding.drawerNavView.setVisibility(View.GONE); binding.navView.inflateMenu(R.menu.bottom_nav_menu_peertube);
binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} }
overviewFragment = new DisplayOverviewFragment(); overviewFragment = new DisplayOverviewFragment();
if (!Helper.isLoggedIn()) { if (!Helper.isLoggedIn()) {
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
@ -451,26 +461,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
if (search_cast) { if (search_cast) {
super.discoverCast(); super.discoverCast();
} }
//Instance
if (HelperInstance.getLiveInstance(PeertubeMainActivity.this) == null) {
getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, this, (requestKey, result) -> {
String instance = result.getString(INSTANCE_ADDRESS, null);
if (instance != null) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_INSTANCE, instance);
editor.commit();
PeertubeMainActivity.this.recreate();
}
getSupportFragmentManager().clearFragmentResultListener(requestKey);
});
addFragment(
getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(),
null, null, FragmentLoginPickInstancePeertube.class.getName());
}
mamageNewIntent(PeertubeMainActivity.this, getIntent()); mamageNewIntent(PeertubeMainActivity.this, getIntent());
fetchRecentAccounts(PeertubeMainActivity.this, headerMainBinding);
} }
public DisplayVideosFragment getSubscriptionFragment() { public DisplayVideosFragment getSubscriptionFragment() {
@ -498,7 +489,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
private void refreshToken() { private void refreshToken() {
new Thread(() -> { new Thread(() -> {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this);
String tokenStr = Helper.getToken(PeertubeMainActivity.this); String tokenStr = HelperInstance.getToken();
String instance = HelperInstance.getLiveInstance(PeertubeMainActivity.this); String instance = HelperInstance.getLiveInstance(PeertubeMainActivity.this);
String instanceShar = sharedpreferences.getString(PREF_USER_INSTANCE, null); String instanceShar = sharedpreferences.getString(PREF_USER_INSTANCE, null);
String userIdShar = sharedpreferences.getString(PREF_USER_ID, null); String userIdShar = sharedpreferences.getString(PREF_USER_ID, null);

View file

@ -310,7 +310,7 @@ public class PeertubeUploadActivity extends BaseBarActivity {
filename = binding.videoTitle.getText().toString().trim(); filename = binding.videoTitle.getText().toString().trim();
} }
try { try {
String token = Helper.getToken(PeertubeUploadActivity.this); String token = HelperInstance.getToken();
new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + HelperInstance.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload") new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + HelperInstance.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.setMethod("POST") .setMethod("POST")
.setBearerAuth(token) .setBearerAuth(token)

View file

@ -237,7 +237,7 @@ public class RetrofitPeertubeAPI {
.build(); .build();
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(_context);
if (token == null) { if (token == null) {
token = Helper.getToken(_context); token = HelperInstance.getToken();
} }
selection = sharedpreferences.getStringSet(_context.getString(R.string.set_video_language_choice), null); selection = sharedpreferences.getStringSet(_context.getString(R.string.set_video_language_choice), null);
return retrofit.create(PeertubeService.class); return retrofit.create(PeertubeService.class);

View file

@ -26,7 +26,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -307,7 +306,6 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, instance); editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, instance);
editor.commit(); editor.commit();
Log.v(Helper.TAG, "-->: " + instance);
requireActivity().recreate(); requireActivity().recreate();
} else { } else {

View file

@ -666,11 +666,6 @@ public class Helper {
} }
public static String getToken(Context context) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedpreferences.getString(PREF_USER_TOKEN, null);
}
/** /**
* Converts dp to pixel * Converts dp to pixel
* *

View file

@ -29,7 +29,7 @@ import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.peertube.client.APIResponse; import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI; import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.data.AccountData; import app.fedilab.android.peertube.client.data.AccountData;
import app.fedilab.android.peertube.helper.Helper; import app.fedilab.android.peertube.helper.HelperInstance;
public class ChannelsVM extends AndroidViewModel { public class ChannelsVM extends AndroidViewModel {
@ -57,7 +57,7 @@ public class ChannelsVM extends AndroidViewModel {
String finalElement = element; String finalElement = element;
try { try {
if (type == RetrofitPeertubeAPI.DataType.MY_CHANNELS) { if (type == RetrofitPeertubeAPI.DataType.MY_CHANNELS) {
String token = Helper.getToken(_mContext); String token = HelperInstance.getToken();
BaseAccount baseAccount = new Account(_mContext).getAccountByToken(token); BaseAccount baseAccount = new Account(_mContext).getAccountByToken(token);
AccountData.PeertubeAccount account = baseAccount.peertube_account; AccountData.PeertubeAccount account = baseAccount.peertube_account;
finalElement = account.getUsername() + "@" + account.getHost(); finalElement = account.getUsername() + "@" + account.getHost();

View file

@ -33,7 +33,7 @@ import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI; import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.data.PlaylistData.Playlist; import app.fedilab.android.peertube.client.data.PlaylistData.Playlist;
import app.fedilab.android.peertube.client.data.VideoPlaylistData; import app.fedilab.android.peertube.client.data.VideoPlaylistData;
import app.fedilab.android.peertube.helper.Helper; import app.fedilab.android.peertube.helper.HelperInstance;
public class PlaylistsVM extends AndroidViewModel { public class PlaylistsVM extends AndroidViewModel {
@ -72,7 +72,7 @@ public class PlaylistsVM extends AndroidViewModel {
Context _mContext = getApplication().getApplicationContext(); Context _mContext = getApplication().getApplicationContext();
new Thread(() -> { new Thread(() -> {
try { try {
String token = Helper.getToken(_mContext); String token = HelperInstance.getToken();
BaseAccount account = new Account(_mContext).getAccountByToken(token); BaseAccount account = new Account(_mContext).getAccountByToken(token);
int statusCode = -1; int statusCode = -1;
APIResponse apiResponse; APIResponse apiResponse;