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

View File

@ -41,7 +41,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
@ -54,6 +53,7 @@ import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.TooltipCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
@ -61,7 +61,6 @@ import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.kobakei.ratethisapp.RateThisApp;
@ -118,27 +117,6 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
private DisplayOverviewFragment overviewFragment;
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) {
@ -178,7 +156,6 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) {
String defaultInstance = sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null);
Log.v(app.fedilab.android.mastodon.helper.Helper.TAG, "defaultInstance-->: " + defaultInstance);
if (defaultInstance == null) {
getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, PeertubeMainActivity.this, (requestKey, result) -> {
new Thread(() -> {
@ -192,8 +169,8 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
addFragment(
getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(),
null, null, FragmentLoginPickInstancePeertube.class.getName());
return;
}
return;
}
Toolbar toolbar = findViewById(R.id.toolbar);
@ -202,8 +179,48 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
badgeCount = 0;
headerMenuOpen = false;
binding.navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
startInForeground();
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();
} 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) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
@ -232,10 +249,10 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.MOST_LIKED);
mostLikedFragment.setArguments(bundle);
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
currentAccount = null;
if (Helper.isLoggedIn()) {
NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater());
new Thread(() -> {
try {
if (currentToken == null) {
@ -313,15 +330,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
};
mainHandler.post(myRunnable);
}).start();
} else {
binding.navView.inflateMenu(R.menu.bottom_nav_menu_peertube);
}
headerMainBinding.instanceInfo.setVisibility(View.GONE);
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager()));
if (Helper.isLoggedIn()) {
headerMainBinding.instanceInfo.setVisibility(View.GONE);
binding.drawerNavView.addHeaderView(headerMainBinding.getRoot());
binding.drawerNavView.setNavigationItemSelectedListener(item -> {
if (item.getItemId() == R.id.action_settings) {
@ -377,11 +386,12 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
binding.drawerLayout.close();
return false;
});
headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager()));
fetchRecentAccounts(PeertubeMainActivity.this, headerMainBinding);
} 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();
if (!Helper.isLoggedIn()) {
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
@ -451,26 +461,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
if (search_cast) {
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());
fetchRecentAccounts(PeertubeMainActivity.this, headerMainBinding);
}
public DisplayVideosFragment getSubscriptionFragment() {
@ -498,7 +489,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
private void refreshToken() {
new Thread(() -> {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this);
String tokenStr = Helper.getToken(PeertubeMainActivity.this);
String tokenStr = HelperInstance.getToken();
String instance = HelperInstance.getLiveInstance(PeertubeMainActivity.this);
String instanceShar = sharedpreferences.getString(PREF_USER_INSTANCE, 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();
}
try {
String token = Helper.getToken(PeertubeUploadActivity.this);
String token = HelperInstance.getToken();
new MultipartUploadRequest(PeertubeUploadActivity.this, "https://" + HelperInstance.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.setMethod("POST")
.setBearerAuth(token)

View File

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

View File

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

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.RetrofitPeertubeAPI;
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 {
@ -57,7 +57,7 @@ public class ChannelsVM extends AndroidViewModel {
String finalElement = element;
try {
if (type == RetrofitPeertubeAPI.DataType.MY_CHANNELS) {
String token = Helper.getToken(_mContext);
String token = HelperInstance.getToken();
BaseAccount baseAccount = new Account(_mContext).getAccountByToken(token);
AccountData.PeertubeAccount account = baseAccount.peertube_account;
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.data.PlaylistData.Playlist;
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 {
@ -72,7 +72,7 @@ public class PlaylistsVM extends AndroidViewModel {
Context _mContext = getApplication().getApplicationContext();
new Thread(() -> {
try {
String token = Helper.getToken(_mContext);
String token = HelperInstance.getToken();
BaseAccount account = new Account(_mContext).getAccountByToken(token);
int statusCode = -1;
APIResponse apiResponse;