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.text.style.UnderlineSpan;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; 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(); 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); TextView instanceView = findViewById(R.id.instance);
Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token); Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token);
if (account == null) { if (account == null) {
Helper.logoutCurrentUser(AccountActivity.this, null); Helper.logoutCurrentUser(AccountActivity.this, null);
return; return;
@ -121,11 +122,12 @@ public class AccountActivity extends AppCompatActivity {
tabLayout = findViewById(R.id.account_tabLayout); tabLayout = findViewById(R.id.account_tabLayout);
mPager = findViewById(R.id.account_viewpager); mPager = findViewById(R.id.account_viewpager);
if (Helper.isLoggedIn(AccountActivity.this)) {
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_notifications))); 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_muted)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_channel))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_channel)));
mPager.setOffscreenPageLimit(3); mPager.setOffscreenPageLimit(3);
@ -190,7 +192,10 @@ public class AccountActivity extends AppCompatActivity {
PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager()); PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter); mPager.setAdapter(mPagerAdapter);
} else {
tabLayout.setVisibility(View.GONE);
mPager.setVisibility(View.GONE);
}
} }
@Override @Override

View File

@ -360,11 +360,14 @@ public class LoginActivity extends AppCompatActivity {
private void proceedLogin(Token token, String host, String software) { private void proceedLogin(Token token, String host, String software) {
runOnUiThread(() -> { runOnUiThread(() -> {
if (token != null) { if (token != null) {
boolean remote_account = software != null && software.toUpperCase().trim().compareTo("PEERTUBE") != 0;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token.getAccess_token()); 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_SOFTWARE, remote_account ? software : null);
if (!remote_account) {
editor.putString(Helper.PREF_INSTANCE, host); editor.putString(Helper.PREF_INSTANCE, host);
}
editor.commit(); editor.commit();
//Update the account with the token; //Update the account with the token;
updateCredential(LoginActivity.this, token.getAccess_token(), client_id, client_secret, token.getRefresh_token(), host, software); 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.NORMAL;
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.SURFING; import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.SURFING;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedInType;
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation; import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
@ -320,6 +321,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
int tryFind = 0; int tryFind = 0;
while (ChromeCasts.get().isEmpty() && tryFind < 5) { while (ChromeCasts.get().isEmpty() && tryFind < 5) {
try { try {
//noinspection BusyWait
Thread.sleep(1000); Thread.sleep(1000);
tryFind++; tryFind++;
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
@ -710,6 +712,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
mostLikedItem.setVisible(false); mostLikedItem.setVisible(false);
incognitoItem.setVisible(false); incognitoItem.setVisible(false);
break; break;
case REMOTE_ACCOUNT:
case NORMAL: case NORMAL:
accountItem.setVisible(true); accountItem.setVisible(true);
if (Helper.isLoggedIn(MainActivity.this)) { if (Helper.isLoggedIn(MainActivity.this)) {
@ -763,7 +766,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
new Thread(() -> { new Thread(() -> {
try { try {
typeOfConnection = NORMAL; 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(); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<Account> accounts = new AccountDAO(MainActivity.this, db).getAllAccount(); List<Account> accounts = new AccountDAO(MainActivity.this, db).getAllAccount();
if (accounts != null && accounts.size() > 0) { if (accounts != null && accounts.size() > 0) {

View File

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

View File

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

View File

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

View File

@ -165,7 +165,8 @@ public class RetrofitPeertubeAPI {
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_KEY_NAME, account.getUsername()); 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.putString(Helper.PREF_INSTANCE, host);
} }
editor.apply(); editor.apply();

View File

@ -507,7 +507,7 @@ public class Helper {
* @param context Context * @param context Context
* @return MainActivity.TypeOfConnection * @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); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null); String prefKeyOauthTokenT = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
String prefSoftware = sharedpreferences.getString(PREF_SOFTWARE, null); String prefSoftware = sharedpreferences.getString(PREF_SOFTWARE, null);

View File

@ -53,10 +53,13 @@ public class SwitchAccountHelper {
builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> { builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> {
final AccountData.Account account = accountArray[which]; final AccountData.Account account = accountArray[which];
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); 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(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken()); 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_SOFTWARE, remote_account ? account.getSoftware() : null);
if (!remote_account) {
editor.putString(Helper.PREF_INSTANCE, account.getHost()); editor.putString(Helper.PREF_INSTANCE, account.getHost());
}
editor.putString(Helper.PREF_KEY_ID, account.getId()); editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.putString(Helper.PREF_KEY_NAME, account.getUsername()); editor.putString(Helper.PREF_KEY_NAME, account.getUsername());
editor.apply(); editor.apply();