Some changes

This commit is contained in:
Thomas 2021-01-02 11:21:30 +01:00
parent b932ed2c13
commit d83929f80a
10 changed files with 114 additions and 76 deletions

17
.github/stale.yml vendored Normal file
View File

@ -0,0 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: inactive
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

View File

@ -24,6 +24,7 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
@ -76,11 +77,11 @@ public class AccountActivity extends AppCompatActivity {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String token = Helper.getToken(AccountActivity.this);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
TextView instanceView = findViewById(R.id.instance);
Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token);
if (account == null) {
Helper.logoutCurrentUser(AccountActivity.this, null);
return;
@ -121,76 +122,80 @@ public class AccountActivity extends AppCompatActivity {
tabLayout = findViewById(R.id.account_tabLayout);
mPager = findViewById(R.id.account_viewpager);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_notifications)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_muted)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_channel)));
if (Helper.isLoggedIn(AccountActivity.this)) {
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_notifications)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_muted)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_channel)));
mPager.setOffscreenPageLimit(3);
mPager.setOffscreenPageLimit(3);
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if (tab != null)
tab.select();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null;
if (mPager.getAdapter() != null)
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
switch (tab.getPosition()) {
case 0:
if (fragment != null) {
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
displayNotificationsFragment.scrollToTop();
}
break;
case 1:
if (fragment != null) {
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
displayAccountsFragment.scrollToTop();
}
break;
case 2:
if (fragment != null) {
DisplayChannelsFragment displayChannelsFragment = ((DisplayChannelsFragment) fragment);
displayChannelsFragment.scrollToTop();
}
break;
}
}
});
PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
if (tab != null)
tab.select();
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = null;
if (mPager.getAdapter() != null)
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
switch (tab.getPosition()) {
case 0:
if (fragment != null) {
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
displayNotificationsFragment.scrollToTop();
}
break;
case 1:
if (fragment != null) {
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
displayAccountsFragment.scrollToTop();
}
break;
case 2:
if (fragment != null) {
DisplayChannelsFragment displayChannelsFragment = ((DisplayChannelsFragment) fragment);
displayChannelsFragment.scrollToTop();
}
break;
}
}
});
PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
} else {
tabLayout.setVisibility(View.GONE);
mPager.setVisibility(View.GONE);
}
}
@Override

View File

@ -360,11 +360,14 @@ public class LoginActivity extends AppCompatActivity {
private void proceedLogin(Token token, String host, String software) {
runOnUiThread(() -> {
if (token != null) {
boolean remote_account = software != null && software.toUpperCase().trim().compareTo("PEERTUBE") != 0;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token());
editor.putString(Helper.PREF_SOFTWARE, software != null && software.toUpperCase().trim().compareTo("PEERTUBE") != 0 ? software : null);
editor.putString(Helper.PREF_INSTANCE, host);
editor.putString(Helper.PREF_SOFTWARE, remote_account ? software : null);
if (!remote_account) {
editor.putString(Helper.PREF_INSTANCE, host);
}
editor.commit();
//Update the account with the token;
updateCredential(LoginActivity.this, token.getAccess_token(), client_id, client_secret, token.getRefresh_token(), host, software);

View File

@ -100,6 +100,7 @@ import su.litvak.chromecast.api.v2.MediaStatus;
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.NORMAL;
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.SURFING;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedInType;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
@ -320,6 +321,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
int tryFind = 0;
while (ChromeCasts.get().isEmpty() && tryFind < 5) {
try {
//noinspection BusyWait
Thread.sleep(1000);
tryFind++;
} catch (InterruptedException ignored) {
@ -710,6 +712,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
mostLikedItem.setVisible(false);
incognitoItem.setVisible(false);
break;
case REMOTE_ACCOUNT:
case NORMAL:
accountItem.setVisible(true);
if (Helper.isLoggedIn(MainActivity.this)) {
@ -763,7 +766,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
new Thread(() -> {
try {
typeOfConnection = NORMAL;
if (!Helper.isLoggedIn(MainActivity.this)) {
if (!Helper.canMakeAction(MainActivity.this)) {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<Account> accounts = new AccountDAO(MainActivity.this, db).getAllAccount();
if (accounts != null && accounts.size() > 0) {

View File

@ -89,7 +89,9 @@ public class MastodonWebviewConnectActivity extends AppCompatActivity {
}
if (instance == null)
finish();
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.login);
webView = findViewById(R.id.webviewConnect);
clearCookies(MastodonWebviewConnectActivity.this);
webView.getSettings().setJavaScriptEnabled(true);

View File

@ -91,7 +91,9 @@ public class WebviewConnectActivity extends AppCompatActivity {
} else {
CookieManager.getInstance().setAcceptCookie(true);
}
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(R.string.login);
final ProgressBar pbar = findViewById(R.id.progress_bar);
webView.setWebChromeClient(new WebChromeClient() {

View File

@ -69,7 +69,9 @@ public class RetrofitMastodonAPI {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_KEY_NAME, account.getUsername());
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
if (token != null) {
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
}
editor.putString(Helper.PREF_SOFTWARE, software);
editor.apply();
if (userExists) {

View File

@ -165,7 +165,8 @@ public class RetrofitPeertubeAPI {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_KEY_NAME, account.getUsername());
if (!host.startsWith("tube")) {
boolean remote_account = software != null && software.toUpperCase().trim().compareTo("PEERTUBE") != 0;
if (!remote_account) {
editor.putString(Helper.PREF_INSTANCE, host);
}
editor.apply();

View File

@ -507,7 +507,7 @@ public class Helper {
* @param context Context
* @return MainActivity.TypeOfConnection
*/
private static MainActivity.TypeOfConnection isLoggedInType(Context context) {
public static MainActivity.TypeOfConnection isLoggedInType(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
String prefSoftware = sharedpreferences.getString(PREF_SOFTWARE, null);

View File

@ -53,10 +53,13 @@ public class SwitchAccountHelper {
builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> {
final AccountData.Account account = accountArray[which];
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean remote_account = account.getSoftware() != null && account.getSoftware().toUpperCase().trim().compareTo("PEERTUBE") != 0;
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
editor.putString(Helper.PREF_SOFTWARE, account.getSoftware() != null && account.getSoftware().trim().toUpperCase().compareTo("PEERTUBE") != 0 ? account.getSoftware() : null);
editor.putString(Helper.PREF_INSTANCE, account.getHost());
editor.putString(Helper.PREF_SOFTWARE, remote_account ? account.getSoftware() : null);
if (!remote_account) {
editor.putString(Helper.PREF_INSTANCE, account.getHost());
}
editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_KEY_NAME, account.getUsername());
editor.apply();